forked from firka/flutter
Rasterizer: Add missing context switches (flutter/engine#26847)
Fixes https://github.com/flutter/flutter/issues/84930
This commit is contained in:
@@ -75,11 +75,17 @@ fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> Rasterizer::GetSnapshotDelegate()
|
||||
|
||||
void Rasterizer::Setup(std::unique_ptr<Surface> surface) {
|
||||
surface_ = std::move(surface);
|
||||
|
||||
if (max_cache_bytes_.has_value()) {
|
||||
SetResourceCacheMaxBytes(max_cache_bytes_.value(),
|
||||
user_override_resource_cache_bytes_);
|
||||
}
|
||||
compositor_context_->OnGrContextCreated();
|
||||
|
||||
auto context_switch = surface_->MakeRenderContextCurrent();
|
||||
if (context_switch->GetResult()) {
|
||||
compositor_context_->OnGrContextCreated();
|
||||
}
|
||||
|
||||
if (external_view_embedder_ &&
|
||||
external_view_embedder_->SupportsDynamicThreadMerging() &&
|
||||
!raster_thread_merger_) {
|
||||
@@ -101,7 +107,12 @@ void Rasterizer::Setup(std::unique_ptr<Surface> surface) {
|
||||
}
|
||||
|
||||
void Rasterizer::Teardown() {
|
||||
compositor_context_->OnGrContextDestroyed();
|
||||
auto context_switch =
|
||||
surface_ ? surface_->MakeRenderContextCurrent() : nullptr;
|
||||
if (context_switch && context_switch->GetResult()) {
|
||||
compositor_context_->OnGrContextDestroyed();
|
||||
}
|
||||
|
||||
surface_.reset();
|
||||
last_layer_tree_.reset();
|
||||
|
||||
@@ -137,6 +148,10 @@ void Rasterizer::NotifyLowMemoryWarning() const {
|
||||
<< "Rasterizer::NotifyLowMemoryWarning called with no GrContext.";
|
||||
return;
|
||||
}
|
||||
auto context_switch = surface_->MakeRenderContextCurrent();
|
||||
if (!context_switch->GetResult()) {
|
||||
return;
|
||||
}
|
||||
context->performDeferredCleanup(std::chrono::milliseconds(0));
|
||||
}
|
||||
|
||||
@@ -721,6 +736,11 @@ void Rasterizer::SetResourceCacheMaxBytes(size_t max_bytes, bool from_user) {
|
||||
|
||||
GrDirectContext* context = surface_->GetContext();
|
||||
if (context) {
|
||||
auto context_switch = surface_->MakeRenderContextCurrent();
|
||||
if (!context_switch->GetResult()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int max_resources;
|
||||
context->getResourceCacheLimits(&max_resources, nullptr);
|
||||
context->setResourceCacheLimits(max_resources, max_bytes);
|
||||
|
||||
@@ -102,6 +102,8 @@ TEST(RasterizerTest, drawEmptyPipeline) {
|
||||
ON_CALL(delegate, GetTaskRunners()).WillByDefault(ReturnRef(task_runners));
|
||||
auto rasterizer = std::make_unique<Rasterizer>(delegate);
|
||||
auto surface = std::make_unique<MockSurface>();
|
||||
EXPECT_CALL(*surface, MakeRenderContextCurrent())
|
||||
.WillOnce(Return(ByMove(std::make_unique<GLContextDefaultResult>(true))));
|
||||
rasterizer->Setup(std::move(surface));
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
thread_host.raster_thread->GetTaskRunner()->PostTask([&] {
|
||||
@@ -139,6 +141,8 @@ TEST(RasterizerTest,
|
||||
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; });
|
||||
EXPECT_CALL(*surface, AcquireFrame(SkISize()))
|
||||
.WillOnce(Return(ByMove(std::move(surface_frame))));
|
||||
EXPECT_CALL(*surface, MakeRenderContextCurrent())
|
||||
.WillOnce(Return(ByMove(std::make_unique<GLContextDefaultResult>(true))));
|
||||
|
||||
EXPECT_CALL(*external_view_embedder,
|
||||
BeginFrame(/*frame_size=*/SkISize(), /*context=*/nullptr,
|
||||
@@ -197,6 +201,8 @@ TEST(
|
||||
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; });
|
||||
EXPECT_CALL(*surface, AcquireFrame(SkISize()))
|
||||
.WillOnce(Return(ByMove(std::move(surface_frame))));
|
||||
EXPECT_CALL(*surface, MakeRenderContextCurrent())
|
||||
.WillOnce(Return(ByMove(std::make_unique<GLContextDefaultResult>(true))));
|
||||
|
||||
EXPECT_CALL(*external_view_embedder,
|
||||
BeginFrame(/*frame_size=*/SkISize(), /*context=*/nullptr,
|
||||
@@ -255,6 +261,8 @@ TEST(
|
||||
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; });
|
||||
EXPECT_CALL(*surface, AcquireFrame(SkISize()))
|
||||
.WillOnce(Return(ByMove(std::move(surface_frame))));
|
||||
EXPECT_CALL(*surface, MakeRenderContextCurrent())
|
||||
.WillOnce(Return(ByMove(std::make_unique<GLContextDefaultResult>(true))));
|
||||
EXPECT_CALL(*external_view_embedder, SupportsDynamicThreadMerging)
|
||||
.WillRepeatedly(Return(true));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user