OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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/output/compositor_frame.h" |
| 6 #include "cc/quads/render_pass.h" |
| 7 #include "cc/quads/solid_color_draw_quad.h" |
| 8 #include "cc/quads/surface_draw_quad.h" |
| 9 #include "cc/surfaces/surface.h" |
| 10 #include "cc/surfaces/surface_aggregator.h" |
| 11 #include "cc/surfaces/surface_factory.h" |
| 12 #include "cc/surfaces/surface_factory_client.h" |
| 13 #include "cc/surfaces/surface_id_allocator.h" |
| 14 #include "cc/surfaces/surface_manager.h" |
| 15 #include "cc/test/pixel_comparator.h" |
| 16 #include "cc/test/pixel_test.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 |
| 19 #if !defined(OS_ANDROID) |
| 20 |
| 21 namespace cc { |
| 22 namespace { |
| 23 |
| 24 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { |
| 25 public: |
| 26 void ReturnResources(const ReturnedResourceArray& resources) override {} |
| 27 }; |
| 28 |
| 29 class SurfacesPixelTest : public RendererPixelTest<GLRenderer> { |
| 30 public: |
| 31 SurfacesPixelTest() : allocator_(1u), factory_(&manager_, &client_) {} |
| 32 |
| 33 protected: |
| 34 SurfaceManager manager_; |
| 35 SurfaceIdAllocator allocator_; |
| 36 EmptySurfaceFactoryClient client_; |
| 37 SurfaceFactory factory_; |
| 38 }; |
| 39 |
| 40 SharedQuadState* CreateAndAppendTestSharedQuadState( |
| 41 RenderPass* render_pass, |
| 42 const gfx::Transform& transform, |
| 43 const gfx::Size& size) { |
| 44 const gfx::Size content_bounds = size; |
| 45 const gfx::Rect visible_content_rect = gfx::Rect(size); |
| 46 const gfx::Rect clip_rect = gfx::Rect(size); |
| 47 bool is_clipped = false; |
| 48 float opacity = 1.f; |
| 49 const SkXfermode::Mode blend_mode = SkXfermode::kSrcOver_Mode; |
| 50 SharedQuadState* shared_state = render_pass->CreateAndAppendSharedQuadState(); |
| 51 shared_state->SetAll(transform, |
| 52 content_bounds, |
| 53 visible_content_rect, |
| 54 clip_rect, |
| 55 is_clipped, |
| 56 opacity, |
| 57 blend_mode, |
| 58 0); |
| 59 return shared_state; |
| 60 } |
| 61 |
| 62 // Draws a very simple frame with no surface references. |
| 63 TEST_F(SurfacesPixelTest, DrawSimpleFrame) { |
| 64 gfx::Rect rect(device_viewport_size_); |
| 65 RenderPassId id(1, 1); |
| 66 scoped_ptr<RenderPass> pass = RenderPass::Create(); |
| 67 pass->SetNew(id, rect, rect, gfx::Transform()); |
| 68 |
| 69 CreateAndAppendTestSharedQuadState( |
| 70 pass.get(), gfx::Transform(), device_viewport_size_); |
| 71 |
| 72 SolidColorDrawQuad* color_quad = |
| 73 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 74 bool force_anti_aliasing_off = false; |
| 75 color_quad->SetNew(pass->shared_quad_state_list.back(), |
| 76 rect, |
| 77 rect, |
| 78 SK_ColorGREEN, |
| 79 force_anti_aliasing_off); |
| 80 |
| 81 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData); |
| 82 delegated_frame_data->render_pass_list.push_back(pass.Pass()); |
| 83 |
| 84 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame); |
| 85 root_frame->delegated_frame_data = delegated_frame_data.Pass(); |
| 86 |
| 87 SurfaceId root_surface_id = allocator_.GenerateId(); |
| 88 factory_.Create(root_surface_id); |
| 89 factory_.SubmitFrame(root_surface_id, root_frame.Pass(), |
| 90 SurfaceFactory::DrawCallback()); |
| 91 |
| 92 SurfaceAggregator aggregator(&manager_, resource_provider_.get()); |
| 93 scoped_ptr<CompositorFrame> aggregated_frame = |
| 94 aggregator.Aggregate(root_surface_id); |
| 95 factory_.Destroy(root_surface_id); |
| 96 |
| 97 bool discard_alpha = false; |
| 98 ExactPixelComparator pixel_comparator(discard_alpha); |
| 99 RenderPassList* pass_list = |
| 100 &aggregated_frame->delegated_frame_data->render_pass_list; |
| 101 EXPECT_TRUE(RunPixelTest(pass_list, |
| 102 base::FilePath(FILE_PATH_LITERAL("green.png")), |
| 103 pixel_comparator)); |
| 104 } |
| 105 |
| 106 // Draws a frame with simple surface embedding. |
| 107 TEST_F(SurfacesPixelTest, DrawSimpleAggregatedFrame) { |
| 108 gfx::Size child_size(200, 100); |
| 109 SurfaceId child_surface_id = allocator_.GenerateId(); |
| 110 SurfaceId root_surface_id = allocator_.GenerateId(); |
| 111 factory_.Create(child_surface_id); |
| 112 factory_.Create(root_surface_id); |
| 113 { |
| 114 gfx::Rect rect(device_viewport_size_); |
| 115 RenderPassId id(1, 1); |
| 116 scoped_ptr<RenderPass> pass = RenderPass::Create(); |
| 117 pass->SetNew(id, rect, rect, gfx::Transform()); |
| 118 |
| 119 CreateAndAppendTestSharedQuadState( |
| 120 pass.get(), gfx::Transform(), device_viewport_size_); |
| 121 |
| 122 SurfaceDrawQuad* surface_quad = |
| 123 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); |
| 124 surface_quad->SetNew(pass->shared_quad_state_list.back(), |
| 125 gfx::Rect(child_size), |
| 126 gfx::Rect(child_size), |
| 127 child_surface_id); |
| 128 |
| 129 SolidColorDrawQuad* color_quad = |
| 130 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 131 bool force_anti_aliasing_off = false; |
| 132 color_quad->SetNew(pass->shared_quad_state_list.back(), |
| 133 rect, |
| 134 rect, |
| 135 SK_ColorYELLOW, |
| 136 force_anti_aliasing_off); |
| 137 |
| 138 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData); |
| 139 delegated_frame_data->render_pass_list.push_back(pass.Pass()); |
| 140 |
| 141 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame); |
| 142 root_frame->delegated_frame_data = delegated_frame_data.Pass(); |
| 143 |
| 144 factory_.SubmitFrame(root_surface_id, root_frame.Pass(), |
| 145 SurfaceFactory::DrawCallback()); |
| 146 } |
| 147 |
| 148 { |
| 149 gfx::Rect rect(child_size); |
| 150 RenderPassId id(1, 1); |
| 151 scoped_ptr<RenderPass> pass = RenderPass::Create(); |
| 152 pass->SetNew(id, rect, rect, gfx::Transform()); |
| 153 |
| 154 CreateAndAppendTestSharedQuadState( |
| 155 pass.get(), gfx::Transform(), child_size); |
| 156 |
| 157 SolidColorDrawQuad* color_quad = |
| 158 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 159 bool force_anti_aliasing_off = false; |
| 160 color_quad->SetNew(pass->shared_quad_state_list.back(), |
| 161 rect, |
| 162 rect, |
| 163 SK_ColorBLUE, |
| 164 force_anti_aliasing_off); |
| 165 |
| 166 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData); |
| 167 delegated_frame_data->render_pass_list.push_back(pass.Pass()); |
| 168 |
| 169 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame); |
| 170 child_frame->delegated_frame_data = delegated_frame_data.Pass(); |
| 171 |
| 172 factory_.SubmitFrame(child_surface_id, child_frame.Pass(), |
| 173 SurfaceFactory::DrawCallback()); |
| 174 } |
| 175 |
| 176 SurfaceAggregator aggregator(&manager_, resource_provider_.get()); |
| 177 scoped_ptr<CompositorFrame> aggregated_frame = |
| 178 aggregator.Aggregate(root_surface_id); |
| 179 |
| 180 bool discard_alpha = false; |
| 181 ExactPixelComparator pixel_comparator(discard_alpha); |
| 182 RenderPassList* pass_list = |
| 183 &aggregated_frame->delegated_frame_data->render_pass_list; |
| 184 EXPECT_TRUE(RunPixelTest(pass_list, |
| 185 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")), |
| 186 pixel_comparator)); |
| 187 factory_.Destroy(root_surface_id); |
| 188 factory_.Destroy(child_surface_id); |
| 189 } |
| 190 |
| 191 // Tests a surface quad that has a non-identity transform into its pass. |
| 192 TEST_F(SurfacesPixelTest, DrawAggregatedFrameWithSurfaceTransforms) { |
| 193 gfx::Size child_size(100, 200); |
| 194 gfx::Size quad_size(100, 100); |
| 195 // Structure: |
| 196 // root (200x200) -> left_child (100x200 @ 0x0, |
| 197 // right_child (100x200 @ 0x100) |
| 198 // left_child -> top_green_quad (100x100 @ 0x0), |
| 199 // bottom_blue_quad (100x100 @ 0x100) |
| 200 // right_child -> top_blue_quad (100x100 @ 0x0), |
| 201 // bottom_green_quad (100x100 @ 0x100) |
| 202 SurfaceId left_child_id = allocator_.GenerateId(); |
| 203 SurfaceId right_child_id = allocator_.GenerateId(); |
| 204 SurfaceId root_surface_id = allocator_.GenerateId(); |
| 205 factory_.Create(left_child_id); |
| 206 factory_.Create(right_child_id); |
| 207 factory_.Create(root_surface_id); |
| 208 |
| 209 { |
| 210 gfx::Rect rect(device_viewport_size_); |
| 211 RenderPassId id(1, 1); |
| 212 scoped_ptr<RenderPass> pass = RenderPass::Create(); |
| 213 pass->SetNew(id, rect, rect, gfx::Transform()); |
| 214 |
| 215 gfx::Transform surface_transform; |
| 216 CreateAndAppendTestSharedQuadState( |
| 217 pass.get(), surface_transform, device_viewport_size_); |
| 218 |
| 219 SurfaceDrawQuad* left_surface_quad = |
| 220 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); |
| 221 left_surface_quad->SetNew(pass->shared_quad_state_list.back(), |
| 222 gfx::Rect(child_size), |
| 223 gfx::Rect(child_size), |
| 224 left_child_id); |
| 225 |
| 226 surface_transform.Translate(100, 0); |
| 227 CreateAndAppendTestSharedQuadState( |
| 228 pass.get(), surface_transform, device_viewport_size_); |
| 229 |
| 230 SurfaceDrawQuad* right_surface_quad = |
| 231 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); |
| 232 right_surface_quad->SetNew(pass->shared_quad_state_list.back(), |
| 233 gfx::Rect(child_size), |
| 234 gfx::Rect(child_size), |
| 235 right_child_id); |
| 236 |
| 237 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData); |
| 238 delegated_frame_data->render_pass_list.push_back(pass.Pass()); |
| 239 |
| 240 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame); |
| 241 root_frame->delegated_frame_data = delegated_frame_data.Pass(); |
| 242 |
| 243 factory_.SubmitFrame(root_surface_id, root_frame.Pass(), |
| 244 SurfaceFactory::DrawCallback()); |
| 245 } |
| 246 |
| 247 { |
| 248 gfx::Rect rect(child_size); |
| 249 RenderPassId id(1, 1); |
| 250 scoped_ptr<RenderPass> pass = RenderPass::Create(); |
| 251 pass->SetNew(id, rect, rect, gfx::Transform()); |
| 252 |
| 253 CreateAndAppendTestSharedQuadState( |
| 254 pass.get(), gfx::Transform(), child_size); |
| 255 |
| 256 SolidColorDrawQuad* top_color_quad = |
| 257 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 258 bool force_anti_aliasing_off = false; |
| 259 top_color_quad->SetNew(pass->shared_quad_state_list.back(), |
| 260 gfx::Rect(quad_size), |
| 261 gfx::Rect(quad_size), |
| 262 SK_ColorGREEN, |
| 263 force_anti_aliasing_off); |
| 264 |
| 265 SolidColorDrawQuad* bottom_color_quad = |
| 266 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 267 bottom_color_quad->SetNew(pass->shared_quad_state_list.back(), |
| 268 gfx::Rect(0, 100, 100, 100), |
| 269 gfx::Rect(0, 100, 100, 100), |
| 270 SK_ColorBLUE, |
| 271 force_anti_aliasing_off); |
| 272 |
| 273 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData); |
| 274 delegated_frame_data->render_pass_list.push_back(pass.Pass()); |
| 275 |
| 276 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame); |
| 277 child_frame->delegated_frame_data = delegated_frame_data.Pass(); |
| 278 |
| 279 factory_.SubmitFrame(left_child_id, child_frame.Pass(), |
| 280 SurfaceFactory::DrawCallback()); |
| 281 } |
| 282 |
| 283 { |
| 284 gfx::Rect rect(child_size); |
| 285 RenderPassId id(1, 1); |
| 286 scoped_ptr<RenderPass> pass = RenderPass::Create(); |
| 287 pass->SetNew(id, rect, rect, gfx::Transform()); |
| 288 |
| 289 CreateAndAppendTestSharedQuadState( |
| 290 pass.get(), gfx::Transform(), child_size); |
| 291 |
| 292 SolidColorDrawQuad* top_color_quad = |
| 293 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 294 bool force_anti_aliasing_off = false; |
| 295 top_color_quad->SetNew(pass->shared_quad_state_list.back(), |
| 296 gfx::Rect(quad_size), |
| 297 gfx::Rect(quad_size), |
| 298 SK_ColorBLUE, |
| 299 force_anti_aliasing_off); |
| 300 |
| 301 SolidColorDrawQuad* bottom_color_quad = |
| 302 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 303 bottom_color_quad->SetNew(pass->shared_quad_state_list.back(), |
| 304 gfx::Rect(0, 100, 100, 100), |
| 305 gfx::Rect(0, 100, 100, 100), |
| 306 SK_ColorGREEN, |
| 307 force_anti_aliasing_off); |
| 308 |
| 309 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData); |
| 310 delegated_frame_data->render_pass_list.push_back(pass.Pass()); |
| 311 |
| 312 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame); |
| 313 child_frame->delegated_frame_data = delegated_frame_data.Pass(); |
| 314 |
| 315 factory_.SubmitFrame(right_child_id, child_frame.Pass(), |
| 316 SurfaceFactory::DrawCallback()); |
| 317 } |
| 318 |
| 319 SurfaceAggregator aggregator(&manager_, resource_provider_.get()); |
| 320 scoped_ptr<CompositorFrame> aggregated_frame = |
| 321 aggregator.Aggregate(root_surface_id); |
| 322 |
| 323 bool discard_alpha = false; |
| 324 ExactPixelComparator pixel_comparator(discard_alpha); |
| 325 RenderPassList* pass_list = |
| 326 &aggregated_frame->delegated_frame_data->render_pass_list; |
| 327 EXPECT_TRUE(RunPixelTest( |
| 328 pass_list, |
| 329 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")), |
| 330 pixel_comparator)); |
| 331 |
| 332 factory_.Destroy(root_surface_id); |
| 333 factory_.Destroy(left_child_id); |
| 334 factory_.Destroy(right_child_id); |
| 335 } |
| 336 |
| 337 } // namespace |
| 338 } // namespace cc |
| 339 |
| 340 #endif // !defined(OS_ANDROID) |
OLD | NEW |