1// Copyright 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "cc/quads/render_pass.h" 6 7#include "cc/base/math_util.h" 8#include "cc/base/scoped_ptr_vector.h" 9#include "cc/output/copy_output_request.h" 10#include "cc/quads/checkerboard_draw_quad.h" 11#include "cc/test/geometry_test_utils.h" 12#include "cc/test/render_pass_test_common.h" 13#include "testing/gtest/include/gtest/gtest.h" 14#include "third_party/skia/include/effects/SkBlurImageFilter.h" 15#include "ui/gfx/transform.h" 16 17using cc::TestRenderPass; 18 19namespace cc { 20namespace { 21 22struct RenderPassSize { 23 // If you add a new field to this class, make sure to add it to the 24 // Copy() tests. 25 RenderPass::Id id; 26 QuadList quad_list; 27 SharedQuadStateList shared_quad_state_list; 28 gfx::Transform transform_to_root_target; 29 gfx::Rect output_rect; 30 gfx::RectF damage_rect; 31 bool has_transparent_background; 32 bool has_occlusion_from_outside_target_surface; 33 ScopedPtrVector<CopyOutputRequest> copy_callbacks; 34}; 35 36TEST(RenderPassTest, CopyShouldBeIdenticalExceptIdAndQuads) { 37 RenderPass::Id id(3, 2); 38 gfx::Rect output_rect(45, 22, 120, 13); 39 gfx::Transform transform_to_root = 40 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); 41 gfx::Rect damage_rect(56, 123, 19, 43); 42 bool has_transparent_background = true; 43 bool has_occlusion_from_outside_target_surface = true; 44 45 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); 46 pass->SetAll(id, 47 output_rect, 48 damage_rect, 49 transform_to_root, 50 has_transparent_background, 51 has_occlusion_from_outside_target_surface); 52 pass->copy_requests.push_back(CopyOutputRequest::CreateEmptyRequest()); 53 54 // Stick a quad in the pass, this should not get copied. 55 scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create(); 56 shared_state->SetAll( 57 gfx::Transform(), gfx::Size(), gfx::Rect(), gfx::Rect(), false, 1); 58 pass->AppendSharedQuadState(shared_state.Pass()); 59 60 scoped_ptr<CheckerboardDrawQuad> checkerboard_quad = 61 CheckerboardDrawQuad::Create(); 62 checkerboard_quad->SetNew( 63 pass->shared_quad_state_list.back(), gfx::Rect(), SkColor()); 64 pass->quad_list.push_back(checkerboard_quad.PassAs<DrawQuad>()); 65 66 RenderPass::Id new_id(63, 4); 67 68 scoped_ptr<RenderPass> copy = pass->Copy(new_id); 69 EXPECT_EQ(new_id, copy->id); 70 EXPECT_RECT_EQ(pass->output_rect, copy->output_rect); 71 EXPECT_EQ(pass->transform_to_root_target, copy->transform_to_root_target); 72 EXPECT_RECT_EQ(pass->damage_rect, copy->damage_rect); 73 EXPECT_EQ(pass->has_transparent_background, copy->has_transparent_background); 74 EXPECT_EQ(pass->has_occlusion_from_outside_target_surface, 75 copy->has_occlusion_from_outside_target_surface); 76 EXPECT_EQ(0u, copy->quad_list.size()); 77 78 // The copy request should not be copied/duplicated. 79 EXPECT_EQ(1u, pass->copy_requests.size()); 80 EXPECT_EQ(0u, copy->copy_requests.size()); 81 82 EXPECT_EQ(sizeof(RenderPassSize), sizeof(RenderPass)); 83} 84 85} // namespace 86} // namespace cc 87