[canvaskit] Add API for deleting webgl ctx

Change-Id: I55e70cc1ae6b16d642dd63170e9402bd3c192d5f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/343101
Reviewed-by: Nathaniel Nifong <nifong@google.com>
This commit is contained in:
Kevin Lubick 2020-12-10 15:21:01 -05:00
parent 5284e96599
commit f7fdf1aa29
5 changed files with 15 additions and 2 deletions

View File

@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- `getImageInfo()` and `getColorSpace()` to the `Image` type.
- `CanvasKit.deleteContext` for deleting WebGL contexts when done with them, resizing, etc.
### Breaking
- `Path.addPoly()` no longer accepts a 2d array of points, but a flattened 1d array.

View File

@ -344,6 +344,7 @@ function fontMgrTests(CK: CanvasKit) {
function globalTests(CK: CanvasKit) {
const ctx = CK.currentContext();
CK.setCurrentContext(ctx);
CK.deleteContext(ctx);
const n = CK.getDecodeCacheLimitBytes();
const u = CK.getDecodeCacheUsedBytes();
CK.setDecodeCacheLimitBytes(1000);

View File

@ -263,6 +263,12 @@ export interface CanvasKit {
*/
setCurrentContext(ctx: WebGLContextHandle): void;
/**
* Deletes the associated WebGLContext. Function not available on the CPU version.
* @param ctx
*/
deleteContext(ctx: WebGLContextHandle): void;
/**
* Returns the max size of the global cache for bitmaps used by CanvasKit.
*/

View File

@ -62,6 +62,7 @@ var CanvasKit = {
Free: function() {},
computeTonalColors: function() {},
currentContext: function() {},
deleteContext: function() {},
getColorComponents: function() {},
getDecodeCacheLimitBytes: function() {},
getDecodeCacheUsageBytes: function() {},
@ -72,7 +73,7 @@ var CanvasKit = {
setDecodeCacheLimitBytes: function() {},
// Defined by emscripten.
createContext:function() {},
createContext: function() {},
// private API (i.e. things declared in the bindings that we use
// in the pre-js file)

View File

@ -48,7 +48,11 @@
}
GL.makeContextCurrent(handle);
return handle;
}
};
CanvasKit.deleteContext = function(handle) {
GL.deleteContext(handle);
};
// idOrElement can be of types:
// - String - in which case it is interpreted as an id of a