Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / cc / quads / draw_quad_unittest.cc
blob5755ea898407bc02fee9fd0221c0968295af0add
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.
5 #include "cc/quads/draw_quad.h"
7 #include <algorithm>
9 #include "base/bind.h"
10 #include "base/compiler_specific.h"
11 #include "cc/base/math_util.h"
12 #include "cc/output/filter_operations.h"
13 #include "cc/quads/checkerboard_draw_quad.h"
14 #include "cc/quads/debug_border_draw_quad.h"
15 #include "cc/quads/io_surface_draw_quad.h"
16 #include "cc/quads/largest_draw_quad.h"
17 #include "cc/quads/picture_draw_quad.h"
18 #include "cc/quads/render_pass.h"
19 #include "cc/quads/render_pass_draw_quad.h"
20 #include "cc/quads/solid_color_draw_quad.h"
21 #include "cc/quads/stream_video_draw_quad.h"
22 #include "cc/quads/surface_draw_quad.h"
23 #include "cc/quads/texture_draw_quad.h"
24 #include "cc/quads/tile_draw_quad.h"
25 #include "cc/quads/yuv_video_draw_quad.h"
26 #include "cc/resources/picture_pile_impl.h"
27 #include "cc/test/geometry_test_utils.h"
28 #include "testing/gtest/include/gtest/gtest.h"
29 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
30 #include "ui/gfx/transform.h"
32 namespace cc {
33 namespace {
35 TEST(DrawQuadTest, CopySharedQuadState) {
36 gfx::Transform quad_transform = gfx::Transform(1.0, 0.0, 0.5, 1.0, 0.5, 0.0);
37 gfx::Size content_bounds(26, 28);
38 gfx::Rect visible_content_rect(10, 12, 14, 16);
39 gfx::Rect clip_rect(19, 21, 23, 25);
40 bool is_clipped = true;
41 float opacity = 0.25f;
42 SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode;
43 int sorting_context_id = 65536;
45 scoped_ptr<SharedQuadState> state(new SharedQuadState);
46 state->SetAll(quad_transform,
47 content_bounds,
48 visible_content_rect,
49 clip_rect,
50 is_clipped,
51 opacity,
52 blend_mode,
53 sorting_context_id);
55 scoped_ptr<SharedQuadState> copy(new SharedQuadState);
56 copy->CopyFrom(state.get());
57 EXPECT_EQ(quad_transform, copy->content_to_target_transform);
58 EXPECT_RECT_EQ(visible_content_rect, copy->visible_content_rect);
59 EXPECT_EQ(opacity, copy->opacity);
60 EXPECT_RECT_EQ(clip_rect, copy->clip_rect);
61 EXPECT_EQ(is_clipped, copy->is_clipped);
62 EXPECT_EQ(blend_mode, copy->blend_mode);
65 SharedQuadState* CreateSharedQuadState(RenderPass* render_pass) {
66 gfx::Transform quad_transform = gfx::Transform(1.0, 0.0, 0.5, 1.0, 0.5, 0.0);
67 gfx::Size content_bounds(26, 28);
68 gfx::Rect visible_content_rect(10, 12, 14, 16);
69 gfx::Rect clip_rect(19, 21, 23, 25);
70 bool is_clipped = false;
71 float opacity = 1.f;
72 int sorting_context_id = 65536;
73 SkXfermode::Mode blend_mode = SkXfermode::kSrcOver_Mode;
75 SharedQuadState* state = render_pass->CreateAndAppendSharedQuadState();
76 state->SetAll(quad_transform,
77 content_bounds,
78 visible_content_rect,
79 clip_rect,
80 is_clipped,
81 opacity,
82 blend_mode,
83 sorting_context_id);
84 return state;
87 void CompareDrawQuad(DrawQuad* quad,
88 DrawQuad* copy,
89 SharedQuadState* copy_shared_state) {
90 EXPECT_EQ(quad->material, copy->material);
91 EXPECT_RECT_EQ(quad->rect, copy->rect);
92 EXPECT_RECT_EQ(quad->visible_rect, copy->visible_rect);
93 EXPECT_RECT_EQ(quad->opaque_rect, copy->opaque_rect);
94 EXPECT_EQ(quad->needs_blending, copy->needs_blending);
95 EXPECT_EQ(copy_shared_state, copy->shared_quad_state);
98 #define CREATE_SHARED_STATE() \
99 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); \
100 SharedQuadState* shared_state(CreateSharedQuadState(render_pass.get())); \
101 SharedQuadState* copy_shared_state = \
102 render_pass->CreateAndAppendSharedQuadState(); \
103 copy_shared_state->CopyFrom(shared_state);
105 #define QUAD_DATA \
106 gfx::Rect quad_rect(30, 40, 50, 60); \
107 gfx::Rect quad_visible_rect(40, 50, 30, 20); \
108 gfx::Rect quad_opaque_rect(60, 55, 10, 10); \
109 ALLOW_UNUSED_LOCAL(quad_opaque_rect); \
110 bool needs_blending = true; \
111 ALLOW_UNUSED_LOCAL(needs_blending);
113 #define SETUP_AND_COPY_QUAD_NEW(Type, quad) \
114 DrawQuad* copy_new = \
115 render_pass->CopyFromAndAppendDrawQuad(quad_new, copy_shared_state); \
116 CompareDrawQuad(quad_new, copy_new, copy_shared_state); \
117 const Type* copy_quad = Type::MaterialCast(copy_new); \
118 ALLOW_UNUSED_LOCAL(copy_quad);
120 #define SETUP_AND_COPY_QUAD_ALL(Type, quad) \
121 DrawQuad* copy_all = \
122 render_pass->CopyFromAndAppendDrawQuad(quad_all, copy_shared_state); \
123 CompareDrawQuad(quad_all, copy_all, copy_shared_state); \
124 copy_quad = Type::MaterialCast(copy_all);
126 #define SETUP_AND_COPY_QUAD_NEW_RP(Type, quad, a) \
127 DrawQuad* copy_new = render_pass->CopyFromAndAppendRenderPassDrawQuad( \
128 quad_new, copy_shared_state, a); \
129 CompareDrawQuad(quad_new, copy_new, copy_shared_state); \
130 const Type* copy_quad = Type::MaterialCast(copy_new); \
131 ALLOW_UNUSED_LOCAL(copy_quad);
133 #define SETUP_AND_COPY_QUAD_ALL_RP(Type, quad, a) \
134 DrawQuad* copy_all = render_pass->CopyFromAndAppendRenderPassDrawQuad( \
135 quad_all, copy_shared_state, a); \
136 CompareDrawQuad(quad_all, copy_all, copy_shared_state); \
137 copy_quad = Type::MaterialCast(copy_all);
139 #define CREATE_QUAD_1_NEW(Type, a) \
140 Type* quad_new = render_pass->CreateAndAppendDrawQuad<Type>(); \
141 { QUAD_DATA quad_new->SetNew(shared_state, quad_rect, a); } \
142 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
144 #define CREATE_QUAD_1_ALL(Type, a) \
145 Type* quad_all = render_pass->CreateAndAppendDrawQuad<Type>(); \
147 QUAD_DATA quad_all->SetAll(shared_state, \
148 quad_rect, \
149 quad_opaque_rect, \
150 quad_visible_rect, \
151 needs_blending, \
152 a); \
154 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
156 #define CREATE_QUAD_2_NEW(Type, a, b) \
157 Type* quad_new = render_pass->CreateAndAppendDrawQuad<Type>(); \
158 { QUAD_DATA quad_new->SetNew(shared_state, quad_rect, a, b); } \
159 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
161 #define CREATE_QUAD_2_ALL(Type, a, b) \
162 Type* quad_all = render_pass->CreateAndAppendDrawQuad<Type>(); \
164 QUAD_DATA quad_all->SetAll(shared_state, \
165 quad_rect, \
166 quad_opaque_rect, \
167 quad_visible_rect, \
168 needs_blending, \
169 a, \
170 b); \
172 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
174 #define CREATE_QUAD_3_NEW(Type, a, b, c) \
175 Type* quad_new = render_pass->CreateAndAppendDrawQuad<Type>(); \
176 { QUAD_DATA quad_new->SetNew(shared_state, quad_rect, a, b, c); } \
177 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
179 #define CREATE_QUAD_3_ALL(Type, a, b, c) \
180 Type* quad_all = render_pass->CreateAndAppendDrawQuad<Type>(); \
182 QUAD_DATA quad_all->SetAll(shared_state, \
183 quad_rect, \
184 quad_opaque_rect, \
185 quad_visible_rect, \
186 needs_blending, \
187 a, \
188 b, \
189 c); \
191 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
193 #define CREATE_QUAD_4_NEW(Type, a, b, c, d) \
194 Type* quad_new = render_pass->CreateAndAppendDrawQuad<Type>(); \
195 { QUAD_DATA quad_new->SetNew(shared_state, quad_rect, a, b, c, d); } \
196 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
198 #define CREATE_QUAD_4_ALL(Type, a, b, c, d) \
199 Type* quad_all = render_pass->CreateAndAppendDrawQuad<Type>(); \
201 QUAD_DATA quad_all->SetAll(shared_state, \
202 quad_rect, \
203 quad_opaque_rect, \
204 quad_visible_rect, \
205 needs_blending, \
206 a, \
207 b, \
208 c, \
209 d); \
211 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
213 #define CREATE_QUAD_5_NEW(Type, a, b, c, d, e) \
214 Type* quad_new = render_pass->CreateAndAppendDrawQuad<Type>(); \
215 { QUAD_DATA quad_new->SetNew(shared_state, quad_rect, a, b, c, d, e); } \
216 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
218 #define CREATE_QUAD_5_ALL(Type, a, b, c, d, e) \
219 Type* quad_all = render_pass->CreateAndAppendDrawQuad<Type>(); \
221 QUAD_DATA quad_all->SetAll(shared_state, \
222 quad_rect, \
223 quad_opaque_rect, \
224 quad_visible_rect, \
225 needs_blending, \
226 a, \
227 b, \
228 c, \
229 d, \
230 e); \
232 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
234 #define CREATE_QUAD_6_NEW(Type, a, b, c, d, e, f) \
235 Type* quad_new = render_pass->CreateAndAppendDrawQuad<Type>(); \
236 { QUAD_DATA quad_new->SetNew(shared_state, quad_rect, a, b, c, d, e, f); } \
237 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
239 #define CREATE_QUAD_6_ALL(Type, a, b, c, d, e, f) \
240 Type* quad_all = render_pass->CreateAndAppendDrawQuad<Type>(); \
242 QUAD_DATA quad_all->SetAll(shared_state, \
243 quad_rect, \
244 quad_opaque_rect, \
245 quad_visible_rect, \
246 needs_blending, \
247 a, \
248 b, \
249 c, \
250 d, \
251 e, \
252 f); \
254 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
256 #define CREATE_QUAD_7_NEW(Type, a, b, c, d, e, f, g) \
257 Type* quad_new = render_pass->CreateAndAppendDrawQuad<Type>(); \
259 QUAD_DATA quad_new->SetNew(shared_state, quad_rect, a, b, c, d, e, f, g); \
261 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
263 #define CREATE_QUAD_7_ALL(Type, a, b, c, d, e, f, g) \
264 Type* quad_all = render_pass->CreateAndAppendDrawQuad<Type>(); \
266 QUAD_DATA quad_all->SetAll(shared_state, \
267 quad_rect, \
268 quad_opaque_rect, \
269 quad_visible_rect, \
270 needs_blending, \
271 a, \
272 b, \
273 c, \
274 d, \
275 e, \
276 f, \
277 g); \
279 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
281 #define CREATE_QUAD_8_NEW(Type, a, b, c, d, e, f, g, h) \
282 Type* quad_new = render_pass->CreateAndAppendDrawQuad<Type>(); \
284 QUAD_DATA quad_new->SetNew( \
285 shared_state, quad_rect, a, b, c, d, e, f, g, h); \
287 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
289 #define CREATE_QUAD_8_ALL(Type, a, b, c, d, e, f, g, h) \
290 Type* quad_all = render_pass->CreateAndAppendDrawQuad<Type>(); \
292 QUAD_DATA quad_all->SetAll(shared_state, \
293 quad_rect, \
294 quad_opaque_rect, \
295 quad_visible_rect, \
296 needs_blending, \
297 a, \
298 b, \
299 c, \
300 d, \
301 e, \
302 f, \
303 g, \
304 h); \
306 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
308 #define CREATE_QUAD_9_NEW(Type, a, b, c, d, e, f, g, h, i) \
309 Type* quad_new = render_pass->CreateAndAppendDrawQuad<Type>(); \
311 QUAD_DATA quad_new->SetNew( \
312 shared_state, quad_rect, a, b, c, d, e, f, g, h, i); \
314 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
316 #define CREATE_QUAD_9_ALL(Type, a, b, c, d, e, f, g, h, i) \
318 QUAD_DATA quad_all->SetAll(shared_state, \
319 quad_rect, \
320 quad_opaque_rect, \
321 quad_visible_rect, \
322 needs_blending, \
323 a, \
324 b, \
325 c, \
326 d, \
327 e, \
328 f, \
329 g, \
330 h, \
331 i); \
333 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
335 #define CREATE_QUAD_ALL_RP(Type, a, b, c, d, e, f, g, copy_a) \
336 Type* quad_all = render_pass->CreateAndAppendDrawQuad<Type>(); \
338 QUAD_DATA quad_all->SetAll(shared_state, \
339 quad_rect, \
340 quad_opaque_rect, \
341 quad_visible_rect, \
342 needs_blending, \
343 a, \
344 b, \
345 c, \
346 d, \
347 e, \
348 f, \
349 g); \
351 SETUP_AND_COPY_QUAD_ALL_RP(Type, quad_all, copy_a);
353 #define CREATE_QUAD_NEW_RP(Type, a, b, c, d, e, f, g, h, copy_a) \
354 Type* quad_new = render_pass->CreateAndAppendDrawQuad<Type>(); \
356 QUAD_DATA quad_new->SetNew( \
357 shared_state, quad_rect, a, b, c, d, e, f, g, h); \
359 SETUP_AND_COPY_QUAD_NEW_RP(Type, quad_new, copy_a);
361 TEST(DrawQuadTest, CopyCheckerboardDrawQuad) {
362 gfx::Rect visible_rect(40, 50, 30, 20);
363 SkColor color = 0xfabb0011;
364 CREATE_SHARED_STATE();
366 CREATE_QUAD_2_NEW(CheckerboardDrawQuad, visible_rect, color);
367 EXPECT_EQ(DrawQuad::CHECKERBOARD, copy_quad->material);
368 EXPECT_RECT_EQ(visible_rect, copy_quad->visible_rect);
369 EXPECT_EQ(color, copy_quad->color);
371 CREATE_QUAD_1_ALL(CheckerboardDrawQuad, color);
372 EXPECT_EQ(DrawQuad::CHECKERBOARD, copy_quad->material);
373 EXPECT_EQ(color, copy_quad->color);
376 TEST(DrawQuadTest, CopyDebugBorderDrawQuad) {
377 gfx::Rect visible_rect(40, 50, 30, 20);
378 SkColor color = 0xfabb0011;
379 int width = 99;
380 CREATE_SHARED_STATE();
382 CREATE_QUAD_3_NEW(DebugBorderDrawQuad, visible_rect, color, width);
383 EXPECT_EQ(DrawQuad::DEBUG_BORDER, copy_quad->material);
384 EXPECT_RECT_EQ(visible_rect, copy_quad->visible_rect);
385 EXPECT_EQ(color, copy_quad->color);
386 EXPECT_EQ(width, copy_quad->width);
388 CREATE_QUAD_2_ALL(DebugBorderDrawQuad, color, width);
389 EXPECT_EQ(DrawQuad::DEBUG_BORDER, copy_quad->material);
390 EXPECT_EQ(color, copy_quad->color);
391 EXPECT_EQ(width, copy_quad->width);
394 TEST(DrawQuadTest, CopyIOSurfaceDrawQuad) {
395 gfx::Rect opaque_rect(33, 47, 10, 12);
396 gfx::Rect visible_rect(40, 50, 30, 20);
397 gfx::Size size(58, 95);
398 ResourceProvider::ResourceId resource_id = 72;
399 IOSurfaceDrawQuad::Orientation orientation = IOSurfaceDrawQuad::UNFLIPPED;
400 CREATE_SHARED_STATE();
402 CREATE_QUAD_5_NEW(IOSurfaceDrawQuad,
403 opaque_rect,
404 visible_rect,
405 size,
406 resource_id,
407 orientation);
408 EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT, copy_quad->material);
409 EXPECT_RECT_EQ(visible_rect, copy_quad->visible_rect);
410 EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
411 EXPECT_EQ(size, copy_quad->io_surface_size);
412 EXPECT_EQ(resource_id, copy_quad->io_surface_resource_id);
413 EXPECT_EQ(orientation, copy_quad->orientation);
415 CREATE_QUAD_3_ALL(IOSurfaceDrawQuad, size, resource_id, orientation);
416 EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT, copy_quad->material);
417 EXPECT_EQ(size, copy_quad->io_surface_size);
418 EXPECT_EQ(resource_id, copy_quad->io_surface_resource_id);
419 EXPECT_EQ(orientation, copy_quad->orientation);
422 TEST(DrawQuadTest, CopyRenderPassDrawQuad) {
423 gfx::Rect visible_rect(40, 50, 30, 20);
424 RenderPassId render_pass_id(22, 64);
425 ResourceProvider::ResourceId mask_resource_id = 78;
426 gfx::Vector2dF mask_uv_scale(33.f, 19.f);
427 gfx::Size mask_texture_size(128, 134);
428 FilterOperations filters;
429 filters.Append(FilterOperation::CreateBlurFilter(1.f));
430 gfx::Vector2dF filters_scale;
431 FilterOperations background_filters;
432 background_filters.Append(
433 FilterOperation::CreateGrayscaleFilter(1.f));
435 RenderPassId copied_render_pass_id(235, 11);
436 CREATE_SHARED_STATE();
438 CREATE_QUAD_NEW_RP(RenderPassDrawQuad,
439 visible_rect,
440 render_pass_id,
441 mask_resource_id,
442 mask_uv_scale,
443 mask_texture_size,
444 filters,
445 filters_scale,
446 background_filters,
447 copied_render_pass_id);
448 EXPECT_EQ(DrawQuad::RENDER_PASS, copy_quad->material);
449 EXPECT_RECT_EQ(visible_rect, copy_quad->visible_rect);
450 EXPECT_EQ(copied_render_pass_id, copy_quad->render_pass_id);
451 EXPECT_EQ(mask_resource_id, copy_quad->mask_resource_id);
452 EXPECT_EQ(mask_uv_scale.ToString(), copy_quad->mask_uv_scale.ToString());
453 EXPECT_EQ(mask_texture_size.ToString(),
454 copy_quad->mask_texture_size.ToString());
455 EXPECT_EQ(filters, copy_quad->filters);
456 EXPECT_EQ(filters_scale, copy_quad->filters_scale);
457 EXPECT_EQ(background_filters, copy_quad->background_filters);
459 CREATE_QUAD_ALL_RP(RenderPassDrawQuad,
460 render_pass_id,
461 mask_resource_id,
462 mask_uv_scale,
463 mask_texture_size,
464 filters,
465 filters_scale,
466 background_filters,
467 copied_render_pass_id);
468 EXPECT_EQ(DrawQuad::RENDER_PASS, copy_quad->material);
469 EXPECT_EQ(copied_render_pass_id, copy_quad->render_pass_id);
470 EXPECT_EQ(mask_resource_id, copy_quad->mask_resource_id);
471 EXPECT_EQ(mask_uv_scale.ToString(), copy_quad->mask_uv_scale.ToString());
472 EXPECT_EQ(mask_texture_size.ToString(),
473 copy_quad->mask_texture_size.ToString());
474 EXPECT_EQ(filters, copy_quad->filters);
475 EXPECT_EQ(filters_scale, copy_quad->filters_scale);
476 EXPECT_EQ(background_filters, copy_quad->background_filters);
479 TEST(DrawQuadTest, CopySolidColorDrawQuad) {
480 gfx::Rect visible_rect(40, 50, 30, 20);
481 SkColor color = 0x49494949;
482 bool force_anti_aliasing_off = false;
483 CREATE_SHARED_STATE();
485 CREATE_QUAD_3_NEW(
486 SolidColorDrawQuad, visible_rect, color, force_anti_aliasing_off);
487 EXPECT_EQ(DrawQuad::SOLID_COLOR, copy_quad->material);
488 EXPECT_RECT_EQ(visible_rect, copy_quad->visible_rect);
489 EXPECT_EQ(color, copy_quad->color);
490 EXPECT_EQ(force_anti_aliasing_off, copy_quad->force_anti_aliasing_off);
492 CREATE_QUAD_2_ALL(SolidColorDrawQuad, color, force_anti_aliasing_off);
493 EXPECT_EQ(DrawQuad::SOLID_COLOR, copy_quad->material);
494 EXPECT_EQ(color, copy_quad->color);
495 EXPECT_EQ(force_anti_aliasing_off, copy_quad->force_anti_aliasing_off);
498 TEST(DrawQuadTest, CopyStreamVideoDrawQuad) {
499 gfx::Rect opaque_rect(33, 47, 10, 12);
500 gfx::Rect visible_rect(40, 50, 30, 20);
501 ResourceProvider::ResourceId resource_id = 64;
502 gfx::Transform matrix = gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
503 CREATE_SHARED_STATE();
505 CREATE_QUAD_4_NEW(
506 StreamVideoDrawQuad, opaque_rect, visible_rect, resource_id, matrix);
507 EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT, copy_quad->material);
508 EXPECT_RECT_EQ(visible_rect, copy_quad->visible_rect);
509 EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
510 EXPECT_EQ(resource_id, copy_quad->resource_id);
511 EXPECT_EQ(matrix, copy_quad->matrix);
513 CREATE_QUAD_2_ALL(StreamVideoDrawQuad, resource_id, matrix);
514 EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT, copy_quad->material);
515 EXPECT_EQ(resource_id, copy_quad->resource_id);
516 EXPECT_EQ(matrix, copy_quad->matrix);
519 TEST(DrawQuadTest, CopySurfaceDrawQuad) {
520 gfx::Rect visible_rect(40, 50, 30, 20);
521 SurfaceId surface_id(1234);
522 CREATE_SHARED_STATE();
524 CREATE_QUAD_2_NEW(SurfaceDrawQuad, visible_rect, surface_id);
525 EXPECT_EQ(DrawQuad::SURFACE_CONTENT, copy_quad->material);
526 EXPECT_RECT_EQ(visible_rect, copy_quad->visible_rect);
527 EXPECT_EQ(surface_id, copy_quad->surface_id);
529 CREATE_QUAD_1_ALL(SurfaceDrawQuad, surface_id);
530 EXPECT_EQ(DrawQuad::SURFACE_CONTENT, copy_quad->material);
531 EXPECT_EQ(surface_id, copy_quad->surface_id);
535 TEST(DrawQuadTest, CopyTextureDrawQuad) {
536 gfx::Rect opaque_rect(33, 47, 10, 12);
537 gfx::Rect visible_rect(40, 50, 30, 20);
538 unsigned resource_id = 82;
539 bool premultiplied_alpha = true;
540 gfx::PointF uv_top_left(0.5f, 224.f);
541 gfx::PointF uv_bottom_right(51.5f, 260.f);
542 const float vertex_opacity[] = { 1.0f, 1.0f, 1.0f, 1.0f };
543 bool flipped = true;
544 CREATE_SHARED_STATE();
546 CREATE_QUAD_9_NEW(TextureDrawQuad,
547 opaque_rect,
548 visible_rect,
549 resource_id,
550 premultiplied_alpha,
551 uv_top_left,
552 uv_bottom_right,
553 SK_ColorTRANSPARENT,
554 vertex_opacity,
555 flipped);
556 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, copy_quad->material);
557 EXPECT_RECT_EQ(visible_rect, copy_quad->visible_rect);
558 EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
559 EXPECT_EQ(resource_id, copy_quad->resource_id);
560 EXPECT_EQ(premultiplied_alpha, copy_quad->premultiplied_alpha);
561 EXPECT_EQ(uv_top_left, copy_quad->uv_top_left);
562 EXPECT_EQ(uv_bottom_right, copy_quad->uv_bottom_right);
563 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copy_quad->vertex_opacity, 4);
564 EXPECT_EQ(flipped, copy_quad->flipped);
566 CREATE_QUAD_7_ALL(TextureDrawQuad,
567 resource_id,
568 premultiplied_alpha,
569 uv_top_left,
570 uv_bottom_right,
571 SK_ColorTRANSPARENT,
572 vertex_opacity,
573 flipped);
574 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, copy_quad->material);
575 EXPECT_EQ(resource_id, copy_quad->resource_id);
576 EXPECT_EQ(premultiplied_alpha, copy_quad->premultiplied_alpha);
577 EXPECT_EQ(uv_top_left, copy_quad->uv_top_left);
578 EXPECT_EQ(uv_bottom_right, copy_quad->uv_bottom_right);
579 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copy_quad->vertex_opacity, 4);
580 EXPECT_EQ(flipped, copy_quad->flipped);
583 TEST(DrawQuadTest, CopyTileDrawQuad) {
584 gfx::Rect opaque_rect(33, 44, 22, 33);
585 gfx::Rect visible_rect(40, 50, 30, 20);
586 unsigned resource_id = 104;
587 gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
588 gfx::Size texture_size(85, 32);
589 bool swizzle_contents = true;
590 CREATE_SHARED_STATE();
592 CREATE_QUAD_6_NEW(TileDrawQuad,
593 opaque_rect,
594 visible_rect,
595 resource_id,
596 tex_coord_rect,
597 texture_size,
598 swizzle_contents);
599 EXPECT_EQ(DrawQuad::TILED_CONTENT, copy_quad->material);
600 EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
601 EXPECT_RECT_EQ(visible_rect, copy_quad->visible_rect);
602 EXPECT_EQ(resource_id, copy_quad->resource_id);
603 EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
604 EXPECT_EQ(texture_size, copy_quad->texture_size);
605 EXPECT_EQ(swizzle_contents, copy_quad->swizzle_contents);
607 CREATE_QUAD_4_ALL(TileDrawQuad,
608 resource_id,
609 tex_coord_rect,
610 texture_size,
611 swizzle_contents);
612 EXPECT_EQ(DrawQuad::TILED_CONTENT, copy_quad->material);
613 EXPECT_EQ(resource_id, copy_quad->resource_id);
614 EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
615 EXPECT_EQ(texture_size, copy_quad->texture_size);
616 EXPECT_EQ(swizzle_contents, copy_quad->swizzle_contents);
619 TEST(DrawQuadTest, CopyYUVVideoDrawQuad) {
620 gfx::Rect opaque_rect(33, 47, 10, 12);
621 gfx::Rect visible_rect(40, 50, 30, 20);
622 gfx::RectF tex_coord_rect(0.0f, 0.0f, 0.75f, 0.5f);
623 ResourceProvider::ResourceId y_plane_resource_id = 45;
624 ResourceProvider::ResourceId u_plane_resource_id = 532;
625 ResourceProvider::ResourceId v_plane_resource_id = 4;
626 ResourceProvider::ResourceId a_plane_resource_id = 63;
627 YUVVideoDrawQuad::ColorSpace color_space = YUVVideoDrawQuad::REC_601_JPEG;
628 CREATE_SHARED_STATE();
630 CREATE_QUAD_8_NEW(YUVVideoDrawQuad,
631 opaque_rect,
632 visible_rect,
633 tex_coord_rect,
634 y_plane_resource_id,
635 u_plane_resource_id,
636 v_plane_resource_id,
637 a_plane_resource_id,
638 color_space);
639 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copy_quad->material);
640 EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
641 EXPECT_RECT_EQ(visible_rect, copy_quad->visible_rect);
642 EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
643 EXPECT_EQ(y_plane_resource_id, copy_quad->y_plane_resource_id);
644 EXPECT_EQ(u_plane_resource_id, copy_quad->u_plane_resource_id);
645 EXPECT_EQ(v_plane_resource_id, copy_quad->v_plane_resource_id);
646 EXPECT_EQ(a_plane_resource_id, copy_quad->a_plane_resource_id);
647 EXPECT_EQ(color_space, copy_quad->color_space);
649 CREATE_QUAD_6_ALL(YUVVideoDrawQuad,
650 tex_coord_rect,
651 y_plane_resource_id,
652 u_plane_resource_id,
653 v_plane_resource_id,
654 a_plane_resource_id,
655 color_space);
656 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copy_quad->material);
657 EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
658 EXPECT_EQ(y_plane_resource_id, copy_quad->y_plane_resource_id);
659 EXPECT_EQ(u_plane_resource_id, copy_quad->u_plane_resource_id);
660 EXPECT_EQ(v_plane_resource_id, copy_quad->v_plane_resource_id);
661 EXPECT_EQ(a_plane_resource_id, copy_quad->a_plane_resource_id);
662 EXPECT_EQ(color_space, copy_quad->color_space);
665 TEST(DrawQuadTest, CopyPictureDrawQuad) {
666 gfx::Rect opaque_rect(33, 44, 22, 33);
667 gfx::Rect visible_rect(40, 50, 30, 20);
668 gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
669 gfx::Size texture_size(85, 32);
670 ResourceFormat texture_format = RGBA_8888;
671 gfx::Rect content_rect(30, 40, 20, 30);
672 float contents_scale = 3.141592f;
673 scoped_refptr<RasterSource> raster_source = PicturePileImpl::Create();
674 CREATE_SHARED_STATE();
676 CREATE_QUAD_8_NEW(PictureDrawQuad, opaque_rect, visible_rect, tex_coord_rect,
677 texture_size, texture_format, content_rect, contents_scale,
678 raster_source);
679 EXPECT_EQ(DrawQuad::PICTURE_CONTENT, copy_quad->material);
680 EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
681 EXPECT_RECT_EQ(visible_rect, copy_quad->visible_rect);
682 EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
683 EXPECT_EQ(texture_size, copy_quad->texture_size);
684 EXPECT_EQ(texture_format, copy_quad->texture_format);
685 EXPECT_RECT_EQ(content_rect, copy_quad->content_rect);
686 EXPECT_EQ(contents_scale, copy_quad->contents_scale);
687 EXPECT_EQ(raster_source, copy_quad->raster_source);
689 CREATE_QUAD_6_ALL(PictureDrawQuad, tex_coord_rect, texture_size,
690 texture_format, content_rect, contents_scale,
691 raster_source);
692 EXPECT_EQ(DrawQuad::PICTURE_CONTENT, copy_quad->material);
693 EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
694 EXPECT_EQ(texture_size, copy_quad->texture_size);
695 EXPECT_EQ(texture_format, copy_quad->texture_format);
696 EXPECT_RECT_EQ(content_rect, copy_quad->content_rect);
697 EXPECT_EQ(contents_scale, copy_quad->contents_scale);
698 EXPECT_EQ(raster_source, copy_quad->raster_source);
701 class DrawQuadIteratorTest : public testing::Test {
702 protected:
703 ResourceProvider::ResourceId IncrementResourceId(
704 ResourceProvider::ResourceId id) {
705 ++num_resources_;
706 return id + 1;
709 int IterateAndCount(DrawQuad* quad) {
710 num_resources_ = 0;
711 quad->IterateResources(base::Bind(
712 &DrawQuadIteratorTest::IncrementResourceId, base::Unretained(this)));
713 return num_resources_;
716 private:
717 int num_resources_;
720 TEST_F(DrawQuadIteratorTest, CheckerboardDrawQuad) {
721 gfx::Rect visible_rect(40, 50, 30, 20);
722 SkColor color = 0xfabb0011;
724 CREATE_SHARED_STATE();
725 CREATE_QUAD_2_NEW(CheckerboardDrawQuad, visible_rect, color);
726 EXPECT_EQ(0, IterateAndCount(quad_new));
729 TEST_F(DrawQuadIteratorTest, DebugBorderDrawQuad) {
730 gfx::Rect visible_rect(40, 50, 30, 20);
731 SkColor color = 0xfabb0011;
732 int width = 99;
734 CREATE_SHARED_STATE();
735 CREATE_QUAD_3_NEW(DebugBorderDrawQuad, visible_rect, color, width);
736 EXPECT_EQ(0, IterateAndCount(quad_new));
739 TEST_F(DrawQuadIteratorTest, IOSurfaceDrawQuad) {
740 gfx::Rect opaque_rect(33, 47, 10, 12);
741 gfx::Rect visible_rect(40, 50, 30, 20);
742 gfx::Size size(58, 95);
743 ResourceProvider::ResourceId resource_id = 72;
744 IOSurfaceDrawQuad::Orientation orientation = IOSurfaceDrawQuad::UNFLIPPED;
746 CREATE_SHARED_STATE();
747 CREATE_QUAD_5_NEW(IOSurfaceDrawQuad,
748 opaque_rect,
749 visible_rect,
750 size,
751 resource_id,
752 orientation);
753 EXPECT_EQ(resource_id, quad_new->io_surface_resource_id);
754 EXPECT_EQ(1, IterateAndCount(quad_new));
755 EXPECT_EQ(resource_id + 1, quad_new->io_surface_resource_id);
758 TEST_F(DrawQuadIteratorTest, RenderPassDrawQuad) {
759 gfx::Rect visible_rect(40, 50, 30, 20);
760 RenderPassId render_pass_id(22, 64);
761 ResourceProvider::ResourceId mask_resource_id = 78;
762 gfx::Vector2dF mask_uv_scale(33.f, 19.f);
763 gfx::Size mask_texture_size(128, 134);
764 FilterOperations filters;
765 filters.Append(FilterOperation::CreateBlurFilter(1.f));
766 gfx::Vector2dF filters_scale(2.f, 3.f);
767 FilterOperations background_filters;
768 background_filters.Append(
769 FilterOperation::CreateGrayscaleFilter(1.f));
771 RenderPassId copied_render_pass_id(235, 11);
773 CREATE_SHARED_STATE();
774 CREATE_QUAD_NEW_RP(RenderPassDrawQuad,
775 visible_rect,
776 render_pass_id,
777 mask_resource_id,
778 mask_uv_scale,
779 mask_texture_size,
780 filters,
781 filters_scale,
782 background_filters,
783 copied_render_pass_id);
784 EXPECT_EQ(mask_resource_id, quad_new->mask_resource_id);
785 EXPECT_EQ(1, IterateAndCount(quad_new));
786 EXPECT_EQ(mask_resource_id + 1, quad_new->mask_resource_id);
787 quad_new->mask_resource_id = 0;
788 EXPECT_EQ(0, IterateAndCount(quad_new));
789 EXPECT_EQ(0u, quad_new->mask_resource_id);
792 TEST_F(DrawQuadIteratorTest, SolidColorDrawQuad) {
793 gfx::Rect visible_rect(40, 50, 30, 20);
794 SkColor color = 0x49494949;
795 bool force_anti_aliasing_off = false;
797 CREATE_SHARED_STATE();
798 CREATE_QUAD_3_NEW(
799 SolidColorDrawQuad, visible_rect, color, force_anti_aliasing_off);
800 EXPECT_EQ(0, IterateAndCount(quad_new));
803 TEST_F(DrawQuadIteratorTest, StreamVideoDrawQuad) {
804 gfx::Rect opaque_rect(33, 47, 10, 12);
805 gfx::Rect visible_rect(40, 50, 30, 20);
806 ResourceProvider::ResourceId resource_id = 64;
807 gfx::Transform matrix = gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
809 CREATE_SHARED_STATE();
810 CREATE_QUAD_4_NEW(
811 StreamVideoDrawQuad, opaque_rect, visible_rect, resource_id, matrix);
812 EXPECT_EQ(resource_id, quad_new->resource_id);
813 EXPECT_EQ(1, IterateAndCount(quad_new));
814 EXPECT_EQ(resource_id + 1, quad_new->resource_id);
817 TEST_F(DrawQuadIteratorTest, SurfaceDrawQuad) {
818 gfx::Rect visible_rect(40, 50, 30, 20);
819 SurfaceId surface_id(4321);
821 CREATE_SHARED_STATE();
822 CREATE_QUAD_2_NEW(SurfaceDrawQuad, visible_rect, surface_id);
823 EXPECT_EQ(0, IterateAndCount(quad_new));
826 TEST_F(DrawQuadIteratorTest, TextureDrawQuad) {
827 gfx::Rect opaque_rect(33, 47, 10, 12);
828 gfx::Rect visible_rect(40, 50, 30, 20);
829 unsigned resource_id = 82;
830 bool premultiplied_alpha = true;
831 gfx::PointF uv_top_left(0.5f, 224.f);
832 gfx::PointF uv_bottom_right(51.5f, 260.f);
833 const float vertex_opacity[] = { 1.0f, 1.0f, 1.0f, 1.0f };
834 bool flipped = true;
836 CREATE_SHARED_STATE();
837 CREATE_QUAD_9_NEW(TextureDrawQuad,
838 opaque_rect,
839 visible_rect,
840 resource_id,
841 premultiplied_alpha,
842 uv_top_left,
843 uv_bottom_right,
844 SK_ColorTRANSPARENT,
845 vertex_opacity,
846 flipped);
847 EXPECT_EQ(resource_id, quad_new->resource_id);
848 EXPECT_EQ(1, IterateAndCount(quad_new));
849 EXPECT_EQ(resource_id + 1, quad_new->resource_id);
852 TEST_F(DrawQuadIteratorTest, TileDrawQuad) {
853 gfx::Rect opaque_rect(33, 44, 22, 33);
854 gfx::Rect visible_rect(40, 50, 30, 20);
855 unsigned resource_id = 104;
856 gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
857 gfx::Size texture_size(85, 32);
858 bool swizzle_contents = true;
860 CREATE_SHARED_STATE();
861 CREATE_QUAD_6_NEW(TileDrawQuad,
862 opaque_rect,
863 visible_rect,
864 resource_id,
865 tex_coord_rect,
866 texture_size,
867 swizzle_contents);
868 EXPECT_EQ(resource_id, quad_new->resource_id);
869 EXPECT_EQ(1, IterateAndCount(quad_new));
870 EXPECT_EQ(resource_id + 1, quad_new->resource_id);
873 TEST_F(DrawQuadIteratorTest, YUVVideoDrawQuad) {
874 gfx::Rect opaque_rect(33, 47, 10, 12);
875 gfx::Rect visible_rect(40, 50, 30, 20);
876 gfx::RectF tex_coord_rect(0.0f, 0.0f, 0.75f, 0.5f);
877 ResourceProvider::ResourceId y_plane_resource_id = 45;
878 ResourceProvider::ResourceId u_plane_resource_id = 532;
879 ResourceProvider::ResourceId v_plane_resource_id = 4;
880 ResourceProvider::ResourceId a_plane_resource_id = 63;
881 YUVVideoDrawQuad::ColorSpace color_space = YUVVideoDrawQuad::REC_601_JPEG;
883 CREATE_SHARED_STATE();
884 CREATE_QUAD_8_NEW(YUVVideoDrawQuad,
885 opaque_rect,
886 visible_rect,
887 tex_coord_rect,
888 y_plane_resource_id,
889 u_plane_resource_id,
890 v_plane_resource_id,
891 a_plane_resource_id,
892 color_space);
893 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copy_quad->material);
894 EXPECT_EQ(y_plane_resource_id, quad_new->y_plane_resource_id);
895 EXPECT_EQ(u_plane_resource_id, quad_new->u_plane_resource_id);
896 EXPECT_EQ(v_plane_resource_id, quad_new->v_plane_resource_id);
897 EXPECT_EQ(a_plane_resource_id, quad_new->a_plane_resource_id);
898 EXPECT_EQ(color_space, quad_new->color_space);
899 EXPECT_EQ(4, IterateAndCount(quad_new));
900 EXPECT_EQ(y_plane_resource_id + 1, quad_new->y_plane_resource_id);
901 EXPECT_EQ(u_plane_resource_id + 1, quad_new->u_plane_resource_id);
902 EXPECT_EQ(v_plane_resource_id + 1, quad_new->v_plane_resource_id);
903 EXPECT_EQ(a_plane_resource_id + 1, quad_new->a_plane_resource_id);
906 // Disabled until picture draw quad is supported for ubercomp: crbug.com/231715
907 TEST_F(DrawQuadIteratorTest, DISABLED_PictureDrawQuad) {
908 gfx::Rect opaque_rect(33, 44, 22, 33);
909 gfx::Rect visible_rect(40, 50, 30, 20);
910 gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
911 gfx::Size texture_size(85, 32);
912 ResourceFormat texture_format = RGBA_8888;
913 gfx::Rect content_rect(30, 40, 20, 30);
914 float contents_scale = 3.141592f;
915 scoped_refptr<PicturePileImpl> raster_source = PicturePileImpl::Create();
917 CREATE_SHARED_STATE();
918 CREATE_QUAD_8_NEW(PictureDrawQuad, opaque_rect, visible_rect, tex_coord_rect,
919 texture_size, texture_format, content_rect, contents_scale,
920 raster_source);
921 EXPECT_EQ(0, IterateAndCount(quad_new));
924 TEST(DrawQuadTest, LargestQuadType) {
925 size_t largest = 0;
927 for (int i = 0; i <= DrawQuad::MATERIAL_LAST; ++i) {
928 switch (static_cast<DrawQuad::Material>(i)) {
929 case DrawQuad::CHECKERBOARD:
930 largest = std::max(largest, sizeof(CheckerboardDrawQuad));
931 break;
932 case DrawQuad::DEBUG_BORDER:
933 largest = std::max(largest, sizeof(DebugBorderDrawQuad));
934 break;
935 case DrawQuad::IO_SURFACE_CONTENT:
936 largest = std::max(largest, sizeof(IOSurfaceDrawQuad));
937 break;
938 case DrawQuad::PICTURE_CONTENT:
939 largest = std::max(largest, sizeof(PictureDrawQuad));
940 break;
941 case DrawQuad::TEXTURE_CONTENT:
942 largest = std::max(largest, sizeof(TextureDrawQuad));
943 break;
944 case DrawQuad::RENDER_PASS:
945 largest = std::max(largest, sizeof(RenderPassDrawQuad));
946 break;
947 case DrawQuad::SOLID_COLOR:
948 largest = std::max(largest, sizeof(SolidColorDrawQuad));
949 break;
950 case DrawQuad::SURFACE_CONTENT:
951 largest = std::max(largest, sizeof(SurfaceDrawQuad));
952 break;
953 case DrawQuad::TILED_CONTENT:
954 largest = std::max(largest, sizeof(TileDrawQuad));
955 break;
956 case DrawQuad::STREAM_VIDEO_CONTENT:
957 largest = std::max(largest, sizeof(StreamVideoDrawQuad));
958 break;
959 case DrawQuad::YUV_VIDEO_CONTENT:
960 largest = std::max(largest, sizeof(YUVVideoDrawQuad));
961 break;
962 case DrawQuad::INVALID:
963 break;
966 EXPECT_EQ(LargestDrawQuadSize(), largest);
968 if (!HasFailure())
969 return;
971 // On failure, output the size of all quads for debugging.
972 LOG(ERROR) << "largest " << largest;
973 LOG(ERROR) << "kLargestDrawQuad " << LargestDrawQuadSize();
974 for (int i = 0; i <= DrawQuad::MATERIAL_LAST; ++i) {
975 switch (static_cast<DrawQuad::Material>(i)) {
976 case DrawQuad::CHECKERBOARD:
977 LOG(ERROR) << "CheckerboardDrawQuad " << sizeof(CheckerboardDrawQuad);
978 break;
979 case DrawQuad::DEBUG_BORDER:
980 LOG(ERROR) << "DebugBorderDrawQuad " << sizeof(DebugBorderDrawQuad);
981 break;
982 case DrawQuad::IO_SURFACE_CONTENT:
983 LOG(ERROR) << "IOSurfaceDrawQuad " << sizeof(IOSurfaceDrawQuad);
984 break;
985 case DrawQuad::PICTURE_CONTENT:
986 LOG(ERROR) << "PictureDrawQuad " << sizeof(PictureDrawQuad);
987 break;
988 case DrawQuad::TEXTURE_CONTENT:
989 LOG(ERROR) << "TextureDrawQuad " << sizeof(TextureDrawQuad);
990 break;
991 case DrawQuad::RENDER_PASS:
992 LOG(ERROR) << "RenderPassDrawQuad " << sizeof(RenderPassDrawQuad);
993 break;
994 case DrawQuad::SOLID_COLOR:
995 LOG(ERROR) << "SolidColorDrawQuad " << sizeof(SolidColorDrawQuad);
996 break;
997 case DrawQuad::SURFACE_CONTENT:
998 LOG(ERROR) << "SurfaceDrawQuad " << sizeof(SurfaceDrawQuad);
999 break;
1000 case DrawQuad::TILED_CONTENT:
1001 LOG(ERROR) << "TileDrawQuad " << sizeof(TileDrawQuad);
1002 break;
1003 case DrawQuad::STREAM_VIDEO_CONTENT:
1004 LOG(ERROR) << "StreamVideoDrawQuad " << sizeof(StreamVideoDrawQuad);
1005 break;
1006 case DrawQuad::YUV_VIDEO_CONTENT:
1007 LOG(ERROR) << "YUVVideoDrawQuad " << sizeof(YUVVideoDrawQuad);
1008 break;
1009 case DrawQuad::INVALID:
1010 break;
1015 } // namespace
1016 } // namespace cc