Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3547)

Unified Diff: cc/trees/layer_tree_host_unittest_copyrequest.cc

Issue 1985973002: Defer compositor context creation to the thread. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/trees/layer_tree_host_unittest_copyrequest.cc
diff --git a/cc/trees/layer_tree_host_unittest_copyrequest.cc b/cc/trees/layer_tree_host_unittest_copyrequest.cc
index b92c687529b3f31449e347ab7428e9f2c823ac00..6466b576c4f75a8b9d4abf4cd7fa2ee1febaf755 100644
--- a/cc/trees/layer_tree_host_unittest_copyrequest.cc
+++ b/cc/trees/layer_tree_host_unittest_copyrequest.cc
@@ -128,16 +128,23 @@ class LayerTreeHostCopyRequestTestMultipleRequests
return FakeOutputSurface::CreateSoftware(
base::WrapUnique(new SoftwareOutputDevice));
}
- std::unique_ptr<FakeOutputSurface> output_surface =
- FakeOutputSurface::Create3d();
- TestContextSupport* context_support = static_cast<TestContextSupport*>(
- output_surface->context_provider()->ContextSupport());
- context_support->set_out_of_order_callbacks(out_of_order_callbacks_);
- return output_surface;
+ auto create = base::MakeUnique<TestContextProvider::DeferredCreate>();
+ create->created_context = &context_provider_;
+ return FakeOutputSurface::Create3d(std::move(create));
+ }
+
+ void InitializedRendererOnThread(LayerTreeHostImpl* host_impl,
+ bool success) override {
+ ASSERT_TRUE(success);
+ if (use_gl_renderer_) {
+ context_provider_->support()->set_out_of_order_callbacks(
+ out_of_order_callbacks_);
+ }
}
bool use_gl_renderer_;
bool out_of_order_callbacks_ = false;
+ TestContextProvider* context_provider_ = nullptr;
std::map<size_t, gfx::Size> callbacks_;
FakeContentLayerClient client_;
scoped_refptr<FakePictureLayer> root;
@@ -707,13 +714,17 @@ class LayerTreeHostCopyRequestTestLostOutputSurface
protected:
std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override {
if (!first_context_provider_) {
- first_context_provider_ = TestContextProvider::Create();
- return FakeOutputSurface::Create3d(first_context_provider_);
+ std::unique_ptr<TestContextProvider::DeferredCreate> first_create(
+ new TestContextProvider::DeferredCreate);
+ first_create->created_context = &first_context_provider_;
+ return FakeOutputSurface::Create3d(std::move(first_create));
}
EXPECT_FALSE(second_context_provider_);
- second_context_provider_ = TestContextProvider::Create();
- return FakeOutputSurface::Create3d(second_context_provider_);
+ std::unique_ptr<TestContextProvider::DeferredCreate> second_create(
+ new TestContextProvider::DeferredCreate);
+ second_create->created_context = &second_context_provider_;
+ return FakeOutputSurface::Create3d(std::move(second_create));
}
void SetupTree() override {
@@ -767,13 +778,18 @@ class LayerTreeHostCopyRequestTestLostOutputSurface
// releasing the copy output request will cause the texture in the request
// to be released, so we should have 1 less by now.
EXPECT_EQ(num_textures_after_loss_ - 1,
- first_context_provider_->TestContext3d()->NumTextures());
+ saved_first_context_provider_->TestContext3d()->NumTextures());
+ // Drop the saved reference on the compositor thread.
+ saved_first_context_provider_ = nullptr;
EndTest();
}
void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override {
switch (impl->active_tree()->source_frame_number()) {
case 0:
+ EXPECT_TRUE(first_context_provider_);
+ EXPECT_FALSE(second_context_provider_);
+
// The layers have been drawn, so their textures have been allocated.
EXPECT_FALSE(result_);
num_textures_without_readback_ =
@@ -787,6 +803,9 @@ class LayerTreeHostCopyRequestTestLostOutputSurface
base::Unretained(this)));
break;
case 1:
+ EXPECT_TRUE(first_context_provider_);
+ EXPECT_FALSE(second_context_provider_);
+
// We did a readback, so there will be a readback texture around now.
EXPECT_LT(num_textures_without_readback_,
first_context_provider_->TestContext3d()->NumTextures());
@@ -796,9 +815,15 @@ class LayerTreeHostCopyRequestTestLostOutputSurface
// the test to advance to the next case.
break;
case 2:
+ EXPECT_TRUE(first_context_provider_);
+ EXPECT_FALSE(second_context_provider_);
+
// The readback texture is collected.
EXPECT_TRUE(result_);
+ saved_first_context_provider_ =
+ make_scoped_refptr(first_context_provider_);
+
// Lose the output surface.
first_context_provider_->TestContext3d()->loseContextCHROMIUM(
GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
@@ -808,7 +833,7 @@ class LayerTreeHostCopyRequestTestLostOutputSurface
EXPECT_TRUE(second_context_provider_);
num_textures_after_loss_ =
- first_context_provider_->TestContext3d()->NumTextures();
+ saved_first_context_provider_->TestContext3d()->NumTextures();
// Now destroy the CopyOutputResult, releasing the texture inside back
// to the compositor. Then check the resulting number of allocated
@@ -824,8 +849,11 @@ class LayerTreeHostCopyRequestTestLostOutputSurface
void AfterTest() override {}
- scoped_refptr<TestContextProvider> first_context_provider_;
- scoped_refptr<TestContextProvider> second_context_provider_;
+ TestContextProvider* first_context_provider_ = nullptr;
+ TestContextProvider* second_context_provider_ = nullptr;
+ // Keep the first_context_provider_ alive past this compositor instance being
+ // done with it.
+ scoped_refptr<TestContextProvider> saved_first_context_provider_;
size_t num_textures_without_readback_ = 0;
size_t num_textures_after_loss_ = 0;
FakeContentLayerClient client_;
@@ -841,8 +869,10 @@ class LayerTreeHostCopyRequestTestCountTextures
: public LayerTreeHostCopyRequestTest {
protected:
std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override {
- context_provider_ = TestContextProvider::Create();
- return FakeOutputSurface::Create3d(context_provider_);
+ std::unique_ptr<TestContextProvider::DeferredCreate> create(
+ new TestContextProvider::DeferredCreate);
+ create->created_context = &context_provider_;
+ return FakeOutputSurface::Create3d(std::move(create));
}
void SetupTree() override {
@@ -903,7 +933,7 @@ class LayerTreeHostCopyRequestTestCountTextures
virtual void DoEndTest() { EndTest(); }
- scoped_refptr<TestContextProvider> context_provider_;
+ TestContextProvider* context_provider_ = nullptr;
size_t num_textures_without_readback_;
size_t num_textures_with_readback_;
gpu::SyncToken waited_sync_token_after_readback_;
@@ -951,7 +981,6 @@ class LayerTreeHostCopyRequestTestProvideTexture
protected:
void BeginTest() override {
external_context_provider_ = TestContextProvider::Create();
- EXPECT_TRUE(external_context_provider_->BindToCurrentThread());
LayerTreeHostCopyRequestTestCountTextures::BeginTest();
}

Powered by Google App Engine
This is Rietveld 408576698