Cleanup initialization of GrContext.
Update GrContext options and setup the cache sizes to be based on
the size of the display and not the current default value of 255MB.
Test: atest librenderengine_test
Bug: 183391755
Change-Id: I5be8d6fc54c31f0e2d1c44968284ad772866d6ab
diff --git a/libs/renderengine/skia/SkiaGLRenderEngine.cpp b/libs/renderengine/skia/SkiaGLRenderEngine.cpp
index c7001b9..0798562 100644
--- a/libs/renderengine/skia/SkiaGLRenderEngine.cpp
+++ b/libs/renderengine/skia/SkiaGLRenderEngine.cpp
@@ -294,12 +294,13 @@
mPlaceholderSurface(placeholder),
mProtectedEGLContext(protectedContext),
mProtectedPlaceholderSurface(protectedPlaceholder),
+ mDefaultPixelFormat(static_cast<PixelFormat>(args.pixelFormat)),
mUseColorManagement(args.useColorManagement) {
sk_sp<const GrGLInterface> glInterface(GrGLCreateNativeInterface());
LOG_ALWAYS_FATAL_IF(!glInterface.get());
GrContextOptions options;
- options.fPreferExternalImagesOverES3 = true;
+ options.fDisableDriverCorrectnessWorkarounds = true;
options.fDisableDistanceFieldPaths = true;
options.fPersistentCache = &mSkSLCacheMonitor;
mGrContext = GrDirectContext::MakeGL(glInterface, options);
@@ -1186,6 +1187,27 @@
return value;
}
+void SkiaGLRenderEngine::onPrimaryDisplaySizeChanged(ui::Size size) {
+ // This cache multiplier was selected based on review of cache sizes relative
+ // to the screen resolution. Looking at the worst case memory needed by blur (~1.5x),
+ // shadows (~1x), and general data structures (e.g. vertex buffers) we selected this as a
+ // conservative default based on that analysis.
+ const float SURFACE_SIZE_MULTIPLIER = 3.5f * bytesPerPixel(mDefaultPixelFormat);
+ const int maxResourceBytes = size.width * size.height * SURFACE_SIZE_MULTIPLIER;
+
+ // start by resizing the current context
+ auto grContext = mInProtectedContext ? mProtectedGrContext : mGrContext;
+ grContext->setResourceCacheLimit(maxResourceBytes);
+
+ // if it is possible to switch contexts then we will resize the other context
+ if (useProtectedContext(!mInProtectedContext)) {
+ grContext = mInProtectedContext ? mProtectedGrContext : mGrContext;
+ grContext->setResourceCacheLimit(maxResourceBytes);
+ // reset back to the initial context that was active when this method was called
+ useProtectedContext(!mInProtectedContext);
+ }
+}
+
void SkiaGLRenderEngine::dump(std::string& result) {
const gl::GLExtensions& extensions = gl::GLExtensions::getInstance();