OLD | NEW |
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/copy_output_request.h" | 5 #include "cc/output/copy_output_request.h" |
6 #include "cc/output/copy_output_result.h" | 6 #include "cc/output/copy_output_result.h" |
7 #include "cc/test/fake_content_layer.h" | 7 #include "cc/test/fake_content_layer.h" |
8 #include "cc/test/fake_content_layer_client.h" | 8 #include "cc/test/fake_content_layer_client.h" |
9 #include "cc/test/fake_output_surface.h" | 9 #include "cc/test/fake_output_surface.h" |
10 #include "cc/test/layer_tree_test.h" | 10 #include "cc/test/layer_tree_test.h" |
11 #include "cc/trees/layer_tree_impl.h" | 11 #include "cc/trees/layer_tree_impl.h" |
12 #include "gpu/GLES2/gl2extchromium.h" | 12 #include "gpu/GLES2/gl2extchromium.h" |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 namespace { | 15 namespace { |
16 | 16 |
17 // These tests only use direct rendering, as there is no output to copy for | 17 // These tests only use direct rendering, as there is no output to copy for |
18 // delegated renderers. | 18 // delegated renderers. |
19 class LayerTreeHostCopyRequestTest : public LayerTreeTest {}; | 19 class LayerTreeHostCopyRequestTest : public LayerTreeTest {}; |
20 | 20 |
21 class LayerTreeHostCopyRequestTestMultipleRequests | 21 class LayerTreeHostCopyRequestTestMultipleRequests |
22 : public LayerTreeHostCopyRequestTest { | 22 : public LayerTreeHostCopyRequestTest { |
23 protected: | 23 protected: |
24 virtual void SetupTree() OVERRIDE { | 24 virtual void SetupTree() override { |
25 root = FakeContentLayer::Create(&client_); | 25 root = FakeContentLayer::Create(&client_); |
26 root->SetBounds(gfx::Size(20, 20)); | 26 root->SetBounds(gfx::Size(20, 20)); |
27 | 27 |
28 child = FakeContentLayer::Create(&client_); | 28 child = FakeContentLayer::Create(&client_); |
29 child->SetBounds(gfx::Size(10, 10)); | 29 child->SetBounds(gfx::Size(10, 10)); |
30 root->AddChild(child); | 30 root->AddChild(child); |
31 | 31 |
32 layer_tree_host()->SetRootLayer(root); | 32 layer_tree_host()->SetRootLayer(root); |
33 LayerTreeHostCopyRequestTest::SetupTree(); | 33 LayerTreeHostCopyRequestTest::SetupTree(); |
34 } | 34 } |
35 | 35 |
36 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 36 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
37 | 37 |
38 virtual void DidCommitAndDrawFrame() OVERRIDE { WaitForCallback(); } | 38 virtual void DidCommitAndDrawFrame() override { WaitForCallback(); } |
39 | 39 |
40 void WaitForCallback() { | 40 void WaitForCallback() { |
41 base::MessageLoop::current()->PostTask( | 41 base::MessageLoop::current()->PostTask( |
42 FROM_HERE, | 42 FROM_HERE, |
43 base::Bind(&LayerTreeHostCopyRequestTestMultipleRequests::NextStep, | 43 base::Bind(&LayerTreeHostCopyRequestTestMultipleRequests::NextStep, |
44 base::Unretained(this))); | 44 base::Unretained(this))); |
45 } | 45 } |
46 | 46 |
47 void NextStep() { | 47 void NextStep() { |
48 int frame = layer_tree_host()->source_frame_number(); | 48 int frame = layer_tree_host()->source_frame_number(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 95 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
96 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 96 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |
97 EXPECT_TRUE(result->HasBitmap()); | 97 EXPECT_TRUE(result->HasBitmap()); |
98 scoped_ptr<SkBitmap> bitmap = result->TakeBitmap().Pass(); | 98 scoped_ptr<SkBitmap> bitmap = result->TakeBitmap().Pass(); |
99 EXPECT_EQ(result->size().ToString(), | 99 EXPECT_EQ(result->size().ToString(), |
100 gfx::Size(bitmap->width(), bitmap->height()).ToString()); | 100 gfx::Size(bitmap->width(), bitmap->height()).ToString()); |
101 callbacks_.push_back(result->size()); | 101 callbacks_.push_back(result->size()); |
102 } | 102 } |
103 | 103 |
104 virtual void AfterTest() OVERRIDE { EXPECT_EQ(4u, callbacks_.size()); } | 104 virtual void AfterTest() override { EXPECT_EQ(4u, callbacks_.size()); } |
105 | 105 |
106 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) | 106 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) |
107 OVERRIDE { | 107 override { |
108 if (use_gl_renderer_) | 108 if (use_gl_renderer_) |
109 return FakeOutputSurface::Create3d(); | 109 return FakeOutputSurface::Create3d(); |
110 return FakeOutputSurface::CreateSoftware( | 110 return FakeOutputSurface::CreateSoftware( |
111 make_scoped_ptr(new SoftwareOutputDevice)); | 111 make_scoped_ptr(new SoftwareOutputDevice)); |
112 } | 112 } |
113 | 113 |
114 bool use_gl_renderer_; | 114 bool use_gl_renderer_; |
115 std::vector<gfx::Size> callbacks_; | 115 std::vector<gfx::Size> callbacks_; |
116 FakeContentLayerClient client_; | 116 FakeContentLayerClient client_; |
117 scoped_refptr<FakeContentLayer> root; | 117 scoped_refptr<FakeContentLayer> root; |
(...skipping 21 matching lines...) Expand all Loading... |
139 | 139 |
140 TEST_F(LayerTreeHostCopyRequestTestMultipleRequests, | 140 TEST_F(LayerTreeHostCopyRequestTestMultipleRequests, |
141 SoftwareRenderer_RunMultiThread_MainThreadPainting) { | 141 SoftwareRenderer_RunMultiThread_MainThreadPainting) { |
142 use_gl_renderer_ = false; | 142 use_gl_renderer_ = false; |
143 RunTest(true, false, false); | 143 RunTest(true, false, false); |
144 } | 144 } |
145 | 145 |
146 class LayerTreeHostCopyRequestTestLayerDestroyed | 146 class LayerTreeHostCopyRequestTestLayerDestroyed |
147 : public LayerTreeHostCopyRequestTest { | 147 : public LayerTreeHostCopyRequestTest { |
148 protected: | 148 protected: |
149 virtual void SetupTree() OVERRIDE { | 149 virtual void SetupTree() override { |
150 root_ = FakeContentLayer::Create(&client_); | 150 root_ = FakeContentLayer::Create(&client_); |
151 root_->SetBounds(gfx::Size(20, 20)); | 151 root_->SetBounds(gfx::Size(20, 20)); |
152 | 152 |
153 main_destroyed_ = FakeContentLayer::Create(&client_); | 153 main_destroyed_ = FakeContentLayer::Create(&client_); |
154 main_destroyed_->SetBounds(gfx::Size(15, 15)); | 154 main_destroyed_->SetBounds(gfx::Size(15, 15)); |
155 root_->AddChild(main_destroyed_); | 155 root_->AddChild(main_destroyed_); |
156 | 156 |
157 impl_destroyed_ = FakeContentLayer::Create(&client_); | 157 impl_destroyed_ = FakeContentLayer::Create(&client_); |
158 impl_destroyed_->SetBounds(gfx::Size(10, 10)); | 158 impl_destroyed_->SetBounds(gfx::Size(10, 10)); |
159 root_->AddChild(impl_destroyed_); | 159 root_->AddChild(impl_destroyed_); |
160 | 160 |
161 layer_tree_host()->SetRootLayer(root_); | 161 layer_tree_host()->SetRootLayer(root_); |
162 LayerTreeHostCopyRequestTest::SetupTree(); | 162 LayerTreeHostCopyRequestTest::SetupTree(); |
163 } | 163 } |
164 | 164 |
165 virtual void BeginTest() OVERRIDE { | 165 virtual void BeginTest() override { |
166 callback_count_ = 0; | 166 callback_count_ = 0; |
167 PostSetNeedsCommitToMainThread(); | 167 PostSetNeedsCommitToMainThread(); |
168 } | 168 } |
169 | 169 |
170 virtual void DidCommit() OVERRIDE { | 170 virtual void DidCommit() override { |
171 int frame = layer_tree_host()->source_frame_number(); | 171 int frame = layer_tree_host()->source_frame_number(); |
172 switch (frame) { | 172 switch (frame) { |
173 case 1: | 173 case 1: |
174 main_destroyed_->RequestCopyOfOutput( | 174 main_destroyed_->RequestCopyOfOutput( |
175 CopyOutputRequest::CreateBitmapRequest(base::Bind( | 175 CopyOutputRequest::CreateBitmapRequest(base::Bind( |
176 &LayerTreeHostCopyRequestTestLayerDestroyed::CopyOutputCallback, | 176 &LayerTreeHostCopyRequestTestLayerDestroyed::CopyOutputCallback, |
177 base::Unretained(this)))); | 177 base::Unretained(this)))); |
178 impl_destroyed_->RequestCopyOfOutput( | 178 impl_destroyed_->RequestCopyOfOutput( |
179 CopyOutputRequest::CreateBitmapRequest(base::Bind( | 179 CopyOutputRequest::CreateBitmapRequest(base::Bind( |
180 &LayerTreeHostCopyRequestTestLayerDestroyed::CopyOutputCallback, | 180 &LayerTreeHostCopyRequestTestLayerDestroyed::CopyOutputCallback, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 break; | 217 break; |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 221 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
222 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 222 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |
223 EXPECT_TRUE(result->IsEmpty()); | 223 EXPECT_TRUE(result->IsEmpty()); |
224 ++callback_count_; | 224 ++callback_count_; |
225 } | 225 } |
226 | 226 |
227 virtual void AfterTest() OVERRIDE {} | 227 virtual void AfterTest() override {} |
228 | 228 |
229 int callback_count_; | 229 int callback_count_; |
230 FakeContentLayerClient client_; | 230 FakeContentLayerClient client_; |
231 scoped_refptr<FakeContentLayer> root_; | 231 scoped_refptr<FakeContentLayer> root_; |
232 scoped_refptr<FakeContentLayer> main_destroyed_; | 232 scoped_refptr<FakeContentLayer> main_destroyed_; |
233 scoped_refptr<FakeContentLayer> impl_destroyed_; | 233 scoped_refptr<FakeContentLayer> impl_destroyed_; |
234 }; | 234 }; |
235 | 235 |
236 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostCopyRequestTestLayerDestroyed); | 236 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostCopyRequestTestLayerDestroyed); |
237 | 237 |
238 class LayerTreeHostCopyRequestTestInHiddenSubtree | 238 class LayerTreeHostCopyRequestTestInHiddenSubtree |
239 : public LayerTreeHostCopyRequestTest { | 239 : public LayerTreeHostCopyRequestTest { |
240 protected: | 240 protected: |
241 virtual void SetupTree() OVERRIDE { | 241 virtual void SetupTree() override { |
242 root_ = FakeContentLayer::Create(&client_); | 242 root_ = FakeContentLayer::Create(&client_); |
243 root_->SetBounds(gfx::Size(20, 20)); | 243 root_->SetBounds(gfx::Size(20, 20)); |
244 | 244 |
245 grand_parent_layer_ = FakeContentLayer::Create(&client_); | 245 grand_parent_layer_ = FakeContentLayer::Create(&client_); |
246 grand_parent_layer_->SetBounds(gfx::Size(15, 15)); | 246 grand_parent_layer_->SetBounds(gfx::Size(15, 15)); |
247 root_->AddChild(grand_parent_layer_); | 247 root_->AddChild(grand_parent_layer_); |
248 | 248 |
249 // parent_layer_ owns a render surface. | 249 // parent_layer_ owns a render surface. |
250 parent_layer_ = FakeContentLayer::Create(&client_); | 250 parent_layer_ = FakeContentLayer::Create(&client_); |
251 parent_layer_->SetBounds(gfx::Size(15, 15)); | 251 parent_layer_->SetBounds(gfx::Size(15, 15)); |
252 parent_layer_->SetForceRenderSurface(true); | 252 parent_layer_->SetForceRenderSurface(true); |
253 grand_parent_layer_->AddChild(parent_layer_); | 253 grand_parent_layer_->AddChild(parent_layer_); |
254 | 254 |
255 copy_layer_ = FakeContentLayer::Create(&client_); | 255 copy_layer_ = FakeContentLayer::Create(&client_); |
256 copy_layer_->SetBounds(gfx::Size(10, 10)); | 256 copy_layer_->SetBounds(gfx::Size(10, 10)); |
257 parent_layer_->AddChild(copy_layer_); | 257 parent_layer_->AddChild(copy_layer_); |
258 | 258 |
259 layer_tree_host()->SetRootLayer(root_); | 259 layer_tree_host()->SetRootLayer(root_); |
260 LayerTreeHostCopyRequestTest::SetupTree(); | 260 LayerTreeHostCopyRequestTest::SetupTree(); |
261 } | 261 } |
262 | 262 |
263 void AddCopyRequest(Layer* layer) { | 263 void AddCopyRequest(Layer* layer) { |
264 layer->RequestCopyOfOutput( | 264 layer->RequestCopyOfOutput( |
265 CopyOutputRequest::CreateBitmapRequest(base::Bind( | 265 CopyOutputRequest::CreateBitmapRequest(base::Bind( |
266 &LayerTreeHostCopyRequestTestInHiddenSubtree::CopyOutputCallback, | 266 &LayerTreeHostCopyRequestTestInHiddenSubtree::CopyOutputCallback, |
267 base::Unretained(this)))); | 267 base::Unretained(this)))); |
268 } | 268 } |
269 | 269 |
270 virtual void BeginTest() OVERRIDE { | 270 virtual void BeginTest() override { |
271 callback_count_ = 0; | 271 callback_count_ = 0; |
272 PostSetNeedsCommitToMainThread(); | 272 PostSetNeedsCommitToMainThread(); |
273 | 273 |
274 AddCopyRequest(copy_layer_.get()); | 274 AddCopyRequest(copy_layer_.get()); |
275 } | 275 } |
276 | 276 |
277 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 277 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
278 ++callback_count_; | 278 ++callback_count_; |
279 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 279 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |
280 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()) | 280 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 parent_layer_->SetHideLayerAndSubtree(true); | 314 parent_layer_->SetHideLayerAndSubtree(true); |
315 copy_layer_->SetHideLayerAndSubtree(true); | 315 copy_layer_->SetHideLayerAndSubtree(true); |
316 AddCopyRequest(copy_layer_.get()); | 316 AddCopyRequest(copy_layer_.get()); |
317 break; | 317 break; |
318 case 6: | 318 case 6: |
319 EndTest(); | 319 EndTest(); |
320 break; | 320 break; |
321 } | 321 } |
322 } | 322 } |
323 | 323 |
324 virtual void AfterTest() OVERRIDE {} | 324 virtual void AfterTest() override {} |
325 | 325 |
326 int callback_count_; | 326 int callback_count_; |
327 FakeContentLayerClient client_; | 327 FakeContentLayerClient client_; |
328 scoped_refptr<FakeContentLayer> root_; | 328 scoped_refptr<FakeContentLayer> root_; |
329 scoped_refptr<FakeContentLayer> grand_parent_layer_; | 329 scoped_refptr<FakeContentLayer> grand_parent_layer_; |
330 scoped_refptr<FakeContentLayer> parent_layer_; | 330 scoped_refptr<FakeContentLayer> parent_layer_; |
331 scoped_refptr<FakeContentLayer> copy_layer_; | 331 scoped_refptr<FakeContentLayer> copy_layer_; |
332 }; | 332 }; |
333 | 333 |
334 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( | 334 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( |
335 LayerTreeHostCopyRequestTestInHiddenSubtree); | 335 LayerTreeHostCopyRequestTestInHiddenSubtree); |
336 | 336 |
337 class LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest | 337 class LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest |
338 : public LayerTreeHostCopyRequestTest { | 338 : public LayerTreeHostCopyRequestTest { |
339 protected: | 339 protected: |
340 virtual void SetupTree() OVERRIDE { | 340 virtual void SetupTree() override { |
341 root_ = FakeContentLayer::Create(&client_); | 341 root_ = FakeContentLayer::Create(&client_); |
342 root_->SetBounds(gfx::Size(20, 20)); | 342 root_->SetBounds(gfx::Size(20, 20)); |
343 | 343 |
344 grand_parent_layer_ = FakeContentLayer::Create(&client_); | 344 grand_parent_layer_ = FakeContentLayer::Create(&client_); |
345 grand_parent_layer_->SetBounds(gfx::Size(15, 15)); | 345 grand_parent_layer_->SetBounds(gfx::Size(15, 15)); |
346 grand_parent_layer_->SetHideLayerAndSubtree(true); | 346 grand_parent_layer_->SetHideLayerAndSubtree(true); |
347 root_->AddChild(grand_parent_layer_); | 347 root_->AddChild(grand_parent_layer_); |
348 | 348 |
349 // parent_layer_ owns a render surface. | 349 // parent_layer_ owns a render surface. |
350 parent_layer_ = FakeContentLayer::Create(&client_); | 350 parent_layer_ = FakeContentLayer::Create(&client_); |
351 parent_layer_->SetBounds(gfx::Size(15, 15)); | 351 parent_layer_->SetBounds(gfx::Size(15, 15)); |
352 parent_layer_->SetForceRenderSurface(true); | 352 parent_layer_->SetForceRenderSurface(true); |
353 grand_parent_layer_->AddChild(parent_layer_); | 353 grand_parent_layer_->AddChild(parent_layer_); |
354 | 354 |
355 copy_layer_ = FakeContentLayer::Create(&client_); | 355 copy_layer_ = FakeContentLayer::Create(&client_); |
356 copy_layer_->SetBounds(gfx::Size(10, 10)); | 356 copy_layer_->SetBounds(gfx::Size(10, 10)); |
357 parent_layer_->AddChild(copy_layer_); | 357 parent_layer_->AddChild(copy_layer_); |
358 | 358 |
359 layer_tree_host()->SetRootLayer(root_); | 359 layer_tree_host()->SetRootLayer(root_); |
360 LayerTreeHostCopyRequestTest::SetupTree(); | 360 LayerTreeHostCopyRequestTest::SetupTree(); |
361 } | 361 } |
362 | 362 |
363 virtual void BeginTest() OVERRIDE { | 363 virtual void BeginTest() override { |
364 did_draw_ = false; | 364 did_draw_ = false; |
365 PostSetNeedsCommitToMainThread(); | 365 PostSetNeedsCommitToMainThread(); |
366 | 366 |
367 copy_layer_->RequestCopyOfOutput( | 367 copy_layer_->RequestCopyOfOutput( |
368 CopyOutputRequest::CreateBitmapRequest(base::Bind( | 368 CopyOutputRequest::CreateBitmapRequest(base::Bind( |
369 &LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest:: | 369 &LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest:: |
370 CopyOutputCallback, | 370 CopyOutputCallback, |
371 base::Unretained(this)))); | 371 base::Unretained(this)))); |
372 } | 372 } |
373 | 373 |
374 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 374 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
375 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 375 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |
376 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()); | 376 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()); |
377 EndTest(); | 377 EndTest(); |
378 } | 378 } |
379 | 379 |
380 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 380 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
381 Renderer* renderer = host_impl->renderer(); | 381 Renderer* renderer = host_impl->renderer(); |
382 | 382 |
383 LayerImpl* root = host_impl->active_tree()->root_layer(); | 383 LayerImpl* root = host_impl->active_tree()->root_layer(); |
384 LayerImpl* grand_parent = root->children()[0]; | 384 LayerImpl* grand_parent = root->children()[0]; |
385 LayerImpl* parent = grand_parent->children()[0]; | 385 LayerImpl* parent = grand_parent->children()[0]; |
386 LayerImpl* copy_layer = parent->children()[0]; | 386 LayerImpl* copy_layer = parent->children()[0]; |
387 | 387 |
388 // |parent| owns a surface, but it was hidden and not part of the copy | 388 // |parent| owns a surface, but it was hidden and not part of the copy |
389 // request so it should not allocate any resource. | 389 // request so it should not allocate any resource. |
390 EXPECT_FALSE(renderer->HasAllocatedResourcesForTesting( | 390 EXPECT_FALSE(renderer->HasAllocatedResourcesForTesting( |
391 parent->render_surface()->GetRenderPassId())); | 391 parent->render_surface()->GetRenderPassId())); |
392 | 392 |
393 // |copy_layer| should have been rendered to a texture since it was needed | 393 // |copy_layer| should have been rendered to a texture since it was needed |
394 // for a copy request. | 394 // for a copy request. |
395 EXPECT_TRUE(renderer->HasAllocatedResourcesForTesting( | 395 EXPECT_TRUE(renderer->HasAllocatedResourcesForTesting( |
396 copy_layer->render_surface()->GetRenderPassId())); | 396 copy_layer->render_surface()->GetRenderPassId())); |
397 | 397 |
398 did_draw_ = true; | 398 did_draw_ = true; |
399 } | 399 } |
400 | 400 |
401 virtual void AfterTest() OVERRIDE { EXPECT_TRUE(did_draw_); } | 401 virtual void AfterTest() override { EXPECT_TRUE(did_draw_); } |
402 | 402 |
403 FakeContentLayerClient client_; | 403 FakeContentLayerClient client_; |
404 bool did_draw_; | 404 bool did_draw_; |
405 scoped_refptr<FakeContentLayer> root_; | 405 scoped_refptr<FakeContentLayer> root_; |
406 scoped_refptr<FakeContentLayer> grand_parent_layer_; | 406 scoped_refptr<FakeContentLayer> grand_parent_layer_; |
407 scoped_refptr<FakeContentLayer> parent_layer_; | 407 scoped_refptr<FakeContentLayer> parent_layer_; |
408 scoped_refptr<FakeContentLayer> copy_layer_; | 408 scoped_refptr<FakeContentLayer> copy_layer_; |
409 }; | 409 }; |
410 | 410 |
411 // No output to copy for delegated renderers. | 411 // No output to copy for delegated renderers. |
412 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 412 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
413 LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest); | 413 LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest); |
414 | 414 |
415 class LayerTreeHostCopyRequestTestClippedOut | 415 class LayerTreeHostCopyRequestTestClippedOut |
416 : public LayerTreeHostCopyRequestTest { | 416 : public LayerTreeHostCopyRequestTest { |
417 protected: | 417 protected: |
418 virtual void SetupTree() OVERRIDE { | 418 virtual void SetupTree() override { |
419 root_ = FakeContentLayer::Create(&client_); | 419 root_ = FakeContentLayer::Create(&client_); |
420 root_->SetBounds(gfx::Size(20, 20)); | 420 root_->SetBounds(gfx::Size(20, 20)); |
421 | 421 |
422 parent_layer_ = FakeContentLayer::Create(&client_); | 422 parent_layer_ = FakeContentLayer::Create(&client_); |
423 parent_layer_->SetBounds(gfx::Size(15, 15)); | 423 parent_layer_->SetBounds(gfx::Size(15, 15)); |
424 parent_layer_->SetMasksToBounds(true); | 424 parent_layer_->SetMasksToBounds(true); |
425 root_->AddChild(parent_layer_); | 425 root_->AddChild(parent_layer_); |
426 | 426 |
427 copy_layer_ = FakeContentLayer::Create(&client_); | 427 copy_layer_ = FakeContentLayer::Create(&client_); |
428 copy_layer_->SetPosition(gfx::Point(15, 15)); | 428 copy_layer_->SetPosition(gfx::Point(15, 15)); |
429 copy_layer_->SetBounds(gfx::Size(10, 10)); | 429 copy_layer_->SetBounds(gfx::Size(10, 10)); |
430 parent_layer_->AddChild(copy_layer_); | 430 parent_layer_->AddChild(copy_layer_); |
431 | 431 |
432 layer_tree_host()->SetRootLayer(root_); | 432 layer_tree_host()->SetRootLayer(root_); |
433 LayerTreeHostCopyRequestTest::SetupTree(); | 433 LayerTreeHostCopyRequestTest::SetupTree(); |
434 } | 434 } |
435 | 435 |
436 virtual void BeginTest() OVERRIDE { | 436 virtual void BeginTest() override { |
437 PostSetNeedsCommitToMainThread(); | 437 PostSetNeedsCommitToMainThread(); |
438 | 438 |
439 copy_layer_->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( | 439 copy_layer_->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( |
440 base::Bind(&LayerTreeHostCopyRequestTestClippedOut::CopyOutputCallback, | 440 base::Bind(&LayerTreeHostCopyRequestTestClippedOut::CopyOutputCallback, |
441 base::Unretained(this)))); | 441 base::Unretained(this)))); |
442 } | 442 } |
443 | 443 |
444 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 444 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
445 // We should still get a callback with no output if the copy requested layer | 445 // We should still get a callback with no output if the copy requested layer |
446 // was completely clipped away. | 446 // was completely clipped away. |
447 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 447 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |
448 EXPECT_EQ(gfx::Size().ToString(), result->size().ToString()); | 448 EXPECT_EQ(gfx::Size().ToString(), result->size().ToString()); |
449 EndTest(); | 449 EndTest(); |
450 } | 450 } |
451 | 451 |
452 virtual void AfterTest() OVERRIDE {} | 452 virtual void AfterTest() override {} |
453 | 453 |
454 FakeContentLayerClient client_; | 454 FakeContentLayerClient client_; |
455 scoped_refptr<FakeContentLayer> root_; | 455 scoped_refptr<FakeContentLayer> root_; |
456 scoped_refptr<FakeContentLayer> parent_layer_; | 456 scoped_refptr<FakeContentLayer> parent_layer_; |
457 scoped_refptr<FakeContentLayer> copy_layer_; | 457 scoped_refptr<FakeContentLayer> copy_layer_; |
458 }; | 458 }; |
459 | 459 |
460 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 460 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
461 LayerTreeHostCopyRequestTestClippedOut); | 461 LayerTreeHostCopyRequestTestClippedOut); |
462 | 462 |
463 class LayerTreeHostTestAsyncTwoReadbacksWithoutDraw | 463 class LayerTreeHostTestAsyncTwoReadbacksWithoutDraw |
464 : public LayerTreeHostCopyRequestTest { | 464 : public LayerTreeHostCopyRequestTest { |
465 protected: | 465 protected: |
466 virtual void SetupTree() OVERRIDE { | 466 virtual void SetupTree() override { |
467 root_ = FakeContentLayer::Create(&client_); | 467 root_ = FakeContentLayer::Create(&client_); |
468 root_->SetBounds(gfx::Size(20, 20)); | 468 root_->SetBounds(gfx::Size(20, 20)); |
469 | 469 |
470 copy_layer_ = FakeContentLayer::Create(&client_); | 470 copy_layer_ = FakeContentLayer::Create(&client_); |
471 copy_layer_->SetBounds(gfx::Size(10, 10)); | 471 copy_layer_->SetBounds(gfx::Size(10, 10)); |
472 root_->AddChild(copy_layer_); | 472 root_->AddChild(copy_layer_); |
473 | 473 |
474 layer_tree_host()->SetRootLayer(root_); | 474 layer_tree_host()->SetRootLayer(root_); |
475 LayerTreeHostCopyRequestTest::SetupTree(); | 475 LayerTreeHostCopyRequestTest::SetupTree(); |
476 } | 476 } |
477 | 477 |
478 void AddCopyRequest(Layer* layer) { | 478 void AddCopyRequest(Layer* layer) { |
479 layer->RequestCopyOfOutput( | 479 layer->RequestCopyOfOutput( |
480 CopyOutputRequest::CreateBitmapRequest(base::Bind( | 480 CopyOutputRequest::CreateBitmapRequest(base::Bind( |
481 &LayerTreeHostTestAsyncTwoReadbacksWithoutDraw::CopyOutputCallback, | 481 &LayerTreeHostTestAsyncTwoReadbacksWithoutDraw::CopyOutputCallback, |
482 base::Unretained(this)))); | 482 base::Unretained(this)))); |
483 } | 483 } |
484 | 484 |
485 virtual void BeginTest() OVERRIDE { | 485 virtual void BeginTest() override { |
486 saw_copy_request_ = false; | 486 saw_copy_request_ = false; |
487 callback_count_ = 0; | 487 callback_count_ = 0; |
488 PostSetNeedsCommitToMainThread(); | 488 PostSetNeedsCommitToMainThread(); |
489 | 489 |
490 // Prevent drawing. | 490 // Prevent drawing. |
491 layer_tree_host()->SetViewportSize(gfx::Size(0, 0)); | 491 layer_tree_host()->SetViewportSize(gfx::Size(0, 0)); |
492 | 492 |
493 AddCopyRequest(copy_layer_.get()); | 493 AddCopyRequest(copy_layer_.get()); |
494 } | 494 } |
495 | 495 |
496 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 496 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
497 if (impl->active_tree()->source_frame_number() == 0) { | 497 if (impl->active_tree()->source_frame_number() == 0) { |
498 LayerImpl* root = impl->active_tree()->root_layer(); | 498 LayerImpl* root = impl->active_tree()->root_layer(); |
499 EXPECT_TRUE(root->children()[0]->HasCopyRequest()); | 499 EXPECT_TRUE(root->children()[0]->HasCopyRequest()); |
500 saw_copy_request_ = true; | 500 saw_copy_request_ = true; |
501 } | 501 } |
502 } | 502 } |
503 | 503 |
504 virtual void DidCommit() OVERRIDE { | 504 virtual void DidCommit() override { |
505 if (layer_tree_host()->source_frame_number() == 1) { | 505 if (layer_tree_host()->source_frame_number() == 1) { |
506 // Allow drawing. | 506 // Allow drawing. |
507 layer_tree_host()->SetViewportSize(gfx::Size(root_->bounds())); | 507 layer_tree_host()->SetViewportSize(gfx::Size(root_->bounds())); |
508 | 508 |
509 AddCopyRequest(copy_layer_.get()); | 509 AddCopyRequest(copy_layer_.get()); |
510 } | 510 } |
511 } | 511 } |
512 | 512 |
513 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 513 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
514 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 514 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |
515 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()); | 515 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()); |
516 ++callback_count_; | 516 ++callback_count_; |
517 | 517 |
518 if (callback_count_ == 2) | 518 if (callback_count_ == 2) |
519 EndTest(); | 519 EndTest(); |
520 } | 520 } |
521 | 521 |
522 virtual void AfterTest() OVERRIDE { EXPECT_TRUE(saw_copy_request_); } | 522 virtual void AfterTest() override { EXPECT_TRUE(saw_copy_request_); } |
523 | 523 |
524 bool saw_copy_request_; | 524 bool saw_copy_request_; |
525 int callback_count_; | 525 int callback_count_; |
526 FakeContentLayerClient client_; | 526 FakeContentLayerClient client_; |
527 scoped_refptr<FakeContentLayer> root_; | 527 scoped_refptr<FakeContentLayer> root_; |
528 scoped_refptr<FakeContentLayer> copy_layer_; | 528 scoped_refptr<FakeContentLayer> copy_layer_; |
529 }; | 529 }; |
530 | 530 |
531 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( | 531 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( |
532 LayerTreeHostTestAsyncTwoReadbacksWithoutDraw); | 532 LayerTreeHostTestAsyncTwoReadbacksWithoutDraw); |
533 | 533 |
534 class LayerTreeHostCopyRequestTestLostOutputSurface | 534 class LayerTreeHostCopyRequestTestLostOutputSurface |
535 : public LayerTreeHostCopyRequestTest { | 535 : public LayerTreeHostCopyRequestTest { |
536 protected: | 536 protected: |
537 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) | 537 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) |
538 OVERRIDE { | 538 override { |
539 if (!first_context_provider_.get()) { | 539 if (!first_context_provider_.get()) { |
540 first_context_provider_ = TestContextProvider::Create(); | 540 first_context_provider_ = TestContextProvider::Create(); |
541 return FakeOutputSurface::Create3d(first_context_provider_); | 541 return FakeOutputSurface::Create3d(first_context_provider_); |
542 } | 542 } |
543 | 543 |
544 EXPECT_FALSE(second_context_provider_.get()); | 544 EXPECT_FALSE(second_context_provider_.get()); |
545 second_context_provider_ = TestContextProvider::Create(); | 545 second_context_provider_ = TestContextProvider::Create(); |
546 return FakeOutputSurface::Create3d(second_context_provider_); | 546 return FakeOutputSurface::Create3d(second_context_provider_); |
547 } | 547 } |
548 | 548 |
549 virtual void SetupTree() OVERRIDE { | 549 virtual void SetupTree() override { |
550 root_ = FakeContentLayer::Create(&client_); | 550 root_ = FakeContentLayer::Create(&client_); |
551 root_->SetBounds(gfx::Size(20, 20)); | 551 root_->SetBounds(gfx::Size(20, 20)); |
552 | 552 |
553 copy_layer_ = FakeContentLayer::Create(&client_); | 553 copy_layer_ = FakeContentLayer::Create(&client_); |
554 copy_layer_->SetBounds(gfx::Size(10, 10)); | 554 copy_layer_->SetBounds(gfx::Size(10, 10)); |
555 root_->AddChild(copy_layer_); | 555 root_->AddChild(copy_layer_); |
556 | 556 |
557 layer_tree_host()->SetRootLayer(root_); | 557 layer_tree_host()->SetRootLayer(root_); |
558 LayerTreeHostCopyRequestTest::SetupTree(); | 558 LayerTreeHostCopyRequestTest::SetupTree(); |
559 } | 559 } |
560 | 560 |
561 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 561 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
562 | 562 |
563 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 563 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
564 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 564 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |
565 EXPECT_EQ(gfx::Size(10, 10).ToString(), result->size().ToString()); | 565 EXPECT_EQ(gfx::Size(10, 10).ToString(), result->size().ToString()); |
566 EXPECT_TRUE(result->HasTexture()); | 566 EXPECT_TRUE(result->HasTexture()); |
567 | 567 |
568 // Save the result for later. | 568 // Save the result for later. |
569 EXPECT_FALSE(result_); | 569 EXPECT_FALSE(result_); |
570 result_ = result.Pass(); | 570 result_ = result.Pass(); |
571 | 571 |
572 // Post a commit to lose the output surface. | 572 // Post a commit to lose the output surface. |
573 layer_tree_host()->SetNeedsCommit(); | 573 layer_tree_host()->SetNeedsCommit(); |
574 } | 574 } |
575 | 575 |
576 virtual void DidCommitAndDrawFrame() OVERRIDE { | 576 virtual void DidCommitAndDrawFrame() override { |
577 switch (layer_tree_host()->source_frame_number()) { | 577 switch (layer_tree_host()->source_frame_number()) { |
578 case 1: | 578 case 1: |
579 // The layers have been pushed to the impl side. The layer textures have | 579 // The layers have been pushed to the impl side. The layer textures have |
580 // been allocated. | 580 // been allocated. |
581 | 581 |
582 // Request a copy of the layer. This will use another texture. | 582 // Request a copy of the layer. This will use another texture. |
583 copy_layer_->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( | 583 copy_layer_->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
584 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: | 584 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: |
585 CopyOutputCallback, | 585 CopyOutputCallback, |
586 base::Unretained(this)))); | 586 base::Unretained(this)))); |
(...skipping 12 matching lines...) Expand all Loading... |
599 FROM_HERE, | 599 FROM_HERE, |
600 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: | 600 base::Bind(&LayerTreeHostCopyRequestTestLostOutputSurface:: |
601 CheckNumTextures, | 601 CheckNumTextures, |
602 base::Unretained(this), | 602 base::Unretained(this), |
603 num_textures_after_loss_ - 1)); | 603 num_textures_after_loss_ - 1)); |
604 break; | 604 break; |
605 } | 605 } |
606 } | 606 } |
607 | 607 |
608 virtual void SwapBuffersOnThread(LayerTreeHostImpl* impl, | 608 virtual void SwapBuffersOnThread(LayerTreeHostImpl* impl, |
609 bool result) OVERRIDE { | 609 bool result) override { |
610 switch (impl->active_tree()->source_frame_number()) { | 610 switch (impl->active_tree()->source_frame_number()) { |
611 case 0: | 611 case 0: |
612 // The layers have been drawn, so their textures have been allocated. | 612 // The layers have been drawn, so their textures have been allocated. |
613 EXPECT_FALSE(result_); | 613 EXPECT_FALSE(result_); |
614 num_textures_without_readback_ = | 614 num_textures_without_readback_ = |
615 first_context_provider_->TestContext3d()->NumTextures(); | 615 first_context_provider_->TestContext3d()->NumTextures(); |
616 break; | 616 break; |
617 case 1: | 617 case 1: |
618 // We did a readback, so there will be a readback texture around now. | 618 // We did a readback, so there will be a readback texture around now. |
619 EXPECT_LT(num_textures_without_readback_, | 619 EXPECT_LT(num_textures_without_readback_, |
(...skipping 19 matching lines...) Expand all Loading... |
639 break; | 639 break; |
640 } | 640 } |
641 } | 641 } |
642 | 642 |
643 void CheckNumTextures(size_t expected_num_textures) { | 643 void CheckNumTextures(size_t expected_num_textures) { |
644 EXPECT_EQ(expected_num_textures, | 644 EXPECT_EQ(expected_num_textures, |
645 first_context_provider_->TestContext3d()->NumTextures()); | 645 first_context_provider_->TestContext3d()->NumTextures()); |
646 EndTest(); | 646 EndTest(); |
647 } | 647 } |
648 | 648 |
649 virtual void AfterTest() OVERRIDE {} | 649 virtual void AfterTest() override {} |
650 | 650 |
651 scoped_refptr<TestContextProvider> first_context_provider_; | 651 scoped_refptr<TestContextProvider> first_context_provider_; |
652 scoped_refptr<TestContextProvider> second_context_provider_; | 652 scoped_refptr<TestContextProvider> second_context_provider_; |
653 size_t num_textures_without_readback_; | 653 size_t num_textures_without_readback_; |
654 size_t num_textures_after_loss_; | 654 size_t num_textures_after_loss_; |
655 FakeContentLayerClient client_; | 655 FakeContentLayerClient client_; |
656 scoped_refptr<FakeContentLayer> root_; | 656 scoped_refptr<FakeContentLayer> root_; |
657 scoped_refptr<FakeContentLayer> copy_layer_; | 657 scoped_refptr<FakeContentLayer> copy_layer_; |
658 scoped_ptr<CopyOutputResult> result_; | 658 scoped_ptr<CopyOutputResult> result_; |
659 }; | 659 }; |
660 | 660 |
661 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( | 661 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( |
662 LayerTreeHostCopyRequestTestLostOutputSurface); | 662 LayerTreeHostCopyRequestTestLostOutputSurface); |
663 | 663 |
664 class LayerTreeHostCopyRequestTestCountTextures | 664 class LayerTreeHostCopyRequestTestCountTextures |
665 : public LayerTreeHostCopyRequestTest { | 665 : public LayerTreeHostCopyRequestTest { |
666 protected: | 666 protected: |
667 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) | 667 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) |
668 OVERRIDE { | 668 override { |
669 context_provider_ = TestContextProvider::Create(); | 669 context_provider_ = TestContextProvider::Create(); |
670 return FakeOutputSurface::Create3d(context_provider_); | 670 return FakeOutputSurface::Create3d(context_provider_); |
671 } | 671 } |
672 | 672 |
673 virtual void SetupTree() OVERRIDE { | 673 virtual void SetupTree() override { |
674 root_ = FakeContentLayer::Create(&client_); | 674 root_ = FakeContentLayer::Create(&client_); |
675 root_->SetBounds(gfx::Size(20, 20)); | 675 root_->SetBounds(gfx::Size(20, 20)); |
676 | 676 |
677 copy_layer_ = FakeContentLayer::Create(&client_); | 677 copy_layer_ = FakeContentLayer::Create(&client_); |
678 copy_layer_->SetBounds(gfx::Size(10, 10)); | 678 copy_layer_->SetBounds(gfx::Size(10, 10)); |
679 root_->AddChild(copy_layer_); | 679 root_->AddChild(copy_layer_); |
680 | 680 |
681 layer_tree_host()->SetRootLayer(root_); | 681 layer_tree_host()->SetRootLayer(root_); |
682 LayerTreeHostCopyRequestTest::SetupTree(); | 682 LayerTreeHostCopyRequestTest::SetupTree(); |
683 } | 683 } |
684 | 684 |
685 virtual void BeginTest() OVERRIDE { | 685 virtual void BeginTest() override { |
686 num_textures_without_readback_ = 0; | 686 num_textures_without_readback_ = 0; |
687 num_textures_with_readback_ = 0; | 687 num_textures_with_readback_ = 0; |
688 waited_sync_point_after_readback_ = 0; | 688 waited_sync_point_after_readback_ = 0; |
689 PostSetNeedsCommitToMainThread(); | 689 PostSetNeedsCommitToMainThread(); |
690 } | 690 } |
691 | 691 |
692 virtual void RequestCopy(Layer* layer) = 0; | 692 virtual void RequestCopy(Layer* layer) = 0; |
693 | 693 |
694 virtual void DidCommitAndDrawFrame() OVERRIDE { | 694 virtual void DidCommitAndDrawFrame() override { |
695 switch (layer_tree_host()->source_frame_number()) { | 695 switch (layer_tree_host()->source_frame_number()) { |
696 case 1: | 696 case 1: |
697 // The layers have been pushed to the impl side. The layer textures have | 697 // The layers have been pushed to the impl side. The layer textures have |
698 // been allocated. | 698 // been allocated. |
699 RequestCopy(copy_layer_.get()); | 699 RequestCopy(copy_layer_.get()); |
700 break; | 700 break; |
701 } | 701 } |
702 } | 702 } |
703 | 703 |
704 virtual void SwapBuffersOnThread(LayerTreeHostImpl* impl, | 704 virtual void SwapBuffersOnThread(LayerTreeHostImpl* impl, |
705 bool result) OVERRIDE { | 705 bool result) override { |
706 switch (impl->active_tree()->source_frame_number()) { | 706 switch (impl->active_tree()->source_frame_number()) { |
707 case 0: | 707 case 0: |
708 // The layers have been drawn, so their textures have been allocated. | 708 // The layers have been drawn, so their textures have been allocated. |
709 num_textures_without_readback_ = | 709 num_textures_without_readback_ = |
710 context_provider_->TestContext3d()->NumTextures(); | 710 context_provider_->TestContext3d()->NumTextures(); |
711 break; | 711 break; |
712 case 1: | 712 case 1: |
713 // We did a readback, so there will be a readback texture around now. | 713 // We did a readback, so there will be a readback texture around now. |
714 num_textures_with_readback_ = | 714 num_textures_with_readback_ = |
715 context_provider_->TestContext3d()->NumTextures(); | 715 context_provider_->TestContext3d()->NumTextures(); |
(...skipping 15 matching lines...) Expand all Loading... |
731 size_t num_textures_with_readback_; | 731 size_t num_textures_with_readback_; |
732 unsigned waited_sync_point_after_readback_; | 732 unsigned waited_sync_point_after_readback_; |
733 FakeContentLayerClient client_; | 733 FakeContentLayerClient client_; |
734 scoped_refptr<FakeContentLayer> root_; | 734 scoped_refptr<FakeContentLayer> root_; |
735 scoped_refptr<FakeContentLayer> copy_layer_; | 735 scoped_refptr<FakeContentLayer> copy_layer_; |
736 }; | 736 }; |
737 | 737 |
738 class LayerTreeHostCopyRequestTestCreatesTexture | 738 class LayerTreeHostCopyRequestTestCreatesTexture |
739 : public LayerTreeHostCopyRequestTestCountTextures { | 739 : public LayerTreeHostCopyRequestTestCountTextures { |
740 protected: | 740 protected: |
741 virtual void RequestCopy(Layer* layer) OVERRIDE { | 741 virtual void RequestCopy(Layer* layer) override { |
742 // Request a normal texture copy. This should create a new texture. | 742 // Request a normal texture copy. This should create a new texture. |
743 copy_layer_->RequestCopyOfOutput( | 743 copy_layer_->RequestCopyOfOutput( |
744 CopyOutputRequest::CreateRequest(base::Bind( | 744 CopyOutputRequest::CreateRequest(base::Bind( |
745 &LayerTreeHostCopyRequestTestCreatesTexture::CopyOutputCallback, | 745 &LayerTreeHostCopyRequestTestCreatesTexture::CopyOutputCallback, |
746 base::Unretained(this)))); | 746 base::Unretained(this)))); |
747 } | 747 } |
748 | 748 |
749 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 749 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
750 EXPECT_FALSE(result->IsEmpty()); | 750 EXPECT_FALSE(result->IsEmpty()); |
751 EXPECT_TRUE(result->HasTexture()); | 751 EXPECT_TRUE(result->HasTexture()); |
752 | 752 |
753 TextureMailbox mailbox; | 753 TextureMailbox mailbox; |
754 scoped_ptr<SingleReleaseCallback> release; | 754 scoped_ptr<SingleReleaseCallback> release; |
755 result->TakeTexture(&mailbox, &release); | 755 result->TakeTexture(&mailbox, &release); |
756 EXPECT_TRUE(release); | 756 EXPECT_TRUE(release); |
757 | 757 |
758 release->Run(0, false); | 758 release->Run(0, false); |
759 } | 759 } |
760 | 760 |
761 virtual void AfterTest() OVERRIDE { | 761 virtual void AfterTest() override { |
762 // No sync point was needed. | 762 // No sync point was needed. |
763 EXPECT_EQ(0u, waited_sync_point_after_readback_); | 763 EXPECT_EQ(0u, waited_sync_point_after_readback_); |
764 // Except the copy to have made another texture. | 764 // Except the copy to have made another texture. |
765 EXPECT_EQ(num_textures_without_readback_ + 1, num_textures_with_readback_); | 765 EXPECT_EQ(num_textures_without_readback_ + 1, num_textures_with_readback_); |
766 } | 766 } |
767 }; | 767 }; |
768 | 768 |
769 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( | 769 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( |
770 LayerTreeHostCopyRequestTestCreatesTexture); | 770 LayerTreeHostCopyRequestTestCreatesTexture); |
771 | 771 |
772 class LayerTreeHostCopyRequestTestProvideTexture | 772 class LayerTreeHostCopyRequestTestProvideTexture |
773 : public LayerTreeHostCopyRequestTestCountTextures { | 773 : public LayerTreeHostCopyRequestTestCountTextures { |
774 protected: | 774 protected: |
775 virtual void BeginTest() OVERRIDE { | 775 virtual void BeginTest() override { |
776 external_context_provider_ = TestContextProvider::Create(); | 776 external_context_provider_ = TestContextProvider::Create(); |
777 EXPECT_TRUE(external_context_provider_->BindToCurrentThread()); | 777 EXPECT_TRUE(external_context_provider_->BindToCurrentThread()); |
778 LayerTreeHostCopyRequestTestCountTextures::BeginTest(); | 778 LayerTreeHostCopyRequestTestCountTextures::BeginTest(); |
779 } | 779 } |
780 | 780 |
781 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 781 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
782 EXPECT_FALSE(result->IsEmpty()); | 782 EXPECT_FALSE(result->IsEmpty()); |
783 EXPECT_TRUE(result->HasTexture()); | 783 EXPECT_TRUE(result->HasTexture()); |
784 | 784 |
785 TextureMailbox mailbox; | 785 TextureMailbox mailbox; |
786 scoped_ptr<SingleReleaseCallback> release; | 786 scoped_ptr<SingleReleaseCallback> release; |
787 result->TakeTexture(&mailbox, &release); | 787 result->TakeTexture(&mailbox, &release); |
788 EXPECT_FALSE(release); | 788 EXPECT_FALSE(release); |
789 } | 789 } |
790 | 790 |
791 virtual void RequestCopy(Layer* layer) OVERRIDE { | 791 virtual void RequestCopy(Layer* layer) override { |
792 // Request a copy to a provided texture. This should not create a new | 792 // Request a copy to a provided texture. This should not create a new |
793 // texture. | 793 // texture. |
794 scoped_ptr<CopyOutputRequest> request = | 794 scoped_ptr<CopyOutputRequest> request = |
795 CopyOutputRequest::CreateRequest(base::Bind( | 795 CopyOutputRequest::CreateRequest(base::Bind( |
796 &LayerTreeHostCopyRequestTestProvideTexture::CopyOutputCallback, | 796 &LayerTreeHostCopyRequestTestProvideTexture::CopyOutputCallback, |
797 base::Unretained(this))); | 797 base::Unretained(this))); |
798 | 798 |
799 gpu::gles2::GLES2Interface* gl = external_context_provider_->ContextGL(); | 799 gpu::gles2::GLES2Interface* gl = external_context_provider_->ContextGL(); |
800 gpu::Mailbox mailbox; | 800 gpu::Mailbox mailbox; |
801 gl->GenMailboxCHROMIUM(mailbox.name); | 801 gl->GenMailboxCHROMIUM(mailbox.name); |
802 sync_point_ = gl->InsertSyncPointCHROMIUM(); | 802 sync_point_ = gl->InsertSyncPointCHROMIUM(); |
803 request->SetTextureMailbox( | 803 request->SetTextureMailbox( |
804 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point_)); | 804 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point_)); |
805 EXPECT_TRUE(request->has_texture_mailbox()); | 805 EXPECT_TRUE(request->has_texture_mailbox()); |
806 | 806 |
807 copy_layer_->RequestCopyOfOutput(request.Pass()); | 807 copy_layer_->RequestCopyOfOutput(request.Pass()); |
808 } | 808 } |
809 | 809 |
810 virtual void AfterTest() OVERRIDE { | 810 virtual void AfterTest() override { |
811 // Expect the compositor to have waited for the sync point in the provided | 811 // Expect the compositor to have waited for the sync point in the provided |
812 // TextureMailbox. | 812 // TextureMailbox. |
813 EXPECT_EQ(sync_point_, waited_sync_point_after_readback_); | 813 EXPECT_EQ(sync_point_, waited_sync_point_after_readback_); |
814 // Except the copy to have *not* made another texture. | 814 // Except the copy to have *not* made another texture. |
815 EXPECT_EQ(num_textures_without_readback_, num_textures_with_readback_); | 815 EXPECT_EQ(num_textures_without_readback_, num_textures_with_readback_); |
816 } | 816 } |
817 | 817 |
818 scoped_refptr<TestContextProvider> external_context_provider_; | 818 scoped_refptr<TestContextProvider> external_context_provider_; |
819 unsigned sync_point_; | 819 unsigned sync_point_; |
820 }; | 820 }; |
821 | 821 |
822 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( | 822 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( |
823 LayerTreeHostCopyRequestTestProvideTexture); | 823 LayerTreeHostCopyRequestTestProvideTexture); |
824 | 824 |
825 class LayerTreeHostCopyRequestTestDestroyBeforeCopy | 825 class LayerTreeHostCopyRequestTestDestroyBeforeCopy |
826 : public LayerTreeHostCopyRequestTest { | 826 : public LayerTreeHostCopyRequestTest { |
827 protected: | 827 protected: |
828 virtual void SetupTree() OVERRIDE { | 828 virtual void SetupTree() override { |
829 root_ = FakeContentLayer::Create(&client_); | 829 root_ = FakeContentLayer::Create(&client_); |
830 root_->SetBounds(gfx::Size(20, 20)); | 830 root_->SetBounds(gfx::Size(20, 20)); |
831 | 831 |
832 copy_layer_ = FakeContentLayer::Create(&client_); | 832 copy_layer_ = FakeContentLayer::Create(&client_); |
833 copy_layer_->SetBounds(gfx::Size(10, 10)); | 833 copy_layer_->SetBounds(gfx::Size(10, 10)); |
834 root_->AddChild(copy_layer_); | 834 root_->AddChild(copy_layer_); |
835 | 835 |
836 layer_tree_host()->SetRootLayer(root_); | 836 layer_tree_host()->SetRootLayer(root_); |
837 LayerTreeHostCopyRequestTest::SetupTree(); | 837 LayerTreeHostCopyRequestTest::SetupTree(); |
838 } | 838 } |
839 | 839 |
840 virtual void BeginTest() OVERRIDE { | 840 virtual void BeginTest() override { |
841 callback_count_ = 0; | 841 callback_count_ = 0; |
842 PostSetNeedsCommitToMainThread(); | 842 PostSetNeedsCommitToMainThread(); |
843 } | 843 } |
844 | 844 |
845 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 845 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
846 EXPECT_TRUE(result->IsEmpty()); | 846 EXPECT_TRUE(result->IsEmpty()); |
847 ++callback_count_; | 847 ++callback_count_; |
848 } | 848 } |
849 | 849 |
850 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 850 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
851 MainThreadTaskRunner()->PostTask( | 851 MainThreadTaskRunner()->PostTask( |
852 FROM_HERE, | 852 FROM_HERE, |
853 base::Bind(&LayerTreeHostCopyRequestTestDestroyBeforeCopy::DidActivate, | 853 base::Bind(&LayerTreeHostCopyRequestTestDestroyBeforeCopy::DidActivate, |
854 base::Unretained(this))); | 854 base::Unretained(this))); |
855 } | 855 } |
856 | 856 |
857 void DidActivate() { | 857 void DidActivate() { |
858 switch (layer_tree_host()->source_frame_number()) { | 858 switch (layer_tree_host()->source_frame_number()) { |
859 case 1: { | 859 case 1: { |
860 EXPECT_EQ(0, callback_count_); | 860 EXPECT_EQ(0, callback_count_); |
(...skipping 20 matching lines...) Expand all Loading... |
881 layer_tree_host()->SetViewportSize( | 881 layer_tree_host()->SetViewportSize( |
882 layer_tree_host()->root_layer()->bounds()); | 882 layer_tree_host()->root_layer()->bounds()); |
883 break; | 883 break; |
884 case 4: | 884 case 4: |
885 EXPECT_EQ(1, callback_count_); | 885 EXPECT_EQ(1, callback_count_); |
886 // We should not have crashed. | 886 // We should not have crashed. |
887 EndTest(); | 887 EndTest(); |
888 } | 888 } |
889 } | 889 } |
890 | 890 |
891 virtual void AfterTest() OVERRIDE {} | 891 virtual void AfterTest() override {} |
892 | 892 |
893 int callback_count_; | 893 int callback_count_; |
894 FakeContentLayerClient client_; | 894 FakeContentLayerClient client_; |
895 scoped_refptr<FakeContentLayer> root_; | 895 scoped_refptr<FakeContentLayer> root_; |
896 scoped_refptr<FakeContentLayer> copy_layer_; | 896 scoped_refptr<FakeContentLayer> copy_layer_; |
897 }; | 897 }; |
898 | 898 |
899 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 899 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
900 LayerTreeHostCopyRequestTestDestroyBeforeCopy); | 900 LayerTreeHostCopyRequestTestDestroyBeforeCopy); |
901 | 901 |
902 class LayerTreeHostCopyRequestTestShutdownBeforeCopy | 902 class LayerTreeHostCopyRequestTestShutdownBeforeCopy |
903 : public LayerTreeHostCopyRequestTest { | 903 : public LayerTreeHostCopyRequestTest { |
904 protected: | 904 protected: |
905 virtual void SetupTree() OVERRIDE { | 905 virtual void SetupTree() override { |
906 root_ = FakeContentLayer::Create(&client_); | 906 root_ = FakeContentLayer::Create(&client_); |
907 root_->SetBounds(gfx::Size(20, 20)); | 907 root_->SetBounds(gfx::Size(20, 20)); |
908 | 908 |
909 copy_layer_ = FakeContentLayer::Create(&client_); | 909 copy_layer_ = FakeContentLayer::Create(&client_); |
910 copy_layer_->SetBounds(gfx::Size(10, 10)); | 910 copy_layer_->SetBounds(gfx::Size(10, 10)); |
911 root_->AddChild(copy_layer_); | 911 root_->AddChild(copy_layer_); |
912 | 912 |
913 layer_tree_host()->SetRootLayer(root_); | 913 layer_tree_host()->SetRootLayer(root_); |
914 LayerTreeHostCopyRequestTest::SetupTree(); | 914 LayerTreeHostCopyRequestTest::SetupTree(); |
915 } | 915 } |
916 | 916 |
917 virtual void BeginTest() OVERRIDE { | 917 virtual void BeginTest() override { |
918 callback_count_ = 0; | 918 callback_count_ = 0; |
919 PostSetNeedsCommitToMainThread(); | 919 PostSetNeedsCommitToMainThread(); |
920 } | 920 } |
921 | 921 |
922 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 922 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
923 EXPECT_TRUE(result->IsEmpty()); | 923 EXPECT_TRUE(result->IsEmpty()); |
924 ++callback_count_; | 924 ++callback_count_; |
925 } | 925 } |
926 | 926 |
927 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 927 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
928 MainThreadTaskRunner()->PostTask( | 928 MainThreadTaskRunner()->PostTask( |
929 FROM_HERE, | 929 FROM_HERE, |
930 base::Bind(&LayerTreeHostCopyRequestTestShutdownBeforeCopy::DidActivate, | 930 base::Bind(&LayerTreeHostCopyRequestTestShutdownBeforeCopy::DidActivate, |
931 base::Unretained(this))); | 931 base::Unretained(this))); |
932 } | 932 } |
933 | 933 |
934 void DidActivate() { | 934 void DidActivate() { |
935 switch (layer_tree_host()->source_frame_number()) { | 935 switch (layer_tree_host()->source_frame_number()) { |
936 case 1: { | 936 case 1: { |
937 EXPECT_EQ(0, callback_count_); | 937 EXPECT_EQ(0, callback_count_); |
(...skipping 14 matching lines...) Expand all Loading... |
952 // End the test after the copy result has had a chance to get back to | 952 // End the test after the copy result has had a chance to get back to |
953 // the main thread. | 953 // the main thread. |
954 MainThreadTaskRunner()->PostTask( | 954 MainThreadTaskRunner()->PostTask( |
955 FROM_HERE, | 955 FROM_HERE, |
956 base::Bind(&LayerTreeHostCopyRequestTestShutdownBeforeCopy::EndTest, | 956 base::Bind(&LayerTreeHostCopyRequestTestShutdownBeforeCopy::EndTest, |
957 base::Unretained(this))); | 957 base::Unretained(this))); |
958 break; | 958 break; |
959 } | 959 } |
960 } | 960 } |
961 | 961 |
962 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, callback_count_); } | 962 virtual void AfterTest() override { EXPECT_EQ(1, callback_count_); } |
963 | 963 |
964 int callback_count_; | 964 int callback_count_; |
965 FakeContentLayerClient client_; | 965 FakeContentLayerClient client_; |
966 scoped_refptr<FakeContentLayer> root_; | 966 scoped_refptr<FakeContentLayer> root_; |
967 scoped_refptr<FakeContentLayer> copy_layer_; | 967 scoped_refptr<FakeContentLayer> copy_layer_; |
968 }; | 968 }; |
969 | 969 |
970 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 970 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
971 LayerTreeHostCopyRequestTestShutdownBeforeCopy); | 971 LayerTreeHostCopyRequestTestShutdownBeforeCopy); |
972 | 972 |
973 } // namespace | 973 } // namespace |
974 } // namespace cc | 974 } // namespace cc |
OLD | NEW |