Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / cc / surfaces / surfaces_pixeltest.cc
blobc70028b7281f5ded3f2826712433b8212238501b
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.
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"
19 #if !defined(OS_ANDROID)
21 namespace cc {
22 namespace {
24 class EmptySurfaceFactoryClient : public SurfaceFactoryClient {
25 public:
26 void ReturnResources(const ReturnedResourceArray& resources) override {}
29 class SurfacesPixelTest : public RendererPixelTest<GLRenderer> {
30 public:
31 SurfacesPixelTest() : allocator_(1u), factory_(&manager_, &client_) {}
33 protected:
34 SurfaceManager manager_;
35 SurfaceIdAllocator allocator_;
36 EmptySurfaceFactoryClient client_;
37 SurfaceFactory factory_;
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;
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());
69 CreateAndAppendTestSharedQuadState(
70 pass.get(), gfx::Transform(), device_viewport_size_);
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);
81 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
82 delegated_frame_data->render_pass_list.push_back(pass.Pass());
84 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame);
85 root_frame->delegated_frame_data = delegated_frame_data.Pass();
87 SurfaceId root_surface_id = allocator_.GenerateId();
88 factory_.Create(root_surface_id, device_viewport_size_);
89 factory_.SubmitFrame(root_surface_id, root_frame.Pass(), base::Closure());
91 SurfaceAggregator aggregator(&manager_, resource_provider_.get());
92 scoped_ptr<CompositorFrame> aggregated_frame =
93 aggregator.Aggregate(root_surface_id);
94 factory_.Destroy(root_surface_id);
96 bool discard_alpha = false;
97 ExactPixelComparator pixel_comparator(discard_alpha);
98 RenderPassList* pass_list =
99 &aggregated_frame->delegated_frame_data->render_pass_list;
100 EXPECT_TRUE(RunPixelTest(pass_list,
101 base::FilePath(FILE_PATH_LITERAL("green.png")),
102 pixel_comparator));
105 // Draws a frame with simple surface embedding.
106 TEST_F(SurfacesPixelTest, DrawSimpleAggregatedFrame) {
107 gfx::Size child_size(200, 100);
108 SurfaceId child_surface_id = allocator_.GenerateId();
109 SurfaceId root_surface_id = allocator_.GenerateId();
110 factory_.Create(child_surface_id, child_size);
111 factory_.Create(root_surface_id, device_viewport_size_);
113 gfx::Rect rect(device_viewport_size_);
114 RenderPassId id(1, 1);
115 scoped_ptr<RenderPass> pass = RenderPass::Create();
116 pass->SetNew(id, rect, rect, gfx::Transform());
118 CreateAndAppendTestSharedQuadState(
119 pass.get(), gfx::Transform(), device_viewport_size_);
121 SurfaceDrawQuad* surface_quad =
122 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
123 surface_quad->SetNew(pass->shared_quad_state_list.back(),
124 gfx::Rect(child_size),
125 gfx::Rect(child_size),
126 child_surface_id);
128 SolidColorDrawQuad* color_quad =
129 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
130 bool force_anti_aliasing_off = false;
131 color_quad->SetNew(pass->shared_quad_state_list.back(),
132 rect,
133 rect,
134 SK_ColorYELLOW,
135 force_anti_aliasing_off);
137 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
138 delegated_frame_data->render_pass_list.push_back(pass.Pass());
140 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame);
141 root_frame->delegated_frame_data = delegated_frame_data.Pass();
143 factory_.SubmitFrame(root_surface_id, root_frame.Pass(), base::Closure());
147 gfx::Rect rect(child_size);
148 RenderPassId id(1, 1);
149 scoped_ptr<RenderPass> pass = RenderPass::Create();
150 pass->SetNew(id, rect, rect, gfx::Transform());
152 CreateAndAppendTestSharedQuadState(
153 pass.get(), gfx::Transform(), child_size);
155 SolidColorDrawQuad* color_quad =
156 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
157 bool force_anti_aliasing_off = false;
158 color_quad->SetNew(pass->shared_quad_state_list.back(),
159 rect,
160 rect,
161 SK_ColorBLUE,
162 force_anti_aliasing_off);
164 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
165 delegated_frame_data->render_pass_list.push_back(pass.Pass());
167 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame);
168 child_frame->delegated_frame_data = delegated_frame_data.Pass();
170 factory_.SubmitFrame(child_surface_id, child_frame.Pass(), base::Closure());
173 SurfaceAggregator aggregator(&manager_, resource_provider_.get());
174 scoped_ptr<CompositorFrame> aggregated_frame =
175 aggregator.Aggregate(root_surface_id);
177 bool discard_alpha = false;
178 ExactPixelComparator pixel_comparator(discard_alpha);
179 RenderPassList* pass_list =
180 &aggregated_frame->delegated_frame_data->render_pass_list;
181 EXPECT_TRUE(RunPixelTest(pass_list,
182 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")),
183 pixel_comparator));
184 factory_.Destroy(root_surface_id);
185 factory_.Destroy(child_surface_id);
188 // Tests a surface quad that has a non-identity transform into its pass.
189 TEST_F(SurfacesPixelTest, DrawAggregatedFrameWithSurfaceTransforms) {
190 gfx::Size child_size(100, 200);
191 gfx::Size quad_size(100, 100);
192 // Structure:
193 // root (200x200) -> left_child (100x200 @ 0x0,
194 // right_child (100x200 @ 0x100)
195 // left_child -> top_green_quad (100x100 @ 0x0),
196 // bottom_blue_quad (100x100 @ 0x100)
197 // right_child -> top_blue_quad (100x100 @ 0x0),
198 // bottom_green_quad (100x100 @ 0x100)
199 SurfaceId left_child_id = allocator_.GenerateId();
200 SurfaceId right_child_id = allocator_.GenerateId();
201 SurfaceId root_surface_id = allocator_.GenerateId();
202 factory_.Create(left_child_id, child_size);
203 factory_.Create(right_child_id, child_size);
204 factory_.Create(root_surface_id, device_viewport_size_);
207 gfx::Rect rect(device_viewport_size_);
208 RenderPassId id(1, 1);
209 scoped_ptr<RenderPass> pass = RenderPass::Create();
210 pass->SetNew(id, rect, rect, gfx::Transform());
212 gfx::Transform surface_transform;
213 CreateAndAppendTestSharedQuadState(
214 pass.get(), surface_transform, device_viewport_size_);
216 SurfaceDrawQuad* left_surface_quad =
217 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
218 left_surface_quad->SetNew(pass->shared_quad_state_list.back(),
219 gfx::Rect(child_size),
220 gfx::Rect(child_size),
221 left_child_id);
223 surface_transform.Translate(100, 0);
224 CreateAndAppendTestSharedQuadState(
225 pass.get(), surface_transform, device_viewport_size_);
227 SurfaceDrawQuad* right_surface_quad =
228 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
229 right_surface_quad->SetNew(pass->shared_quad_state_list.back(),
230 gfx::Rect(child_size),
231 gfx::Rect(child_size),
232 right_child_id);
234 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
235 delegated_frame_data->render_pass_list.push_back(pass.Pass());
237 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame);
238 root_frame->delegated_frame_data = delegated_frame_data.Pass();
240 factory_.SubmitFrame(root_surface_id, root_frame.Pass(), base::Closure());
244 gfx::Rect rect(child_size);
245 RenderPassId id(1, 1);
246 scoped_ptr<RenderPass> pass = RenderPass::Create();
247 pass->SetNew(id, rect, rect, gfx::Transform());
249 CreateAndAppendTestSharedQuadState(
250 pass.get(), gfx::Transform(), child_size);
252 SolidColorDrawQuad* top_color_quad =
253 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
254 bool force_anti_aliasing_off = false;
255 top_color_quad->SetNew(pass->shared_quad_state_list.back(),
256 gfx::Rect(quad_size),
257 gfx::Rect(quad_size),
258 SK_ColorGREEN,
259 force_anti_aliasing_off);
261 SolidColorDrawQuad* bottom_color_quad =
262 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
263 bottom_color_quad->SetNew(pass->shared_quad_state_list.back(),
264 gfx::Rect(0, 100, 100, 100),
265 gfx::Rect(0, 100, 100, 100),
266 SK_ColorBLUE,
267 force_anti_aliasing_off);
269 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
270 delegated_frame_data->render_pass_list.push_back(pass.Pass());
272 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame);
273 child_frame->delegated_frame_data = delegated_frame_data.Pass();
275 factory_.SubmitFrame(left_child_id, child_frame.Pass(), base::Closure());
279 gfx::Rect rect(child_size);
280 RenderPassId id(1, 1);
281 scoped_ptr<RenderPass> pass = RenderPass::Create();
282 pass->SetNew(id, rect, rect, gfx::Transform());
284 CreateAndAppendTestSharedQuadState(
285 pass.get(), gfx::Transform(), child_size);
287 SolidColorDrawQuad* top_color_quad =
288 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
289 bool force_anti_aliasing_off = false;
290 top_color_quad->SetNew(pass->shared_quad_state_list.back(),
291 gfx::Rect(quad_size),
292 gfx::Rect(quad_size),
293 SK_ColorBLUE,
294 force_anti_aliasing_off);
296 SolidColorDrawQuad* bottom_color_quad =
297 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
298 bottom_color_quad->SetNew(pass->shared_quad_state_list.back(),
299 gfx::Rect(0, 100, 100, 100),
300 gfx::Rect(0, 100, 100, 100),
301 SK_ColorGREEN,
302 force_anti_aliasing_off);
304 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
305 delegated_frame_data->render_pass_list.push_back(pass.Pass());
307 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame);
308 child_frame->delegated_frame_data = delegated_frame_data.Pass();
310 factory_.SubmitFrame(right_child_id, child_frame.Pass(), base::Closure());
313 SurfaceAggregator aggregator(&manager_, resource_provider_.get());
314 scoped_ptr<CompositorFrame> aggregated_frame =
315 aggregator.Aggregate(root_surface_id);
317 bool discard_alpha = false;
318 ExactPixelComparator pixel_comparator(discard_alpha);
319 RenderPassList* pass_list =
320 &aggregated_frame->delegated_frame_data->render_pass_list;
321 EXPECT_TRUE(RunPixelTest(
322 pass_list,
323 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
324 pixel_comparator));
326 factory_.Destroy(root_surface_id);
327 factory_.Destroy(left_child_id);
328 factory_.Destroy(right_child_id);
331 } // namespace
332 } // namespace cc
334 #endif // !defined(OS_ANDROID)