| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/output/compositor_frame.h" | 5 #include "cc/output/compositor_frame.h" |
| 6 #include "cc/quads/render_pass.h" | 6 #include "cc/quads/render_pass.h" |
| 7 #include "cc/quads/solid_color_draw_quad.h" | 7 #include "cc/quads/solid_color_draw_quad.h" |
| 8 #include "cc/quads/surface_draw_quad.h" | 8 #include "cc/quads/surface_draw_quad.h" |
| 9 #include "cc/surfaces/surface.h" | 9 #include "cc/surfaces/surface.h" |
| 10 #include "cc/surfaces/surface_aggregator.h" | 10 #include "cc/surfaces/surface_aggregator.h" |
| 11 #include "cc/surfaces/surface_factory.h" | 11 #include "cc/surfaces/surface_factory.h" |
| 12 #include "cc/surfaces/surface_factory_client.h" | 12 #include "cc/surfaces/surface_factory_client.h" |
| 13 #include "cc/surfaces/surface_id_allocator.h" | 13 #include "cc/surfaces/surface_id_allocator.h" |
| 14 #include "cc/surfaces/surface_manager.h" | 14 #include "cc/surfaces/surface_manager.h" |
| 15 #include "cc/test/pixel_comparator.h" | 15 #include "cc/test/pixel_comparator.h" |
| 16 #include "cc/test/pixel_test.h" | 16 #include "cc/test/pixel_test.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 #if !defined(OS_ANDROID) | 19 #if !defined(OS_ANDROID) |
| 20 | 20 |
| 21 namespace cc { | 21 namespace cc { |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 static constexpr FrameSinkId kArbitraryRootFrameSinkId(1, 1); | 24 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); |
| 25 static constexpr FrameSinkId kArbitraryChildFrameSinkId(2, 2); | |
| 26 static constexpr FrameSinkId kArbitraryLeftFrameSinkId(3, 3); | |
| 27 static constexpr FrameSinkId kArbitraryRightFrameSinkId(4, 4); | |
| 28 | 25 |
| 29 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { | 26 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { |
| 30 public: | 27 public: |
| 31 void ReturnResources(const ReturnedResourceArray& resources) override {} | 28 void ReturnResources(const ReturnedResourceArray& resources) override {} |
| 32 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {} | 29 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {} |
| 33 }; | 30 }; |
| 34 | 31 |
| 35 class SurfacesPixelTest : public RendererPixelTest<GLRenderer> { | 32 class SurfacesPixelTest : public RendererPixelTest<GLRenderer> { |
| 36 public: | 33 public: |
| 37 SurfacesPixelTest() | 34 SurfacesPixelTest() : factory_(kArbitraryFrameSinkId, &manager_, &client_) {} |
| 38 : factory_(kArbitraryRootFrameSinkId, &manager_, &client_) {} | |
| 39 ~SurfacesPixelTest() override { factory_.EvictSurface(); } | |
| 40 | 35 |
| 41 protected: | 36 protected: |
| 42 SurfaceManager manager_; | 37 SurfaceManager manager_; |
| 43 SurfaceIdAllocator allocator_; | 38 SurfaceIdAllocator allocator_; |
| 44 EmptySurfaceFactoryClient client_; | 39 EmptySurfaceFactoryClient client_; |
| 45 SurfaceFactory factory_; | 40 SurfaceFactory factory_; |
| 46 }; | 41 }; |
| 47 | 42 |
| 48 SharedQuadState* CreateAndAppendTestSharedQuadState( | 43 SharedQuadState* CreateAndAppendTestSharedQuadState( |
| 49 RenderPass* render_pass, | 44 RenderPass* render_pass, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 79 rect, | 74 rect, |
| 80 SK_ColorGREEN, | 75 SK_ColorGREEN, |
| 81 force_anti_aliasing_off); | 76 force_anti_aliasing_off); |
| 82 | 77 |
| 83 | 78 |
| 84 CompositorFrame root_frame; | 79 CompositorFrame root_frame; |
| 85 root_frame.render_pass_list.push_back(std::move(pass)); | 80 root_frame.render_pass_list.push_back(std::move(pass)); |
| 86 | 81 |
| 87 LocalFrameId root_local_frame_id = allocator_.GenerateId(); | 82 LocalFrameId root_local_frame_id = allocator_.GenerateId(); |
| 88 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id); | 83 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id); |
| 84 factory_.Create(root_local_frame_id); |
| 89 factory_.SubmitCompositorFrame(root_local_frame_id, std::move(root_frame), | 85 factory_.SubmitCompositorFrame(root_local_frame_id, std::move(root_frame), |
| 90 SurfaceFactory::DrawCallback()); | 86 SurfaceFactory::DrawCallback()); |
| 91 | 87 |
| 92 SurfaceAggregator aggregator(&manager_, resource_provider_.get(), true); | 88 SurfaceAggregator aggregator(&manager_, resource_provider_.get(), true); |
| 93 CompositorFrame aggregated_frame = aggregator.Aggregate(root_surface_id); | 89 CompositorFrame aggregated_frame = aggregator.Aggregate(root_surface_id); |
| 90 factory_.Destroy(root_local_frame_id); |
| 94 | 91 |
| 95 bool discard_alpha = false; | 92 bool discard_alpha = false; |
| 96 ExactPixelComparator pixel_comparator(discard_alpha); | 93 ExactPixelComparator pixel_comparator(discard_alpha); |
| 97 RenderPassList* pass_list = &aggregated_frame.render_pass_list; | 94 RenderPassList* pass_list = &aggregated_frame.render_pass_list; |
| 98 EXPECT_TRUE(RunPixelTest(pass_list, | 95 EXPECT_TRUE(RunPixelTest(pass_list, |
| 99 base::FilePath(FILE_PATH_LITERAL("green.png")), | 96 base::FilePath(FILE_PATH_LITERAL("green.png")), |
| 100 pixel_comparator)); | 97 pixel_comparator)); |
| 101 } | 98 } |
| 102 | 99 |
| 103 // Draws a frame with simple surface embedding. | 100 // Draws a frame with simple surface embedding. |
| 104 TEST_F(SurfacesPixelTest, DrawSimpleAggregatedFrame) { | 101 TEST_F(SurfacesPixelTest, DrawSimpleAggregatedFrame) { |
| 105 gfx::Size child_size(200, 100); | 102 gfx::Size child_size(200, 100); |
| 106 SurfaceFactory child_factory(kArbitraryChildFrameSinkId, &manager_, &client_); | |
| 107 LocalFrameId child_local_frame_id = allocator_.GenerateId(); | 103 LocalFrameId child_local_frame_id = allocator_.GenerateId(); |
| 108 SurfaceId child_surface_id(child_factory.frame_sink_id(), | 104 SurfaceId child_surface_id(factory_.frame_sink_id(), child_local_frame_id); |
| 109 child_local_frame_id); | |
| 110 LocalFrameId root_local_frame_id = allocator_.GenerateId(); | 105 LocalFrameId root_local_frame_id = allocator_.GenerateId(); |
| 111 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id); | 106 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id); |
| 112 | 107 |
| 108 factory_.Create(child_local_frame_id); |
| 109 factory_.Create(root_local_frame_id); |
| 113 { | 110 { |
| 114 gfx::Rect rect(device_viewport_size_); | 111 gfx::Rect rect(device_viewport_size_); |
| 115 RenderPassId id(1, 1); | 112 RenderPassId id(1, 1); |
| 116 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 113 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
| 117 pass->SetNew(id, rect, rect, gfx::Transform()); | 114 pass->SetNew(id, rect, rect, gfx::Transform()); |
| 118 | 115 |
| 119 CreateAndAppendTestSharedQuadState( | 116 CreateAndAppendTestSharedQuadState( |
| 120 pass.get(), gfx::Transform(), device_viewport_size_); | 117 pass.get(), gfx::Transform(), device_viewport_size_); |
| 121 | 118 |
| 122 SurfaceDrawQuad* surface_quad = | 119 SurfaceDrawQuad* surface_quad = |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 bool force_anti_aliasing_off = false; | 153 bool force_anti_aliasing_off = false; |
| 157 color_quad->SetNew(pass->shared_quad_state_list.back(), | 154 color_quad->SetNew(pass->shared_quad_state_list.back(), |
| 158 rect, | 155 rect, |
| 159 rect, | 156 rect, |
| 160 SK_ColorBLUE, | 157 SK_ColorBLUE, |
| 161 force_anti_aliasing_off); | 158 force_anti_aliasing_off); |
| 162 | 159 |
| 163 CompositorFrame child_frame; | 160 CompositorFrame child_frame; |
| 164 child_frame.render_pass_list.push_back(std::move(pass)); | 161 child_frame.render_pass_list.push_back(std::move(pass)); |
| 165 | 162 |
| 166 child_factory.SubmitCompositorFrame(child_local_frame_id, | 163 factory_.SubmitCompositorFrame(child_local_frame_id, std::move(child_frame), |
| 167 std::move(child_frame), | 164 SurfaceFactory::DrawCallback()); |
| 168 SurfaceFactory::DrawCallback()); | |
| 169 } | 165 } |
| 170 | 166 |
| 171 SurfaceAggregator aggregator(&manager_, resource_provider_.get(), true); | 167 SurfaceAggregator aggregator(&manager_, resource_provider_.get(), true); |
| 172 CompositorFrame aggregated_frame = aggregator.Aggregate(root_surface_id); | 168 CompositorFrame aggregated_frame = aggregator.Aggregate(root_surface_id); |
| 173 | 169 |
| 174 bool discard_alpha = false; | 170 bool discard_alpha = false; |
| 175 ExactPixelComparator pixel_comparator(discard_alpha); | 171 ExactPixelComparator pixel_comparator(discard_alpha); |
| 176 RenderPassList* pass_list = &aggregated_frame.render_pass_list; | 172 RenderPassList* pass_list = &aggregated_frame.render_pass_list; |
| 177 EXPECT_TRUE(RunPixelTest(pass_list, | 173 EXPECT_TRUE(RunPixelTest(pass_list, |
| 178 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")), | 174 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")), |
| 179 pixel_comparator)); | 175 pixel_comparator)); |
| 180 | 176 factory_.Destroy(root_local_frame_id); |
| 181 child_factory.EvictSurface(); | 177 factory_.Destroy(child_local_frame_id); |
| 182 } | 178 } |
| 183 | 179 |
| 184 // Tests a surface quad that has a non-identity transform into its pass. | 180 // Tests a surface quad that has a non-identity transform into its pass. |
| 185 TEST_F(SurfacesPixelTest, DrawAggregatedFrameWithSurfaceTransforms) { | 181 TEST_F(SurfacesPixelTest, DrawAggregatedFrameWithSurfaceTransforms) { |
| 186 gfx::Size child_size(100, 200); | 182 gfx::Size child_size(100, 200); |
| 187 gfx::Size quad_size(100, 100); | 183 gfx::Size quad_size(100, 100); |
| 188 // Structure: | 184 // Structure: |
| 189 // root (200x200) -> left_child (100x200 @ 0x0, | 185 // root (200x200) -> left_child (100x200 @ 0x0, |
| 190 // right_child (100x200 @ 0x100) | 186 // right_child (100x200 @ 0x100) |
| 191 // left_child -> top_green_quad (100x100 @ 0x0), | 187 // left_child -> top_green_quad (100x100 @ 0x0), |
| 192 // bottom_blue_quad (100x100 @ 0x100) | 188 // bottom_blue_quad (100x100 @ 0x100) |
| 193 // right_child -> top_blue_quad (100x100 @ 0x0), | 189 // right_child -> top_blue_quad (100x100 @ 0x0), |
| 194 // bottom_green_quad (100x100 @ 0x100) | 190 // bottom_green_quad (100x100 @ 0x100) |
| 195 SurfaceFactory left_factory(kArbitraryLeftFrameSinkId, &manager_, &client_); | |
| 196 SurfaceFactory right_factory(kArbitraryRightFrameSinkId, &manager_, &client_); | |
| 197 LocalFrameId left_child_local_id = allocator_.GenerateId(); | 191 LocalFrameId left_child_local_id = allocator_.GenerateId(); |
| 198 SurfaceId left_child_id(left_factory.frame_sink_id(), left_child_local_id); | 192 SurfaceId left_child_id(factory_.frame_sink_id(), left_child_local_id); |
| 199 LocalFrameId right_child_local_id = allocator_.GenerateId(); | 193 LocalFrameId right_child_local_id = allocator_.GenerateId(); |
| 200 SurfaceId right_child_id(right_factory.frame_sink_id(), right_child_local_id); | 194 SurfaceId right_child_id(factory_.frame_sink_id(), right_child_local_id); |
| 201 LocalFrameId root_local_frame_id = allocator_.GenerateId(); | 195 LocalFrameId root_local_frame_id = allocator_.GenerateId(); |
| 202 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id); | 196 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id); |
| 197 factory_.Create(left_child_local_id); |
| 198 factory_.Create(right_child_local_id); |
| 199 factory_.Create(root_local_frame_id); |
| 203 | 200 |
| 204 { | 201 { |
| 205 gfx::Rect rect(device_viewport_size_); | 202 gfx::Rect rect(device_viewport_size_); |
| 206 RenderPassId id(1, 1); | 203 RenderPassId id(1, 1); |
| 207 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 204 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
| 208 pass->SetNew(id, rect, rect, gfx::Transform()); | 205 pass->SetNew(id, rect, rect, gfx::Transform()); |
| 209 | 206 |
| 210 gfx::Transform surface_transform; | 207 gfx::Transform surface_transform; |
| 211 CreateAndAppendTestSharedQuadState( | 208 CreateAndAppendTestSharedQuadState( |
| 212 pass.get(), surface_transform, device_viewport_size_); | 209 pass.get(), surface_transform, device_viewport_size_); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); | 255 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 259 bottom_color_quad->SetNew(pass->shared_quad_state_list.back(), | 256 bottom_color_quad->SetNew(pass->shared_quad_state_list.back(), |
| 260 gfx::Rect(0, 100, 100, 100), | 257 gfx::Rect(0, 100, 100, 100), |
| 261 gfx::Rect(0, 100, 100, 100), | 258 gfx::Rect(0, 100, 100, 100), |
| 262 SK_ColorBLUE, | 259 SK_ColorBLUE, |
| 263 force_anti_aliasing_off); | 260 force_anti_aliasing_off); |
| 264 | 261 |
| 265 CompositorFrame child_frame; | 262 CompositorFrame child_frame; |
| 266 child_frame.render_pass_list.push_back(std::move(pass)); | 263 child_frame.render_pass_list.push_back(std::move(pass)); |
| 267 | 264 |
| 268 left_factory.SubmitCompositorFrame(left_child_local_id, | 265 factory_.SubmitCompositorFrame(left_child_local_id, std::move(child_frame), |
| 269 std::move(child_frame), | 266 SurfaceFactory::DrawCallback()); |
| 270 SurfaceFactory::DrawCallback()); | |
| 271 } | 267 } |
| 272 | 268 |
| 273 { | 269 { |
| 274 gfx::Rect rect(child_size); | 270 gfx::Rect rect(child_size); |
| 275 RenderPassId id(1, 1); | 271 RenderPassId id(1, 1); |
| 276 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 272 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
| 277 pass->SetNew(id, rect, rect, gfx::Transform()); | 273 pass->SetNew(id, rect, rect, gfx::Transform()); |
| 278 | 274 |
| 279 CreateAndAppendTestSharedQuadState( | 275 CreateAndAppendTestSharedQuadState( |
| 280 pass.get(), gfx::Transform(), child_size); | 276 pass.get(), gfx::Transform(), child_size); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 292 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); | 288 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 293 bottom_color_quad->SetNew(pass->shared_quad_state_list.back(), | 289 bottom_color_quad->SetNew(pass->shared_quad_state_list.back(), |
| 294 gfx::Rect(0, 100, 100, 100), | 290 gfx::Rect(0, 100, 100, 100), |
| 295 gfx::Rect(0, 100, 100, 100), | 291 gfx::Rect(0, 100, 100, 100), |
| 296 SK_ColorGREEN, | 292 SK_ColorGREEN, |
| 297 force_anti_aliasing_off); | 293 force_anti_aliasing_off); |
| 298 | 294 |
| 299 CompositorFrame child_frame; | 295 CompositorFrame child_frame; |
| 300 child_frame.render_pass_list.push_back(std::move(pass)); | 296 child_frame.render_pass_list.push_back(std::move(pass)); |
| 301 | 297 |
| 302 right_factory.SubmitCompositorFrame(right_child_local_id, | 298 factory_.SubmitCompositorFrame(right_child_local_id, std::move(child_frame), |
| 303 std::move(child_frame), | 299 SurfaceFactory::DrawCallback()); |
| 304 SurfaceFactory::DrawCallback()); | |
| 305 } | 300 } |
| 306 | 301 |
| 307 SurfaceAggregator aggregator(&manager_, resource_provider_.get(), true); | 302 SurfaceAggregator aggregator(&manager_, resource_provider_.get(), true); |
| 308 CompositorFrame aggregated_frame = aggregator.Aggregate(root_surface_id); | 303 CompositorFrame aggregated_frame = aggregator.Aggregate(root_surface_id); |
| 309 | 304 |
| 310 bool discard_alpha = false; | 305 bool discard_alpha = false; |
| 311 ExactPixelComparator pixel_comparator(discard_alpha); | 306 ExactPixelComparator pixel_comparator(discard_alpha); |
| 312 RenderPassList* pass_list = &aggregated_frame.render_pass_list; | 307 RenderPassList* pass_list = &aggregated_frame.render_pass_list; |
| 313 EXPECT_TRUE(RunPixelTest( | 308 EXPECT_TRUE(RunPixelTest( |
| 314 pass_list, | 309 pass_list, |
| 315 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")), | 310 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")), |
| 316 pixel_comparator)); | 311 pixel_comparator)); |
| 317 | 312 |
| 318 left_factory.EvictSurface(); | 313 factory_.Destroy(root_local_frame_id); |
| 319 right_factory.EvictSurface(); | 314 factory_.Destroy(left_child_local_id); |
| 315 factory_.Destroy(right_child_local_id); |
| 320 } | 316 } |
| 321 | 317 |
| 322 } // namespace | 318 } // namespace |
| 323 } // namespace cc | 319 } // namespace cc |
| 324 | 320 |
| 325 #endif // !defined(OS_ANDROID) | 321 #endif // !defined(OS_ANDROID) |
| OLD | NEW |