From aa63b8f8013d7fe32fb3c34f829f7ec55479fc08 Mon Sep 17 00:00:00 2001 From: ColdPaleLight <31977171+ColdPaleLight@users.noreply.github.com> Date: Tue, 15 Mar 2022 07:50:10 +0800 Subject: [PATCH] Migrate the API of GrDirectContext about resource memory limit (flutter/engine#31977) --- engine/src/flutter/shell/common/rasterizer.cc | 8 ++------ engine/src/flutter/shell/common/shell_io_manager.cc | 2 +- .../shell/common/shell_test_platform_view_vulkan.cc | 3 +-- engine/src/flutter/shell/gpu/gpu_surface_gl.cc | 5 +---- .../platform/darwin/graphics/FlutterDarwinContextMetal.mm | 2 +- .../platform/fuchsia/flutter/vulkan_surface_producer.cc | 3 +-- engine/src/flutter/vulkan/vulkan_application.h | 1 - engine/src/flutter/vulkan/vulkan_window.cc | 2 +- 8 files changed, 8 insertions(+), 18 deletions(-) diff --git a/engine/src/flutter/shell/common/rasterizer.cc b/engine/src/flutter/shell/common/rasterizer.cc index eb21f4d49d..031775e2be 100644 --- a/engine/src/flutter/shell/common/rasterizer.cc +++ b/engine/src/flutter/shell/common/rasterizer.cc @@ -824,9 +824,7 @@ void Rasterizer::SetResourceCacheMaxBytes(size_t max_bytes, bool from_user) { return; } - int max_resources; - context->getResourceCacheLimits(&max_resources, nullptr); - context->setResourceCacheLimits(max_resources, max_bytes); + context->setResourceCacheLimit(max_bytes); } } @@ -836,9 +834,7 @@ std::optional Rasterizer::GetResourceCacheMaxBytes() const { } GrDirectContext* context = surface_->GetContext(); if (context) { - size_t max_bytes; - context->getResourceCacheLimits(nullptr, &max_bytes); - return max_bytes; + return context->getResourceCacheLimit(); } return std::nullopt; } diff --git a/engine/src/flutter/shell/common/shell_io_manager.cc b/engine/src/flutter/shell/common/shell_io_manager.cc index c8b6269001..115b5efaf7 100644 --- a/engine/src/flutter/shell/common/shell_io_manager.cc +++ b/engine/src/flutter/shell/common/shell_io_manager.cc @@ -23,7 +23,7 @@ sk_sp ShellIOManager::CreateCompatibleResourceLoadingContext( if (auto context = GrDirectContext::MakeGL(gl_interface, options)) { // Do not cache textures created by the image decoder. These textures // should be deleted when they are no longer referenced by an SkImage. - context->setResourceCacheLimits(0, 0); + context->setResourceCacheLimit(0); return context; } #endif diff --git a/engine/src/flutter/shell/common/shell_test_platform_view_vulkan.cc b/engine/src/flutter/shell/common/shell_test_platform_view_vulkan.cc index df1baf6fa4..853e621e75 100644 --- a/engine/src/flutter/shell/common/shell_test_platform_view_vulkan.cc +++ b/engine/src/flutter/shell/common/shell_test_platform_view_vulkan.cc @@ -125,8 +125,7 @@ bool ShellTestPlatformViewVulkan::OffScreenSurface::CreateSkiaGrContext() { return false; } - context->setResourceCacheLimits(vulkan::kGrCacheMaxCount, - vulkan::kGrCacheMaxByteSize); + context->setResourceCacheLimit(vulkan::kGrCacheMaxByteSize); context_ = context; diff --git a/engine/src/flutter/shell/gpu/gpu_surface_gl.cc b/engine/src/flutter/shell/gpu/gpu_surface_gl.cc index 218eb76e97..296a41d97a 100644 --- a/engine/src/flutter/shell/gpu/gpu_surface_gl.cc +++ b/engine/src/flutter/shell/gpu/gpu_surface_gl.cc @@ -25,9 +25,6 @@ namespace flutter { -// Default maximum number of budgeted resources in the cache. -static const int kGrCacheMaxCount = 8192; - // Default maximum number of bytes of GPU memory of budgeted resources in the // cache. // The shell will dynamically increase or decrease this cache based on the @@ -54,7 +51,7 @@ sk_sp GPUSurfaceGL::MakeGLContext( return nullptr; } - context->setResourceCacheLimits(kGrCacheMaxCount, kGrCacheMaxByteSize); + context->setResourceCacheLimit(kGrCacheMaxByteSize); PersistentCache::GetCacheForProcess()->PrecompileKnownSkSLs(context.get()); diff --git a/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetal.mm b/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetal.mm index 6e350815a3..0cd3fe9890 100644 --- a/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetal.mm +++ b/engine/src/flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetal.mm @@ -60,7 +60,7 @@ FLUTTER_ASSERT_ARC return nil; } - _resourceContext->setResourceCacheLimits(0u, 0u); + _resourceContext->setResourceCacheLimit(0u); } return self; } diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc index f1cd71146f..fe0213d68a 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc @@ -22,7 +22,6 @@ namespace flutter_runner { namespace { -constexpr int kGrCacheMaxCount = 8192; // Tuning advice: // If you see the following 3 things happening simultaneously in a trace: // * Over budget ("flutter", "GPURasterizer::Draw") durations @@ -150,7 +149,7 @@ bool VulkanSurfaceProducer::Initialize(scenic::Session* scenic_session) { } // Use local limits specified in this file above instead of flutter defaults. - context_->setResourceCacheLimits(kGrCacheMaxCount, kGrCacheMaxByteSize); + context_->setResourceCacheLimit(kGrCacheMaxByteSize); surface_pool_ = std::make_unique(*this, context_, scenic_session); diff --git a/engine/src/flutter/vulkan/vulkan_application.h b/engine/src/flutter/vulkan/vulkan_application.h index 9f2fc3cc03..3fbaf7aca9 100644 --- a/engine/src/flutter/vulkan/vulkan_application.h +++ b/engine/src/flutter/vulkan/vulkan_application.h @@ -15,7 +15,6 @@ namespace vulkan { -static const int kGrCacheMaxCount = 8192; static const size_t kGrCacheMaxByteSize = 512 * (1 << 20); class VulkanDevice; diff --git a/engine/src/flutter/vulkan/vulkan_window.cc b/engine/src/flutter/vulkan/vulkan_window.cc index cf7730c7aa..53c8adb703 100644 --- a/engine/src/flutter/vulkan/vulkan_window.cc +++ b/engine/src/flutter/vulkan/vulkan_window.cc @@ -123,7 +123,7 @@ bool VulkanWindow::CreateSkiaGrContext() { return false; } - context->setResourceCacheLimits(kGrCacheMaxCount, kGrCacheMaxByteSize); + context->setResourceCacheLimit(kGrCacheMaxByteSize); skia_gr_context_ = context;