12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2012 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/quads/render_pass.h" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/base/math_util.h" 890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "cc/base/scoped_ptr_vector.h" 990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "cc/output/copy_output_request.h" 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/quads/checkerboard_draw_quad.h" 114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "cc/quads/render_pass_draw_quad.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/test/geometry_test_utils.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/test/render_pass_test_common.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "third_party/skia/include/effects/SkBlurImageFilter.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/transform.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)using cc::TestRenderPass; 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace cc { 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace { 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct RenderPassSize { 24c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // If you add a new field to this class, make sure to add it to the 25c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Copy() tests. 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderPass::Id id; 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) QuadList quad_list; 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SharedQuadStateList shared_quad_state_list; 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Transform transform_to_root_target; 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect output_rect; 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::RectF damage_rect; 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool has_transparent_background; 3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ScopedPtrVector<CopyOutputRequest> copy_callbacks; 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)static void CompareRenderPassLists(const RenderPassList& expected_list, 371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const RenderPassList& actual_list) { 381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(expected_list.size(), actual_list.size()); 391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) for (size_t i = 0; i < actual_list.size(); ++i) { 401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) RenderPass* expected = expected_list[i]; 411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) RenderPass* actual = actual_list[i]; 421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(expected->id, actual->id); 441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_RECT_EQ(expected->output_rect, actual->output_rect); 451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(expected->transform_to_root_target, 461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) actual->transform_to_root_target); 471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_RECT_EQ(expected->damage_rect, actual->damage_rect); 481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(expected->has_transparent_background, 491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) actual->has_transparent_background); 501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(expected->shared_quad_state_list.size(), 521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) actual->shared_quad_state_list.size()); 531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(expected->quad_list.size(), actual->quad_list.size()); 541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) for (size_t i = 0; i < expected->quad_list.size(); ++i) { 561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(expected->quad_list[i]->rect.ToString(), 571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) actual->quad_list[i]->rect.ToString()); 581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ( 591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) expected->quad_list[i]->shared_quad_state->content_bounds.ToString(), 601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) actual->quad_list[i]->shared_quad_state->content_bounds.ToString()); 611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST(RenderPassTest, CopyShouldBeIdenticalExceptIdAndQuads) { 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderPass::Id id(3, 2); 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect output_rect(45, 22, 120, 13); 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Transform transform_to_root = 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect damage_rect(56, 123, 19, 43); 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool has_transparent_background = true; 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pass->SetAll(id, 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) output_rect, 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) damage_rect, 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) transform_to_root, 784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) has_transparent_background); 797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) pass->copy_requests.push_back(CopyOutputRequest::CreateEmptyRequest()); 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Stick a quad in the pass, this should not get copied. 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create(); 83f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) shared_state->SetAll(gfx::Transform(), 84f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Size(), 85f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Rect(), 86f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Rect(), 87f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) false, 88f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1, 89f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SkXfermode::kSrcOver_Mode); 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pass->AppendSharedQuadState(shared_state.Pass()); 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<CheckerboardDrawQuad> checkerboard_quad = 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckerboardDrawQuad::Create(); 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) checkerboard_quad->SetNew( 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pass->shared_quad_state_list.back(), gfx::Rect(), SkColor()); 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pass->quad_list.push_back(checkerboard_quad.PassAs<DrawQuad>()); 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderPass::Id new_id(63, 4); 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<RenderPass> copy = pass->Copy(new_id); 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(new_id, copy->id); 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_RECT_EQ(pass->output_rect, copy->output_rect); 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(pass->transform_to_root_target, copy->transform_to_root_target); 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_RECT_EQ(pass->damage_rect, copy->damage_rect); 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(pass->has_transparent_background, copy->has_transparent_background); 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(0u, copy->quad_list.size()); 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // The copy request should not be copied/duplicated. 10990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(1u, pass->copy_requests.size()); 11090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(0u, copy->copy_requests.size()); 111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(sizeof(RenderPassSize), sizeof(RenderPass)); 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST(RenderPassTest, CopyAllShouldBeIdentical) { 1164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) RenderPassList pass_list; 1174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) RenderPass::Id id(3, 2); 1194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect output_rect(45, 22, 120, 13); 1204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Transform transform_to_root = 1214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); 1224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect damage_rect(56, 123, 19, 43); 1234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) bool has_transparent_background = true; 1244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); 1264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) pass->SetAll(id, 1274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) output_rect, 1284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) damage_rect, 1294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) transform_to_root, 1304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) has_transparent_background); 1314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Two quads using one shared state. 1334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<SharedQuadState> shared_state1 = SharedQuadState::Create(); 134f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) shared_state1->SetAll(gfx::Transform(), 135f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Size(1, 1), 136f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Rect(), 137f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Rect(), 138f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) false, 139f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1, 140f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SkXfermode::kSrcOver_Mode); 1414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) pass->AppendSharedQuadState(shared_state1.Pass()); 1424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<CheckerboardDrawQuad> checkerboard_quad1 = 1444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) CheckerboardDrawQuad::Create(); 1454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) checkerboard_quad1->SetNew( 1464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) pass->shared_quad_state_list.back(), gfx::Rect(1, 1, 1, 1), SkColor()); 1474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) pass->quad_list.push_back(checkerboard_quad1.PassAs<DrawQuad>()); 1484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<CheckerboardDrawQuad> checkerboard_quad2 = 1504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) CheckerboardDrawQuad::Create(); 1514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) checkerboard_quad2->SetNew( 1524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) pass->shared_quad_state_list.back(), gfx::Rect(2, 2, 2, 2), SkColor()); 1534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) pass->quad_list.push_back(checkerboard_quad2.PassAs<DrawQuad>()); 1544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // And two quads using another shared state. 1564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<SharedQuadState> shared_state2 = SharedQuadState::Create(); 157f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) shared_state2->SetAll(gfx::Transform(), 158f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Size(2, 2), 159f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Rect(), 160f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Rect(), 161f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) false, 162f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1, 163f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SkXfermode::kSrcOver_Mode); 1644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) pass->AppendSharedQuadState(shared_state2.Pass()); 1654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<CheckerboardDrawQuad> checkerboard_quad3 = 1674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) CheckerboardDrawQuad::Create(); 1684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) checkerboard_quad3->SetNew( 1694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) pass->shared_quad_state_list.back(), gfx::Rect(3, 3, 3, 3), SkColor()); 1704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) pass->quad_list.push_back(checkerboard_quad3.PassAs<DrawQuad>()); 1714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<CheckerboardDrawQuad> checkerboard_quad4 = 1734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) CheckerboardDrawQuad::Create(); 1744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) checkerboard_quad4->SetNew( 1754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) pass->shared_quad_state_list.back(), gfx::Rect(4, 4, 4, 4), SkColor()); 1764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) pass->quad_list.push_back(checkerboard_quad4.PassAs<DrawQuad>()); 1774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // A second render pass with a quad. 1794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) RenderPass::Id contrib_id(4, 1); 1804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect contrib_output_rect(10, 15, 12, 17); 1814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Transform contrib_transform_to_root = 1824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); 1834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::Rect contrib_damage_rect(11, 16, 10, 15); 1844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) bool contrib_has_transparent_background = true; 1854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<TestRenderPass> contrib = TestRenderPass::Create(); 1874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) contrib->SetAll(contrib_id, 1884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) contrib_output_rect, 1894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) contrib_damage_rect, 1904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) contrib_transform_to_root, 1914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) contrib_has_transparent_background); 1924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<SharedQuadState> contrib_shared_state = SharedQuadState::Create(); 194f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) contrib_shared_state->SetAll(gfx::Transform(), 195f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Size(2, 2), 196f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Rect(), 197f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Rect(), 198f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) false, 199f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1, 200f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SkXfermode::kSrcOver_Mode); 2014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) contrib->AppendSharedQuadState(contrib_shared_state.Pass()); 2024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<CheckerboardDrawQuad> contrib_quad = 2044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) CheckerboardDrawQuad::Create(); 2054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) contrib_quad->SetNew( 2064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) contrib->shared_quad_state_list.back(), gfx::Rect(3, 3, 3, 3), SkColor()); 2074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) contrib->quad_list.push_back(contrib_quad.PassAs<DrawQuad>()); 2084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // And a RenderPassDrawQuad for the contributing pass. 2104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<RenderPassDrawQuad> pass_quad = RenderPassDrawQuad::Create(); 2114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) pass_quad->SetNew(pass->shared_quad_state_list.back(), 2124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) contrib_output_rect, 2134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) contrib_id, 2144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) false, // is_replica 2154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 0, // mask_resource_id 2164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) contrib_damage_rect, 2174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) gfx::RectF(), // mask_uv_rect 2184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) FilterOperations(), 2194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) FilterOperations()); 2204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) pass->quad_list.push_back(pass_quad.PassAs<DrawQuad>()); 2214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) pass_list.push_back(pass.PassAs<RenderPass>()); 2234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) pass_list.push_back(contrib.PassAs<RenderPass>()); 2244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Make a copy with CopyAll(). 2264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) RenderPassList copy_list; 2274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) RenderPass::CopyAll(pass_list, ©_list); 2284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CompareRenderPassLists(pass_list, copy_list); 2301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 2311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST(RenderPassTest, CopyAllWithCulledQuads) { 2331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) RenderPassList pass_list; 2341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) RenderPass::Id id(3, 2); 2361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) gfx::Rect output_rect(45, 22, 120, 13); 2371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) gfx::Transform transform_to_root = 2381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); 2391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) gfx::Rect damage_rect(56, 123, 19, 43); 2401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool has_transparent_background = true; 2411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); 2431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) pass->SetAll(id, 2441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) output_rect, 2451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) damage_rect, 2461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) transform_to_root, 2471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) has_transparent_background); 2481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // A shared state with a quad. 2501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<SharedQuadState> shared_state1 = SharedQuadState::Create(); 251f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) shared_state1->SetAll(gfx::Transform(), 252f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Size(1, 1), 253f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Rect(), 254f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Rect(), 255f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) false, 256f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1, 257f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SkXfermode::kSrcOver_Mode); 2581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) pass->AppendSharedQuadState(shared_state1.Pass()); 2591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<CheckerboardDrawQuad> checkerboard_quad1 = 2611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckerboardDrawQuad::Create(); 2621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) checkerboard_quad1->SetNew( 2631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) pass->shared_quad_state_list.back(), gfx::Rect(1, 1, 1, 1), SkColor()); 2641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) pass->quad_list.push_back(checkerboard_quad1.PassAs<DrawQuad>()); 2651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // A shared state with no quads, they were culled. 2671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<SharedQuadState> shared_state2 = SharedQuadState::Create(); 268f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) shared_state2->SetAll(gfx::Transform(), 269f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Size(2, 2), 270f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Rect(), 271f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Rect(), 272f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) false, 273f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1, 274f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SkXfermode::kSrcOver_Mode); 2751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) pass->AppendSharedQuadState(shared_state2.Pass()); 2761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // A second shared state with no quads. 2781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<SharedQuadState> shared_state3 = SharedQuadState::Create(); 279f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) shared_state3->SetAll(gfx::Transform(), 280f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Size(2, 2), 281f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Rect(), 282f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Rect(), 283f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) false, 284f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1, 285f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SkXfermode::kSrcOver_Mode); 2861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) pass->AppendSharedQuadState(shared_state3.Pass()); 2871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // A last shared state with a quad again. 2891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<SharedQuadState> shared_state4 = SharedQuadState::Create(); 290f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) shared_state4->SetAll(gfx::Transform(), 291f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Size(2, 2), 292f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Rect(), 293f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Rect(), 294f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) false, 295f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1, 296f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SkXfermode::kSrcOver_Mode); 2971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) pass->AppendSharedQuadState(shared_state4.Pass()); 2981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<CheckerboardDrawQuad> checkerboard_quad2 = 3001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckerboardDrawQuad::Create(); 3011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) checkerboard_quad2->SetNew( 3021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) pass->shared_quad_state_list.back(), gfx::Rect(3, 3, 3, 3), SkColor()); 3031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) pass->quad_list.push_back(checkerboard_quad2.PassAs<DrawQuad>()); 3041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 3051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) pass_list.push_back(pass.PassAs<RenderPass>()); 3061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 3071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Make a copy with CopyAll(). 3081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) RenderPassList copy_list; 3091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) RenderPass::CopyAll(pass_list, ©_list); 3101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 3111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CompareRenderPassLists(pass_list, copy_list); 3124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 3134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace 3152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace cc 316