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

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: add cc::GaneshResourceProvider 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/ganesh_resource_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_graphics_context_3d.h" 27 #include "cc/test/fake_web_graphics_context_3d.h"
27 #include "cc/test/fake_web_scrollbar.h" 28 #include "cc/test/fake_web_scrollbar.h"
28 #include "cc/test/fake_web_scrollbar_theme_geometry.h" 29 #include "cc/test/fake_web_scrollbar_theme_geometry.h"
29 #include "cc/test/layer_tree_test_common.h" 30 #include "cc/test/layer_tree_test_common.h"
30 #include "cc/test/render_pass_test_common.h" 31 #include "cc/test/render_pass_test_common.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_lose_on_create_offscreen_(0),
61 times_to_fail_recreate_offscreen_(0),
62 times_to_lose_on_recreate_offscreen_(0),
63 times_to_expect_recreate_retried_(0),
64 times_recreate_retried_(0) {
57 media::InitializeMediaLibraryForTesting(); 65 media::InitializeMediaLibraryForTesting();
58 } 66 }
59 67
60 void LoseContext() { 68 void LoseContext() {
61 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 69 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
62 GL_INNOCENT_CONTEXT_RESET_ARB); 70 GL_INNOCENT_CONTEXT_RESET_ARB);
63 context3d_ = NULL; 71 context3d_ = NULL;
64 } 72 }
65 73
66 virtual scoped_ptr<FakeWebGraphicsContext3D> CreateContext3d() { 74 virtual scoped_ptr<FakeWebGraphicsContext3D> CreateContext3d() {
67 return FakeWebGraphicsContext3D::Create(); 75 return FakeWebGraphicsContext3D::Create();
68 } 76 }
69 77
70 virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE { 78 virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE {
71 if (times_to_fail_create_) { 79 if (times_to_fail_create_) {
72 --times_to_fail_create_; 80 --times_to_fail_create_;
81 ExpectRecreateToRetry();
73 return scoped_ptr<OutputSurface>(); 82 return scoped_ptr<OutputSurface>();
74 } 83 }
75 84
76 scoped_ptr<FakeWebGraphicsContext3D> context3d = CreateContext3d(); 85 scoped_ptr<FakeWebGraphicsContext3D> context3d = CreateContext3d();
77 context3d_ = context3d.get(); 86 context3d_ = context3d.get();
78 87
79 if (times_to_fail_initialize_) { 88 if (times_to_fail_initialize_) {
80 --times_to_fail_initialize_; 89 --times_to_fail_initialize_;
81 // Make the context get lost during reinitialization. 90 // Make the context get lost during reinitialization.
82 // The number of times MakeCurrent succeeds is not important, and 91 // The number of times MakeCurrent succeeds is not important, and
83 // can be changed if needed to make this pass with future changes. 92 // can be changed if needed to make this pass with future changes.
84 context3d_->set_times_make_current_succeeds(2); 93 context3d_->set_times_make_current_succeeds(2);
94 ExpectRecreateToRetry();
85 } else if (times_to_lose_on_create_) { 95 } else if (times_to_lose_on_create_) {
86 --times_to_lose_on_create_; 96 --times_to_lose_on_create_;
87 LoseContext(); 97 LoseContext();
98 ExpectRecreateToRetry();
88 } 99 }
89 100
90 return FakeOutputSurface::Create3d( 101 return FakeOutputSurface::Create3d(
91 context3d.PassAs<WebGraphicsContext3D>()).PassAs<OutputSurface>(); 102 context3d.PassAs<WebGraphicsContext3D>()).PassAs<OutputSurface>();
92 } 103 }
93 104
94 virtual bool prepareToDrawOnThread( 105 WebKit::WebGraphicsContext3D* CreateOffscreenContext3d() {
95 LayerTreeHostImpl*, LayerTreeHostImpl::FrameData&, bool result) 106 DCHECK(!offscreen_context3d_);
96 OVERRIDE {
97 EXPECT_TRUE(result);
98 if (!times_to_lose_during_draw_)
99 return result;
100 107
101 --times_to_lose_during_draw_; 108 if (times_to_fail_create_offscreen_) {
102 if (context3d_) 109 --times_to_fail_create_offscreen_;
103 context3d_->set_times_make_current_succeeds(0); 110 ExpectRecreateToRetry();
104 return result; 111 return NULL;
105 } 112 }
106 113
114 WebKit::WebGraphicsContext3D::Attributes attrs;
115 offscreen_context3d_ =
116 FakeWebGraphicsContext3D::Create(attrs)
117 .PassAs<WebKit::WebGraphicsContext3D>();
118 DCHECK(offscreen_context3d_);
119
120 if (times_to_lose_on_create_offscreen_) {
121 --times_to_lose_on_create_offscreen_;
122 offscreen_context3d_->loseContextCHROMIUM(
123 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
124 offscreen_context3d_.reset();
125 ExpectRecreateToRetry();
126 }
127
128 return offscreen_context3d_.get();
129 }
130
131 // LayerTreeHostClient implementation.
132 virtual WebKit::WebGraphicsContext3D* offscreenContext3dForMainThread()
133 OVERRIDE {
134 DCHECK(!implThread());
135
136 if (!offscreen_context3d_)
137 CreateOffscreenContext3d();
138 return offscreen_context3d_.get();
139 }
140
141 // LayerTreeHostClient implementation.
142 virtual WebKit::WebGraphicsContext3D* offscreenContext3dForCompositorThread()
143 OVERRIDE {
144 DCHECK(implThread());
145
146 if (!offscreen_context3d_)
147 CreateOffscreenContext3d();
148 return offscreen_context3d_.get();
149 }
150
151 // LayerTreeHostClient implementation.
152 virtual GrContext* offscreenGrContextForMainThread() OVERRIDE {
153 DCHECK(!implThread());
154 // TODO(danakj): Make a FakeGrContext.
155 return NULL;
156 }
157
158 // LayerTreeHostClient implementation.
159 virtual GrContext* offscreenGrContextForCompositorThread() OVERRIDE {
160 DCHECK(implThread());
161 // TODO(danakj): Make a FakeGrContext.
162 return NULL;
163 }
164
165 virtual bool prepareToDrawOnThread(
166 LayerTreeHostImpl*, LayerTreeHostImpl::FrameData&, bool result)
167 OVERRIDE {
168 EXPECT_TRUE(result);
169 if (!times_to_lose_during_draw_)
170 return result;
171
172 --times_to_lose_during_draw_;
173 if (context3d_)
174 context3d_->set_times_make_current_succeeds(0);
175 return result;
176 }
177
107 virtual void commitCompleteOnThread(LayerTreeHostImpl *host_impl) OVERRIDE { 178 virtual void commitCompleteOnThread(LayerTreeHostImpl *host_impl) OVERRIDE {
108 if (!times_to_lose_during_commit_) 179 if (times_to_lose_during_commit_) {
109 return; 180 --times_to_lose_during_commit_;
110 --times_to_lose_during_commit_; 181 LoseContext();
111 LoseContext(); 182 }
112 183
113 times_to_fail_create_ = times_to_fail_recreate_; 184 times_to_fail_create_ = times_to_fail_recreate_;
114 times_to_fail_recreate_ = 0; 185 times_to_fail_recreate_ = 0;
115 times_to_fail_initialize_ = times_to_fail_reinitialize_; 186 times_to_fail_initialize_ = times_to_fail_reinitialize_;
116 times_to_fail_reinitialize_ = 0; 187 times_to_fail_reinitialize_ = 0;
117 times_to_lose_on_create_ = times_to_lose_on_recreate_; 188 times_to_lose_on_create_ = times_to_lose_on_recreate_;
118 times_to_lose_on_recreate_ = 0; 189 times_to_lose_on_recreate_ = 0;
190 times_to_fail_create_offscreen_ = times_to_fail_recreate_offscreen_;
191 times_to_fail_recreate_offscreen_ = 0;
192 times_to_lose_on_create_offscreen_ = times_to_lose_on_recreate_offscreen_;
193 times_to_lose_on_recreate_offscreen_ = 0;
194 }
195
196 virtual void willRetryRecreateOutputSurface() OVERRIDE {
197 ++times_recreate_retried_;
198 }
199
200 virtual void afterTest() OVERRIDE {
201 EXPECT_EQ(times_to_expect_recreate_retried_, times_recreate_retried_);
202 }
203
204 void ExpectRecreateToRetry() {
205 ++times_to_expect_recreate_retried_;
119 } 206 }
120 207
121 protected: 208 protected:
122 FakeWebGraphicsContext3D* context3d_; 209 FakeWebGraphicsContext3D* context3d_;
123 int times_to_fail_create_; 210 int times_to_fail_create_;
124 int times_to_fail_initialize_; 211 int times_to_fail_initialize_;
125 int times_to_lose_on_create_; 212 int times_to_lose_on_create_;
126 int times_to_lose_during_commit_; 213 int times_to_lose_during_commit_;
127 int times_to_lose_during_draw_; 214 int times_to_lose_during_draw_;
128 int times_to_fail_reinitialize_; 215 int times_to_fail_reinitialize_;
129 int times_to_fail_recreate_; 216 int times_to_fail_recreate_;
130 int times_to_lose_on_recreate_; 217 int times_to_lose_on_recreate_;
218 int times_to_fail_create_offscreen_;
219 int times_to_lose_on_create_offscreen_;
220 int times_to_fail_recreate_offscreen_;
221 int times_to_lose_on_recreate_offscreen_;
222 int times_to_expect_recreate_retried_;
223 int times_recreate_retried_;
224
225 scoped_ptr<WebKit::WebGraphicsContext3D> offscreen_context3d_;
131 }; 226 };
132 227
133 class LayerTreeHostContextTestLostContextSucceeds : 228 class LayerTreeHostContextTestLostContextSucceeds :
134 public LayerTreeHostContextTest { 229 public LayerTreeHostContextTest {
135 public: 230 public:
136 LayerTreeHostContextTestLostContextSucceeds() 231 LayerTreeHostContextTestLostContextSucceeds()
137 : LayerTreeHostContextTest(), 232 : LayerTreeHostContextTest(),
138 test_case_(0), 233 test_case_(0),
139 num_losses_(0), 234 num_losses_(0),
140 recovered_context_(true) { 235 recovered_context_(true) {
141 } 236 }
142 237
143 virtual void beginTest() OVERRIDE { 238 virtual void beginTest() OVERRIDE {
144 postSetNeedsCommitToMainThread(); 239 postSetNeedsCommitToMainThread();
145 } 240 }
146 241
147 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { 242 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE {
148 EXPECT_TRUE(succeeded); 243 EXPECT_TRUE(succeeded);
149 ++num_losses_; 244 ++num_losses_;
150 recovered_context_ = true; 245 recovered_context_ = true;
151 } 246 }
152 247
153 virtual void afterTest() OVERRIDE { 248 virtual void afterTest() OVERRIDE {
154 EXPECT_EQ(8, test_case_); 249 LayerTreeHostContextTest::afterTest();
155 EXPECT_EQ(6 + 10 + 10, num_losses_); 250 EXPECT_EQ(12, test_case_);
251 EXPECT_EQ(10 + 10 + 10, num_losses_);
156 } 252 }
157 253
158 virtual void didCommitAndDrawFrame() OVERRIDE { 254 virtual void didCommitAndDrawFrame() OVERRIDE {
159 // If the last frame had a context loss, then we'll commit again to 255 // If the last frame had a context loss, then we'll commit again to
160 // recover. 256 // recover.
161 if (!recovered_context_) 257 if (!recovered_context_)
162 return; 258 return;
163 if (times_to_lose_during_commit_) 259 if (times_to_lose_during_commit_)
164 return; 260 return;
165 if (times_to_lose_during_draw_) 261 if (times_to_lose_during_draw_)
(...skipping 12 matching lines...) Expand all
178 274
179 bool NextTestCase() { 275 bool NextTestCase() {
180 static const TestCase kTests[] = { 276 static const TestCase kTests[] = {
181 // Losing the context and failing to recreate it (or losing it again 277 // Losing the context and failing to recreate it (or losing it again
182 // immediately) a small number of times should succeed. 278 // immediately) a small number of times should succeed.
183 { 1, // times_to_lose_during_commit 279 { 1, // times_to_lose_during_commit
184 0, // times_to_lose_during_draw 280 0, // times_to_lose_during_draw
185 3, // times_to_fail_reinitialize 281 3, // times_to_fail_reinitialize
186 0, // times_to_fail_recreate 282 0, // times_to_fail_recreate
187 0, // times_to_lose_on_recreate 283 0, // times_to_lose_on_recreate
284 0, // times_to_fail_recreate_offscreen;
285 0, // times_to_lose_on_recreate_offscreen;
188 }, 286 },
189 { 0, // times_to_lose_during_commit 287 { 0, // times_to_lose_during_commit
190 1, // times_to_lose_during_draw 288 1, // times_to_lose_during_draw
191 3, // times_to_fail_reinitialize 289 3, // times_to_fail_reinitialize
192 0, // times_to_fail_recreate 290 0, // times_to_fail_recreate
193 0, // times_to_lose_on_recreate 291 0, // times_to_lose_on_recreate
292 0, // times_to_fail_recreate_offscreen;
293 0, // times_to_lose_on_recreate_offscreen;
194 }, 294 },
195 { 1, // times_to_lose_during_commit 295 { 1, // times_to_lose_during_commit
196 0, // times_to_lose_during_draw 296 0, // times_to_lose_during_draw
197 0, // times_to_fail_reinitialize 297 0, // times_to_fail_reinitialize
198 3, // times_to_fail_recreate 298 3, // times_to_fail_recreate
199 0, // times_to_lose_on_recreate 299 0, // times_to_lose_on_recreate
300 0, // times_to_fail_recreate_offscreen;
301 0, // times_to_lose_on_recreate_offscreen;
200 }, 302 },
201 { 0, // times_to_lose_during_commit 303 { 0, // times_to_lose_during_commit
202 1, // times_to_lose_during_draw 304 1, // times_to_lose_during_draw
203 0, // times_to_fail_reinitialize 305 0, // times_to_fail_reinitialize
204 3, // times_to_fail_recreate 306 3, // times_to_fail_recreate
205 0, // times_to_lose_on_recreate 307 0, // times_to_lose_on_recreate
308 0, // times_to_fail_recreate_offscreen;
309 0, // times_to_lose_on_recreate_offscreen;
206 }, 310 },
207 { 1, // times_to_lose_during_commit 311 { 1, // times_to_lose_during_commit
208 0, // times_to_lose_during_draw 312 0, // times_to_lose_during_draw
209 0, // times_to_fail_reinitialize 313 0, // times_to_fail_reinitialize
210 0, // times_to_fail_recreate 314 0, // times_to_fail_recreate
211 3, // times_to_lose_on_recreate 315 3, // times_to_lose_on_recreate
316 0, // times_to_fail_recreate_offscreen;
317 0, // times_to_lose_on_recreate_offscreen;
212 }, 318 },
213 { 0, // times_to_lose_during_commit 319 { 0, // times_to_lose_during_commit
214 1, // times_to_lose_during_draw 320 1, // times_to_lose_during_draw
215 0, // times_to_fail_reinitialize 321 0, // times_to_fail_reinitialize
216 0, // times_to_fail_recreate 322 0, // times_to_fail_recreate
217 3, // times_to_lose_on_recreate 323 3, // times_to_lose_on_recreate
324 0, // times_to_fail_recreate_offscreen;
325 0, // times_to_lose_on_recreate_offscreen;
326 },
327 { 1, // times_to_lose_during_commit
328 0, // times_to_lose_during_draw
329 0, // times_to_fail_reinitialize
330 0, // times_to_fail_recreate
331 0, // times_to_lose_on_recreate
332 3, // times_to_fail_recreate_offscreen;
333 0, // times_to_lose_on_recreate_offscreen;
334 },
335 { 0, // times_to_lose_during_commit
336 1, // times_to_lose_during_draw
337 0, // times_to_fail_reinitialize
338 0, // times_to_fail_recreate
339 0, // times_to_lose_on_recreate
340 3, // times_to_fail_recreate_offscreen;
341 0, // times_to_lose_on_recreate_offscreen;
342 },
343 { 1, // times_to_lose_during_commit
344 0, // times_to_lose_during_draw
345 0, // times_to_fail_reinitialize
346 0, // times_to_fail_recreate
347 0, // times_to_lose_on_recreate
348 3, // times_to_fail_recreate_offscreen;
349 0, // times_to_lose_on_recreate_offscreen;
350 },
351 { 0, // times_to_lose_during_commit
352 1, // times_to_lose_during_draw
353 0, // times_to_fail_reinitialize
354 0, // times_to_fail_recreate
355 0, // times_to_lose_on_recreate
356 0, // times_to_fail_recreate_offscreen;
357 3, // times_to_lose_on_recreate_offscreen;
218 }, 358 },
219 // Losing the context and recreating it any number of times should 359 // Losing the context and recreating it any number of times should
220 // succeed. 360 // succeed.
221 { 10, // times_to_lose_during_commit 361 { 10, // times_to_lose_during_commit
222 0, // times_to_lose_during_draw 362 0, // times_to_lose_during_draw
223 0, // times_to_fail_reinitialize 363 0, // times_to_fail_reinitialize
224 0, // times_to_fail_recreate 364 0, // times_to_fail_recreate
225 0, // times_to_lose_on_recreate 365 0, // times_to_lose_on_recreate
366 0, // times_to_fail_recreate_offscreen;
367 0, // times_to_lose_on_recreate_offscreen;
226 }, 368 },
227 { 0, // times_to_lose_during_commit 369 { 0, // times_to_lose_during_commit
228 10, // times_to_lose_during_draw 370 10, // times_to_lose_during_draw
229 0, // times_to_fail_reinitialize 371 0, // times_to_fail_reinitialize
230 0, // times_to_fail_recreate 372 0, // times_to_fail_recreate
231 0, // times_to_lose_on_recreate 373 0, // times_to_lose_on_recreate
374 0, // times_to_fail_recreate_offscreen;
375 0, // times_to_lose_on_recreate_offscreen;
232 }, 376 },
233 }; 377 };
234 378
235 if (test_case_ >= arraysize(kTests)) 379 if (test_case_ >= arraysize(kTests))
236 return false; 380 return false;
237 381
238 times_to_lose_during_commit_ = 382 times_to_lose_during_commit_ =
239 kTests[test_case_].times_to_lose_during_commit; 383 kTests[test_case_].times_to_lose_during_commit;
240 times_to_lose_during_draw_ = 384 times_to_lose_during_draw_ =
241 kTests[test_case_].times_to_lose_during_draw; 385 kTests[test_case_].times_to_lose_during_draw;
242 times_to_fail_reinitialize_ = kTests[test_case_].times_to_fail_reinitialize; 386 times_to_fail_reinitialize_ = kTests[test_case_].times_to_fail_reinitialize;
243 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate; 387 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; 388 times_to_lose_on_recreate_ = kTests[test_case_].times_to_lose_on_recreate;
389 times_to_fail_recreate_offscreen_ = kTests[test_case_].times_to_fail_recreat e_offscreen;
390 times_to_lose_on_recreate_offscreen_ = kTests[test_case_].times_to_lose_on_r ecreate_offscreen;
245 ++test_case_; 391 ++test_case_;
246 return true; 392 return true;
247 } 393 }
248 394
249 struct TestCase { 395 struct TestCase {
250 int times_to_lose_during_commit; 396 int times_to_lose_during_commit;
251 int times_to_lose_during_draw; 397 int times_to_lose_during_draw;
252 int times_to_fail_reinitialize; 398 int times_to_fail_reinitialize;
253 int times_to_fail_recreate; 399 int times_to_fail_recreate;
254 int times_to_lose_on_recreate; 400 int times_to_lose_on_recreate;
401 int times_to_fail_recreate_offscreen;
402 int times_to_lose_on_recreate_offscreen;
255 }; 403 };
256 404
257 private: 405 private:
258 size_t test_case_; 406 size_t test_case_;
259 int num_losses_; 407 int num_losses_;
260 bool recovered_context_; 408 bool recovered_context_;
261 }; 409 };
262 410
263 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds) 411 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds)
264 412
265 class LayerTreeHostContextTestLostContextSucceedsWithContent : 413 class LayerTreeHostContextTestLostContextSucceedsWithContent :
266 public LayerTreeHostContextTestLostContextSucceeds { 414 public LayerTreeHostContextTestLostContextSucceeds {
267 public: 415 public:
268 416
269 LayerTreeHostContextTestLostContextSucceedsWithContent() 417 LayerTreeHostContextTestLostContextSucceedsWithContent()
270 : LayerTreeHostContextTestLostContextSucceeds() { 418 : LayerTreeHostContextTestLostContextSucceeds() {
271 } 419 }
272 420
273 virtual void setupTree() OVERRIDE { 421 virtual void setupTree() OVERRIDE {
274 root_ = Layer::create(); 422 root_ = Layer::create();
275 root_->setBounds(gfx::Size(10, 10)); 423 root_->setBounds(gfx::Size(10, 10));
276 root_->setAnchorPoint(gfx::PointF()); 424 root_->setAnchorPoint(gfx::PointF());
277 root_->setIsDrawable(true); 425 root_->setIsDrawable(true);
278 426
279 content_ = FakeContentLayer::Create(&client_); 427 content_ = FakeContentLayer::Create(&client_);
280 content_->setBounds(gfx::Size(10, 10)); 428 content_->setBounds(gfx::Size(10, 10));
281 content_->setAnchorPoint(gfx::PointF()); 429 content_->setAnchorPoint(gfx::PointF());
282 content_->setIsDrawable(true); 430 content_->setIsDrawable(true);
283 if (use_surface_) { 431 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); 432 content_->setForceRenderSurface(true);
433 // Filters require us to create an offscreen context.
434 WebKit::WebFilterOperations filters;
435 filters.append(WebKit::WebFilterOperation::createGrayscaleFilter(0.5f));
436 content_->setFilters(filters);
437 content_->setBackgroundFilters(filters);
287 } 438 }
288 439
289 root_->addChild(content_); 440 root_->addChild(content_);
290 441
291 m_layerTreeHost->setRootLayer(root_); 442 m_layerTreeHost->setRootLayer(root_);
292 LayerTreeHostContextTest::setupTree(); 443 LayerTreeHostContextTest::setupTree();
293 } 444 }
294 445
295 virtual void InvalidateAndSetNeedsCommit() OVERRIDE { 446 virtual void InvalidateAndSetNeedsCommit() OVERRIDE {
296 // Invalidate the render surface so we don't try to use a cached copy of the 447 // 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 448 // surface. We want to make sure to test the drawing paths for drawing to
298 // a child surface. 449 // a child surface.
299 content_->setNeedsDisplay(); 450 content_->setNeedsDisplay();
300 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit(); 451 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit();
301 } 452 }
302 453
303 virtual void drawLayersOnThread(LayerTreeHostImpl* host_impl) { 454 virtual void drawLayersOnThread(LayerTreeHostImpl* host_impl) {
304 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>( 455 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>(
305 host_impl->rootLayer()->children()[0]); 456 host_impl->rootLayer()->children()[0]);
306 // Even though the context was lost, we should have a resource. The 457 // Even though the context was lost, we should have a resource. The
307 // FakeWebGraphicsContext3D ensures that this resource is created with 458 // FakeWebGraphicsContext3D ensures that this resource is created with
308 // the active context. 459 // the active context.
309 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); 460 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0));
461
462 GaneshResourceProvider::ScopedContexts contexts(
463 host_impl->resourceProvider()->ganeshResourceProvider());
464 if (use_surface_)
465 EXPECT_TRUE(contexts.context3d());
466 else
467 EXPECT_FALSE(contexts.context3d());
310 } 468 }
311 469
312 protected: 470 protected:
313 bool use_surface_; 471 bool use_surface_;
314 FakeContentLayerClient client_; 472 FakeContentLayerClient client_;
315 scoped_refptr<Layer> root_; 473 scoped_refptr<Layer> root_;
316 scoped_refptr<ContentLayer> content_; 474 scoped_refptr<ContentLayer> content_;
317 }; 475 };
318 476
319 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, 477 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 EXPECT_TRUE(host_impl->resourceProvider()); 527 EXPECT_TRUE(host_impl->resourceProvider());
370 return; 528 return;
371 } 529 }
372 530
373 // When context recreation fails we shouldn't be left with any of them. 531 // When context recreation fails we shouldn't be left with any of them.
374 EXPECT_FALSE(host_impl->outputSurface()); 532 EXPECT_FALSE(host_impl->outputSurface());
375 EXPECT_FALSE(host_impl->renderer()); 533 EXPECT_FALSE(host_impl->renderer());
376 EXPECT_FALSE(host_impl->resourceProvider()); 534 EXPECT_FALSE(host_impl->resourceProvider());
377 } 535 }
378 536
379 virtual void afterTest() OVERRIDE {}
380
381 private: 537 private:
382 int num_commits_; 538 int num_commits_;
383 }; 539 };
384 540
385 TEST_F(LayerTreeHostContextTestLostContextFails, FailReinitialize100_SingleThrea d) { 541 TEST_F(LayerTreeHostContextTestLostContextFails, FailReinitialize100_SingleThrea d) {
386 times_to_fail_reinitialize_ = 100; 542 times_to_fail_reinitialize_ = 100;
387 times_to_fail_recreate_ = 0; 543 times_to_fail_recreate_ = 0;
388 times_to_lose_on_recreate_ = 0; 544 times_to_lose_on_recreate_ = 0;
389 runTest(false); 545 runTest(false);
390 } 546 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 times_to_lose_during_commit_ = 1; 588 times_to_lose_during_commit_ = 1;
433 times_to_fail_reinitialize_ = 10; 589 times_to_fail_reinitialize_ = 10;
434 postSetNeedsCommitToMainThread(); 590 postSetNeedsCommitToMainThread();
435 } 591 }
436 592
437 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { 593 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE {
438 EXPECT_FALSE(succeeded); 594 EXPECT_FALSE(succeeded);
439 m_layerTreeHost->finishAllRendering(); 595 m_layerTreeHost->finishAllRendering();
440 endTest(); 596 endTest();
441 } 597 }
442
443 virtual void afterTest() OVERRIDE {}
444 }; 598 };
445 599
446 SINGLE_AND_MULTI_THREAD_TEST_F( 600 SINGLE_AND_MULTI_THREAD_TEST_F(
447 LayerTreeHostContextTestFinishAllRenderingAfterLoss) 601 LayerTreeHostContextTestFinishAllRenderingAfterLoss)
448 602
449 class LayerTreeHostContextTestLostContextAndEvictTextures : 603 class LayerTreeHostContextTestLostContextAndEvictTextures :
450 public LayerTreeHostContextTest { 604 public LayerTreeHostContextTest {
451 public: 605 public:
452 LayerTreeHostContextTestLostContextAndEvictTextures() 606 LayerTreeHostContextTestLostContextAndEvictTextures()
453 : LayerTreeHostContextTest(), 607 : LayerTreeHostContextTest(),
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 if (!lose_after_evict_) 653 if (!lose_after_evict_)
500 LoseContext(); 654 LoseContext();
501 impl_host_ = impl; 655 impl_host_ = impl;
502 } 656 }
503 657
504 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { 658 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE {
505 EXPECT_TRUE(succeeded); 659 EXPECT_TRUE(succeeded);
506 endTest(); 660 endTest();
507 } 661 }
508 662
509 virtual void afterTest() OVERRIDE {}
510
511 protected: 663 protected:
512 bool lose_after_evict_; 664 bool lose_after_evict_;
513 FakeContentLayerClient client_; 665 FakeContentLayerClient client_;
514 scoped_refptr<FakeContentLayer> layer_; 666 scoped_refptr<FakeContentLayer> layer_;
515 LayerTreeHostImpl* impl_host_; 667 LayerTreeHostImpl* impl_host_;
516 int num_commits_; 668 int num_commits_;
517 }; 669 };
518 670
519 TEST_F(LayerTreeHostContextTestLostContextAndEvictTextures, 671 TEST_F(LayerTreeHostContextTestLostContextAndEvictTextures,
520 LoseAfterEvict_SingleThread) { 672 LoseAfterEvict_SingleThread) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 732
581 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) { 733 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) {
582 endTest(); 734 endTest();
583 } 735 }
584 736
585 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { 737 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE {
586 EXPECT_TRUE(succeeded); 738 EXPECT_TRUE(succeeded);
587 } 739 }
588 740
589 virtual void afterTest() { 741 virtual void afterTest() {
742 LayerTreeHostContextTest::afterTest();
590 EXPECT_EQ(0, times_to_lose_on_end_query_); 743 EXPECT_EQ(0, times_to_lose_on_end_query_);
591 } 744 }
592 745
593 private: 746 private:
594 FakeContentLayerClient client_; 747 FakeContentLayerClient client_;
595 scoped_refptr<FakeContentLayer> parent_; 748 scoped_refptr<FakeContentLayer> parent_;
596 int num_children_; 749 int num_children_;
597 int times_to_lose_on_end_query_; 750 int times_to_lose_on_end_query_;
598 }; 751 };
599 752
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 EXPECT_EQ(5u, root->lost_output_surface_count()); 815 EXPECT_EQ(5u, root->lost_output_surface_count());
663 EXPECT_EQ(5u, child->lost_output_surface_count()); 816 EXPECT_EQ(5u, child->lost_output_surface_count());
664 EXPECT_EQ(5u, grandchild->lost_output_surface_count()); 817 EXPECT_EQ(5u, grandchild->lost_output_surface_count());
665 endTest(); 818 endTest();
666 break; 819 break;
667 default: 820 default:
668 NOTREACHED(); 821 NOTREACHED();
669 } 822 }
670 } 823 }
671 824
672 virtual void afterTest() OVERRIDE {}
673
674 private: 825 private:
675 int num_commits_; 826 int num_commits_;
676 827
677 FakeContentLayerClient client_; 828 FakeContentLayerClient client_;
678 scoped_refptr<FakeContentLayer> root_; 829 scoped_refptr<FakeContentLayer> root_;
679 scoped_refptr<FakeContentLayer> child_; 830 scoped_refptr<FakeContentLayer> child_;
680 scoped_refptr<FakeContentLayer> grandchild_; 831 scoped_refptr<FakeContentLayer> grandchild_;
681 }; 832 };
682 833
683 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLayersNotified) 834 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLayersNotified)
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 } 1014 }
864 return true; 1015 return true;
865 } 1016 }
866 1017
867 virtual void didCommitAndDrawFrame() OVERRIDE { 1018 virtual void didCommitAndDrawFrame() OVERRIDE {
868 // End the test once we know the 3nd frame drew. 1019 // End the test once we know the 3nd frame drew.
869 if (m_layerTreeHost->commitNumber() == 4) 1020 if (m_layerTreeHost->commitNumber() == 4)
870 endTest(); 1021 endTest();
871 } 1022 }
872 1023
873 virtual void afterTest() OVERRIDE {}
874
875 private: 1024 private:
876 FakeContentLayerClient client_; 1025 FakeContentLayerClient client_;
877 1026
878 scoped_refptr<Layer> root_; 1027 scoped_refptr<Layer> root_;
879 scoped_refptr<DelegatedRendererLayer> delegated_; 1028 scoped_refptr<DelegatedRendererLayer> delegated_;
880 scoped_refptr<ContentLayer> content_; 1029 scoped_refptr<ContentLayer> content_;
881 scoped_refptr<TextureLayer> texture_; 1030 scoped_refptr<TextureLayer> texture_;
882 scoped_refptr<ContentLayer> mask_; 1031 scoped_refptr<ContentLayer> mask_;
883 scoped_refptr<ContentLayer> content_with_mask_; 1032 scoped_refptr<ContentLayer> content_with_mask_;
884 scoped_refptr<VideoLayer> video_color_; 1033 scoped_refptr<VideoLayer> video_color_;
(...skipping 20 matching lines...) Expand all
905 LayerTreeHostContextTestFailsImmediately() 1054 LayerTreeHostContextTestFailsImmediately()
906 : LayerTreeHostContextTest() { 1055 : LayerTreeHostContextTest() {
907 } 1056 }
908 1057
909 virtual ~LayerTreeHostContextTestFailsImmediately() {} 1058 virtual ~LayerTreeHostContextTestFailsImmediately() {}
910 1059
911 virtual void beginTest() OVERRIDE { 1060 virtual void beginTest() OVERRIDE {
912 postSetNeedsCommitToMainThread(); 1061 postSetNeedsCommitToMainThread();
913 } 1062 }
914 1063
915 virtual void afterTest() OVERRIDE {
916 }
917
918 virtual scoped_ptr<FakeWebGraphicsContext3D> CreateContext3d() OVERRIDE { 1064 virtual scoped_ptr<FakeWebGraphicsContext3D> CreateContext3d() OVERRIDE {
919 scoped_ptr<FakeWebGraphicsContext3D> context = 1065 scoped_ptr<FakeWebGraphicsContext3D> context =
920 LayerTreeHostContextTest::CreateContext3d(); 1066 LayerTreeHostContextTest::CreateContext3d();
921 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 1067 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
922 GL_INNOCENT_CONTEXT_RESET_ARB); 1068 GL_INNOCENT_CONTEXT_RESET_ARB);
923 return context.Pass(); 1069 return context.Pass();
924 } 1070 }
925 1071
926 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { 1072 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE {
927 EXPECT_FALSE(succeeded); 1073 EXPECT_FALSE(succeeded);
(...skipping 29 matching lines...) Expand all
957 1103
958 m_layerTreeHost->setRootLayer(root); 1104 m_layerTreeHost->setRootLayer(root);
959 LayerTreeHostContextTest::setupTree(); 1105 LayerTreeHostContextTest::setupTree();
960 } 1106 }
961 1107
962 virtual void beginTest() OVERRIDE { 1108 virtual void beginTest() OVERRIDE {
963 times_to_lose_during_commit_ = 1; 1109 times_to_lose_during_commit_ = 1;
964 postSetNeedsCommitToMainThread(); 1110 postSetNeedsCommitToMainThread();
965 } 1111 }
966 1112
967 virtual void afterTest() OVERRIDE {}
968
969 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { 1113 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE {
970 EXPECT_TRUE(succeeded); 1114 EXPECT_TRUE(succeeded);
971 endTest(); 1115 endTest();
972 } 1116 }
973 1117
974 private: 1118 private:
975 FakeContentLayerClient client_; 1119 FakeContentLayerClient client_;
976 }; 1120 };
977 1121
978 MULTI_THREAD_TEST_F(LayerTreeHostContextTestImplSidePainting) 1122 MULTI_THREAD_TEST_F(LayerTreeHostContextTestImplSidePainting)
979 1123
980 class ScrollbarLayerLostContext : public LayerTreeHostContextTest { 1124 class ScrollbarLayerLostContext : public LayerTreeHostContextTest {
981 public: 1125 public:
982 ScrollbarLayerLostContext() : commits_(0) {} 1126 ScrollbarLayerLostContext() : commits_(0) {}
983 1127
984 virtual void beginTest() OVERRIDE { 1128 virtual void beginTest() OVERRIDE {
985 scoped_refptr<Layer> scroll_layer = Layer::create(); 1129 scoped_refptr<Layer> scroll_layer = Layer::create();
986 scrollbar_layer_ = FakeScrollbarLayer::Create( 1130 scrollbar_layer_ = FakeScrollbarLayer::Create(
987 false, true, scroll_layer->id()); 1131 false, true, scroll_layer->id());
988 scrollbar_layer_->setBounds(gfx::Size(10, 100)); 1132 scrollbar_layer_->setBounds(gfx::Size(10, 100));
989 m_layerTreeHost->rootLayer()->addChild(scrollbar_layer_); 1133 m_layerTreeHost->rootLayer()->addChild(scrollbar_layer_);
990 m_layerTreeHost->rootLayer()->addChild(scroll_layer); 1134 m_layerTreeHost->rootLayer()->addChild(scroll_layer);
991 postSetNeedsCommitToMainThread(); 1135 postSetNeedsCommitToMainThread();
992 } 1136 }
993 1137
994 virtual void afterTest() OVERRIDE {
995 }
996
997 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1138 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
998 ++commits_; 1139 ++commits_;
999 size_t upload_count = scrollbar_layer_->last_update_full_upload_size() + 1140 size_t upload_count = scrollbar_layer_->last_update_full_upload_size() +
1000 scrollbar_layer_->last_update_partial_upload_size(); 1141 scrollbar_layer_->last_update_partial_upload_size();
1001 switch(commits_) { 1142 switch(commits_) {
1002 case 1: 1143 case 1:
1003 // First (regular) update, we should upload 2 resources (thumb, and 1144 // First (regular) update, we should upload 2 resources (thumb, and
1004 // backtrack). 1145 // backtrack).
1005 EXPECT_EQ(1, scrollbar_layer_->update_count()); 1146 EXPECT_EQ(1, scrollbar_layer_->update_count());
1006 EXPECT_EQ(2, upload_count); 1147 EXPECT_EQ(2, upload_count);
(...skipping 13 matching lines...) Expand all
1020 1161
1021 private: 1162 private:
1022 int commits_; 1163 int commits_;
1023 scoped_refptr<FakeScrollbarLayer> scrollbar_layer_; 1164 scoped_refptr<FakeScrollbarLayer> scrollbar_layer_;
1024 }; 1165 };
1025 1166
1026 SINGLE_AND_MULTI_THREAD_TEST_F(ScrollbarLayerLostContext) 1167 SINGLE_AND_MULTI_THREAD_TEST_F(ScrollbarLayerLostContext)
1027 1168
1028 } // namespace 1169 } // namespace
1029 } // namespace cc 1170 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698