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

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

Issue 659683002: Include mask texture size in RenderPassDrawQuad (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@update_mask_draw_quad_test
Patch Set: No ToEnclosedRect 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
« no previous file with comments | « cc/test/render_pass_test_utils.cc ('k') | cc/trees/layer_tree_host_unittest_delegated.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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/trees/layer_tree_host_impl.h" 5 #include "cc/trees/layer_tree_host_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 5272 matching lines...) Expand 10 before | Expand all | Expand 10 after
5283 EXPECT_FALSE(host_impl_->GetRendererCapabilities().allow_rasterize_on_demand); 5283 EXPECT_FALSE(host_impl_->GetRendererCapabilities().allow_rasterize_on_demand);
5284 } 5284 }
5285 5285
5286 class FakeMaskLayerImpl : public LayerImpl { 5286 class FakeMaskLayerImpl : public LayerImpl {
5287 public: 5287 public:
5288 static scoped_ptr<FakeMaskLayerImpl> Create(LayerTreeImpl* tree_impl, 5288 static scoped_ptr<FakeMaskLayerImpl> Create(LayerTreeImpl* tree_impl,
5289 int id) { 5289 int id) {
5290 return make_scoped_ptr(new FakeMaskLayerImpl(tree_impl, id)); 5290 return make_scoped_ptr(new FakeMaskLayerImpl(tree_impl, id));
5291 } 5291 }
5292 5292
5293 virtual ResourceProvider::ResourceId ContentsResourceId() const override { 5293 virtual void GetContentsResourceId(ResourceProvider::ResourceId* resource_id,
5294 return 0; 5294 gfx::Size* resource_size) const override {
5295 *resource_id = 0;
5295 } 5296 }
5296 5297
5297 private: 5298 private:
5298 FakeMaskLayerImpl(LayerTreeImpl* tree_impl, int id) 5299 FakeMaskLayerImpl(LayerTreeImpl* tree_impl, int id)
5299 : LayerImpl(tree_impl, id) {} 5300 : LayerImpl(tree_impl, id) {}
5300 }; 5301 };
5301 5302
5302 TEST_F(LayerTreeHostImplTest, MaskLayerWithScaling) { 5303 TEST_F(LayerTreeHostImplTest, MaskLayerWithScaling) {
5303 LayerTreeSettings settings; 5304 LayerTreeSettings settings;
5304 settings.layer_transforms_should_scale_layer_contents = true; 5305 settings.layer_transforms_should_scale_layer_contents = true;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
5366 ASSERT_EQ(1u, frame.render_passes.size()); 5367 ASSERT_EQ(1u, frame.render_passes.size());
5367 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); 5368 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
5368 ASSERT_EQ(DrawQuad::RENDER_PASS, 5369 ASSERT_EQ(DrawQuad::RENDER_PASS,
5369 frame.render_passes[0]->quad_list.front()->material); 5370 frame.render_passes[0]->quad_list.front()->material);
5370 const RenderPassDrawQuad* render_pass_quad = 5371 const RenderPassDrawQuad* render_pass_quad =
5371 RenderPassDrawQuad::MaterialCast( 5372 RenderPassDrawQuad::MaterialCast(
5372 frame.render_passes[0]->quad_list.front()); 5373 frame.render_passes[0]->quad_list.front());
5373 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), 5374 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
5374 render_pass_quad->rect.ToString()); 5375 render_pass_quad->rect.ToString());
5375 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 5376 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
5376 render_pass_quad->mask_uv_rect.ToString()); 5377 render_pass_quad->MaskUVRect().ToString());
5378 EXPECT_EQ(gfx::Vector2dF(1.f, 1.f).ToString(),
5379 render_pass_quad->mask_uv_scale.ToString());
5377 5380
5378 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); 5381 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
5379 host_impl_->DidDrawAllLayers(frame); 5382 host_impl_->DidDrawAllLayers(frame);
5380 } 5383 }
5381 5384
5382 5385
5383 // Applying a DSF should change the render surface size, but won't affect 5386 // Applying a DSF should change the render surface size, but won't affect
5384 // which part of the mask is used. 5387 // which part of the mask is used.
5385 device_scale_factor = 2.f; 5388 device_scale_factor = 2.f;
5386 gfx::Size device_viewport = 5389 gfx::Size device_viewport =
5387 gfx::ToFlooredSize(gfx::ScaleSize(root_size, device_scale_factor)); 5390 gfx::ToFlooredSize(gfx::ScaleSize(root_size, device_scale_factor));
5388 host_impl_->SetViewportSize(device_viewport); 5391 host_impl_->SetViewportSize(device_viewport);
5389 host_impl_->SetDeviceScaleFactor(device_scale_factor); 5392 host_impl_->SetDeviceScaleFactor(device_scale_factor);
5390 host_impl_->active_tree()->set_needs_update_draw_properties(); 5393 host_impl_->active_tree()->set_needs_update_draw_properties();
5391 { 5394 {
5392 LayerTreeHostImpl::FrameData frame; 5395 LayerTreeHostImpl::FrameData frame;
5393 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); 5396 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
5394 5397
5395 ASSERT_EQ(1u, frame.render_passes.size()); 5398 ASSERT_EQ(1u, frame.render_passes.size());
5396 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); 5399 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
5397 ASSERT_EQ(DrawQuad::RENDER_PASS, 5400 ASSERT_EQ(DrawQuad::RENDER_PASS,
5398 frame.render_passes[0]->quad_list.front()->material); 5401 frame.render_passes[0]->quad_list.front()->material);
5399 const RenderPassDrawQuad* render_pass_quad = 5402 const RenderPassDrawQuad* render_pass_quad =
5400 RenderPassDrawQuad::MaterialCast( 5403 RenderPassDrawQuad::MaterialCast(
5401 frame.render_passes[0]->quad_list.front()); 5404 frame.render_passes[0]->quad_list.front());
5402 EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(), 5405 EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(),
5403 render_pass_quad->rect.ToString()); 5406 render_pass_quad->rect.ToString());
5404 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 5407 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
5405 render_pass_quad->mask_uv_rect.ToString()); 5408 render_pass_quad->MaskUVRect().ToString());
5409 EXPECT_EQ(gfx::Vector2dF(1.f, 1.f).ToString(),
5410 render_pass_quad->mask_uv_scale.ToString());
5406 5411
5407 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); 5412 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
5408 host_impl_->DidDrawAllLayers(frame); 5413 host_impl_->DidDrawAllLayers(frame);
5409 } 5414 }
5410 5415
5411 5416
5412 // Applying an equivalent content scale on the content layer and the mask 5417 // Applying an equivalent content scale on the content layer and the mask
5413 // should still result in the same part of the mask being used. 5418 // should still result in the same part of the mask being used.
5414 gfx::Size content_bounds = 5419 gfx::Size content_bounds =
5415 gfx::ToRoundedSize(gfx::ScaleSize(scaling_layer_size, 5420 gfx::ToRoundedSize(gfx::ScaleSize(scaling_layer_size,
(...skipping 10 matching lines...) Expand all
5426 ASSERT_EQ(1u, frame.render_passes.size()); 5431 ASSERT_EQ(1u, frame.render_passes.size());
5427 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); 5432 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
5428 ASSERT_EQ(DrawQuad::RENDER_PASS, 5433 ASSERT_EQ(DrawQuad::RENDER_PASS,
5429 frame.render_passes[0]->quad_list.front()->material); 5434 frame.render_passes[0]->quad_list.front()->material);
5430 const RenderPassDrawQuad* render_pass_quad = 5435 const RenderPassDrawQuad* render_pass_quad =
5431 RenderPassDrawQuad::MaterialCast( 5436 RenderPassDrawQuad::MaterialCast(
5432 frame.render_passes[0]->quad_list.front()); 5437 frame.render_passes[0]->quad_list.front());
5433 EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(), 5438 EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(),
5434 render_pass_quad->rect.ToString()); 5439 render_pass_quad->rect.ToString());
5435 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 5440 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
5436 render_pass_quad->mask_uv_rect.ToString()); 5441 render_pass_quad->MaskUVRect().ToString());
5442 EXPECT_EQ(gfx::Vector2dF(1.f, 1.f).ToString(),
5443 render_pass_quad->mask_uv_scale.ToString());
5437 5444
5438 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); 5445 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
5439 host_impl_->DidDrawAllLayers(frame); 5446 host_impl_->DidDrawAllLayers(frame);
5440 } 5447 }
5441 } 5448 }
5442 5449
5443 TEST_F(LayerTreeHostImplTest, MaskLayerWithDifferentBounds) { 5450 TEST_F(LayerTreeHostImplTest, MaskLayerWithDifferentBounds) {
5444 // The mask layer has bounds 100x100 but is attached to a layer with bounds 5451 // The mask layer has bounds 100x100 but is attached to a layer with bounds
5445 // 50x50. 5452 // 50x50.
5446 5453
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
5487 ASSERT_EQ(1u, frame.render_passes.size()); 5494 ASSERT_EQ(1u, frame.render_passes.size());
5488 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); 5495 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
5489 ASSERT_EQ(DrawQuad::RENDER_PASS, 5496 ASSERT_EQ(DrawQuad::RENDER_PASS,
5490 frame.render_passes[0]->quad_list.front()->material); 5497 frame.render_passes[0]->quad_list.front()->material);
5491 const RenderPassDrawQuad* render_pass_quad = 5498 const RenderPassDrawQuad* render_pass_quad =
5492 RenderPassDrawQuad::MaterialCast( 5499 RenderPassDrawQuad::MaterialCast(
5493 frame.render_passes[0]->quad_list.front()); 5500 frame.render_passes[0]->quad_list.front());
5494 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), 5501 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
5495 render_pass_quad->rect.ToString()); 5502 render_pass_quad->rect.ToString());
5496 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 5503 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
5497 render_pass_quad->mask_uv_rect.ToString()); 5504 render_pass_quad->MaskUVRect().ToString());
5505 EXPECT_EQ(gfx::Vector2dF(1.f, 1.f).ToString(),
5506 render_pass_quad->mask_uv_scale.ToString());
5498 5507
5499 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); 5508 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
5500 host_impl_->DidDrawAllLayers(frame); 5509 host_impl_->DidDrawAllLayers(frame);
5501 } 5510 }
5502 5511
5503 // Applying a DSF should change the render surface size, but won't affect 5512 // Applying a DSF should change the render surface size, but won't affect
5504 // which part of the mask is used. 5513 // which part of the mask is used.
5505 device_scale_factor = 2.f; 5514 device_scale_factor = 2.f;
5506 gfx::Size device_viewport = 5515 gfx::Size device_viewport =
5507 gfx::ToFlooredSize(gfx::ScaleSize(root_size, device_scale_factor)); 5516 gfx::ToFlooredSize(gfx::ScaleSize(root_size, device_scale_factor));
5508 host_impl_->SetViewportSize(device_viewport); 5517 host_impl_->SetViewportSize(device_viewport);
5509 host_impl_->SetDeviceScaleFactor(device_scale_factor); 5518 host_impl_->SetDeviceScaleFactor(device_scale_factor);
5510 host_impl_->active_tree()->set_needs_update_draw_properties(); 5519 host_impl_->active_tree()->set_needs_update_draw_properties();
5511 { 5520 {
5512 LayerTreeHostImpl::FrameData frame; 5521 LayerTreeHostImpl::FrameData frame;
5513 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); 5522 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
5514 5523
5515 ASSERT_EQ(1u, frame.render_passes.size()); 5524 ASSERT_EQ(1u, frame.render_passes.size());
5516 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); 5525 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
5517 ASSERT_EQ(DrawQuad::RENDER_PASS, 5526 ASSERT_EQ(DrawQuad::RENDER_PASS,
5518 frame.render_passes[0]->quad_list.front()->material); 5527 frame.render_passes[0]->quad_list.front()->material);
5519 const RenderPassDrawQuad* render_pass_quad = 5528 const RenderPassDrawQuad* render_pass_quad =
5520 RenderPassDrawQuad::MaterialCast( 5529 RenderPassDrawQuad::MaterialCast(
5521 frame.render_passes[0]->quad_list.front()); 5530 frame.render_passes[0]->quad_list.front());
5522 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), 5531 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
5523 render_pass_quad->rect.ToString()); 5532 render_pass_quad->rect.ToString());
5524 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 5533 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
5525 render_pass_quad->mask_uv_rect.ToString()); 5534 render_pass_quad->MaskUVRect().ToString());
5535 EXPECT_EQ(gfx::Vector2dF(1.f, 1.f).ToString(),
5536 render_pass_quad->mask_uv_scale.ToString());
5526 5537
5527 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); 5538 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
5528 host_impl_->DidDrawAllLayers(frame); 5539 host_impl_->DidDrawAllLayers(frame);
5529 } 5540 }
5530 5541
5531 // Applying an equivalent content scale on the content layer and the mask 5542 // Applying an equivalent content scale on the content layer and the mask
5532 // should still result in the same part of the mask being used. 5543 // should still result in the same part of the mask being used.
5533 gfx::Size layer_size_large = 5544 gfx::Size layer_size_large =
5534 gfx::ToRoundedSize(gfx::ScaleSize(layer_size, device_scale_factor)); 5545 gfx::ToRoundedSize(gfx::ScaleSize(layer_size, device_scale_factor));
5535 content_layer->SetContentBounds(layer_size_large); 5546 content_layer->SetContentBounds(layer_size_large);
(...skipping 10 matching lines...) Expand all
5546 ASSERT_EQ(1u, frame.render_passes.size()); 5557 ASSERT_EQ(1u, frame.render_passes.size());
5547 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); 5558 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
5548 ASSERT_EQ(DrawQuad::RENDER_PASS, 5559 ASSERT_EQ(DrawQuad::RENDER_PASS,
5549 frame.render_passes[0]->quad_list.front()->material); 5560 frame.render_passes[0]->quad_list.front()->material);
5550 const RenderPassDrawQuad* render_pass_quad = 5561 const RenderPassDrawQuad* render_pass_quad =
5551 RenderPassDrawQuad::MaterialCast( 5562 RenderPassDrawQuad::MaterialCast(
5552 frame.render_passes[0]->quad_list.front()); 5563 frame.render_passes[0]->quad_list.front());
5553 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), 5564 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
5554 render_pass_quad->rect.ToString()); 5565 render_pass_quad->rect.ToString());
5555 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 5566 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
5556 render_pass_quad->mask_uv_rect.ToString()); 5567 render_pass_quad->MaskUVRect().ToString());
5568 EXPECT_EQ(gfx::Vector2dF(1.f, 1.f).ToString(),
5569 render_pass_quad->mask_uv_scale.ToString());
5557 5570
5558 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); 5571 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
5559 host_impl_->DidDrawAllLayers(frame); 5572 host_impl_->DidDrawAllLayers(frame);
5560 } 5573 }
5561 5574
5562 // Applying a different contents scale to the mask layer means it will have 5575 // Applying a different contents scale to the mask layer means it will have
5563 // a larger texture, but it should use the same tex coords to cover the 5576 // a larger texture, but it should use the same tex coords to cover the
5564 // layer it masks. 5577 // layer it masks.
5565 mask_layer->SetContentBounds(mask_size); 5578 mask_layer->SetContentBounds(mask_size);
5566 mask_layer->SetContentsScale(1.f, 1.f); 5579 mask_layer->SetContentsScale(1.f, 1.f);
5567 host_impl_->active_tree()->set_needs_update_draw_properties(); 5580 host_impl_->active_tree()->set_needs_update_draw_properties();
5568 { 5581 {
5569 LayerTreeHostImpl::FrameData frame; 5582 LayerTreeHostImpl::FrameData frame;
5570 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); 5583 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
5571 5584
5572 ASSERT_EQ(1u, frame.render_passes.size()); 5585 ASSERT_EQ(1u, frame.render_passes.size());
5573 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); 5586 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
5574 ASSERT_EQ(DrawQuad::RENDER_PASS, 5587 ASSERT_EQ(DrawQuad::RENDER_PASS,
5575 frame.render_passes[0]->quad_list.front()->material); 5588 frame.render_passes[0]->quad_list.front()->material);
5576 const RenderPassDrawQuad* render_pass_quad = 5589 const RenderPassDrawQuad* render_pass_quad =
5577 RenderPassDrawQuad::MaterialCast( 5590 RenderPassDrawQuad::MaterialCast(
5578 frame.render_passes[0]->quad_list.front()); 5591 frame.render_passes[0]->quad_list.front());
5579 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), 5592 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
5580 render_pass_quad->rect.ToString()); 5593 render_pass_quad->rect.ToString());
5581 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 5594 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
5582 render_pass_quad->mask_uv_rect.ToString()); 5595 render_pass_quad->MaskUVRect().ToString());
5596 EXPECT_EQ(gfx::Vector2dF(1.f, 1.f).ToString(),
5597 render_pass_quad->mask_uv_scale.ToString());
5583 5598
5584 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); 5599 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
5585 host_impl_->DidDrawAllLayers(frame); 5600 host_impl_->DidDrawAllLayers(frame);
5586 } 5601 }
5587 } 5602 }
5588 5603
5589 TEST_F(LayerTreeHostImplTest, ReflectionMaskLayerWithDifferentBounds) { 5604 TEST_F(LayerTreeHostImplTest, ReflectionMaskLayerWithDifferentBounds) {
5590 // The replica's mask layer has bounds 100x100 but the replica is of a 5605 // The replica's mask layer has bounds 100x100 but the replica is of a
5591 // layer with bounds 50x50. 5606 // layer with bounds 50x50.
5592 5607
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
5637 5652
5638 ASSERT_EQ(1u, frame.render_passes.size()); 5653 ASSERT_EQ(1u, frame.render_passes.size());
5639 ASSERT_EQ(2u, frame.render_passes[0]->quad_list.size()); 5654 ASSERT_EQ(2u, frame.render_passes[0]->quad_list.size());
5640 ASSERT_EQ(DrawQuad::RENDER_PASS, 5655 ASSERT_EQ(DrawQuad::RENDER_PASS,
5641 frame.render_passes[0]->quad_list.ElementAt(1)->material); 5656 frame.render_passes[0]->quad_list.ElementAt(1)->material);
5642 const RenderPassDrawQuad* replica_quad = RenderPassDrawQuad::MaterialCast( 5657 const RenderPassDrawQuad* replica_quad = RenderPassDrawQuad::MaterialCast(
5643 frame.render_passes[0]->quad_list.ElementAt(1)); 5658 frame.render_passes[0]->quad_list.ElementAt(1));
5644 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), 5659 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
5645 replica_quad->rect.ToString()); 5660 replica_quad->rect.ToString());
5646 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 5661 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
5647 replica_quad->mask_uv_rect.ToString()); 5662 replica_quad->MaskUVRect().ToString());
5663 EXPECT_EQ(gfx::Vector2dF(1.f, 1.f).ToString(),
5664 replica_quad->mask_uv_scale.ToString());
5648 5665
5649 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); 5666 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
5650 host_impl_->DidDrawAllLayers(frame); 5667 host_impl_->DidDrawAllLayers(frame);
5651 } 5668 }
5652 5669
5653 // Applying a DSF should change the render surface size, but won't affect 5670 // Applying a DSF should change the render surface size, but won't affect
5654 // which part of the mask is used. 5671 // which part of the mask is used.
5655 device_scale_factor = 2.f; 5672 device_scale_factor = 2.f;
5656 gfx::Size device_viewport = 5673 gfx::Size device_viewport =
5657 gfx::ToFlooredSize(gfx::ScaleSize(root_size, device_scale_factor)); 5674 gfx::ToFlooredSize(gfx::ScaleSize(root_size, device_scale_factor));
5658 host_impl_->SetViewportSize(device_viewport); 5675 host_impl_->SetViewportSize(device_viewport);
5659 host_impl_->SetDeviceScaleFactor(device_scale_factor); 5676 host_impl_->SetDeviceScaleFactor(device_scale_factor);
5660 host_impl_->active_tree()->set_needs_update_draw_properties(); 5677 host_impl_->active_tree()->set_needs_update_draw_properties();
5661 { 5678 {
5662 LayerTreeHostImpl::FrameData frame; 5679 LayerTreeHostImpl::FrameData frame;
5663 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); 5680 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
5664 5681
5665 ASSERT_EQ(1u, frame.render_passes.size()); 5682 ASSERT_EQ(1u, frame.render_passes.size());
5666 ASSERT_EQ(2u, frame.render_passes[0]->quad_list.size()); 5683 ASSERT_EQ(2u, frame.render_passes[0]->quad_list.size());
5667 ASSERT_EQ(DrawQuad::RENDER_PASS, 5684 ASSERT_EQ(DrawQuad::RENDER_PASS,
5668 frame.render_passes[0]->quad_list.ElementAt(1)->material); 5685 frame.render_passes[0]->quad_list.ElementAt(1)->material);
5669 const RenderPassDrawQuad* replica_quad = RenderPassDrawQuad::MaterialCast( 5686 const RenderPassDrawQuad* replica_quad = RenderPassDrawQuad::MaterialCast(
5670 frame.render_passes[0]->quad_list.ElementAt(1)); 5687 frame.render_passes[0]->quad_list.ElementAt(1));
5671 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), 5688 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
5672 replica_quad->rect.ToString()); 5689 replica_quad->rect.ToString());
5673 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 5690 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
5674 replica_quad->mask_uv_rect.ToString()); 5691 replica_quad->MaskUVRect().ToString());
5692 EXPECT_EQ(gfx::Vector2dF(1.f, 1.f).ToString(),
5693 replica_quad->mask_uv_scale.ToString());
5675 5694
5676 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); 5695 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
5677 host_impl_->DidDrawAllLayers(frame); 5696 host_impl_->DidDrawAllLayers(frame);
5678 } 5697 }
5679 5698
5680 // Applying an equivalent content scale on the content layer and the mask 5699 // Applying an equivalent content scale on the content layer and the mask
5681 // should still result in the same part of the mask being used. 5700 // should still result in the same part of the mask being used.
5682 gfx::Size layer_size_large = 5701 gfx::Size layer_size_large =
5683 gfx::ToRoundedSize(gfx::ScaleSize(layer_size, device_scale_factor)); 5702 gfx::ToRoundedSize(gfx::ScaleSize(layer_size, device_scale_factor));
5684 content_layer->SetContentBounds(layer_size_large); 5703 content_layer->SetContentBounds(layer_size_large);
5685 content_layer->SetContentsScale(device_scale_factor, device_scale_factor); 5704 content_layer->SetContentsScale(device_scale_factor, device_scale_factor);
5686 gfx::Size mask_size_large = 5705 gfx::Size mask_size_large =
5687 gfx::ToRoundedSize(gfx::ScaleSize(mask_size, device_scale_factor)); 5706 gfx::ToRoundedSize(gfx::ScaleSize(mask_size, device_scale_factor));
5688 mask_layer->SetContentBounds(mask_size_large); 5707 mask_layer->SetContentBounds(mask_size_large);
5689 mask_layer->SetContentsScale(device_scale_factor, device_scale_factor); 5708 mask_layer->SetContentsScale(device_scale_factor, device_scale_factor);
5690 host_impl_->active_tree()->set_needs_update_draw_properties(); 5709 host_impl_->active_tree()->set_needs_update_draw_properties();
5691 { 5710 {
5692 LayerTreeHostImpl::FrameData frame; 5711 LayerTreeHostImpl::FrameData frame;
5693 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); 5712 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
5694 5713
5695 ASSERT_EQ(1u, frame.render_passes.size()); 5714 ASSERT_EQ(1u, frame.render_passes.size());
5696 ASSERT_EQ(2u, frame.render_passes[0]->quad_list.size()); 5715 ASSERT_EQ(2u, frame.render_passes[0]->quad_list.size());
5697 ASSERT_EQ(DrawQuad::RENDER_PASS, 5716 ASSERT_EQ(DrawQuad::RENDER_PASS,
5698 frame.render_passes[0]->quad_list.ElementAt(1)->material); 5717 frame.render_passes[0]->quad_list.ElementAt(1)->material);
5699 const RenderPassDrawQuad* replica_quad = RenderPassDrawQuad::MaterialCast( 5718 const RenderPassDrawQuad* replica_quad = RenderPassDrawQuad::MaterialCast(
5700 frame.render_passes[0]->quad_list.ElementAt(1)); 5719 frame.render_passes[0]->quad_list.ElementAt(1));
5701 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), 5720 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
5702 replica_quad->rect.ToString()); 5721 replica_quad->rect.ToString());
5703 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 5722 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
5704 replica_quad->mask_uv_rect.ToString()); 5723 replica_quad->MaskUVRect().ToString());
5724 EXPECT_EQ(gfx::Vector2dF(1.f, 1.f).ToString(),
5725 replica_quad->mask_uv_scale.ToString());
5705 5726
5706 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); 5727 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
5707 host_impl_->DidDrawAllLayers(frame); 5728 host_impl_->DidDrawAllLayers(frame);
5708 } 5729 }
5709 5730
5710 // Applying a different contents scale to the mask layer means it will have 5731 // Applying a different contents scale to the mask layer means it will have
5711 // a larger texture, but it should use the same tex coords to cover the 5732 // a larger texture, but it should use the same tex coords to cover the
5712 // layer it masks. 5733 // layer it masks.
5713 mask_layer->SetContentBounds(mask_size); 5734 mask_layer->SetContentBounds(mask_size);
5714 mask_layer->SetContentsScale(1.f, 1.f); 5735 mask_layer->SetContentsScale(1.f, 1.f);
5715 host_impl_->active_tree()->set_needs_update_draw_properties(); 5736 host_impl_->active_tree()->set_needs_update_draw_properties();
5716 { 5737 {
5717 LayerTreeHostImpl::FrameData frame; 5738 LayerTreeHostImpl::FrameData frame;
5718 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); 5739 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
5719 5740
5720 ASSERT_EQ(1u, frame.render_passes.size()); 5741 ASSERT_EQ(1u, frame.render_passes.size());
5721 ASSERT_EQ(2u, frame.render_passes[0]->quad_list.size()); 5742 ASSERT_EQ(2u, frame.render_passes[0]->quad_list.size());
5722 ASSERT_EQ(DrawQuad::RENDER_PASS, 5743 ASSERT_EQ(DrawQuad::RENDER_PASS,
5723 frame.render_passes[0]->quad_list.ElementAt(1)->material); 5744 frame.render_passes[0]->quad_list.ElementAt(1)->material);
5724 const RenderPassDrawQuad* replica_quad = RenderPassDrawQuad::MaterialCast( 5745 const RenderPassDrawQuad* replica_quad = RenderPassDrawQuad::MaterialCast(
5725 frame.render_passes[0]->quad_list.ElementAt(1)); 5746 frame.render_passes[0]->quad_list.ElementAt(1));
5726 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), 5747 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
5727 replica_quad->rect.ToString()); 5748 replica_quad->rect.ToString());
5728 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 5749 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
5729 replica_quad->mask_uv_rect.ToString()); 5750 replica_quad->MaskUVRect().ToString());
5751 EXPECT_EQ(gfx::Vector2dF(1.f, 1.f).ToString(),
5752 replica_quad->mask_uv_scale.ToString());
5730 5753
5731 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); 5754 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
5732 host_impl_->DidDrawAllLayers(frame); 5755 host_impl_->DidDrawAllLayers(frame);
5733 } 5756 }
5734 } 5757 }
5735 5758
5736 TEST_F(LayerTreeHostImplTest, ReflectionMaskLayerForSurfaceWithUnclippedChild) { 5759 TEST_F(LayerTreeHostImplTest, ReflectionMaskLayerForSurfaceWithUnclippedChild) {
5737 // The replica is of a layer with bounds 50x50, but it has a child that causes 5760 // The replica is of a layer with bounds 50x50, but it has a child that causes
5738 // the surface bounds to be larger. 5761 // the surface bounds to be larger.
5739 5762
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
5805 render_pass_quad->rect.ToString()); 5828 render_pass_quad->rect.ToString());
5806 5829
5807 // The mask covers the owning layer only. 5830 // The mask covers the owning layer only.
5808 ASSERT_EQ(DrawQuad::RENDER_PASS, 5831 ASSERT_EQ(DrawQuad::RENDER_PASS,
5809 frame.render_passes[0]->quad_list.ElementAt(1)->material); 5832 frame.render_passes[0]->quad_list.ElementAt(1)->material);
5810 const RenderPassDrawQuad* replica_quad = RenderPassDrawQuad::MaterialCast( 5833 const RenderPassDrawQuad* replica_quad = RenderPassDrawQuad::MaterialCast(
5811 frame.render_passes[0]->quad_list.ElementAt(1)); 5834 frame.render_passes[0]->quad_list.ElementAt(1));
5812 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), 5835 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
5813 replica_quad->rect.ToString()); 5836 replica_quad->rect.ToString());
5814 EXPECT_EQ(gfx::RectF(0.f, 0.f, 2.f, 1.f).ToString(), 5837 EXPECT_EQ(gfx::RectF(0.f, 0.f, 2.f, 1.f).ToString(),
5815 replica_quad->mask_uv_rect.ToString()); 5838 replica_quad->MaskUVRect().ToString());
5839 EXPECT_EQ(gfx::Vector2dF(2.f, 1.f).ToString(),
5840 replica_quad->mask_uv_scale.ToString());
5816 5841
5817 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); 5842 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
5818 host_impl_->DidDrawAllLayers(frame); 5843 host_impl_->DidDrawAllLayers(frame);
5819 } 5844 }
5820 5845
5821 // Move the child to (-50, 0) instead. Now the mask should be moved to still 5846 // Move the child to (-50, 0) instead. Now the mask should be moved to still
5822 // cover the layer being replicated. 5847 // cover the layer being replicated.
5823 content_child_layer->SetPosition(gfx::Point(-50, 0)); 5848 content_child_layer->SetPosition(gfx::Point(-50, 0));
5824 { 5849 {
5825 LayerTreeHostImpl::FrameData frame; 5850 LayerTreeHostImpl::FrameData frame;
(...skipping 12 matching lines...) Expand all
5838 render_pass_quad->rect.ToString()); 5863 render_pass_quad->rect.ToString());
5839 5864
5840 // The mask covers the owning layer only. 5865 // The mask covers the owning layer only.
5841 ASSERT_EQ(DrawQuad::RENDER_PASS, 5866 ASSERT_EQ(DrawQuad::RENDER_PASS,
5842 frame.render_passes[0]->quad_list.ElementAt(1)->material); 5867 frame.render_passes[0]->quad_list.ElementAt(1)->material);
5843 const RenderPassDrawQuad* replica_quad = RenderPassDrawQuad::MaterialCast( 5868 const RenderPassDrawQuad* replica_quad = RenderPassDrawQuad::MaterialCast(
5844 frame.render_passes[0]->quad_list.ElementAt(1)); 5869 frame.render_passes[0]->quad_list.ElementAt(1));
5845 EXPECT_EQ(gfx::Rect(-50, 0, 100, 50).ToString(), 5870 EXPECT_EQ(gfx::Rect(-50, 0, 100, 50).ToString(),
5846 replica_quad->rect.ToString()); 5871 replica_quad->rect.ToString());
5847 EXPECT_EQ(gfx::RectF(-1.f, 0.f, 2.f, 1.f).ToString(), 5872 EXPECT_EQ(gfx::RectF(-1.f, 0.f, 2.f, 1.f).ToString(),
5848 replica_quad->mask_uv_rect.ToString()); 5873 replica_quad->MaskUVRect().ToString());
5874 EXPECT_EQ(gfx::Vector2dF(2.f, 1.f).ToString(),
5875 replica_quad->mask_uv_scale.ToString());
5849 5876
5850 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); 5877 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
5851 host_impl_->DidDrawAllLayers(frame); 5878 host_impl_->DidDrawAllLayers(frame);
5852 } 5879 }
5853 } 5880 }
5854 5881
5855 TEST_F(LayerTreeHostImplTest, MaskLayerForSurfaceWithClippedLayer) { 5882 TEST_F(LayerTreeHostImplTest, MaskLayerForSurfaceWithClippedLayer) {
5856 // The masked layer has bounds 50x50, but it has a child that causes 5883 // The masked layer has bounds 50x50, but it has a child that causes
5857 // the surface bounds to be larger. It also has a parent that clips the 5884 // the surface bounds to be larger. It also has a parent that clips the
5858 // masked layer and its surface. 5885 // masked layer and its surface.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
5922 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); 5949 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
5923 5950
5924 // The surface is clipped to 10x20. 5951 // The surface is clipped to 10x20.
5925 ASSERT_EQ(DrawQuad::RENDER_PASS, 5952 ASSERT_EQ(DrawQuad::RENDER_PASS,
5926 frame.render_passes[0]->quad_list.front()->material); 5953 frame.render_passes[0]->quad_list.front()->material);
5927 const RenderPassDrawQuad* render_pass_quad = 5954 const RenderPassDrawQuad* render_pass_quad =
5928 RenderPassDrawQuad::MaterialCast( 5955 RenderPassDrawQuad::MaterialCast(
5929 frame.render_passes[0]->quad_list.front()); 5956 frame.render_passes[0]->quad_list.front());
5930 EXPECT_EQ(gfx::Rect(20, 10, 10, 20).ToString(), 5957 EXPECT_EQ(gfx::Rect(20, 10, 10, 20).ToString(),
5931 render_pass_quad->rect.ToString()); 5958 render_pass_quad->rect.ToString());
5932
5933 // The masked layer is 50x50, but the surface size is 10x20. So the texture 5959 // The masked layer is 50x50, but the surface size is 10x20. So the texture
5934 // coords in the mask are scaled by 10/50 and 20/50. 5960 // coords in the mask are scaled by 10/50 and 20/50.
5935 // The surface is clipped to (20,10) so the mask texture coords are offset 5961 // The surface is clipped to (20,10) so the mask texture coords are offset
5936 // by 20/50 and 10/50 5962 // by 20/50 and 10/50
5937 EXPECT_EQ(gfx::ScaleRect(gfx::RectF(20.f, 10.f, 10.f, 20.f), 5963 EXPECT_EQ(gfx::ScaleRect(gfx::RectF(20.f, 10.f, 10.f, 20.f), 1.f / 50.f)
5938 1.f / 50.f).ToString(), 5964 .ToString(),
5939 render_pass_quad->mask_uv_rect.ToString()); 5965 render_pass_quad->MaskUVRect().ToString());
5966 EXPECT_EQ(gfx::Vector2dF(10.f / 50.f, 20.f / 50.f).ToString(),
5967 render_pass_quad->mask_uv_scale.ToString());
5940 5968
5941 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); 5969 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
5942 host_impl_->DidDrawAllLayers(frame); 5970 host_impl_->DidDrawAllLayers(frame);
5943 } 5971 }
5944 } 5972 }
5945 5973
5946 class GLRendererWithSetupQuadForAntialiasing : public GLRenderer { 5974 class GLRendererWithSetupQuadForAntialiasing : public GLRenderer {
5947 public: 5975 public:
5948 using GLRenderer::SetupQuadForAntialiasing; 5976 using GLRenderer::SetupQuadForAntialiasing;
5949 }; 5977 };
(...skipping 1566 matching lines...) Expand 10 before | Expand all | Expand 10 after
7516 // surface. 7544 // surface.
7517 EXPECT_EQ(0, num_lost_surfaces_); 7545 EXPECT_EQ(0, num_lost_surfaces_);
7518 host_impl_->DidLoseOutputSurface(); 7546 host_impl_->DidLoseOutputSurface();
7519 EXPECT_EQ(1, num_lost_surfaces_); 7547 EXPECT_EQ(1, num_lost_surfaces_);
7520 host_impl_->DidLoseOutputSurface(); 7548 host_impl_->DidLoseOutputSurface();
7521 EXPECT_LE(1, num_lost_surfaces_); 7549 EXPECT_LE(1, num_lost_surfaces_);
7522 } 7550 }
7523 7551
7524 } // namespace 7552 } // namespace
7525 } // namespace cc 7553 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/render_pass_test_utils.cc ('k') | cc/trees/layer_tree_host_unittest_delegated.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698