render_pass_unittest.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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/WebKit/public/platform/WebFilterOperations.h" 15#include "third_party/skia/include/effects/SkBlurImageFilter.h" 16#include "ui/gfx/transform.h" 17 18using cc::TestRenderPass; 19 20namespace cc { 21namespace { 22 23struct RenderPassSize { 24 // If you add a new field to this class, make sure to add it to the 25 // Copy() tests. 26 RenderPass::Id id; 27 QuadList quad_list; 28 SharedQuadStateList shared_quad_state_list; 29 gfx::Transform transform_to_root_target; 30 gfx::Rect output_rect; 31 gfx::RectF damage_rect; 32 bool has_transparent_background; 33 bool has_occlusion_from_outside_target_surface; 34 ScopedPtrVector<CopyOutputRequest> copy_callbacks; 35}; 36 37TEST(RenderPassTest, CopyShouldBeIdenticalExceptIdAndQuads) { 38 RenderPass::Id id(3, 2); 39 gfx::Rect output_rect(45, 22, 120, 13); 40 gfx::Transform transform_to_root = 41 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); 42 gfx::Rect damage_rect(56, 123, 19, 43); 43 bool has_transparent_background = true; 44 bool has_occlusion_from_outside_target_surface = true; 45 46 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); 47 pass->SetAll(id, 48 output_rect, 49 damage_rect, 50 transform_to_root, 51 has_transparent_background, 52 has_occlusion_from_outside_target_surface); 53 pass->copy_requests.push_back(CopyOutputRequest::CreateBitmapRequest( 54 CopyOutputRequest::CopyAsBitmapCallback())); 55 56 // Stick a quad in the pass, this should not get copied. 57 scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create(); 58 shared_state->SetAll( 59 gfx::Transform(), gfx::Size(), gfx::Rect(), gfx::Rect(), false, 1); 60 pass->AppendSharedQuadState(shared_state.Pass()); 61 62 scoped_ptr<CheckerboardDrawQuad> checkerboard_quad = 63 CheckerboardDrawQuad::Create(); 64 checkerboard_quad->SetNew( 65 pass->shared_quad_state_list.back(), gfx::Rect(), SkColor()); 66 pass->quad_list.push_back(checkerboard_quad.PassAs<DrawQuad>()); 67 68 RenderPass::Id new_id(63, 4); 69 70 scoped_ptr<RenderPass> copy = pass->Copy(new_id); 71 EXPECT_EQ(new_id, copy->id); 72 EXPECT_RECT_EQ(pass->output_rect, copy->output_rect); 73 EXPECT_EQ(pass->transform_to_root_target, copy->transform_to_root_target); 74 EXPECT_RECT_EQ(pass->damage_rect, copy->damage_rect); 75 EXPECT_EQ(pass->has_transparent_background, copy->has_transparent_background); 76 EXPECT_EQ(pass->has_occlusion_from_outside_target_surface, 77 copy->has_occlusion_from_outside_target_surface); 78 EXPECT_EQ(0u, copy->quad_list.size()); 79 80 // The copy request should not be copied/duplicated. 81 EXPECT_EQ(1u, pass->copy_requests.size()); 82 EXPECT_EQ(0u, copy->copy_requests.size()); 83 84 EXPECT_EQ(sizeof(RenderPassSize), sizeof(RenderPass)); 85} 86 87} // namespace 88} // namespace cc 89