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

Side by Side Diff: cc/layer_tree_host_unittest_context.cc

Issue 12212007: cc: Route offscreen context creation for compositor to the browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove the GrContextProvider::ScopedContexts guard classes Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/layer_tree_host.h" 5 #include "cc/layer_tree_host.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "cc/content_layer.h" 8 #include "cc/content_layer.h"
9 #include "cc/delegated_renderer_layer.h" 9 #include "cc/delegated_renderer_layer.h"
10 #include "cc/delegated_renderer_layer_impl.h" 10 #include "cc/delegated_renderer_layer_impl.h"
11 #include "cc/grcontext_provider.h"
11 #include "cc/heads_up_display_layer.h" 12 #include "cc/heads_up_display_layer.h"
12 #include "cc/io_surface_layer.h" 13 #include "cc/io_surface_layer.h"
13 #include "cc/layer_impl.h" 14 #include "cc/layer_impl.h"
14 #include "cc/layer_tree_host_impl.h" 15 #include "cc/layer_tree_host_impl.h"
15 #include "cc/layer_tree_impl.h" 16 #include "cc/layer_tree_impl.h"
16 #include "cc/picture_layer.h" 17 #include "cc/picture_layer.h"
17 #include "cc/scrollbar_layer.h" 18 #include "cc/scrollbar_layer.h"
18 #include "cc/single_thread_proxy.h" 19 #include "cc/single_thread_proxy.h"
19 #include "cc/test/fake_content_layer.h" 20 #include "cc/test/fake_content_layer.h"
20 #include "cc/test/fake_content_layer_client.h" 21 #include "cc/test/fake_content_layer_client.h"
21 #include "cc/test/fake_content_layer_impl.h" 22 #include "cc/test/fake_content_layer_impl.h"
22 #include "cc/test/fake_output_surface.h" 23 #include "cc/test/fake_output_surface.h"
23 #include "cc/test/fake_scrollbar_layer.h" 24 #include "cc/test/fake_scrollbar_layer.h"
24 #include "cc/test/fake_scrollbar_theme_painter.h" 25 #include "cc/test/fake_scrollbar_theme_painter.h"
25 #include "cc/test/fake_video_frame_provider.h" 26 #include "cc/test/fake_video_frame_provider.h"
26 #include "cc/test/fake_web_scrollbar.h" 27 #include "cc/test/fake_web_scrollbar.h"
27 #include "cc/test/fake_web_scrollbar_theme_geometry.h" 28 #include "cc/test/fake_web_scrollbar_theme_geometry.h"
28 #include "cc/test/layer_tree_test_common.h" 29 #include "cc/test/layer_tree_test_common.h"
29 #include "cc/test/render_pass_test_common.h" 30 #include "cc/test/render_pass_test_common.h"
30 #include "cc/test/test_web_graphics_context_3d.h" 31 #include "cc/test/test_web_graphics_context_3d.h"
31 #include "cc/texture_layer.h" 32 #include "cc/texture_layer.h"
32 #include "cc/video_layer.h" 33 #include "cc/video_layer.h"
33 #include "cc/video_layer_impl.h" 34 #include "cc/video_layer_impl.h"
34 #include "gpu/GLES2/gl2extchromium.h" 35 #include "gpu/GLES2/gl2extchromium.h"
35 #include "media/base/media.h" 36 #include "media/base/media.h"
37 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations .h"
36 38
37 using media::VideoFrame; 39 using media::VideoFrame;
38 using WebKit::WebGraphicsContext3D; 40 using WebKit::WebGraphicsContext3D;
39 41
40 namespace cc { 42 namespace cc {
41 namespace { 43 namespace {
42 44
43 // These tests deal with losing the 3d graphics context. 45 // These tests deal with losing the 3d graphics context.
44 class LayerTreeHostContextTest : public ThreadedTest { 46 class LayerTreeHostContextTest : public ThreadedTest {
45 public: 47 public:
46 LayerTreeHostContextTest() 48 LayerTreeHostContextTest()
47 : ThreadedTest(), 49 : ThreadedTest(),
48 context3d_(NULL), 50 context3d_(NULL),
49 times_to_fail_create_(0), 51 times_to_fail_create_(0),
50 times_to_fail_initialize_(0), 52 times_to_fail_initialize_(0),
51 times_to_lose_on_create_(0), 53 times_to_lose_on_create_(0),
52 times_to_lose_during_commit_(0), 54 times_to_lose_during_commit_(0),
53 times_to_lose_during_draw_(0), 55 times_to_lose_during_draw_(0),
54 times_to_fail_recreate_(0), 56 times_to_fail_recreate_(0),
55 times_to_fail_reinitialize_(0), 57 times_to_fail_reinitialize_(0),
56 times_to_lose_on_recreate_(0) { 58 times_to_lose_on_recreate_(0),
59 times_to_fail_create_offscreen_(0),
60 times_to_fail_recreate_offscreen_(0),
61 times_to_expect_recreate_retried_(0),
62 times_recreate_retried_(0),
63 times_offscreen_created_(0) {
57 media::InitializeMediaLibraryForTesting(); 64 media::InitializeMediaLibraryForTesting();
58 } 65 }
59 66
60 void LoseContext() { 67 void LoseContext() {
61 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 68 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
62 GL_INNOCENT_CONTEXT_RESET_ARB); 69 GL_INNOCENT_CONTEXT_RESET_ARB);
63 context3d_ = NULL; 70 context3d_ = NULL;
64 } 71 }
65 72
66 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() { 73 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() {
67 return TestWebGraphicsContext3D::Create(); 74 return TestWebGraphicsContext3D::Create();
68 } 75 }
69 76
70 virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE { 77 virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE {
78 offscreen_context3d_main_thread_.reset();
79
71 if (times_to_fail_create_) { 80 if (times_to_fail_create_) {
72 --times_to_fail_create_; 81 --times_to_fail_create_;
82 ExpectRecreateToRetry();
73 return scoped_ptr<OutputSurface>(); 83 return scoped_ptr<OutputSurface>();
74 } 84 }
75 85
76 scoped_ptr<TestWebGraphicsContext3D> context3d = CreateContext3d(); 86 scoped_ptr<TestWebGraphicsContext3D> context3d = CreateContext3d();
77 context3d_ = context3d.get(); 87 context3d_ = context3d.get();
78 88
79 if (times_to_fail_initialize_) { 89 if (times_to_fail_initialize_) {
80 --times_to_fail_initialize_; 90 --times_to_fail_initialize_;
81 // Make the context get lost during reinitialization. 91 // Make the context get lost during reinitialization.
82 // The number of times MakeCurrent succeeds is not important, and 92 // The number of times MakeCurrent succeeds is not important, and
83 // can be changed if needed to make this pass with future changes. 93 // can be changed if needed to make this pass with future changes.
84 context3d_->set_times_make_current_succeeds(2); 94 context3d_->set_times_make_current_succeeds(2);
95 ExpectRecreateToRetry();
85 } else if (times_to_lose_on_create_) { 96 } else if (times_to_lose_on_create_) {
86 --times_to_lose_on_create_; 97 --times_to_lose_on_create_;
87 LoseContext(); 98 LoseContext();
99 ExpectRecreateToRetry();
88 } 100 }
89 101
90 return FakeOutputSurface::Create3d( 102 return FakeOutputSurface::Create3d(
91 context3d.PassAs<WebGraphicsContext3D>()).PassAs<OutputSurface>(); 103 context3d.PassAs<WebGraphicsContext3D>()).PassAs<OutputSurface>();
92 } 104 }
93 105
94 virtual bool prepareToDrawOnThread( 106 scoped_ptr<TestWebGraphicsContext3D> CreateOffscreenContext3d() {
95 LayerTreeHostImpl*, LayerTreeHostImpl::FrameData&, bool result) 107 if (times_to_fail_create_offscreen_) {
96 OVERRIDE { 108 --times_to_fail_create_offscreen_;
97 EXPECT_TRUE(result); 109 ExpectRecreateToRetry();
98 if (!times_to_lose_during_draw_) 110 return scoped_ptr<TestWebGraphicsContext3D>();
99 return result; 111 }
100 112
101 --times_to_lose_during_draw_; 113 WebKit::WebGraphicsContext3D::Attributes attrs;
102 if (context3d_) 114 scoped_ptr<TestWebGraphicsContext3D> offscreen_context3d =
103 context3d_->set_times_make_current_succeeds(0); 115 TestWebGraphicsContext3D::Create(attrs).Pass();
116 DCHECK(offscreen_context3d);
117
118 ++times_offscreen_created_;
119 return offscreen_context3d.Pass();
120 }
121
122 // LayerTreeHostClient implementation.
123 virtual WebKit::WebGraphicsContext3D* OffscreenContext3dForMainThread()
124 OVERRIDE {
125 DCHECK(!implThread());
126
127 if (!offscreen_context3d_main_thread_ && context3d_)
128 offscreen_context3d_main_thread_ = CreateOffscreenContext3d().Pass();
129 return offscreen_context3d_main_thread_.get();
130 }
131
132 // LayerTreeHostClient implementation.
133 virtual WebKit::WebGraphicsContext3D* OffscreenContext3dForCompositorThread()
134 OVERRIDE {
135 DCHECK(implThread());
136
137 if (!offscreen_context3d_impl_thread_ && context3d_)
138 offscreen_context3d_impl_thread_ = CreateOffscreenContext3d().Pass();
139 return offscreen_context3d_impl_thread_.get();
140 }
141
142 // LayerTreeHostClient implementation.
143 virtual GrContext* OffscreenGrContextForMainThread() OVERRIDE {
144 DCHECK(!implThread());
145 // TODO(danakj): Make a FakeGrContext.
146 return NULL;
147 }
148
149 // LayerTreeHostClient implementation.
150 virtual GrContext* OffscreenGrContextForCompositorThread() OVERRIDE {
151 DCHECK(implThread());
152 // TODO(danakj): Make a FakeGrContext.
153 return NULL;
154 }
155
156 virtual void DestroyOffscreenContext3dForCompositorThread() OVERRIDE {
157 // TODO(danakj): Delete the FakeGrContext.
158 offscreen_context3d_impl_thread_.reset();
159 }
160
161 virtual bool prepareToDrawOnThread(
162 LayerTreeHostImpl*, LayerTreeHostImpl::FrameData&, bool result)
163 OVERRIDE {
164 EXPECT_TRUE(result);
165 if (!times_to_lose_during_draw_)
104 return result; 166 return result;
105 } 167
168 --times_to_lose_during_draw_;
169 if (context3d_)
170 context3d_->set_times_make_current_succeeds(0);
171 return result;
172 }
106 173
107 virtual void commitCompleteOnThread(LayerTreeHostImpl *host_impl) OVERRIDE { 174 virtual void commitCompleteOnThread(LayerTreeHostImpl *host_impl) OVERRIDE {
108 if (!times_to_lose_during_commit_) 175 if (!times_to_lose_during_commit_)
109 return; 176 return;
110 --times_to_lose_during_commit_; 177 --times_to_lose_during_commit_;
111 LoseContext(); 178 LoseContext();
112 179
113 times_to_fail_create_ = times_to_fail_recreate_; 180 times_to_fail_create_ = times_to_fail_recreate_;
114 times_to_fail_recreate_ = 0; 181 times_to_fail_recreate_ = 0;
115 times_to_fail_initialize_ = times_to_fail_reinitialize_; 182 times_to_fail_initialize_ = times_to_fail_reinitialize_;
116 times_to_fail_reinitialize_ = 0; 183 times_to_fail_reinitialize_ = 0;
117 times_to_lose_on_create_ = times_to_lose_on_recreate_; 184 times_to_lose_on_create_ = times_to_lose_on_recreate_;
118 times_to_lose_on_recreate_ = 0; 185 times_to_lose_on_recreate_ = 0;
186 times_to_fail_create_offscreen_ = times_to_fail_recreate_offscreen_;
187 times_to_fail_recreate_offscreen_ = 0;
188 }
189
190 virtual void willRetryRecreateOutputSurface() OVERRIDE {
191 ++times_recreate_retried_;
192 }
193
194 virtual void TearDown() OVERRIDE {
195 ThreadedTest::TearDown();
196 EXPECT_EQ(times_to_expect_recreate_retried_, times_recreate_retried_);
197 }
198
199 void ExpectRecreateToRetry() {
200 ++times_to_expect_recreate_retried_;
119 } 201 }
120 202
121 protected: 203 protected:
122 TestWebGraphicsContext3D* context3d_; 204 TestWebGraphicsContext3D* context3d_;
123 int times_to_fail_create_; 205 int times_to_fail_create_;
124 int times_to_fail_initialize_; 206 int times_to_fail_initialize_;
125 int times_to_lose_on_create_; 207 int times_to_lose_on_create_;
126 int times_to_lose_during_commit_; 208 int times_to_lose_during_commit_;
127 int times_to_lose_during_draw_; 209 int times_to_lose_during_draw_;
128 int times_to_fail_reinitialize_; 210 int times_to_fail_reinitialize_;
129 int times_to_fail_recreate_; 211 int times_to_fail_recreate_;
130 int times_to_lose_on_recreate_; 212 int times_to_lose_on_recreate_;
213 int times_to_fail_create_offscreen_;
214 int times_to_fail_recreate_offscreen_;
215 int times_to_expect_recreate_retried_;
216 int times_recreate_retried_;
217 int times_offscreen_created_;
218
219 scoped_ptr<TestWebGraphicsContext3D> offscreen_context3d_main_thread_;
220 scoped_ptr<TestWebGraphicsContext3D> offscreen_context3d_impl_thread_;
131 }; 221 };
132 222
133 class LayerTreeHostContextTestLostContextSucceeds : 223 class LayerTreeHostContextTestLostContextSucceeds :
134 public LayerTreeHostContextTest { 224 public LayerTreeHostContextTest {
135 public: 225 public:
136 LayerTreeHostContextTestLostContextSucceeds() 226 LayerTreeHostContextTestLostContextSucceeds()
137 : LayerTreeHostContextTest(), 227 : LayerTreeHostContextTest(),
138 test_case_(0), 228 test_case_(0),
139 num_losses_(0), 229 num_losses_(0),
140 recovered_context_(true) { 230 recovered_context_(true) {
141 } 231 }
142 232
143 virtual void beginTest() OVERRIDE { 233 virtual void beginTest() OVERRIDE {
144 postSetNeedsCommitToMainThread(); 234 postSetNeedsCommitToMainThread();
145 } 235 }
146 236
147 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { 237 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE {
148 EXPECT_TRUE(succeeded); 238 EXPECT_TRUE(succeeded);
149 ++num_losses_; 239 ++num_losses_;
150 recovered_context_ = true; 240 recovered_context_ = true;
151 } 241 }
152 242
153 virtual void afterTest() OVERRIDE { 243 virtual void afterTest() OVERRIDE {
154 EXPECT_EQ(8, test_case_); 244 EXPECT_EQ(12, test_case_);
155 EXPECT_EQ(6 + 10 + 10, num_losses_); 245 EXPECT_EQ(10 + 10 + 10, num_losses_);
156 } 246 }
157 247
158 virtual void didCommitAndDrawFrame() OVERRIDE { 248 virtual void didCommitAndDrawFrame() OVERRIDE {
159 // If the last frame had a context loss, then we'll commit again to 249 // If the last frame had a context loss, then we'll commit again to
160 // recover. 250 // recover.
161 if (!recovered_context_) 251 if (!recovered_context_)
162 return; 252 return;
163 if (times_to_lose_during_commit_) 253 if (times_to_lose_during_commit_)
164 return; 254 return;
165 if (times_to_lose_during_draw_) 255 if (times_to_lose_during_draw_)
(...skipping 12 matching lines...) Expand all
178 268
179 bool NextTestCase() { 269 bool NextTestCase() {
180 static const TestCase kTests[] = { 270 static const TestCase kTests[] = {
181 // Losing the context and failing to recreate it (or losing it again 271 // Losing the context and failing to recreate it (or losing it again
182 // immediately) a small number of times should succeed. 272 // immediately) a small number of times should succeed.
183 { 1, // times_to_lose_during_commit 273 { 1, // times_to_lose_during_commit
184 0, // times_to_lose_during_draw 274 0, // times_to_lose_during_draw
185 3, // times_to_fail_reinitialize 275 3, // times_to_fail_reinitialize
186 0, // times_to_fail_recreate 276 0, // times_to_fail_recreate
187 0, // times_to_lose_on_recreate 277 0, // times_to_lose_on_recreate
278 0, // times_to_fail_recreate_offscreen;
188 }, 279 },
189 { 0, // times_to_lose_during_commit 280 { 0, // times_to_lose_during_commit
190 1, // times_to_lose_during_draw 281 1, // times_to_lose_during_draw
191 3, // times_to_fail_reinitialize 282 3, // times_to_fail_reinitialize
192 0, // times_to_fail_recreate 283 0, // times_to_fail_recreate
193 0, // times_to_lose_on_recreate 284 0, // times_to_lose_on_recreate
285 0, // times_to_fail_recreate_offscreen;
194 }, 286 },
195 { 1, // times_to_lose_during_commit 287 { 1, // times_to_lose_during_commit
196 0, // times_to_lose_during_draw 288 0, // times_to_lose_during_draw
197 0, // times_to_fail_reinitialize 289 0, // times_to_fail_reinitialize
198 3, // times_to_fail_recreate 290 3, // times_to_fail_recreate
199 0, // times_to_lose_on_recreate 291 0, // times_to_lose_on_recreate
292 0, // times_to_fail_recreate_offscreen;
200 }, 293 },
201 { 0, // times_to_lose_during_commit 294 { 0, // times_to_lose_during_commit
202 1, // times_to_lose_during_draw 295 1, // times_to_lose_during_draw
203 0, // times_to_fail_reinitialize 296 0, // times_to_fail_reinitialize
204 3, // times_to_fail_recreate 297 3, // times_to_fail_recreate
205 0, // times_to_lose_on_recreate 298 0, // times_to_lose_on_recreate
299 0, // times_to_fail_recreate_offscreen;
206 }, 300 },
207 { 1, // times_to_lose_during_commit 301 { 1, // times_to_lose_during_commit
208 0, // times_to_lose_during_draw 302 0, // times_to_lose_during_draw
209 0, // times_to_fail_reinitialize 303 0, // times_to_fail_reinitialize
210 0, // times_to_fail_recreate 304 0, // times_to_fail_recreate
211 3, // times_to_lose_on_recreate 305 3, // times_to_lose_on_recreate
306 0, // times_to_fail_recreate_offscreen;
212 }, 307 },
213 { 0, // times_to_lose_during_commit 308 { 0, // times_to_lose_during_commit
214 1, // times_to_lose_during_draw 309 1, // times_to_lose_during_draw
215 0, // times_to_fail_reinitialize 310 0, // times_to_fail_reinitialize
216 0, // times_to_fail_recreate 311 0, // times_to_fail_recreate
217 3, // times_to_lose_on_recreate 312 3, // times_to_lose_on_recreate
313 0, // times_to_fail_recreate_offscreen;
314 },
315 { 1, // times_to_lose_during_commit
316 0, // times_to_lose_during_draw
317 0, // times_to_fail_reinitialize
318 0, // times_to_fail_recreate
319 0, // times_to_lose_on_recreate
320 3, // times_to_fail_recreate_offscreen;
321 },
322 { 0, // times_to_lose_during_commit
323 1, // times_to_lose_during_draw
324 0, // times_to_fail_reinitialize
325 0, // times_to_fail_recreate
326 0, // times_to_lose_on_recreate
327 3, // times_to_fail_recreate_offscreen;
328 },
329 { 1, // times_to_lose_during_commit
330 0, // times_to_lose_during_draw
331 0, // times_to_fail_reinitialize
332 0, // times_to_fail_recreate
333 0, // times_to_lose_on_recreate
334 3, // times_to_fail_recreate_offscreen;
335 },
336 { 0, // times_to_lose_during_commit
337 1, // times_to_lose_during_draw
338 0, // times_to_fail_reinitialize
339 0, // times_to_fail_recreate
340 0, // times_to_lose_on_recreate
341 0, // times_to_fail_recreate_offscreen;
218 }, 342 },
219 // Losing the context and recreating it any number of times should 343 // Losing the context and recreating it any number of times should
220 // succeed. 344 // succeed.
221 { 10, // times_to_lose_during_commit 345 { 10, // times_to_lose_during_commit
222 0, // times_to_lose_during_draw 346 0, // times_to_lose_during_draw
223 0, // times_to_fail_reinitialize 347 0, // times_to_fail_reinitialize
224 0, // times_to_fail_recreate 348 0, // times_to_fail_recreate
225 0, // times_to_lose_on_recreate 349 0, // times_to_lose_on_recreate
350 0, // times_to_fail_recreate_offscreen;
226 }, 351 },
227 { 0, // times_to_lose_during_commit 352 { 0, // times_to_lose_during_commit
228 10, // times_to_lose_during_draw 353 10, // times_to_lose_during_draw
229 0, // times_to_fail_reinitialize 354 0, // times_to_fail_reinitialize
230 0, // times_to_fail_recreate 355 0, // times_to_fail_recreate
231 0, // times_to_lose_on_recreate 356 0, // times_to_lose_on_recreate
357 0, // times_to_fail_recreate_offscreen;
232 }, 358 },
233 }; 359 };
234 360
235 if (test_case_ >= arraysize(kTests)) 361 if (test_case_ >= arraysize(kTests))
236 return false; 362 return false;
237 363
238 times_to_lose_during_commit_ = 364 times_to_lose_during_commit_ =
239 kTests[test_case_].times_to_lose_during_commit; 365 kTests[test_case_].times_to_lose_during_commit;
240 times_to_lose_during_draw_ = 366 times_to_lose_during_draw_ =
241 kTests[test_case_].times_to_lose_during_draw; 367 kTests[test_case_].times_to_lose_during_draw;
242 times_to_fail_reinitialize_ = kTests[test_case_].times_to_fail_reinitialize; 368 times_to_fail_reinitialize_ = kTests[test_case_].times_to_fail_reinitialize;
243 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate; 369 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate;
244 times_to_lose_on_recreate_ = kTests[test_case_].times_to_lose_on_recreate; 370 times_to_lose_on_recreate_ = kTests[test_case_].times_to_lose_on_recreate;
371 times_to_fail_recreate_offscreen_ = kTests[test_case_].times_to_fail_recreat e_offscreen;
245 ++test_case_; 372 ++test_case_;
246 return true; 373 return true;
247 } 374 }
248 375
249 struct TestCase { 376 struct TestCase {
250 int times_to_lose_during_commit; 377 int times_to_lose_during_commit;
251 int times_to_lose_during_draw; 378 int times_to_lose_during_draw;
252 int times_to_fail_reinitialize; 379 int times_to_fail_reinitialize;
253 int times_to_fail_recreate; 380 int times_to_fail_recreate;
254 int times_to_lose_on_recreate; 381 int times_to_lose_on_recreate;
382 int times_to_fail_recreate_offscreen;
255 }; 383 };
256 384
257 private: 385 private:
258 size_t test_case_; 386 size_t test_case_;
259 int num_losses_; 387 int num_losses_;
260 bool recovered_context_; 388 bool recovered_context_;
261 }; 389 };
262 390
263 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds) 391 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds)
264 392
265 class LayerTreeHostContextTestLostContextSucceedsWithContent : 393 class LayerTreeHostContextTestLostContextSucceedsWithContent :
266 public LayerTreeHostContextTestLostContextSucceeds { 394 public LayerTreeHostContextTestLostContextSucceeds {
267 public: 395 public:
268 396
269 LayerTreeHostContextTestLostContextSucceedsWithContent() 397 LayerTreeHostContextTestLostContextSucceedsWithContent()
270 : LayerTreeHostContextTestLostContextSucceeds() { 398 : LayerTreeHostContextTestLostContextSucceeds() {
271 } 399 }
272 400
273 virtual void setupTree() OVERRIDE { 401 virtual void setupTree() OVERRIDE {
274 root_ = Layer::create(); 402 root_ = Layer::create();
275 root_->setBounds(gfx::Size(10, 10)); 403 root_->setBounds(gfx::Size(10, 10));
276 root_->setAnchorPoint(gfx::PointF()); 404 root_->setAnchorPoint(gfx::PointF());
277 root_->setIsDrawable(true); 405 root_->setIsDrawable(true);
278 406
279 content_ = FakeContentLayer::Create(&client_); 407 content_ = FakeContentLayer::Create(&client_);
280 content_->setBounds(gfx::Size(10, 10)); 408 content_->setBounds(gfx::Size(10, 10));
281 content_->setAnchorPoint(gfx::PointF()); 409 content_->setAnchorPoint(gfx::PointF());
282 content_->setIsDrawable(true); 410 content_->setIsDrawable(true);
283 if (use_surface_) { 411 if (use_surface_) {
284 // TODO(danakj): Give the surface a filter to test more code when we can
285 // do so without crashing in the shared context creation.
286 content_->setForceRenderSurface(true); 412 content_->setForceRenderSurface(true);
413 // Filters require us to create an offscreen context.
414 WebKit::WebFilterOperations filters;
415 filters.append(WebKit::WebFilterOperation::createGrayscaleFilter(0.5f));
416 content_->setFilters(filters);
417 content_->setBackgroundFilters(filters);
287 } 418 }
288 419
289 root_->addChild(content_); 420 root_->addChild(content_);
290 421
291 m_layerTreeHost->setRootLayer(root_); 422 m_layerTreeHost->setRootLayer(root_);
292 LayerTreeHostContextTest::setupTree(); 423 LayerTreeHostContextTest::setupTree();
293 } 424 }
294 425
295 virtual void InvalidateAndSetNeedsCommit() OVERRIDE { 426 virtual void InvalidateAndSetNeedsCommit() OVERRIDE {
296 // Invalidate the render surface so we don't try to use a cached copy of the 427 // Invalidate the render surface so we don't try to use a cached copy of the
297 // surface. We want to make sure to test the drawing paths for drawing to 428 // surface. We want to make sure to test the drawing paths for drawing to
298 // a child surface. 429 // a child surface.
299 content_->setNeedsDisplay(); 430 content_->setNeedsDisplay();
300 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit(); 431 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit();
301 } 432 }
302 433
303 virtual void drawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 434 virtual void drawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
304 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>( 435 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>(
305 host_impl->rootLayer()->children()[0]); 436 host_impl->rootLayer()->children()[0]);
306 // Even though the context was lost, we should have a resource. The 437 // Even though the context was lost, we should have a resource. The
307 // TestWebGraphicsContext3D ensures that this resource is created with 438 // TestWebGraphicsContext3D ensures that this resource is created with
308 // the active context. 439 // the active context.
309 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); 440 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0));
441
442 GrContextProvider* contexts =
443 host_impl->resourceProvider()->offscreenContextProvider();
444 if (use_surface_) {
445 EXPECT_TRUE(contexts->context3d());
446 // TODO(danakj): Make a fake GrContext.
447 //EXPECT_TRUE(contexts->gr_context());
448 } else {
449 EXPECT_FALSE(contexts->context3d());
450 EXPECT_FALSE(contexts->gr_context());
451 }
452 }
453
454 virtual void afterTest() OVERRIDE {
455 LayerTreeHostContextTestLostContextSucceeds::afterTest();
456 if (use_surface_)
457 EXPECT_EQ(14 + 10 + 10, times_offscreen_created_);
458 else
459 EXPECT_EQ(0, times_offscreen_created_);
310 } 460 }
311 461
312 protected: 462 protected:
313 bool use_surface_; 463 bool use_surface_;
314 FakeContentLayerClient client_; 464 FakeContentLayerClient client_;
315 scoped_refptr<Layer> root_; 465 scoped_refptr<Layer> root_;
316 scoped_refptr<ContentLayer> content_; 466 scoped_refptr<ContentLayer> content_;
317 }; 467 };
318 468
319 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, 469 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent,
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 1170
1021 private: 1171 private:
1022 int commits_; 1172 int commits_;
1023 scoped_refptr<FakeScrollbarLayer> scrollbar_layer_; 1173 scoped_refptr<FakeScrollbarLayer> scrollbar_layer_;
1024 }; 1174 };
1025 1175
1026 SINGLE_AND_MULTI_THREAD_TEST_F(ScrollbarLayerLostContext) 1176 SINGLE_AND_MULTI_THREAD_TEST_F(ScrollbarLayerLostContext)
1027 1177
1028 } // namespace 1178 } // namespace
1029 } // namespace cc 1179 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698