Skip to content

Commit

Permalink
test: GlCalculatorHelper#CreateSourceTexture
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed Nov 22, 2020
1 parent 87b454d commit f49b5bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Assets/MediaPipe/SDK/Scripts/Gpu/GlCalculatorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ public GlTexture CreateSourceTexture(ImageFrame imageFrame) {
UnsafeNativeMethods.mp_GlCalculatorHelper__CreateSourceTexture__Rif(mpPtr, imageFrame.mpPtr, out var texturePtr).Assert();

GC.KeepAlive(this);
GC.KeepAlive(imageFrame);
return new GlTexture(texturePtr);
}

public GlTexture CreateSourceTexture(GpuBuffer gpuBuffer) {
UnsafeNativeMethods.mp_GlCalculatorHelper__CreateSourceTexture__Rgb(mpPtr, gpuBuffer.mpPtr, out var texturePtr).Assert();

GC.KeepAlive(this);
GC.KeepAlive(gpuBuffer);
return new GlTexture(texturePtr);
}

Expand Down
29 changes: 25 additions & 4 deletions Assets/MediaPipe/SDK/Tests/Gpu/GlCalculatorHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,37 @@ public void RunInGlContext_ShouldReturnFailedPreCondition_When_FunctionThrows()

#region #CreateSourceTexture
[Test, GpuOnly]
[Ignore("Skip because MediaPipe aborts in test environment")]
public void CreateSourceTexture_ShouldReturnGlTexture_When_CalledWithImageFrame() {
var glCalculatorHelper = new GlCalculatorHelper();
glCalculatorHelper.InitializeForTest(GpuResources.Create().ConsumeValueOrDie());

var imageFrame = new ImageFrame(ImageFormat.Format.SRGBA, 32, 24);
var status = glCalculatorHelper.RunInGlContext(() => {
var texture = glCalculatorHelper.CreateSourceTexture(imageFrame);
Assert.AreEqual(texture.width, 32);
Assert.AreEqual(texture.height, 24);
texture.Dispose();
return Status.Ok();
});

Assert.AreEqual(status.code, Status.StatusCode.Ok);
}

[Test, GpuOnly]
public void CreateSourceTexture_ShouldFail_When_ImageFrameFormatIsInvalid() {
var glCalculatorHelper = new GlCalculatorHelper();
glCalculatorHelper.InitializeForTest(GpuResources.Create().ConsumeValueOrDie());

var imageFrame = new ImageFrame(ImageFormat.Format.SBGRA, 32, 24);
var texture = glCalculatorHelper.CreateSourceTexture(imageFrame);
var status = glCalculatorHelper.RunInGlContext(() => {
var texture = glCalculatorHelper.CreateSourceTexture(imageFrame);
texture.Dispose();
return Status.Ok();
});

Assert.AreEqual(texture.width, 32);
Assert.AreEqual(texture.height, 24);
Assert.AreEqual(status.code, Status.StatusCode.FailedPrecondition);
}
#endregion
}
Expand Down

0 comments on commit f49b5bb

Please sign in to comment.