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

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: Restart with GrContext owned in cc 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_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_fail_recreate_offscreen_(0),
61 times_to_expect_recreate_retried_(0),
62 times_recreate_retried_(0) {
57 media::InitializeMediaLibraryForTesting(); 63 media::InitializeMediaLibraryForTesting();
58 } 64 }
59 65
60 void LoseContext() { 66 void LoseContext() {
61 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 67 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
62 GL_INNOCENT_CONTEXT_RESET_ARB); 68 GL_INNOCENT_CONTEXT_RESET_ARB);
63 context3d_ = NULL; 69 context3d_ = NULL;
64 } 70 }
65 71
66 virtual scoped_ptr<FakeWebGraphicsContext3D> CreateContext3d() { 72 virtual scoped_ptr<FakeWebGraphicsContext3D> CreateContext3d() {
67 return FakeWebGraphicsContext3D::Create(); 73 return FakeWebGraphicsContext3D::Create();
68 } 74 }
69 75
70 virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE { 76 virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE {
71 if (times_to_fail_create_) { 77 if (times_to_fail_create_) {
72 --times_to_fail_create_; 78 --times_to_fail_create_;
79 ExpectRecreateToRetry();
73 return scoped_ptr<OutputSurface>(); 80 return scoped_ptr<OutputSurface>();
74 } 81 }
75 82
76 scoped_ptr<FakeWebGraphicsContext3D> context3d = CreateContext3d(); 83 scoped_ptr<FakeWebGraphicsContext3D> context3d = CreateContext3d();
77 context3d_ = context3d.get(); 84 context3d_ = context3d.get();
78 85
79 if (times_to_fail_initialize_) { 86 if (times_to_fail_initialize_) {
80 --times_to_fail_initialize_; 87 --times_to_fail_initialize_;
81 // Make the context get lost during reinitialization. 88 // Make the context get lost during reinitialization.
82 // The number of times MakeCurrent succeeds is not important, and 89 // The number of times MakeCurrent succeeds is not important, and
83 // can be changed if needed to make this pass with future changes. 90 // can be changed if needed to make this pass with future changes.
84 context3d_->set_times_make_current_succeeds(2); 91 context3d_->set_times_make_current_succeeds(2);
92 ExpectRecreateToRetry();
85 } else if (times_to_lose_on_create_) { 93 } else if (times_to_lose_on_create_) {
86 --times_to_lose_on_create_; 94 --times_to_lose_on_create_;
87 LoseContext(); 95 LoseContext();
96 ExpectRecreateToRetry();
88 } 97 }
89 98
90 return FakeOutputSurface::Create3d( 99 return FakeOutputSurface::Create3d(
91 context3d.PassAs<WebGraphicsContext3D>()).PassAs<OutputSurface>(); 100 context3d.PassAs<WebGraphicsContext3D>()).PassAs<OutputSurface>();
92 } 101 }
93 102
94 virtual bool prepareToDrawOnThread( 103 WebKit::WebGraphicsContext3D* CreateOffscreenContext3d() {
95 LayerTreeHostImpl*, LayerTreeHostImpl::FrameData&, bool result) 104 DCHECK(!offscreen_context3d_);
96 OVERRIDE {
97 EXPECT_TRUE(result);
98 if (!times_to_lose_during_draw_)
99 return result;
100 105
101 --times_to_lose_during_draw_; 106 if (times_to_fail_create_offscreen_) {
102 if (context3d_) 107 --times_to_fail_create_offscreen_;
103 context3d_->set_times_make_current_succeeds(0); 108 ExpectRecreateToRetry();
109 return NULL;
110 }
111
112 WebKit::WebGraphicsContext3D::Attributes attrs;
113 offscreen_context3d_ =
114 FakeWebGraphicsContext3D::Create(attrs)
115 .PassAs<WebKit::WebGraphicsContext3D>();
116 DCHECK(offscreen_context3d_);
117 return offscreen_context3d_.get();
118 }
119
120 // LayerTreeHostClient implementation.
121 virtual WebKit::WebGraphicsContext3D* OffscreenContext3dForMainThread()
122 OVERRIDE {
123 DCHECK(!implThread());
124
125 if (!offscreen_context3d_)
126 CreateOffscreenContext3d();
127 return offscreen_context3d_.get();
128 }
129
130 // LayerTreeHostClient implementation.
131 virtual WebKit::WebGraphicsContext3D* OffscreenContext3dForCompositorThread()
132 OVERRIDE {
133 DCHECK(implThread());
134
135 if (!offscreen_context3d_)
136 CreateOffscreenContext3d();
137 return offscreen_context3d_.get();
138 }
139
140 virtual bool prepareToDrawOnThread(
141 LayerTreeHostImpl*, LayerTreeHostImpl::FrameData&, bool result)
142 OVERRIDE {
143 EXPECT_TRUE(result);
144 if (!times_to_lose_during_draw_)
104 return result; 145 return result;
105 } 146
147 --times_to_lose_during_draw_;
148 if (context3d_)
149 context3d_->set_times_make_current_succeeds(0);
150 return result;
151 }
106 152
107 virtual void commitCompleteOnThread(LayerTreeHostImpl *host_impl) OVERRIDE { 153 virtual void commitCompleteOnThread(LayerTreeHostImpl *host_impl) OVERRIDE {
108 if (!times_to_lose_during_commit_) 154 if (!times_to_lose_during_commit_)
109 return; 155 return;
110 --times_to_lose_during_commit_; 156 --times_to_lose_during_commit_;
111 LoseContext(); 157 LoseContext();
112 158
113 times_to_fail_create_ = times_to_fail_recreate_; 159 times_to_fail_create_ = times_to_fail_recreate_;
114 times_to_fail_recreate_ = 0; 160 times_to_fail_recreate_ = 0;
115 times_to_fail_initialize_ = times_to_fail_reinitialize_; 161 times_to_fail_initialize_ = times_to_fail_reinitialize_;
116 times_to_fail_reinitialize_ = 0; 162 times_to_fail_reinitialize_ = 0;
117 times_to_lose_on_create_ = times_to_lose_on_recreate_; 163 times_to_lose_on_create_ = times_to_lose_on_recreate_;
118 times_to_lose_on_recreate_ = 0; 164 times_to_lose_on_recreate_ = 0;
165 times_to_fail_create_offscreen_ = times_to_fail_recreate_offscreen_;
166 times_to_fail_recreate_offscreen_ = 0;
167 }
168
169 virtual void willRetryRecreateOutputSurface() OVERRIDE {
170 ++times_recreate_retried_;
171 }
172
173 virtual void TearDown() OVERRIDE {
174 ThreadedTest::TearDown();
175 EXPECT_EQ(times_to_expect_recreate_retried_, times_recreate_retried_);
176 }
177
178 void ExpectRecreateToRetry() {
179 ++times_to_expect_recreate_retried_;
119 } 180 }
120 181
121 protected: 182 protected:
122 FakeWebGraphicsContext3D* context3d_; 183 FakeWebGraphicsContext3D* context3d_;
123 int times_to_fail_create_; 184 int times_to_fail_create_;
124 int times_to_fail_initialize_; 185 int times_to_fail_initialize_;
125 int times_to_lose_on_create_; 186 int times_to_lose_on_create_;
126 int times_to_lose_during_commit_; 187 int times_to_lose_during_commit_;
127 int times_to_lose_during_draw_; 188 int times_to_lose_during_draw_;
128 int times_to_fail_reinitialize_; 189 int times_to_fail_reinitialize_;
129 int times_to_fail_recreate_; 190 int times_to_fail_recreate_;
130 int times_to_lose_on_recreate_; 191 int times_to_lose_on_recreate_;
192 int times_to_fail_create_offscreen_;
193 int times_to_fail_recreate_offscreen_;
194 int times_to_expect_recreate_retried_;
195 int times_recreate_retried_;
196
197 scoped_ptr<WebKit::WebGraphicsContext3D> offscreen_context3d_;
131 }; 198 };
132 199
133 class LayerTreeHostContextTestLostContextSucceeds : 200 class LayerTreeHostContextTestLostContextSucceeds :
134 public LayerTreeHostContextTest { 201 public LayerTreeHostContextTest {
135 public: 202 public:
136 LayerTreeHostContextTestLostContextSucceeds() 203 LayerTreeHostContextTestLostContextSucceeds()
137 : LayerTreeHostContextTest(), 204 : LayerTreeHostContextTest(),
138 test_case_(0), 205 test_case_(0),
139 num_losses_(0), 206 num_losses_(0),
140 recovered_context_(true) { 207 recovered_context_(true) {
141 } 208 }
142 209
143 virtual void beginTest() OVERRIDE { 210 virtual void beginTest() OVERRIDE {
144 postSetNeedsCommitToMainThread(); 211 postSetNeedsCommitToMainThread();
145 } 212 }
146 213
147 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { 214 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE {
148 EXPECT_TRUE(succeeded); 215 EXPECT_TRUE(succeeded);
149 ++num_losses_; 216 ++num_losses_;
150 recovered_context_ = true; 217 recovered_context_ = true;
151 } 218 }
152 219
153 virtual void afterTest() OVERRIDE { 220 virtual void afterTest() OVERRIDE {
154 EXPECT_EQ(8, test_case_); 221 EXPECT_EQ(12, test_case_);
155 EXPECT_EQ(6 + 10 + 10, num_losses_); 222 EXPECT_EQ(10 + 10 + 10, num_losses_);
156 } 223 }
157 224
158 virtual void didCommitAndDrawFrame() OVERRIDE { 225 virtual void didCommitAndDrawFrame() OVERRIDE {
159 // If the last frame had a context loss, then we'll commit again to 226 // If the last frame had a context loss, then we'll commit again to
160 // recover. 227 // recover.
161 if (!recovered_context_) 228 if (!recovered_context_)
162 return; 229 return;
163 if (times_to_lose_during_commit_) 230 if (times_to_lose_during_commit_)
164 return; 231 return;
165 if (times_to_lose_during_draw_) 232 if (times_to_lose_during_draw_)
(...skipping 12 matching lines...) Expand all
178 245
179 bool NextTestCase() { 246 bool NextTestCase() {
180 static const TestCase kTests[] = { 247 static const TestCase kTests[] = {
181 // Losing the context and failing to recreate it (or losing it again 248 // Losing the context and failing to recreate it (or losing it again
182 // immediately) a small number of times should succeed. 249 // immediately) a small number of times should succeed.
183 { 1, // times_to_lose_during_commit 250 { 1, // times_to_lose_during_commit
184 0, // times_to_lose_during_draw 251 0, // times_to_lose_during_draw
185 3, // times_to_fail_reinitialize 252 3, // times_to_fail_reinitialize
186 0, // times_to_fail_recreate 253 0, // times_to_fail_recreate
187 0, // times_to_lose_on_recreate 254 0, // times_to_lose_on_recreate
255 0, // times_to_fail_recreate_offscreen;
188 }, 256 },
189 { 0, // times_to_lose_during_commit 257 { 0, // times_to_lose_during_commit
190 1, // times_to_lose_during_draw 258 1, // times_to_lose_during_draw
191 3, // times_to_fail_reinitialize 259 3, // times_to_fail_reinitialize
192 0, // times_to_fail_recreate 260 0, // times_to_fail_recreate
193 0, // times_to_lose_on_recreate 261 0, // times_to_lose_on_recreate
262 0, // times_to_fail_recreate_offscreen;
194 }, 263 },
195 { 1, // times_to_lose_during_commit 264 { 1, // times_to_lose_during_commit
196 0, // times_to_lose_during_draw 265 0, // times_to_lose_during_draw
197 0, // times_to_fail_reinitialize 266 0, // times_to_fail_reinitialize
198 3, // times_to_fail_recreate 267 3, // times_to_fail_recreate
199 0, // times_to_lose_on_recreate 268 0, // times_to_lose_on_recreate
269 0, // times_to_fail_recreate_offscreen;
200 }, 270 },
201 { 0, // times_to_lose_during_commit 271 { 0, // times_to_lose_during_commit
202 1, // times_to_lose_during_draw 272 1, // times_to_lose_during_draw
203 0, // times_to_fail_reinitialize 273 0, // times_to_fail_reinitialize
204 3, // times_to_fail_recreate 274 3, // times_to_fail_recreate
205 0, // times_to_lose_on_recreate 275 0, // times_to_lose_on_recreate
276 0, // times_to_fail_recreate_offscreen;
206 }, 277 },
207 { 1, // times_to_lose_during_commit 278 { 1, // times_to_lose_during_commit
208 0, // times_to_lose_during_draw 279 0, // times_to_lose_during_draw
209 0, // times_to_fail_reinitialize 280 0, // times_to_fail_reinitialize
210 0, // times_to_fail_recreate 281 0, // times_to_fail_recreate
211 3, // times_to_lose_on_recreate 282 3, // times_to_lose_on_recreate
283 0, // times_to_fail_recreate_offscreen;
212 }, 284 },
213 { 0, // times_to_lose_during_commit 285 { 0, // times_to_lose_during_commit
214 1, // times_to_lose_during_draw 286 1, // times_to_lose_during_draw
215 0, // times_to_fail_reinitialize 287 0, // times_to_fail_reinitialize
216 0, // times_to_fail_recreate 288 0, // times_to_fail_recreate
217 3, // times_to_lose_on_recreate 289 3, // times_to_lose_on_recreate
290 0, // times_to_fail_recreate_offscreen;
291 },
292 { 1, // times_to_lose_during_commit
293 0, // times_to_lose_during_draw
294 0, // times_to_fail_reinitialize
295 0, // times_to_fail_recreate
296 0, // times_to_lose_on_recreate
297 3, // times_to_fail_recreate_offscreen;
298 },
299 { 0, // times_to_lose_during_commit
300 1, // times_to_lose_during_draw
301 0, // times_to_fail_reinitialize
302 0, // times_to_fail_recreate
303 0, // times_to_lose_on_recreate
304 3, // times_to_fail_recreate_offscreen;
305 },
306 { 1, // times_to_lose_during_commit
307 0, // times_to_lose_during_draw
308 0, // times_to_fail_reinitialize
309 0, // times_to_fail_recreate
310 0, // times_to_lose_on_recreate
311 3, // times_to_fail_recreate_offscreen;
312 },
313 { 0, // times_to_lose_during_commit
314 1, // times_to_lose_during_draw
315 0, // times_to_fail_reinitialize
316 0, // times_to_fail_recreate
317 0, // times_to_lose_on_recreate
318 0, // times_to_fail_recreate_offscreen;
218 }, 319 },
219 // Losing the context and recreating it any number of times should 320 // Losing the context and recreating it any number of times should
220 // succeed. 321 // succeed.
221 { 10, // times_to_lose_during_commit 322 { 10, // times_to_lose_during_commit
222 0, // times_to_lose_during_draw 323 0, // times_to_lose_during_draw
223 0, // times_to_fail_reinitialize 324 0, // times_to_fail_reinitialize
224 0, // times_to_fail_recreate 325 0, // times_to_fail_recreate
225 0, // times_to_lose_on_recreate 326 0, // times_to_lose_on_recreate
327 0, // times_to_fail_recreate_offscreen;
226 }, 328 },
227 { 0, // times_to_lose_during_commit 329 { 0, // times_to_lose_during_commit
228 10, // times_to_lose_during_draw 330 10, // times_to_lose_during_draw
229 0, // times_to_fail_reinitialize 331 0, // times_to_fail_reinitialize
230 0, // times_to_fail_recreate 332 0, // times_to_fail_recreate
231 0, // times_to_lose_on_recreate 333 0, // times_to_lose_on_recreate
334 0, // times_to_fail_recreate_offscreen;
232 }, 335 },
233 }; 336 };
234 337
235 if (test_case_ >= arraysize(kTests)) 338 if (test_case_ >= arraysize(kTests))
236 return false; 339 return false;
237 340
238 times_to_lose_during_commit_ = 341 times_to_lose_during_commit_ =
239 kTests[test_case_].times_to_lose_during_commit; 342 kTests[test_case_].times_to_lose_during_commit;
240 times_to_lose_during_draw_ = 343 times_to_lose_during_draw_ =
241 kTests[test_case_].times_to_lose_during_draw; 344 kTests[test_case_].times_to_lose_during_draw;
242 times_to_fail_reinitialize_ = kTests[test_case_].times_to_fail_reinitialize; 345 times_to_fail_reinitialize_ = kTests[test_case_].times_to_fail_reinitialize;
243 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate; 346 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; 347 times_to_lose_on_recreate_ = kTests[test_case_].times_to_lose_on_recreate;
348 times_to_fail_recreate_offscreen_ = kTests[test_case_].times_to_fail_recreat e_offscreen;
245 ++test_case_; 349 ++test_case_;
246 return true; 350 return true;
247 } 351 }
248 352
249 struct TestCase { 353 struct TestCase {
250 int times_to_lose_during_commit; 354 int times_to_lose_during_commit;
251 int times_to_lose_during_draw; 355 int times_to_lose_during_draw;
252 int times_to_fail_reinitialize; 356 int times_to_fail_reinitialize;
253 int times_to_fail_recreate; 357 int times_to_fail_recreate;
254 int times_to_lose_on_recreate; 358 int times_to_lose_on_recreate;
359 int times_to_fail_recreate_offscreen;
255 }; 360 };
256 361
257 private: 362 private:
258 size_t test_case_; 363 size_t test_case_;
259 int num_losses_; 364 int num_losses_;
260 bool recovered_context_; 365 bool recovered_context_;
261 }; 366 };
262 367
263 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds) 368 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds)
264 369
265 class LayerTreeHostContextTestLostContextSucceedsWithContent : 370 class LayerTreeHostContextTestLostContextSucceedsWithContent :
266 public LayerTreeHostContextTestLostContextSucceeds { 371 public LayerTreeHostContextTestLostContextSucceeds {
267 public: 372 public:
268 373
269 LayerTreeHostContextTestLostContextSucceedsWithContent() 374 LayerTreeHostContextTestLostContextSucceedsWithContent()
270 : LayerTreeHostContextTestLostContextSucceeds() { 375 : LayerTreeHostContextTestLostContextSucceeds() {
271 } 376 }
272 377
273 virtual void setupTree() OVERRIDE { 378 virtual void setupTree() OVERRIDE {
274 root_ = Layer::create(); 379 root_ = Layer::create();
275 root_->setBounds(gfx::Size(10, 10)); 380 root_->setBounds(gfx::Size(10, 10));
276 root_->setAnchorPoint(gfx::PointF()); 381 root_->setAnchorPoint(gfx::PointF());
277 root_->setIsDrawable(true); 382 root_->setIsDrawable(true);
278 383
279 content_ = FakeContentLayer::Create(&client_); 384 content_ = FakeContentLayer::Create(&client_);
280 content_->setBounds(gfx::Size(10, 10)); 385 content_->setBounds(gfx::Size(10, 10));
281 content_->setAnchorPoint(gfx::PointF()); 386 content_->setAnchorPoint(gfx::PointF());
282 content_->setIsDrawable(true); 387 content_->setIsDrawable(true);
283 if (use_surface_) { 388 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); 389 content_->setForceRenderSurface(true);
390 // Filters require us to create an offscreen context.
391 WebKit::WebFilterOperations filters;
392 filters.append(WebKit::WebFilterOperation::createGrayscaleFilter(0.5f));
393 content_->setFilters(filters);
394 content_->setBackgroundFilters(filters);
287 } 395 }
288 396
289 root_->addChild(content_); 397 root_->addChild(content_);
290 398
291 m_layerTreeHost->setRootLayer(root_); 399 m_layerTreeHost->setRootLayer(root_);
292 LayerTreeHostContextTest::setupTree(); 400 LayerTreeHostContextTest::setupTree();
293 } 401 }
294 402
295 virtual void InvalidateAndSetNeedsCommit() OVERRIDE { 403 virtual void InvalidateAndSetNeedsCommit() OVERRIDE {
296 // Invalidate the render surface so we don't try to use a cached copy of the 404 // 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 405 // surface. We want to make sure to test the drawing paths for drawing to
298 // a child surface. 406 // a child surface.
299 content_->setNeedsDisplay(); 407 content_->setNeedsDisplay();
300 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit(); 408 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit();
301 } 409 }
302 410
303 virtual void drawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 411 virtual void drawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
304 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>( 412 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>(
305 host_impl->rootLayer()->children()[0]); 413 host_impl->rootLayer()->children()[0]);
306 // Even though the context was lost, we should have a resource. The 414 // Even though the context was lost, we should have a resource. The
307 // FakeWebGraphicsContext3D ensures that this resource is created with 415 // FakeWebGraphicsContext3D ensures that this resource is created with
308 // the active context. 416 // the active context.
309 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); 417 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0));
418
419 GrContextProvider::ScopedContexts contexts(
420 host_impl->resourceProvider()->grContextProvider());
421 if (use_surface_) {
422 EXPECT_TRUE(contexts.context3d());
423 // TODO(danakj): Make FakeWGC3D "real" enough for Ganesh.
424 //EXPECT_TRUE(contexts.gr_context());
425 } else {
426 EXPECT_FALSE(contexts.context3d());
427 EXPECT_FALSE(contexts.gr_context());
428 }
310 } 429 }
311 430
312 protected: 431 protected:
313 bool use_surface_; 432 bool use_surface_;
314 FakeContentLayerClient client_; 433 FakeContentLayerClient client_;
315 scoped_refptr<Layer> root_; 434 scoped_refptr<Layer> root_;
316 scoped_refptr<ContentLayer> content_; 435 scoped_refptr<ContentLayer> content_;
317 }; 436 };
318 437
319 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, 438 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent,
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 1139
1021 private: 1140 private:
1022 int commits_; 1141 int commits_;
1023 scoped_refptr<FakeScrollbarLayer> scrollbar_layer_; 1142 scoped_refptr<FakeScrollbarLayer> scrollbar_layer_;
1024 }; 1143 };
1025 1144
1026 SINGLE_AND_MULTI_THREAD_TEST_F(ScrollbarLayerLostContext) 1145 SINGLE_AND_MULTI_THREAD_TEST_F(ScrollbarLayerLostContext)
1027 1146
1028 } // namespace 1147 } // namespace
1029 } // namespace cc 1148 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698