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/test/render_pass_test_common.h" 6 7 #include "cc/quads/checkerboard_draw_quad.h" 8 #include "cc/quads/debug_border_draw_quad.h" 9 #include "cc/quads/io_surface_draw_quad.h" 10 #include "cc/quads/render_pass_draw_quad.h" 11 #include "cc/quads/shared_quad_state.h" 12 #include "cc/quads/solid_color_draw_quad.h" 13 #include "cc/quads/stream_video_draw_quad.h" 14 #include "cc/quads/texture_draw_quad.h" 15 #include "cc/quads/tile_draw_quad.h" 16 #include "cc/quads/yuv_video_draw_quad.h" 17 #include "cc/resources/resource_provider.h" 18 #include "ui/gfx/transform.h" 19 20 namespace cc { 21 22 void TestRenderPass::AppendQuad(scoped_ptr<cc::DrawQuad> quad) { 23 quad_list.push_back(quad.Pass()); 24 } 25 26 void TestRenderPass::AppendSharedQuadState( 27 scoped_ptr<cc::SharedQuadState> state) { 28 shared_quad_state_list.push_back(state.Pass()); 29 } 30 31 void TestRenderPass::AppendOneOfEveryQuadType( 32 cc::ResourceProvider* resource_provider, RenderPass::Id child_pass) { 33 gfx::Rect rect(0, 0, 100, 100); 34 gfx::Rect opaque_rect(10, 10, 80, 80); 35 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; 36 cc::ResourceProvider::ResourceId resource1 = 37 resource_provider->CreateResource( 38 gfx::Size(45, 5), 39 resource_provider->best_texture_format(), 40 ResourceProvider::TextureUsageAny); 41 resource_provider->AllocateForTesting(resource1); 42 cc::ResourceProvider::ResourceId resource2 = 43 resource_provider->CreateResource( 44 gfx::Size(346, 61), 45 resource_provider->best_texture_format(), 46 ResourceProvider::TextureUsageAny); 47 resource_provider->AllocateForTesting(resource2); 48 cc::ResourceProvider::ResourceId resource3 = 49 resource_provider->CreateResource( 50 gfx::Size(12, 134), 51 resource_provider->best_texture_format(), 52 ResourceProvider::TextureUsageAny); 53 resource_provider->AllocateForTesting(resource3); 54 cc::ResourceProvider::ResourceId resource4 = 55 resource_provider->CreateResource( 56 gfx::Size(56, 12), 57 resource_provider->best_texture_format(), 58 ResourceProvider::TextureUsageAny); 59 resource_provider->AllocateForTesting(resource4); 60 cc::ResourceProvider::ResourceId resource5 = 61 resource_provider->CreateResource( 62 gfx::Size(73, 26), 63 resource_provider->best_texture_format(), 64 ResourceProvider::TextureUsageAny); 65 resource_provider->AllocateForTesting(resource5); 66 cc::ResourceProvider::ResourceId resource6 = 67 resource_provider->CreateResource( 68 gfx::Size(64, 92), 69 resource_provider->best_texture_format(), 70 ResourceProvider::TextureUsageAny); 71 resource_provider->AllocateForTesting(resource6); 72 cc::ResourceProvider::ResourceId resource7 = 73 resource_provider->CreateResource( 74 gfx::Size(9, 14), 75 resource_provider->best_texture_format(), 76 ResourceProvider::TextureUsageAny); 77 resource_provider->AllocateForTesting(resource7); 78 79 scoped_ptr<cc::SharedQuadState> shared_state = cc::SharedQuadState::Create(); 80 shared_state->SetAll(gfx::Transform(), 81 rect.size(), 82 rect, 83 rect, 84 false, 85 1); 86 87 scoped_ptr<cc::CheckerboardDrawQuad> checkerboard_quad = 88 cc::CheckerboardDrawQuad::Create(); 89 checkerboard_quad->SetNew(shared_state.get(), 90 rect, 91 SK_ColorRED); 92 AppendQuad(checkerboard_quad.PassAs<DrawQuad>()); 93 94 scoped_ptr<cc::DebugBorderDrawQuad> debug_border_quad = 95 cc::DebugBorderDrawQuad::Create(); 96 debug_border_quad->SetNew(shared_state.get(), 97 rect, 98 SK_ColorRED, 99 1); 100 AppendQuad(debug_border_quad.PassAs<DrawQuad>()); 101 102 scoped_ptr<cc::IOSurfaceDrawQuad> io_surface_quad = 103 cc::IOSurfaceDrawQuad::Create(); 104 io_surface_quad->SetNew(shared_state.get(), 105 rect, 106 opaque_rect, 107 gfx::Size(50, 50), 108 resource7, 109 cc::IOSurfaceDrawQuad::FLIPPED); 110 AppendQuad(io_surface_quad.PassAs<DrawQuad>()); 111 112 if (child_pass.layer_id) { 113 scoped_ptr<cc::RenderPassDrawQuad> render_pass_quad = 114 cc::RenderPassDrawQuad::Create(); 115 render_pass_quad->SetNew(shared_state.get(), 116 rect, 117 child_pass, 118 false, 119 resource5, 120 rect, 121 gfx::RectF(), 122 FilterOperations(), 123 skia::RefPtr<SkImageFilter>(), 124 FilterOperations()); 125 AppendQuad(render_pass_quad.PassAs<DrawQuad>()); 126 127 scoped_ptr<cc::RenderPassDrawQuad> render_pass_replica_quad = 128 cc::RenderPassDrawQuad::Create(); 129 render_pass_replica_quad->SetNew(shared_state.get(), 130 rect, 131 child_pass, 132 true, 133 resource5, 134 rect, 135 gfx::RectF(), 136 FilterOperations(), 137 skia::RefPtr<SkImageFilter>(), 138 FilterOperations()); 139 AppendQuad(render_pass_replica_quad.PassAs<DrawQuad>()); 140 } 141 142 scoped_ptr<cc::SolidColorDrawQuad> solid_color_quad = 143 cc::SolidColorDrawQuad::Create(); 144 solid_color_quad->SetNew(shared_state.get(), 145 rect, 146 SK_ColorRED, 147 false); 148 AppendQuad(solid_color_quad.PassAs<DrawQuad>()); 149 150 scoped_ptr<cc::StreamVideoDrawQuad> stream_video_quad = 151 cc::StreamVideoDrawQuad::Create(); 152 stream_video_quad->SetNew(shared_state.get(), 153 rect, 154 opaque_rect, 155 resource6, 156 gfx::Transform()); 157 AppendQuad(stream_video_quad.PassAs<DrawQuad>()); 158 159 scoped_ptr<cc::TextureDrawQuad> texture_quad = 160 cc::TextureDrawQuad::Create(); 161 texture_quad->SetNew(shared_state.get(), 162 rect, 163 opaque_rect, 164 resource1, 165 false, 166 gfx::PointF(0.f, 0.f), 167 gfx::PointF(1.f, 1.f), 168 SK_ColorTRANSPARENT, 169 vertex_opacity, 170 false); 171 AppendQuad(texture_quad.PassAs<DrawQuad>()); 172 173 scoped_ptr<cc::TileDrawQuad> scaled_tile_quad = 174 cc::TileDrawQuad::Create(); 175 scaled_tile_quad->SetNew(shared_state.get(), 176 rect, 177 opaque_rect, 178 resource2, 179 gfx::RectF(0, 0, 50, 50), 180 gfx::Size(50, 50), 181 false); 182 AppendQuad(scaled_tile_quad.PassAs<DrawQuad>()); 183 184 scoped_ptr<cc::SharedQuadState> transformed_state = shared_state->Copy(); 185 gfx::Transform rotation; 186 rotation.Rotate(45); 187 transformed_state->content_to_target_transform = 188 transformed_state->content_to_target_transform * rotation; 189 scoped_ptr<cc::TileDrawQuad> transformed_tile_quad = 190 cc::TileDrawQuad::Create(); 191 transformed_tile_quad->SetNew(transformed_state.get(), 192 rect, 193 opaque_rect, 194 resource3, 195 gfx::RectF(0, 0, 100, 100), 196 gfx::Size(100, 100), 197 false); 198 AppendQuad(transformed_tile_quad.PassAs<DrawQuad>()); 199 200 scoped_ptr<cc::TileDrawQuad> tile_quad = 201 cc::TileDrawQuad::Create(); 202 tile_quad->SetNew(shared_state.get(), 203 rect, 204 opaque_rect, 205 resource4, 206 gfx::RectF(0, 0, 100, 100), 207 gfx::Size(100, 100), 208 false); 209 AppendQuad(tile_quad.PassAs<DrawQuad>()); 210 211 ResourceProvider::ResourceId plane_resources[4]; 212 for (int i = 0; i < 4; ++i) { 213 plane_resources[i] = 214 resource_provider->CreateResource( 215 gfx::Size(20, 12), 216 resource_provider->best_texture_format(), 217 ResourceProvider::TextureUsageAny); 218 resource_provider->AllocateForTesting(plane_resources[i]); 219 } 220 scoped_ptr<cc::YUVVideoDrawQuad> yuv_quad = 221 cc::YUVVideoDrawQuad::Create(); 222 yuv_quad->SetNew(shared_state.get(), 223 rect, 224 opaque_rect, 225 gfx::Size(100, 100), 226 plane_resources[0], 227 plane_resources[1], 228 plane_resources[2], 229 plane_resources[3]); 230 AppendQuad(yuv_quad.PassAs<DrawQuad>()); 231 232 AppendSharedQuadState(transformed_state.Pass()); 233 AppendSharedQuadState(shared_state.Pass()); 234 } 235 236 } // namespace cc 237