Cleanup/ remove unwanted duplicated option on tabs.json
[chromium-blink-merge.git] / cc / surfaces / surfaces_pixeltest.cc
blob6c821a69f70640cebedb1492cacb8f6660a447cd
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 layer_bounds = size;
45 const gfx::Rect visible_layer_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, layer_bounds, visible_layer_rect, clip_rect,
52 is_clipped, opacity, blend_mode, 0);
53 return shared_state;
56 // Draws a very simple frame with no surface references.
57 TEST_F(SurfacesPixelTest, DrawSimpleFrame) {
58 gfx::Rect rect(device_viewport_size_);
59 RenderPassId id(1, 1);
60 scoped_ptr<RenderPass> pass = RenderPass::Create();
61 pass->SetNew(id, rect, rect, gfx::Transform());
63 CreateAndAppendTestSharedQuadState(
64 pass.get(), gfx::Transform(), device_viewport_size_);
66 SolidColorDrawQuad* color_quad =
67 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
68 bool force_anti_aliasing_off = false;
69 color_quad->SetNew(pass->shared_quad_state_list.back(),
70 rect,
71 rect,
72 SK_ColorGREEN,
73 force_anti_aliasing_off);
75 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
76 delegated_frame_data->render_pass_list.push_back(pass.Pass());
78 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame);
79 root_frame->delegated_frame_data = delegated_frame_data.Pass();
81 SurfaceId root_surface_id = allocator_.GenerateId();
82 factory_.Create(root_surface_id);
83 factory_.SubmitFrame(root_surface_id, root_frame.Pass(),
84 SurfaceFactory::DrawCallback());
86 SurfaceAggregator aggregator(&manager_, resource_provider_.get(), true);
87 scoped_ptr<CompositorFrame> aggregated_frame =
88 aggregator.Aggregate(root_surface_id);
89 factory_.Destroy(root_surface_id);
91 bool discard_alpha = false;
92 ExactPixelComparator pixel_comparator(discard_alpha);
93 RenderPassList* pass_list =
94 &aggregated_frame->delegated_frame_data->render_pass_list;
95 EXPECT_TRUE(RunPixelTest(pass_list,
96 base::FilePath(FILE_PATH_LITERAL("green.png")),
97 pixel_comparator));
100 // Draws a frame with simple surface embedding.
101 TEST_F(SurfacesPixelTest, DrawSimpleAggregatedFrame) {
102 gfx::Size child_size(200, 100);
103 SurfaceId child_surface_id = allocator_.GenerateId();
104 SurfaceId root_surface_id = allocator_.GenerateId();
105 factory_.Create(child_surface_id);
106 factory_.Create(root_surface_id);
108 gfx::Rect rect(device_viewport_size_);
109 RenderPassId id(1, 1);
110 scoped_ptr<RenderPass> pass = RenderPass::Create();
111 pass->SetNew(id, rect, rect, gfx::Transform());
113 CreateAndAppendTestSharedQuadState(
114 pass.get(), gfx::Transform(), device_viewport_size_);
116 SurfaceDrawQuad* surface_quad =
117 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
118 surface_quad->SetNew(pass->shared_quad_state_list.back(),
119 gfx::Rect(child_size),
120 gfx::Rect(child_size),
121 child_surface_id);
123 SolidColorDrawQuad* color_quad =
124 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
125 bool force_anti_aliasing_off = false;
126 color_quad->SetNew(pass->shared_quad_state_list.back(),
127 rect,
128 rect,
129 SK_ColorYELLOW,
130 force_anti_aliasing_off);
132 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
133 delegated_frame_data->render_pass_list.push_back(pass.Pass());
135 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame);
136 root_frame->delegated_frame_data = delegated_frame_data.Pass();
138 factory_.SubmitFrame(root_surface_id, root_frame.Pass(),
139 SurfaceFactory::DrawCallback());
143 gfx::Rect rect(child_size);
144 RenderPassId id(1, 1);
145 scoped_ptr<RenderPass> pass = RenderPass::Create();
146 pass->SetNew(id, rect, rect, gfx::Transform());
148 CreateAndAppendTestSharedQuadState(
149 pass.get(), gfx::Transform(), child_size);
151 SolidColorDrawQuad* color_quad =
152 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
153 bool force_anti_aliasing_off = false;
154 color_quad->SetNew(pass->shared_quad_state_list.back(),
155 rect,
156 rect,
157 SK_ColorBLUE,
158 force_anti_aliasing_off);
160 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
161 delegated_frame_data->render_pass_list.push_back(pass.Pass());
163 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame);
164 child_frame->delegated_frame_data = delegated_frame_data.Pass();
166 factory_.SubmitFrame(child_surface_id, child_frame.Pass(),
167 SurfaceFactory::DrawCallback());
170 SurfaceAggregator aggregator(&manager_, resource_provider_.get(), true);
171 scoped_ptr<CompositorFrame> aggregated_frame =
172 aggregator.Aggregate(root_surface_id);
174 bool discard_alpha = false;
175 ExactPixelComparator pixel_comparator(discard_alpha);
176 RenderPassList* pass_list =
177 &aggregated_frame->delegated_frame_data->render_pass_list;
178 EXPECT_TRUE(RunPixelTest(pass_list,
179 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")),
180 pixel_comparator));
181 factory_.Destroy(root_surface_id);
182 factory_.Destroy(child_surface_id);
185 // Tests a surface quad that has a non-identity transform into its pass.
186 TEST_F(SurfacesPixelTest, DrawAggregatedFrameWithSurfaceTransforms) {
187 gfx::Size child_size(100, 200);
188 gfx::Size quad_size(100, 100);
189 // Structure:
190 // root (200x200) -> left_child (100x200 @ 0x0,
191 // right_child (100x200 @ 0x100)
192 // left_child -> top_green_quad (100x100 @ 0x0),
193 // bottom_blue_quad (100x100 @ 0x100)
194 // right_child -> top_blue_quad (100x100 @ 0x0),
195 // bottom_green_quad (100x100 @ 0x100)
196 SurfaceId left_child_id = allocator_.GenerateId();
197 SurfaceId right_child_id = allocator_.GenerateId();
198 SurfaceId root_surface_id = allocator_.GenerateId();
199 factory_.Create(left_child_id);
200 factory_.Create(right_child_id);
201 factory_.Create(root_surface_id);
204 gfx::Rect rect(device_viewport_size_);
205 RenderPassId id(1, 1);
206 scoped_ptr<RenderPass> pass = RenderPass::Create();
207 pass->SetNew(id, rect, rect, gfx::Transform());
209 gfx::Transform surface_transform;
210 CreateAndAppendTestSharedQuadState(
211 pass.get(), surface_transform, device_viewport_size_);
213 SurfaceDrawQuad* left_surface_quad =
214 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
215 left_surface_quad->SetNew(pass->shared_quad_state_list.back(),
216 gfx::Rect(child_size),
217 gfx::Rect(child_size),
218 left_child_id);
220 surface_transform.Translate(100, 0);
221 CreateAndAppendTestSharedQuadState(
222 pass.get(), surface_transform, device_viewport_size_);
224 SurfaceDrawQuad* right_surface_quad =
225 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
226 right_surface_quad->SetNew(pass->shared_quad_state_list.back(),
227 gfx::Rect(child_size),
228 gfx::Rect(child_size),
229 right_child_id);
231 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
232 delegated_frame_data->render_pass_list.push_back(pass.Pass());
234 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame);
235 root_frame->delegated_frame_data = delegated_frame_data.Pass();
237 factory_.SubmitFrame(root_surface_id, root_frame.Pass(),
238 SurfaceFactory::DrawCallback());
242 gfx::Rect rect(child_size);
243 RenderPassId id(1, 1);
244 scoped_ptr<RenderPass> pass = RenderPass::Create();
245 pass->SetNew(id, rect, rect, gfx::Transform());
247 CreateAndAppendTestSharedQuadState(
248 pass.get(), gfx::Transform(), child_size);
250 SolidColorDrawQuad* top_color_quad =
251 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
252 bool force_anti_aliasing_off = false;
253 top_color_quad->SetNew(pass->shared_quad_state_list.back(),
254 gfx::Rect(quad_size),
255 gfx::Rect(quad_size),
256 SK_ColorGREEN,
257 force_anti_aliasing_off);
259 SolidColorDrawQuad* bottom_color_quad =
260 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
261 bottom_color_quad->SetNew(pass->shared_quad_state_list.back(),
262 gfx::Rect(0, 100, 100, 100),
263 gfx::Rect(0, 100, 100, 100),
264 SK_ColorBLUE,
265 force_anti_aliasing_off);
267 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
268 delegated_frame_data->render_pass_list.push_back(pass.Pass());
270 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame);
271 child_frame->delegated_frame_data = delegated_frame_data.Pass();
273 factory_.SubmitFrame(left_child_id, child_frame.Pass(),
274 SurfaceFactory::DrawCallback());
278 gfx::Rect rect(child_size);
279 RenderPassId id(1, 1);
280 scoped_ptr<RenderPass> pass = RenderPass::Create();
281 pass->SetNew(id, rect, rect, gfx::Transform());
283 CreateAndAppendTestSharedQuadState(
284 pass.get(), gfx::Transform(), child_size);
286 SolidColorDrawQuad* top_color_quad =
287 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
288 bool force_anti_aliasing_off = false;
289 top_color_quad->SetNew(pass->shared_quad_state_list.back(),
290 gfx::Rect(quad_size),
291 gfx::Rect(quad_size),
292 SK_ColorBLUE,
293 force_anti_aliasing_off);
295 SolidColorDrawQuad* bottom_color_quad =
296 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
297 bottom_color_quad->SetNew(pass->shared_quad_state_list.back(),
298 gfx::Rect(0, 100, 100, 100),
299 gfx::Rect(0, 100, 100, 100),
300 SK_ColorGREEN,
301 force_anti_aliasing_off);
303 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
304 delegated_frame_data->render_pass_list.push_back(pass.Pass());
306 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame);
307 child_frame->delegated_frame_data = delegated_frame_data.Pass();
309 factory_.SubmitFrame(right_child_id, child_frame.Pass(),
310 SurfaceFactory::DrawCallback());
313 SurfaceAggregator aggregator(&manager_, resource_provider_.get(), true);
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)