Add a system message channel for controlling the Skia resource cache size (flutter/engine#7257)
See https://github.com/flutter/flutter/issues/25244
This commit is contained in:
@@ -360,6 +360,15 @@ void Rasterizer::FireNextFrameCallbackIfPresent() {
|
||||
callback();
|
||||
}
|
||||
|
||||
void Rasterizer::SetResourceCacheMaxBytes(int max_bytes) {
|
||||
GrContext* context = surface_->GetContext();
|
||||
if (context) {
|
||||
int max_resources;
|
||||
context->getResourceCacheLimits(&max_resources, nullptr);
|
||||
context->setResourceCacheLimits(max_resources, max_bytes);
|
||||
}
|
||||
}
|
||||
|
||||
Rasterizer::Screenshot::Screenshot() {}
|
||||
|
||||
Rasterizer::Screenshot::Screenshot(sk_sp<SkData> p_data, SkISize p_size)
|
||||
|
||||
@@ -73,6 +73,8 @@ class Rasterizer final : public blink::SnapshotDelegate {
|
||||
return compositor_context_.get();
|
||||
}
|
||||
|
||||
void SetResourceCacheMaxBytes(int max_bytes);
|
||||
|
||||
private:
|
||||
blink::TaskRunners task_runners_;
|
||||
std::unique_ptr<Surface> surface_;
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
|
||||
namespace shell {
|
||||
|
||||
constexpr char kSkiaChannel[] = "flutter/skia";
|
||||
|
||||
std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
|
||||
blink::TaskRunners task_runners,
|
||||
blink::Settings settings,
|
||||
@@ -727,6 +729,11 @@ void Shell::OnEngineHandlePlatformMessage(
|
||||
FML_DCHECK(is_setup_);
|
||||
FML_DCHECK(task_runners_.GetUITaskRunner()->RunsTasksOnCurrentThread());
|
||||
|
||||
if (message->channel() == kSkiaChannel) {
|
||||
HandleEngineSkiaMessage(std::move(message));
|
||||
return;
|
||||
}
|
||||
|
||||
task_runners_.GetPlatformTaskRunner()->PostTask(
|
||||
[view = platform_view_->GetWeakPtr(), message = std::move(message)]() {
|
||||
if (view) {
|
||||
@@ -735,6 +742,31 @@ void Shell::OnEngineHandlePlatformMessage(
|
||||
});
|
||||
}
|
||||
|
||||
void Shell::HandleEngineSkiaMessage(
|
||||
fml::RefPtr<blink::PlatformMessage> message) {
|
||||
const auto& data = message->data();
|
||||
|
||||
rapidjson::Document document;
|
||||
document.Parse(reinterpret_cast<const char*>(data.data()), data.size());
|
||||
if (document.HasParseError() || !document.IsObject())
|
||||
return;
|
||||
auto root = document.GetObject();
|
||||
auto method = root.FindMember("method");
|
||||
if (method->value != "Skia.setResourceCacheMaxBytes")
|
||||
return;
|
||||
auto args = root.FindMember("args");
|
||||
if (args == root.MemberEnd() || !args->value.IsInt())
|
||||
return;
|
||||
|
||||
task_runners_.GetGPUTaskRunner()->PostTask(
|
||||
[rasterizer = rasterizer_->GetWeakPtr(),
|
||||
max_bytes = args->value.GetInt()] {
|
||||
if (rasterizer) {
|
||||
rasterizer->SetResourceCacheMaxBytes(max_bytes);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// |shell::Engine::Delegate|
|
||||
void Shell::OnPreEngineRestart() {
|
||||
FML_DCHECK(is_setup_);
|
||||
|
||||
@@ -179,6 +179,8 @@ class Shell final : public PlatformView::Delegate,
|
||||
void OnEngineHandlePlatformMessage(
|
||||
fml::RefPtr<blink::PlatformMessage> message) override;
|
||||
|
||||
void HandleEngineSkiaMessage(fml::RefPtr<blink::PlatformMessage> message);
|
||||
|
||||
// |shell::Engine::Delegate|
|
||||
void OnPreEngineRestart() override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user