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

Side by Side Diff: cc/trees/layer_tree_host_unittest_copyrequest.cc

Issue 645853008: Standardize usage of virtual/override/final in cc/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Formatted Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/output/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 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 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
37 37
38 virtual void DidCommitAndDrawFrame() override { WaitForCallback(); } 38 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
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 void AfterTest() override { EXPECT_EQ(4u, callbacks_.size()); }
105 105
106 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) 106 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(
107 override { 107 bool fallback) 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
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 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 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 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
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 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 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 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
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 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 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 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 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 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 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 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 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 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 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 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 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 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 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(
538 override { 538 bool fallback) 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 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 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 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 11 matching lines...) Expand all
598 ImplThreadTaskRunner()->PostTask( 598 ImplThreadTaskRunner()->PostTask(
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 void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override {
609 bool result) override {
610 switch (impl->active_tree()->source_frame_number()) { 609 switch (impl->active_tree()->source_frame_number()) {
611 case 0: 610 case 0:
612 // The layers have been drawn, so their textures have been allocated. 611 // The layers have been drawn, so their textures have been allocated.
613 EXPECT_FALSE(result_); 612 EXPECT_FALSE(result_);
614 num_textures_without_readback_ = 613 num_textures_without_readback_ =
615 first_context_provider_->TestContext3d()->NumTextures(); 614 first_context_provider_->TestContext3d()->NumTextures();
616 break; 615 break;
617 case 1: 616 case 1:
618 // We did a readback, so there will be a readback texture around now. 617 // We did a readback, so there will be a readback texture around now.
619 EXPECT_LT(num_textures_without_readback_, 618 EXPECT_LT(num_textures_without_readback_,
(...skipping 19 matching lines...) Expand all
639 break; 638 break;
640 } 639 }
641 } 640 }
642 641
643 void CheckNumTextures(size_t expected_num_textures) { 642 void CheckNumTextures(size_t expected_num_textures) {
644 EXPECT_EQ(expected_num_textures, 643 EXPECT_EQ(expected_num_textures,
645 first_context_provider_->TestContext3d()->NumTextures()); 644 first_context_provider_->TestContext3d()->NumTextures());
646 EndTest(); 645 EndTest();
647 } 646 }
648 647
649 virtual void AfterTest() override {} 648 void AfterTest() override {}
650 649
651 scoped_refptr<TestContextProvider> first_context_provider_; 650 scoped_refptr<TestContextProvider> first_context_provider_;
652 scoped_refptr<TestContextProvider> second_context_provider_; 651 scoped_refptr<TestContextProvider> second_context_provider_;
653 size_t num_textures_without_readback_; 652 size_t num_textures_without_readback_;
654 size_t num_textures_after_loss_; 653 size_t num_textures_after_loss_;
655 FakeContentLayerClient client_; 654 FakeContentLayerClient client_;
656 scoped_refptr<FakeContentLayer> root_; 655 scoped_refptr<FakeContentLayer> root_;
657 scoped_refptr<FakeContentLayer> copy_layer_; 656 scoped_refptr<FakeContentLayer> copy_layer_;
658 scoped_ptr<CopyOutputResult> result_; 657 scoped_ptr<CopyOutputResult> result_;
659 }; 658 };
660 659
661 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( 660 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F(
662 LayerTreeHostCopyRequestTestLostOutputSurface); 661 LayerTreeHostCopyRequestTestLostOutputSurface);
663 662
664 class LayerTreeHostCopyRequestTestCountTextures 663 class LayerTreeHostCopyRequestTestCountTextures
665 : public LayerTreeHostCopyRequestTest { 664 : public LayerTreeHostCopyRequestTest {
666 protected: 665 protected:
667 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) 666 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(
668 override { 667 bool fallback) override {
669 context_provider_ = TestContextProvider::Create(); 668 context_provider_ = TestContextProvider::Create();
670 return FakeOutputSurface::Create3d(context_provider_); 669 return FakeOutputSurface::Create3d(context_provider_);
671 } 670 }
672 671
673 virtual void SetupTree() override { 672 void SetupTree() override {
674 root_ = FakeContentLayer::Create(&client_); 673 root_ = FakeContentLayer::Create(&client_);
675 root_->SetBounds(gfx::Size(20, 20)); 674 root_->SetBounds(gfx::Size(20, 20));
676 675
677 copy_layer_ = FakeContentLayer::Create(&client_); 676 copy_layer_ = FakeContentLayer::Create(&client_);
678 copy_layer_->SetBounds(gfx::Size(10, 10)); 677 copy_layer_->SetBounds(gfx::Size(10, 10));
679 root_->AddChild(copy_layer_); 678 root_->AddChild(copy_layer_);
680 679
681 layer_tree_host()->SetRootLayer(root_); 680 layer_tree_host()->SetRootLayer(root_);
682 LayerTreeHostCopyRequestTest::SetupTree(); 681 LayerTreeHostCopyRequestTest::SetupTree();
683 } 682 }
684 683
685 virtual void BeginTest() override { 684 void BeginTest() override {
686 num_textures_without_readback_ = 0; 685 num_textures_without_readback_ = 0;
687 num_textures_with_readback_ = 0; 686 num_textures_with_readback_ = 0;
688 waited_sync_point_after_readback_ = 0; 687 waited_sync_point_after_readback_ = 0;
689 PostSetNeedsCommitToMainThread(); 688 PostSetNeedsCommitToMainThread();
690 } 689 }
691 690
692 virtual void RequestCopy(Layer* layer) = 0; 691 virtual void RequestCopy(Layer* layer) = 0;
693 692
694 virtual void DidCommitAndDrawFrame() override { 693 void DidCommitAndDrawFrame() override {
695 switch (layer_tree_host()->source_frame_number()) { 694 switch (layer_tree_host()->source_frame_number()) {
696 case 1: 695 case 1:
697 // The layers have been pushed to the impl side. The layer textures have 696 // The layers have been pushed to the impl side. The layer textures have
698 // been allocated. 697 // been allocated.
699 RequestCopy(copy_layer_.get()); 698 RequestCopy(copy_layer_.get());
700 break; 699 break;
701 } 700 }
702 } 701 }
703 702
704 virtual void SwapBuffersOnThread(LayerTreeHostImpl* impl, 703 void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override {
705 bool result) override {
706 switch (impl->active_tree()->source_frame_number()) { 704 switch (impl->active_tree()->source_frame_number()) {
707 case 0: 705 case 0:
708 // The layers have been drawn, so their textures have been allocated. 706 // The layers have been drawn, so their textures have been allocated.
709 num_textures_without_readback_ = 707 num_textures_without_readback_ =
710 context_provider_->TestContext3d()->NumTextures(); 708 context_provider_->TestContext3d()->NumTextures();
711 break; 709 break;
712 case 1: 710 case 1:
713 // We did a readback, so there will be a readback texture around now. 711 // We did a readback, so there will be a readback texture around now.
714 num_textures_with_readback_ = 712 num_textures_with_readback_ =
715 context_provider_->TestContext3d()->NumTextures(); 713 context_provider_->TestContext3d()->NumTextures();
(...skipping 15 matching lines...) Expand all
731 size_t num_textures_with_readback_; 729 size_t num_textures_with_readback_;
732 unsigned waited_sync_point_after_readback_; 730 unsigned waited_sync_point_after_readback_;
733 FakeContentLayerClient client_; 731 FakeContentLayerClient client_;
734 scoped_refptr<FakeContentLayer> root_; 732 scoped_refptr<FakeContentLayer> root_;
735 scoped_refptr<FakeContentLayer> copy_layer_; 733 scoped_refptr<FakeContentLayer> copy_layer_;
736 }; 734 };
737 735
738 class LayerTreeHostCopyRequestTestCreatesTexture 736 class LayerTreeHostCopyRequestTestCreatesTexture
739 : public LayerTreeHostCopyRequestTestCountTextures { 737 : public LayerTreeHostCopyRequestTestCountTextures {
740 protected: 738 protected:
741 virtual void RequestCopy(Layer* layer) override { 739 void RequestCopy(Layer* layer) override {
742 // Request a normal texture copy. This should create a new texture. 740 // Request a normal texture copy. This should create a new texture.
743 copy_layer_->RequestCopyOfOutput( 741 copy_layer_->RequestCopyOfOutput(
744 CopyOutputRequest::CreateRequest(base::Bind( 742 CopyOutputRequest::CreateRequest(base::Bind(
745 &LayerTreeHostCopyRequestTestCreatesTexture::CopyOutputCallback, 743 &LayerTreeHostCopyRequestTestCreatesTexture::CopyOutputCallback,
746 base::Unretained(this)))); 744 base::Unretained(this))));
747 } 745 }
748 746
749 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { 747 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {
750 EXPECT_FALSE(result->IsEmpty()); 748 EXPECT_FALSE(result->IsEmpty());
751 EXPECT_TRUE(result->HasTexture()); 749 EXPECT_TRUE(result->HasTexture());
752 750
753 TextureMailbox mailbox; 751 TextureMailbox mailbox;
754 scoped_ptr<SingleReleaseCallback> release; 752 scoped_ptr<SingleReleaseCallback> release;
755 result->TakeTexture(&mailbox, &release); 753 result->TakeTexture(&mailbox, &release);
756 EXPECT_TRUE(release); 754 EXPECT_TRUE(release);
757 755
758 release->Run(0, false); 756 release->Run(0, false);
759 } 757 }
760 758
761 virtual void AfterTest() override { 759 void AfterTest() override {
762 // No sync point was needed. 760 // No sync point was needed.
763 EXPECT_EQ(0u, waited_sync_point_after_readback_); 761 EXPECT_EQ(0u, waited_sync_point_after_readback_);
764 // Except the copy to have made another texture. 762 // Except the copy to have made another texture.
765 EXPECT_EQ(num_textures_without_readback_ + 1, num_textures_with_readback_); 763 EXPECT_EQ(num_textures_without_readback_ + 1, num_textures_with_readback_);
766 } 764 }
767 }; 765 };
768 766
769 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( 767 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F(
770 LayerTreeHostCopyRequestTestCreatesTexture); 768 LayerTreeHostCopyRequestTestCreatesTexture);
771 769
772 class LayerTreeHostCopyRequestTestProvideTexture 770 class LayerTreeHostCopyRequestTestProvideTexture
773 : public LayerTreeHostCopyRequestTestCountTextures { 771 : public LayerTreeHostCopyRequestTestCountTextures {
774 protected: 772 protected:
775 virtual void BeginTest() override { 773 void BeginTest() override {
776 external_context_provider_ = TestContextProvider::Create(); 774 external_context_provider_ = TestContextProvider::Create();
777 EXPECT_TRUE(external_context_provider_->BindToCurrentThread()); 775 EXPECT_TRUE(external_context_provider_->BindToCurrentThread());
778 LayerTreeHostCopyRequestTestCountTextures::BeginTest(); 776 LayerTreeHostCopyRequestTestCountTextures::BeginTest();
779 } 777 }
780 778
781 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { 779 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {
782 EXPECT_FALSE(result->IsEmpty()); 780 EXPECT_FALSE(result->IsEmpty());
783 EXPECT_TRUE(result->HasTexture()); 781 EXPECT_TRUE(result->HasTexture());
784 782
785 TextureMailbox mailbox; 783 TextureMailbox mailbox;
786 scoped_ptr<SingleReleaseCallback> release; 784 scoped_ptr<SingleReleaseCallback> release;
787 result->TakeTexture(&mailbox, &release); 785 result->TakeTexture(&mailbox, &release);
788 EXPECT_FALSE(release); 786 EXPECT_FALSE(release);
789 } 787 }
790 788
791 virtual void RequestCopy(Layer* layer) override { 789 void RequestCopy(Layer* layer) override {
792 // Request a copy to a provided texture. This should not create a new 790 // Request a copy to a provided texture. This should not create a new
793 // texture. 791 // texture.
794 scoped_ptr<CopyOutputRequest> request = 792 scoped_ptr<CopyOutputRequest> request =
795 CopyOutputRequest::CreateRequest(base::Bind( 793 CopyOutputRequest::CreateRequest(base::Bind(
796 &LayerTreeHostCopyRequestTestProvideTexture::CopyOutputCallback, 794 &LayerTreeHostCopyRequestTestProvideTexture::CopyOutputCallback,
797 base::Unretained(this))); 795 base::Unretained(this)));
798 796
799 gpu::gles2::GLES2Interface* gl = external_context_provider_->ContextGL(); 797 gpu::gles2::GLES2Interface* gl = external_context_provider_->ContextGL();
800 gpu::Mailbox mailbox; 798 gpu::Mailbox mailbox;
801 gl->GenMailboxCHROMIUM(mailbox.name); 799 gl->GenMailboxCHROMIUM(mailbox.name);
802 sync_point_ = gl->InsertSyncPointCHROMIUM(); 800 sync_point_ = gl->InsertSyncPointCHROMIUM();
803 request->SetTextureMailbox( 801 request->SetTextureMailbox(
804 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point_)); 802 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point_));
805 EXPECT_TRUE(request->has_texture_mailbox()); 803 EXPECT_TRUE(request->has_texture_mailbox());
806 804
807 copy_layer_->RequestCopyOfOutput(request.Pass()); 805 copy_layer_->RequestCopyOfOutput(request.Pass());
808 } 806 }
809 807
810 virtual void AfterTest() override { 808 void AfterTest() override {
811 // Expect the compositor to have waited for the sync point in the provided 809 // Expect the compositor to have waited for the sync point in the provided
812 // TextureMailbox. 810 // TextureMailbox.
813 EXPECT_EQ(sync_point_, waited_sync_point_after_readback_); 811 EXPECT_EQ(sync_point_, waited_sync_point_after_readback_);
814 // Except the copy to have *not* made another texture. 812 // Except the copy to have *not* made another texture.
815 EXPECT_EQ(num_textures_without_readback_, num_textures_with_readback_); 813 EXPECT_EQ(num_textures_without_readback_, num_textures_with_readback_);
816 } 814 }
817 815
818 scoped_refptr<TestContextProvider> external_context_provider_; 816 scoped_refptr<TestContextProvider> external_context_provider_;
819 unsigned sync_point_; 817 unsigned sync_point_;
820 }; 818 };
821 819
822 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( 820 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F(
823 LayerTreeHostCopyRequestTestProvideTexture); 821 LayerTreeHostCopyRequestTestProvideTexture);
824 822
825 class LayerTreeHostCopyRequestTestDestroyBeforeCopy 823 class LayerTreeHostCopyRequestTestDestroyBeforeCopy
826 : public LayerTreeHostCopyRequestTest { 824 : public LayerTreeHostCopyRequestTest {
827 protected: 825 protected:
828 virtual void SetupTree() override { 826 void SetupTree() override {
829 root_ = FakeContentLayer::Create(&client_); 827 root_ = FakeContentLayer::Create(&client_);
830 root_->SetBounds(gfx::Size(20, 20)); 828 root_->SetBounds(gfx::Size(20, 20));
831 829
832 copy_layer_ = FakeContentLayer::Create(&client_); 830 copy_layer_ = FakeContentLayer::Create(&client_);
833 copy_layer_->SetBounds(gfx::Size(10, 10)); 831 copy_layer_->SetBounds(gfx::Size(10, 10));
834 root_->AddChild(copy_layer_); 832 root_->AddChild(copy_layer_);
835 833
836 layer_tree_host()->SetRootLayer(root_); 834 layer_tree_host()->SetRootLayer(root_);
837 LayerTreeHostCopyRequestTest::SetupTree(); 835 LayerTreeHostCopyRequestTest::SetupTree();
838 } 836 }
839 837
840 virtual void BeginTest() override { 838 void BeginTest() override {
841 callback_count_ = 0; 839 callback_count_ = 0;
842 PostSetNeedsCommitToMainThread(); 840 PostSetNeedsCommitToMainThread();
843 } 841 }
844 842
845 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { 843 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {
846 EXPECT_TRUE(result->IsEmpty()); 844 EXPECT_TRUE(result->IsEmpty());
847 ++callback_count_; 845 ++callback_count_;
848 } 846 }
849 847
850 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 848 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
851 MainThreadTaskRunner()->PostTask( 849 MainThreadTaskRunner()->PostTask(
852 FROM_HERE, 850 FROM_HERE,
853 base::Bind(&LayerTreeHostCopyRequestTestDestroyBeforeCopy::DidActivate, 851 base::Bind(&LayerTreeHostCopyRequestTestDestroyBeforeCopy::DidActivate,
854 base::Unretained(this))); 852 base::Unretained(this)));
855 } 853 }
856 854
857 void DidActivate() { 855 void DidActivate() {
858 switch (layer_tree_host()->source_frame_number()) { 856 switch (layer_tree_host()->source_frame_number()) {
859 case 1: { 857 case 1: {
860 EXPECT_EQ(0, callback_count_); 858 EXPECT_EQ(0, callback_count_);
(...skipping 20 matching lines...) Expand all
881 layer_tree_host()->SetViewportSize( 879 layer_tree_host()->SetViewportSize(
882 layer_tree_host()->root_layer()->bounds()); 880 layer_tree_host()->root_layer()->bounds());
883 break; 881 break;
884 case 4: 882 case 4:
885 EXPECT_EQ(1, callback_count_); 883 EXPECT_EQ(1, callback_count_);
886 // We should not have crashed. 884 // We should not have crashed.
887 EndTest(); 885 EndTest();
888 } 886 }
889 } 887 }
890 888
891 virtual void AfterTest() override {} 889 void AfterTest() override {}
892 890
893 int callback_count_; 891 int callback_count_;
894 FakeContentLayerClient client_; 892 FakeContentLayerClient client_;
895 scoped_refptr<FakeContentLayer> root_; 893 scoped_refptr<FakeContentLayer> root_;
896 scoped_refptr<FakeContentLayer> copy_layer_; 894 scoped_refptr<FakeContentLayer> copy_layer_;
897 }; 895 };
898 896
899 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 897 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
900 LayerTreeHostCopyRequestTestDestroyBeforeCopy); 898 LayerTreeHostCopyRequestTestDestroyBeforeCopy);
901 899
902 class LayerTreeHostCopyRequestTestShutdownBeforeCopy 900 class LayerTreeHostCopyRequestTestShutdownBeforeCopy
903 : public LayerTreeHostCopyRequestTest { 901 : public LayerTreeHostCopyRequestTest {
904 protected: 902 protected:
905 virtual void SetupTree() override { 903 void SetupTree() override {
906 root_ = FakeContentLayer::Create(&client_); 904 root_ = FakeContentLayer::Create(&client_);
907 root_->SetBounds(gfx::Size(20, 20)); 905 root_->SetBounds(gfx::Size(20, 20));
908 906
909 copy_layer_ = FakeContentLayer::Create(&client_); 907 copy_layer_ = FakeContentLayer::Create(&client_);
910 copy_layer_->SetBounds(gfx::Size(10, 10)); 908 copy_layer_->SetBounds(gfx::Size(10, 10));
911 root_->AddChild(copy_layer_); 909 root_->AddChild(copy_layer_);
912 910
913 layer_tree_host()->SetRootLayer(root_); 911 layer_tree_host()->SetRootLayer(root_);
914 LayerTreeHostCopyRequestTest::SetupTree(); 912 LayerTreeHostCopyRequestTest::SetupTree();
915 } 913 }
916 914
917 virtual void BeginTest() override { 915 void BeginTest() override {
918 callback_count_ = 0; 916 callback_count_ = 0;
919 PostSetNeedsCommitToMainThread(); 917 PostSetNeedsCommitToMainThread();
920 } 918 }
921 919
922 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { 920 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {
923 EXPECT_TRUE(result->IsEmpty()); 921 EXPECT_TRUE(result->IsEmpty());
924 ++callback_count_; 922 ++callback_count_;
925 } 923 }
926 924
927 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 925 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
928 MainThreadTaskRunner()->PostTask( 926 MainThreadTaskRunner()->PostTask(
929 FROM_HERE, 927 FROM_HERE,
930 base::Bind(&LayerTreeHostCopyRequestTestShutdownBeforeCopy::DidActivate, 928 base::Bind(&LayerTreeHostCopyRequestTestShutdownBeforeCopy::DidActivate,
931 base::Unretained(this))); 929 base::Unretained(this)));
932 } 930 }
933 931
934 void DidActivate() { 932 void DidActivate() {
935 switch (layer_tree_host()->source_frame_number()) { 933 switch (layer_tree_host()->source_frame_number()) {
936 case 1: { 934 case 1: {
937 EXPECT_EQ(0, callback_count_); 935 EXPECT_EQ(0, callback_count_);
(...skipping 14 matching lines...) Expand all
952 // End the test after the copy result has had a chance to get back to 950 // End the test after the copy result has had a chance to get back to
953 // the main thread. 951 // the main thread.
954 MainThreadTaskRunner()->PostTask( 952 MainThreadTaskRunner()->PostTask(
955 FROM_HERE, 953 FROM_HERE,
956 base::Bind(&LayerTreeHostCopyRequestTestShutdownBeforeCopy::EndTest, 954 base::Bind(&LayerTreeHostCopyRequestTestShutdownBeforeCopy::EndTest,
957 base::Unretained(this))); 955 base::Unretained(this)));
958 break; 956 break;
959 } 957 }
960 } 958 }
961 959
962 virtual void AfterTest() override { EXPECT_EQ(1, callback_count_); } 960 void AfterTest() override { EXPECT_EQ(1, callback_count_); }
963 961
964 int callback_count_; 962 int callback_count_;
965 FakeContentLayerClient client_; 963 FakeContentLayerClient client_;
966 scoped_refptr<FakeContentLayer> root_; 964 scoped_refptr<FakeContentLayer> root_;
967 scoped_refptr<FakeContentLayer> copy_layer_; 965 scoped_refptr<FakeContentLayer> copy_layer_;
968 }; 966 };
969 967
970 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 968 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
971 LayerTreeHostCopyRequestTestShutdownBeforeCopy); 969 LayerTreeHostCopyRequestTestShutdownBeforeCopy);
972 970
973 } // namespace 971 } // namespace
974 } // namespace cc 972 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest_context.cc ('k') | cc/trees/layer_tree_host_unittest_damage.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698