[canvaskit] Fix MakeRenderTarget

Change-Id: I86c296ff2dad8f915e75dd71301cf43f36ce6e00
Bug: skia:12862
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/500438
Reviewed-by: Nathaniel Nifong <nifong@google.com>
This commit is contained in:
Kevin Lubick 2022-01-31 11:01:56 -05:00
parent aa2579cce0
commit 06acd1d194
3 changed files with 30 additions and 12 deletions

View File

@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Supplying textures via `Surface.makeImageFromTextureSource` should not cause issues with
Mipmaps or other places where Skia needs to create textures (skbug.com/12797)
- `CanvasKit.MakeRenderTarget` correctly takes 2 or 3 params, as per the documentation.
## [0.32.0] - 2021-12-15

View File

@ -87,18 +87,21 @@
return surface;
}
CanvasKit.MakeRenderTarget = function(grCtx, w, h) {
var surface = this._MakeRenderTargetWH(grCtx, w, h);
if (!surface) {
return null;
}
surface._context = grCtx._context;
return surface;
}
CanvasKit.MakeRenderTarget = function(grCtx, imageInfo) {
var surface = this._MakeRenderTargetII(grCtx, imageInfo);
if (!surface) {
CanvasKit.MakeRenderTarget = function() {
var grCtx = arguments[0];
var surface;
if (arguments.length === 3) {
surface = this._MakeRenderTargetWH(grCtx, arguments[1], arguments[2]);
if (!surface) {
return null;
}
} else if (arguments.length === 2) {
surface = this._MakeRenderTargetII(grCtx, arguments[1]);
if (!surface) {
return null;
}
} else {
Debug('Expected 2 or 3 params');
return null;
}
surface._context = grCtx._context;

View File

@ -1488,4 +1488,18 @@ describe('Core canvas behavior', () => {
expect(img).toBeTruthy('Could not decode result from '+ format);
img && img.delete();
}
it('can make a render target', () => {
if (!CanvasKit.gpu) {
return;
}
const canvas = document.getElementById('test');
const context = CanvasKit.GetWebGLContext(canvas);
const grContext = CanvasKit.MakeGrContext(context);
expect(grContext).toBeTruthy();
const target = CanvasKit.MakeRenderTarget(grContext, 100, 100);
expect(target).toBeTruthy();
target.delete();
grContext.delete();
})
});