Moved gles pipelines to untracked handles. (flutter/engine#56955)

issue: https://github.com/flutter/flutter/issues/159745

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
gaaclarke 2024-12-05 11:21:18 -08:00 committed by GitHub
parent 5cb8e71fd5
commit 4931dd81fb
6 changed files with 57 additions and 1 deletions

View File

@ -184,6 +184,7 @@
../../../flutter/impeller/playground
../../../flutter/impeller/renderer/backend/gles/buffer_bindings_gles_unittests.cc
../../../flutter/impeller/renderer/backend/gles/test
../../../flutter/impeller/renderer/backend/gles/unique_handle_gles_unittests.cc
../../../flutter/impeller/renderer/backend/metal/allocator_mtl_unittests.mm
../../../flutter/impeller/renderer/backend/metal/texture_mtl_unittests.mm
../../../flutter/impeller/renderer/backend/vulkan/allocator_vk_unittests.cc

View File

@ -27,6 +27,7 @@ impeller_component("gles_unittests") {
"test/specialization_constants_unittests.cc",
"test/surface_gles_unittests.cc",
"test/texture_gles_unittests.cc",
"unique_handle_gles_unittests.cc",
]
deps = [
":gles",

View File

@ -212,7 +212,8 @@ std::shared_ptr<PipelineGLES> PipelineLibraryGLES::CreatePipeline(
desc, //
has_cached_program
? std::move(cached_program)
: std::make_shared<UniqueHandleGLES>(reactor, HandleType::kProgram)));
: std::make_shared<UniqueHandleGLES>(UniqueHandleGLES::MakeUntracked(
reactor, HandleType::kProgram))));
auto program = reactor->GetGLHandle(pipeline->GetProgramHandle());

View File

@ -15,6 +15,14 @@ UniqueHandleGLES::UniqueHandleGLES(ReactorGLES::Ref reactor, HandleType type)
}
}
// static
UniqueHandleGLES UniqueHandleGLES::MakeUntracked(ReactorGLES::Ref reactor,
HandleType type) {
FML_DCHECK(reactor);
HandleGLES handle = reactor->CreateUntrackedHandle(type);
return UniqueHandleGLES(std::move(reactor), handle);
}
UniqueHandleGLES::UniqueHandleGLES(ReactorGLES::Ref reactor, HandleGLES handle)
: reactor_(std::move(reactor)), handle_(handle) {}

View File

@ -19,6 +19,9 @@ class UniqueHandleGLES {
public:
UniqueHandleGLES(ReactorGLES::Ref reactor, HandleType type);
static UniqueHandleGLES MakeUntracked(ReactorGLES::Ref reactor,
HandleType type);
UniqueHandleGLES(ReactorGLES::Ref reactor, HandleGLES handle);
~UniqueHandleGLES();

View File

@ -0,0 +1,42 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/testing/testing.h" // IWYU pragma: keep
#include "gtest/gtest.h"
#include "impeller/renderer/backend/gles/reactor_gles.h"
#include "impeller/renderer/backend/gles/test/mock_gles.h"
#include "impeller/renderer/backend/gles/unique_handle_gles.h"
namespace impeller {
namespace testing {
namespace {
class TestWorker : public ReactorGLES::Worker {
public:
bool CanReactorReactOnCurrentThreadNow(
const ReactorGLES& reactor) const override {
return true;
}
};
} // namespace
TEST(UniqueHandleGLES, MakeUntracked) {
auto mock_gles = MockGLES::Init();
ProcTableGLES::Resolver resolver = kMockResolverGLES;
auto proc_table = std::make_unique<ProcTableGLES>(resolver);
auto worker = std::make_shared<TestWorker>();
auto reactor = std::make_shared<ReactorGLES>(std::move(proc_table));
reactor->AddWorker(worker);
mock_gles->GetCapturedCalls();
UniqueHandleGLES handle =
UniqueHandleGLES::MakeUntracked(reactor, HandleType::kTexture);
EXPECT_FALSE(handle.Get().IsDead());
std::vector<std::string> calls = mock_gles->GetCapturedCalls();
EXPECT_TRUE(std::find(calls.begin(), calls.end(), "glGenTextures") !=
calls.end());
}
} // namespace testing
} // namespace impeller