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

Side by Side Diff: cc/output/output_surface_unittest.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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/output/output_surface.h" 5 #include "cc/output/output_surface.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/test/test_simple_task_runner.h" 8 #include "base/test/test_simple_task_runner.h"
9 #include "cc/output/managed_memory_policy.h" 9 #include "cc/output/managed_memory_policy.h"
10 #include "cc/output/output_surface_client.h" 10 #include "cc/output/output_surface_client.h"
11 #include "cc/output/software_output_device.h" 11 #include "cc/output/software_output_device.h"
12 #include "cc/test/begin_frame_args_test.h" 12 #include "cc/test/begin_frame_args_test.h"
13 #include "cc/test/fake_output_surface.h" 13 #include "cc/test/fake_output_surface.h"
14 #include "cc/test/fake_output_surface_client.h" 14 #include "cc/test/fake_output_surface_client.h"
15 #include "cc/test/test_context_provider.h" 15 #include "cc/test/test_context_provider.h"
16 #include "cc/test/test_web_graphics_context_3d.h" 16 #include "cc/test/test_web_graphics_context_3d.h"
17 #include "gpu/GLES2/gl2extchromium.h" 17 #include "gpu/GLES2/gl2extchromium.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 namespace cc { 20 namespace cc {
21 namespace { 21 namespace {
22 22
23 class TestOutputSurface : public OutputSurface { 23 class TestOutputSurface : public OutputSurface {
24 public: 24 public:
25 explicit TestOutputSurface(scoped_refptr<ContextProvider> context_provider) 25 explicit TestOutputSurface(
26 : OutputSurface(context_provider) {} 26 std::unique_ptr<ContextProvider::Factory> compositor_context_factory)
27 : OutputSurface(std::move(compositor_context_factory)) {}
27 28
28 TestOutputSurface(scoped_refptr<ContextProvider> context_provider, 29 TestOutputSurface(
29 scoped_refptr<ContextProvider> worker_context_provider) 30 std::unique_ptr<ContextProvider::Factory> compositor_context_factory,
30 : OutputSurface(worker_context_provider) {} 31 scoped_refptr<ContextProvider> worker_context_provider)
32 : OutputSurface(std::move(compositor_context_factory),
33 std::move(worker_context_provider)) {}
31 34
32 explicit TestOutputSurface( 35 explicit TestOutputSurface(
33 std::unique_ptr<SoftwareOutputDevice> software_device) 36 std::unique_ptr<SoftwareOutputDevice> software_device)
34 : OutputSurface(std::move(software_device)) {} 37 : OutputSurface(std::move(software_device)) {}
35 38
36 TestOutputSurface(scoped_refptr<ContextProvider> context_provider, 39 TestOutputSurface(
37 std::unique_ptr<SoftwareOutputDevice> software_device) 40 std::unique_ptr<ContextProvider::Factory> compositor_context_factory,
38 : OutputSurface(context_provider, std::move(software_device)) {} 41 std::unique_ptr<SoftwareOutputDevice> software_device)
42 : OutputSurface(std::move(compositor_context_factory),
43 std::move(software_device)) {}
39 44
40 void SwapBuffers(CompositorFrame* frame) override { 45 void SwapBuffers(CompositorFrame* frame) override {
41 client_->DidSwapBuffers(); 46 client_->DidSwapBuffers();
42 client_->DidSwapBuffersComplete(); 47 client_->DidSwapBuffersComplete();
43 } 48 }
44 49
45 void DidSwapBuffersForTesting() { client_->DidSwapBuffers(); } 50 void DidSwapBuffersForTesting() { client_->DidSwapBuffers(); }
46 51
47 void OnSwapBuffersCompleteForTesting() { client_->DidSwapBuffersComplete(); } 52 void OnSwapBuffersCompleteForTesting() { client_->DidSwapBuffersComplete(); }
48 53
(...skipping 26 matching lines...) Expand all
75 SoftwareOutputDevice::DiscardBackbuffer(); 80 SoftwareOutputDevice::DiscardBackbuffer();
76 discard_backbuffer_count_++; 81 discard_backbuffer_count_++;
77 } 82 }
78 83
79 void TestSoftwareOutputDevice::EnsureBackbuffer() { 84 void TestSoftwareOutputDevice::EnsureBackbuffer() {
80 SoftwareOutputDevice::EnsureBackbuffer(); 85 SoftwareOutputDevice::EnsureBackbuffer();
81 ensure_backbuffer_count_++; 86 ensure_backbuffer_count_++;
82 } 87 }
83 88
84 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) { 89 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) {
85 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); 90 TestOutputSurface output_surface(
86 TestOutputSurface output_surface(provider); 91 base::MakeUnique<TestContextProvider::Factory>());
87 EXPECT_FALSE(output_surface.HasClient()); 92 EXPECT_FALSE(output_surface.HasClient());
88 93
89 FakeOutputSurfaceClient client; 94 FakeOutputSurfaceClient client;
90 EXPECT_TRUE(output_surface.BindToClient(&client)); 95 EXPECT_TRUE(output_surface.BindToClient(&client));
91 EXPECT_TRUE(output_surface.HasClient()); 96 EXPECT_TRUE(output_surface.HasClient());
92 97
93 // Verify DidLoseOutputSurface callback is hooked up correctly. 98 // Verify DidLoseOutputSurface callback is hooked up correctly.
94 EXPECT_FALSE(client.did_lose_output_surface_called()); 99 EXPECT_FALSE(client.did_lose_output_surface_called());
95 output_surface.context_provider()->ContextGL()->LoseContextCHROMIUM( 100 output_surface.context_provider()->ContextGL()->LoseContextCHROMIUM(
96 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); 101 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
97 output_surface.context_provider()->ContextGL()->Flush(); 102 output_surface.context_provider()->ContextGL()->Flush();
98 EXPECT_TRUE(client.did_lose_output_surface_called()); 103 EXPECT_TRUE(client.did_lose_output_surface_called());
99 } 104 }
100 105
101 TEST(OutputSurfaceTest, ClientPointerIndicatesWorkerBindToClientSuccess) { 106 TEST(OutputSurfaceTest, ClientPointerIndicatesWorkerBindToClientSuccess) {
102 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); 107 TestOutputSurface output_surface(
103 scoped_refptr<TestContextProvider> worker_provider = 108 base::MakeUnique<TestContextProvider::Factory>(),
104 TestContextProvider::Create(); 109 TestContextProvider::Create());
105 TestOutputSurface output_surface(provider, worker_provider);
106 EXPECT_FALSE(output_surface.HasClient()); 110 EXPECT_FALSE(output_surface.HasClient());
107 111
108 FakeOutputSurfaceClient client; 112 FakeOutputSurfaceClient client;
109 EXPECT_TRUE(output_surface.BindToClient(&client)); 113 EXPECT_TRUE(output_surface.BindToClient(&client));
110 EXPECT_TRUE(output_surface.HasClient()); 114 EXPECT_TRUE(output_surface.HasClient());
111 115
112 // Verify DidLoseOutputSurface callback is hooked up correctly. 116 // Verify DidLoseOutputSurface callback is hooked up correctly.
113 EXPECT_FALSE(client.did_lose_output_surface_called()); 117 EXPECT_FALSE(client.did_lose_output_surface_called());
114 output_surface.context_provider()->ContextGL()->LoseContextCHROMIUM( 118 output_surface.context_provider()->ContextGL()->LoseContextCHROMIUM(
115 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); 119 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
116 output_surface.context_provider()->ContextGL()->Flush(); 120 output_surface.context_provider()->ContextGL()->Flush();
117 EXPECT_TRUE(client.did_lose_output_surface_called()); 121 EXPECT_TRUE(client.did_lose_output_surface_called());
118 } 122 }
119 123
124 // TODO(danakj): Add a test for the worker context failing when we defer its
125 // creation too.
120 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientFailure) { 126 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientFailure) {
121 scoped_refptr<TestContextProvider> context_provider = 127 TestOutputSurface output_surface(
122 TestContextProvider::Create(); 128 base::MakeUnique<TestContextProvider::Factory>(
123 129 TestContextProvider::Factory::kFailCreate));
124 // Lose the context so BindToClient fails.
125 context_provider->UnboundTestContext3d()->set_context_lost(true);
126
127 TestOutputSurface output_surface(context_provider);
128 EXPECT_FALSE(output_surface.HasClient()); 130 EXPECT_FALSE(output_surface.HasClient());
129 131
130 FakeOutputSurfaceClient client; 132 FakeOutputSurfaceClient client;
131 EXPECT_FALSE(output_surface.BindToClient(&client));
132 EXPECT_FALSE(output_surface.HasClient());
133 }
134
135 TEST(OutputSurfaceTest, ClientPointerIndicatesWorkerBindToClientFailure) {
136 scoped_refptr<TestContextProvider> context_provider =
137 TestContextProvider::Create();
138 scoped_refptr<TestContextProvider> worker_context_provider =
139 TestContextProvider::Create();
140
141 // Lose the context so BindToClient fails.
142 worker_context_provider->UnboundTestContext3d()->set_context_lost(true);
143
144 TestOutputSurface output_surface(context_provider, worker_context_provider);
145 EXPECT_FALSE(output_surface.HasClient());
146
147 FakeOutputSurfaceClient client;
148 EXPECT_FALSE(output_surface.BindToClient(&client)); 133 EXPECT_FALSE(output_surface.BindToClient(&client));
149 EXPECT_FALSE(output_surface.HasClient()); 134 EXPECT_FALSE(output_surface.HasClient());
150 } 135 }
151 136
152 TEST(OutputSurfaceTest, SoftwareOutputDeviceBackbufferManagement) { 137 TEST(OutputSurfaceTest, SoftwareOutputDeviceBackbufferManagement) {
153 TestSoftwareOutputDevice* software_output_device = 138 TestSoftwareOutputDevice* software_output_device =
154 new TestSoftwareOutputDevice(); 139 new TestSoftwareOutputDevice();
155 140
156 // TestOutputSurface now owns software_output_device and has responsibility to 141 // TestOutputSurface now owns software_output_device and has responsibility to
157 // free it. 142 // free it.
158 TestOutputSurface output_surface(base::WrapUnique(software_output_device)); 143 TestOutputSurface output_surface(base::WrapUnique(software_output_device));
159 144
160 EXPECT_EQ(0, software_output_device->ensure_backbuffer_count()); 145 EXPECT_EQ(0, software_output_device->ensure_backbuffer_count());
161 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); 146 EXPECT_EQ(0, software_output_device->discard_backbuffer_count());
162 147
163 output_surface.EnsureBackbuffer(); 148 output_surface.EnsureBackbuffer();
164 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); 149 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count());
165 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); 150 EXPECT_EQ(0, software_output_device->discard_backbuffer_count());
166 output_surface.DiscardBackbuffer(); 151 output_surface.DiscardBackbuffer();
167 152
168 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); 153 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count());
169 EXPECT_EQ(1, software_output_device->discard_backbuffer_count()); 154 EXPECT_EQ(1, software_output_device->discard_backbuffer_count());
170 } 155 }
171 156
172 } // namespace 157 } // namespace
173 } // namespace cc 158 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698