Skip to content

Commit f7fdf1a

Browse files
committed
[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>
1 parent 5284e96 commit f7fdf1a

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

modules/canvaskit/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Added
1010
- `getImageInfo()` and `getColorSpace()` to the `Image` type.
11+
- `CanvasKit.deleteContext` for deleting WebGL contexts when done with them, resizing, etc.
1112

1213
### Breaking
1314
- `Path.addPoly()` no longer accepts a 2d array of points, but a flattened 1d array.

modules/canvaskit/canvaskit/types/canvaskit-wasm-tests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ function fontMgrTests(CK: CanvasKit) {
344344
function globalTests(CK: CanvasKit) {
345345
const ctx = CK.currentContext();
346346
CK.setCurrentContext(ctx);
347+
CK.deleteContext(ctx);
347348
const n = CK.getDecodeCacheLimitBytes();
348349
const u = CK.getDecodeCacheUsedBytes();
349350
CK.setDecodeCacheLimitBytes(1000);

modules/canvaskit/canvaskit/types/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ export interface CanvasKit {
263263
*/
264264
setCurrentContext(ctx: WebGLContextHandle): void;
265265

266+
/**
267+
* Deletes the associated WebGLContext. Function not available on the CPU version.
268+
* @param ctx
269+
*/
270+
deleteContext(ctx: WebGLContextHandle): void;
271+
266272
/**
267273
* Returns the max size of the global cache for bitmaps used by CanvasKit.
268274
*/

modules/canvaskit/externs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ var CanvasKit = {
6262
Free: function() {},
6363
computeTonalColors: function() {},
6464
currentContext: function() {},
65+
deleteContext: function() {},
6566
getColorComponents: function() {},
6667
getDecodeCacheLimitBytes: function() {},
6768
getDecodeCacheUsageBytes: function() {},
@@ -72,7 +73,7 @@ var CanvasKit = {
7273
setDecodeCacheLimitBytes: function() {},
7374

7475
// Defined by emscripten.
75-
createContext:function() {},
76+
createContext: function() {},
7677

7778
// private API (i.e. things declared in the bindings that we use
7879
// in the pre-js file)

modules/canvaskit/gpu.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@
4848
}
4949
GL.makeContextCurrent(handle);
5050
return handle;
51-
}
51+
};
52+
53+
CanvasKit.deleteContext = function(handle) {
54+
GL.deleteContext(handle);
55+
};
5256

5357
// idOrElement can be of types:
5458
// - String - in which case it is interpreted as an id of a

0 commit comments

Comments
 (0)