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

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: contextfactory: . 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..d229c36dd7ae27ca4e3162c193ad74b8adb86b34 100644
--- a/cc/trees/layer_tree_host_unittest_copyrequest.cc
+++ b/cc/trees/layer_tree_host_unittest_copyrequest.cc
@@ -128,12 +128,19 @@ 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;
+ return FakeOutputSurface::Create3d(
+ base::MakeUnique<TestContextProvider::Factory>());
+ }
+
+ void InitializedRendererOnThread(LayerTreeHostImpl* impl,
+ bool success) override {
+ ASSERT_TRUE(success);
+ if (use_gl_renderer_) {
+ auto* context_provider = static_cast<TestContextProvider*>(
+ impl->output_surface()->context_provider());
+ context_provider->support()->set_out_of_order_callbacks(
+ out_of_order_callbacks_);
+ }
}
bool use_gl_renderer_;
@@ -707,13 +714,24 @@ class LayerTreeHostCopyRequestTestLostOutputSurface
protected:
std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override {
if (!first_context_provider_) {
- first_context_provider_ = TestContextProvider::Create();
- return FakeOutputSurface::Create3d(first_context_provider_);
+ return FakeOutputSurface::Create3d(
+ base::MakeUnique<TestContextProvider::Factory>());
}
-
EXPECT_FALSE(second_context_provider_);
- second_context_provider_ = TestContextProvider::Create();
- return FakeOutputSurface::Create3d(second_context_provider_);
+ return FakeOutputSurface::Create3d(
+ base::MakeUnique<TestContextProvider::Factory>());
+ }
+
+ void InitializedRendererOnThread(LayerTreeHostImpl* impl,
+ bool success) override {
+ ASSERT_TRUE(success);
+ if (!first_context_provider_) {
+ first_context_provider_ = static_cast<TestContextProvider*>(
+ impl->output_surface()->context_provider());
+ } else {
+ second_context_provider_ = static_cast<TestContextProvider*>(
+ impl->output_surface()->context_provider());
+ }
}
void SetupTree() override {
@@ -767,13 +785,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 +810,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 +822,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 +840,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 +856,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 +876,8 @@ class LayerTreeHostCopyRequestTestCountTextures
: public LayerTreeHostCopyRequestTest {
protected:
std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override {
- context_provider_ = TestContextProvider::Create();
- return FakeOutputSurface::Create3d(context_provider_);
+ return FakeOutputSurface::Create3d(
+ base::MakeUnique<TestContextProvider::Factory>());
}
void SetupTree() override {
@@ -880,18 +915,21 @@ class LayerTreeHostCopyRequestTestCountTextures
}
void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override {
+ auto* context_provider = static_cast<TestContextProvider*>(
+ impl->output_surface()->context_provider());
+
switch (impl->active_tree()->source_frame_number()) {
case 0:
// The layers have been drawn, so their textures have been allocated.
num_textures_without_readback_ =
- context_provider_->TestContext3d()->NumTextures();
+ context_provider->TestContext3d()->NumTextures();
break;
case 1:
// We did a readback, so there will be a readback texture around now.
num_textures_with_readback_ =
- context_provider_->TestContext3d()->NumTextures();
+ context_provider->TestContext3d()->NumTextures();
waited_sync_token_after_readback_ =
- context_provider_->TestContext3d()->last_waited_sync_token();
+ context_provider->TestContext3d()->last_waited_sync_token();
MainThreadTaskRunner()->PostTask(
FROM_HERE,
@@ -903,7 +941,6 @@ class LayerTreeHostCopyRequestTestCountTextures
virtual void DoEndTest() { EndTest(); }
- scoped_refptr<TestContextProvider> context_provider_;
size_t num_textures_without_readback_;
size_t num_textures_with_readback_;
gpu::SyncToken waited_sync_token_after_readback_;
@@ -951,7 +988,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