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