Expose gpu cache knobs

Change-Id: I5911593812ebf6fd235c6a3fc2acfa740c7687aa
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/203164
Reviewed-by: Florin Malita <fmalita@chromium.org>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Kevin Lubick 2019-03-22 15:41:36 -04:00
parent 554bec1fff
commit cd54466473
5 changed files with 38 additions and 2 deletions

View File

@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- `SkSurface.grContext` now exposed. `GrContext` has new methods for monitoring/setting
the cache limits; tweaking these may lead to better performance in some cases.
`getResourceCacheLimitBytes`, `setResourceCacheLimitBytes`, `getResourceCacheUsageBytes`
## [0.5.1] - 2019-03-21
### Added

View File

@ -1145,6 +1145,7 @@
console.error('Could not make surface');
return;
}
const grContext = surface.grContext;
// create a subsurface as a temporary workspace.
const subSurface = surface.makeSurface({
@ -1198,6 +1199,9 @@
canvas.drawOval(CanvasKit.LTRBRect(i % 60, i % 60, 300 - (i% 60), 300 - (i % 60)), patternPaint);
surface.requestAnimationFrame(drawFrame);
if (grContext) {
console.log(grContext.getResourceCacheUsageBytes() + ' bytes used in the GPU');
}
}
surface.requestAnimationFrame(drawFrame);

View File

@ -740,7 +740,25 @@ EMSCRIPTEN_BINDINGS(Skia) {
#if SK_SUPPORT_GPU
class_<GrContext>("GrContext")
.smart_ptr<sk_sp<GrContext>>("sk_sp<GrContext>");
.smart_ptr<sk_sp<GrContext>>("sk_sp<GrContext>")
.function("getResourceCacheLimitBytes", optional_override([](GrContext& self)->size_t {
int maxResources = 0;// ignored
size_t currMax = 0;
self.getResourceCacheLimits(&maxResources, &currMax);
return currMax;
}))
.function("getResourceCacheUsageBytes", optional_override([](GrContext& self)->size_t {
int usedResources = 0;// ignored
size_t currUsage = 0;
self.getResourceCacheUsage(&usedResources, &currUsage);
return currUsage;
}))
.function("setResourceCacheLimitBytes", optional_override([](GrContext& self, size_t maxResourceBytes)->void {
int maxResources = 0;
size_t currMax = 0; // ignored
self.getResourceCacheLimits(&maxResources, &currMax);
self.setResourceCacheLimits(maxResources, maxResourceBytes);
}));
#endif
class_<SkCanvas>("SkCanvas")

View File

@ -84,6 +84,13 @@ var CanvasKit = {
// Objects and properties on CanvasKit
GrContext: {
// public API (from C++ bindings)
getResourceCacheLimitBytes: function() {},
getResourceCacheUsageBytes: function() {},
setResourceCacheLimitBytes: function() {},
},
RSXFormBuilder: function() {},
ShapedText: {
@ -266,6 +273,7 @@ var CanvasKit = {
/** @return {CanvasKit.SkImage} */
makeImageSnapshot: function() {},
makeSurface: function() {},
grContext: {},
// private API
_flush: function() {},

View File

@ -61,7 +61,7 @@
}
}
// we are ok with all the defaults
var ctx = CanvasKit.GetWebGLContext(canvas);
var ctx = this.GetWebGLContext(canvas);
if (!ctx || ctx < 0) {
throw 'failed to create webgl context: err ' + ctx;
@ -90,6 +90,7 @@
return CanvasKit.MakeSWCanvasSurface(newCanvas);
}
surface._context = ctx;
surface.grContext = grcontext;
return surface;
};
// Default to trying WebGL first.