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"
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"
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
,
55 scoped_ptr
<SharedQuadState
> copy(new SharedQuadState
);
56 copy
->CopyFrom(state
.get());
57 EXPECT_EQ(quad_transform
, copy
->content_to_target_transform
);
58 EXPECT_EQ(visible_content_rect
, copy
->visible_content_rect
);
59 EXPECT_EQ(opacity
, copy
->opacity
);
60 EXPECT_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;
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
,
87 void CompareDrawQuad(DrawQuad
* quad
,
89 SharedQuadState
* copy_shared_state
) {
90 EXPECT_EQ(quad
->material
, copy
->material
);
91 EXPECT_EQ(quad
->rect
, copy
->rect
);
92 EXPECT_EQ(quad
->visible_rect
, copy
->visible_rect
);
93 EXPECT_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);
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, \
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, \
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, \
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, \
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, \
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, \
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, \
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, \
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, \
333 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
335 #define CREATE_QUAD_10_NEW(Type, a, b, c, d, e, f, g, h, i, j) \
336 Type* quad_new = render_pass->CreateAndAppendDrawQuad<Type>(); \
338 QUAD_DATA quad_new->SetNew( \
339 shared_state, quad_rect, a, b, c, d, e, f, g, h, i, j); \
341 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
343 #define CREATE_QUAD_ALL_RP(Type, a, b, c, d, e, f, g, copy_a) \
344 Type* quad_all = render_pass->CreateAndAppendDrawQuad<Type>(); \
346 QUAD_DATA quad_all->SetAll(shared_state, \
359 SETUP_AND_COPY_QUAD_ALL_RP(Type, quad_all, copy_a);
361 #define CREATE_QUAD_NEW_RP(Type, a, b, c, d, e, f, g, h, copy_a) \
362 Type* quad_new = render_pass->CreateAndAppendDrawQuad<Type>(); \
364 QUAD_DATA quad_new->SetNew( \
365 shared_state, quad_rect, a, b, c, d, e, f, g, h); \
367 SETUP_AND_COPY_QUAD_NEW_RP(Type, quad_new, copy_a);
369 TEST(DrawQuadTest
, CopyCheckerboardDrawQuad
) {
370 gfx::Rect
visible_rect(40, 50, 30, 20);
371 SkColor color
= 0xfabb0011;
372 CREATE_SHARED_STATE();
374 CREATE_QUAD_2_NEW(CheckerboardDrawQuad
, visible_rect
, color
);
375 EXPECT_EQ(DrawQuad::CHECKERBOARD
, copy_quad
->material
);
376 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
377 EXPECT_EQ(color
, copy_quad
->color
);
379 CREATE_QUAD_1_ALL(CheckerboardDrawQuad
, color
);
380 EXPECT_EQ(DrawQuad::CHECKERBOARD
, copy_quad
->material
);
381 EXPECT_EQ(color
, copy_quad
->color
);
384 TEST(DrawQuadTest
, CopyDebugBorderDrawQuad
) {
385 gfx::Rect
visible_rect(40, 50, 30, 20);
386 SkColor color
= 0xfabb0011;
388 CREATE_SHARED_STATE();
390 CREATE_QUAD_3_NEW(DebugBorderDrawQuad
, visible_rect
, color
, width
);
391 EXPECT_EQ(DrawQuad::DEBUG_BORDER
, copy_quad
->material
);
392 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
393 EXPECT_EQ(color
, copy_quad
->color
);
394 EXPECT_EQ(width
, copy_quad
->width
);
396 CREATE_QUAD_2_ALL(DebugBorderDrawQuad
, color
, width
);
397 EXPECT_EQ(DrawQuad::DEBUG_BORDER
, copy_quad
->material
);
398 EXPECT_EQ(color
, copy_quad
->color
);
399 EXPECT_EQ(width
, copy_quad
->width
);
402 TEST(DrawQuadTest
, CopyIOSurfaceDrawQuad
) {
403 gfx::Rect
opaque_rect(33, 47, 10, 12);
404 gfx::Rect
visible_rect(40, 50, 30, 20);
405 gfx::Size
size(58, 95);
406 ResourceProvider::ResourceId resource_id
= 72;
407 IOSurfaceDrawQuad::Orientation orientation
= IOSurfaceDrawQuad::UNFLIPPED
;
408 CREATE_SHARED_STATE();
410 CREATE_QUAD_5_NEW(IOSurfaceDrawQuad
,
416 EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT
, copy_quad
->material
);
417 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
418 EXPECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
419 EXPECT_EQ(size
, copy_quad
->io_surface_size
);
420 EXPECT_EQ(resource_id
, copy_quad
->io_surface_resource_id
);
421 EXPECT_EQ(orientation
, copy_quad
->orientation
);
423 CREATE_QUAD_3_ALL(IOSurfaceDrawQuad
, size
, resource_id
, orientation
);
424 EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT
, copy_quad
->material
);
425 EXPECT_EQ(size
, copy_quad
->io_surface_size
);
426 EXPECT_EQ(resource_id
, copy_quad
->io_surface_resource_id
);
427 EXPECT_EQ(orientation
, copy_quad
->orientation
);
430 TEST(DrawQuadTest
, CopyRenderPassDrawQuad
) {
431 gfx::Rect
visible_rect(40, 50, 30, 20);
432 RenderPassId
render_pass_id(22, 64);
433 ResourceProvider::ResourceId mask_resource_id
= 78;
434 gfx::Vector2dF
mask_uv_scale(33.f
, 19.f
);
435 gfx::Size
mask_texture_size(128, 134);
436 FilterOperations filters
;
437 filters
.Append(FilterOperation::CreateBlurFilter(1.f
));
438 gfx::Vector2dF filters_scale
;
439 FilterOperations background_filters
;
440 background_filters
.Append(
441 FilterOperation::CreateGrayscaleFilter(1.f
));
443 RenderPassId
copied_render_pass_id(235, 11);
444 CREATE_SHARED_STATE();
446 CREATE_QUAD_NEW_RP(RenderPassDrawQuad
,
455 copied_render_pass_id
);
456 EXPECT_EQ(DrawQuad::RENDER_PASS
, copy_quad
->material
);
457 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
458 EXPECT_EQ(copied_render_pass_id
, copy_quad
->render_pass_id
);
459 EXPECT_EQ(mask_resource_id
, copy_quad
->mask_resource_id
);
460 EXPECT_EQ(mask_uv_scale
.ToString(), copy_quad
->mask_uv_scale
.ToString());
461 EXPECT_EQ(mask_texture_size
.ToString(),
462 copy_quad
->mask_texture_size
.ToString());
463 EXPECT_EQ(filters
, copy_quad
->filters
);
464 EXPECT_EQ(filters_scale
, copy_quad
->filters_scale
);
465 EXPECT_EQ(background_filters
, copy_quad
->background_filters
);
467 CREATE_QUAD_ALL_RP(RenderPassDrawQuad
,
475 copied_render_pass_id
);
476 EXPECT_EQ(DrawQuad::RENDER_PASS
, copy_quad
->material
);
477 EXPECT_EQ(copied_render_pass_id
, copy_quad
->render_pass_id
);
478 EXPECT_EQ(mask_resource_id
, copy_quad
->mask_resource_id
);
479 EXPECT_EQ(mask_uv_scale
.ToString(), copy_quad
->mask_uv_scale
.ToString());
480 EXPECT_EQ(mask_texture_size
.ToString(),
481 copy_quad
->mask_texture_size
.ToString());
482 EXPECT_EQ(filters
, copy_quad
->filters
);
483 EXPECT_EQ(filters_scale
, copy_quad
->filters_scale
);
484 EXPECT_EQ(background_filters
, copy_quad
->background_filters
);
487 TEST(DrawQuadTest
, CopySolidColorDrawQuad
) {
488 gfx::Rect
visible_rect(40, 50, 30, 20);
489 SkColor color
= 0x49494949;
490 bool force_anti_aliasing_off
= false;
491 CREATE_SHARED_STATE();
494 SolidColorDrawQuad
, visible_rect
, color
, force_anti_aliasing_off
);
495 EXPECT_EQ(DrawQuad::SOLID_COLOR
, copy_quad
->material
);
496 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
497 EXPECT_EQ(color
, copy_quad
->color
);
498 EXPECT_EQ(force_anti_aliasing_off
, copy_quad
->force_anti_aliasing_off
);
500 CREATE_QUAD_2_ALL(SolidColorDrawQuad
, color
, force_anti_aliasing_off
);
501 EXPECT_EQ(DrawQuad::SOLID_COLOR
, copy_quad
->material
);
502 EXPECT_EQ(color
, copy_quad
->color
);
503 EXPECT_EQ(force_anti_aliasing_off
, copy_quad
->force_anti_aliasing_off
);
506 TEST(DrawQuadTest
, CopyStreamVideoDrawQuad
) {
507 gfx::Rect
opaque_rect(33, 47, 10, 12);
508 gfx::Rect
visible_rect(40, 50, 30, 20);
509 ResourceProvider::ResourceId resource_id
= 64;
510 gfx::Transform matrix
= gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
511 CREATE_SHARED_STATE();
514 StreamVideoDrawQuad
, opaque_rect
, visible_rect
, resource_id
, matrix
);
515 EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT
, copy_quad
->material
);
516 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
517 EXPECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
518 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
519 EXPECT_EQ(matrix
, copy_quad
->matrix
);
521 CREATE_QUAD_2_ALL(StreamVideoDrawQuad
, resource_id
, matrix
);
522 EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT
, copy_quad
->material
);
523 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
524 EXPECT_EQ(matrix
, copy_quad
->matrix
);
527 TEST(DrawQuadTest
, CopySurfaceDrawQuad
) {
528 gfx::Rect
visible_rect(40, 50, 30, 20);
529 SurfaceId
surface_id(1234);
530 CREATE_SHARED_STATE();
532 CREATE_QUAD_2_NEW(SurfaceDrawQuad
, visible_rect
, surface_id
);
533 EXPECT_EQ(DrawQuad::SURFACE_CONTENT
, copy_quad
->material
);
534 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
535 EXPECT_EQ(surface_id
, copy_quad
->surface_id
);
537 CREATE_QUAD_1_ALL(SurfaceDrawQuad
, surface_id
);
538 EXPECT_EQ(DrawQuad::SURFACE_CONTENT
, copy_quad
->material
);
539 EXPECT_EQ(surface_id
, copy_quad
->surface_id
);
543 TEST(DrawQuadTest
, CopyTextureDrawQuad
) {
544 gfx::Rect
opaque_rect(33, 47, 10, 12);
545 gfx::Rect
visible_rect(40, 50, 30, 20);
546 unsigned resource_id
= 82;
547 bool premultiplied_alpha
= true;
548 gfx::PointF
uv_top_left(0.5f
, 224.f
);
549 gfx::PointF
uv_bottom_right(51.5f
, 260.f
);
550 const float vertex_opacity
[] = { 1.0f
, 1.0f
, 1.0f
, 1.0f
};
552 bool nearest_neighbor
= true;
553 CREATE_SHARED_STATE();
555 CREATE_QUAD_10_NEW(TextureDrawQuad
,
566 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT
, copy_quad
->material
);
567 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
568 EXPECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
569 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
570 EXPECT_EQ(premultiplied_alpha
, copy_quad
->premultiplied_alpha
);
571 EXPECT_EQ(uv_top_left
, copy_quad
->uv_top_left
);
572 EXPECT_EQ(uv_bottom_right
, copy_quad
->uv_bottom_right
);
573 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity
, copy_quad
->vertex_opacity
, 4);
574 EXPECT_EQ(flipped
, copy_quad
->flipped
);
575 EXPECT_EQ(nearest_neighbor
, copy_quad
->nearest_neighbor
);
577 CREATE_QUAD_8_ALL(TextureDrawQuad
,
586 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT
, copy_quad
->material
);
587 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
588 EXPECT_EQ(premultiplied_alpha
, copy_quad
->premultiplied_alpha
);
589 EXPECT_EQ(uv_top_left
, copy_quad
->uv_top_left
);
590 EXPECT_EQ(uv_bottom_right
, copy_quad
->uv_bottom_right
);
591 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity
, copy_quad
->vertex_opacity
, 4);
592 EXPECT_EQ(flipped
, copy_quad
->flipped
);
593 EXPECT_EQ(nearest_neighbor
, copy_quad
->nearest_neighbor
);
596 TEST(DrawQuadTest
, CopyTileDrawQuad
) {
597 gfx::Rect
opaque_rect(33, 44, 22, 33);
598 gfx::Rect
visible_rect(40, 50, 30, 20);
599 unsigned resource_id
= 104;
600 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
601 gfx::Size
texture_size(85, 32);
602 bool swizzle_contents
= true;
603 bool nearest_neighbor
= true;
604 CREATE_SHARED_STATE();
606 CREATE_QUAD_7_NEW(TileDrawQuad
,
614 EXPECT_EQ(DrawQuad::TILED_CONTENT
, copy_quad
->material
);
615 EXPECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
616 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
617 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
618 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
619 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
620 EXPECT_EQ(swizzle_contents
, copy_quad
->swizzle_contents
);
621 EXPECT_EQ(nearest_neighbor
, copy_quad
->nearest_neighbor
);
623 CREATE_QUAD_5_ALL(TileDrawQuad
,
629 EXPECT_EQ(DrawQuad::TILED_CONTENT
, copy_quad
->material
);
630 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
631 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
632 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
633 EXPECT_EQ(swizzle_contents
, copy_quad
->swizzle_contents
);
634 EXPECT_EQ(nearest_neighbor
, copy_quad
->nearest_neighbor
);
637 TEST(DrawQuadTest
, CopyYUVVideoDrawQuad
) {
638 gfx::Rect
opaque_rect(33, 47, 10, 12);
639 gfx::Rect
visible_rect(40, 50, 30, 20);
640 gfx::RectF
tex_coord_rect(0.0f
, 0.0f
, 0.75f
, 0.5f
);
641 ResourceProvider::ResourceId y_plane_resource_id
= 45;
642 ResourceProvider::ResourceId u_plane_resource_id
= 532;
643 ResourceProvider::ResourceId v_plane_resource_id
= 4;
644 ResourceProvider::ResourceId a_plane_resource_id
= 63;
645 YUVVideoDrawQuad::ColorSpace color_space
= YUVVideoDrawQuad::REC_601_JPEG
;
646 CREATE_SHARED_STATE();
648 CREATE_QUAD_8_NEW(YUVVideoDrawQuad
,
657 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
658 EXPECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
659 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
660 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
661 EXPECT_EQ(y_plane_resource_id
, copy_quad
->y_plane_resource_id
);
662 EXPECT_EQ(u_plane_resource_id
, copy_quad
->u_plane_resource_id
);
663 EXPECT_EQ(v_plane_resource_id
, copy_quad
->v_plane_resource_id
);
664 EXPECT_EQ(a_plane_resource_id
, copy_quad
->a_plane_resource_id
);
665 EXPECT_EQ(color_space
, copy_quad
->color_space
);
667 CREATE_QUAD_6_ALL(YUVVideoDrawQuad
,
674 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
675 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
676 EXPECT_EQ(y_plane_resource_id
, copy_quad
->y_plane_resource_id
);
677 EXPECT_EQ(u_plane_resource_id
, copy_quad
->u_plane_resource_id
);
678 EXPECT_EQ(v_plane_resource_id
, copy_quad
->v_plane_resource_id
);
679 EXPECT_EQ(a_plane_resource_id
, copy_quad
->a_plane_resource_id
);
680 EXPECT_EQ(color_space
, copy_quad
->color_space
);
683 TEST(DrawQuadTest
, CopyPictureDrawQuad
) {
684 gfx::Rect
opaque_rect(33, 44, 22, 33);
685 gfx::Rect
visible_rect(40, 50, 30, 20);
686 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
687 gfx::Size
texture_size(85, 32);
688 bool nearest_neighbor
= true;
689 ResourceFormat texture_format
= RGBA_8888
;
690 gfx::Rect
content_rect(30, 40, 20, 30);
691 float contents_scale
= 3.141592f
;
692 scoped_refptr
<RasterSource
> raster_source
= PicturePileImpl::Create();
693 CREATE_SHARED_STATE();
695 CREATE_QUAD_9_NEW(PictureDrawQuad
, opaque_rect
, visible_rect
, tex_coord_rect
,
696 texture_size
, nearest_neighbor
, texture_format
,
697 content_rect
, contents_scale
, raster_source
);
698 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
, copy_quad
->material
);
699 EXPECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
700 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
701 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
702 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
703 EXPECT_EQ(nearest_neighbor
, copy_quad
->nearest_neighbor
);
704 EXPECT_EQ(texture_format
, copy_quad
->texture_format
);
705 EXPECT_EQ(content_rect
, copy_quad
->content_rect
);
706 EXPECT_EQ(contents_scale
, copy_quad
->contents_scale
);
707 EXPECT_EQ(raster_source
, copy_quad
->raster_source
);
709 CREATE_QUAD_7_ALL(PictureDrawQuad
, tex_coord_rect
, texture_size
,
710 nearest_neighbor
, texture_format
, content_rect
,
711 contents_scale
, raster_source
);
712 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
, copy_quad
->material
);
713 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
714 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
715 EXPECT_EQ(nearest_neighbor
, copy_quad
->nearest_neighbor
);
716 EXPECT_EQ(texture_format
, copy_quad
->texture_format
);
717 EXPECT_EQ(content_rect
, copy_quad
->content_rect
);
718 EXPECT_EQ(contents_scale
, copy_quad
->contents_scale
);
719 EXPECT_EQ(raster_source
, copy_quad
->raster_source
);
722 class DrawQuadIteratorTest
: public testing::Test
{
724 ResourceProvider::ResourceId
IncrementResourceId(
725 ResourceProvider::ResourceId id
) {
730 int IterateAndCount(DrawQuad
* quad
) {
732 quad
->IterateResources(base::Bind(
733 &DrawQuadIteratorTest::IncrementResourceId
, base::Unretained(this)));
734 return num_resources_
;
741 TEST_F(DrawQuadIteratorTest
, CheckerboardDrawQuad
) {
742 gfx::Rect
visible_rect(40, 50, 30, 20);
743 SkColor color
= 0xfabb0011;
745 CREATE_SHARED_STATE();
746 CREATE_QUAD_2_NEW(CheckerboardDrawQuad
, visible_rect
, color
);
747 EXPECT_EQ(0, IterateAndCount(quad_new
));
750 TEST_F(DrawQuadIteratorTest
, DebugBorderDrawQuad
) {
751 gfx::Rect
visible_rect(40, 50, 30, 20);
752 SkColor color
= 0xfabb0011;
755 CREATE_SHARED_STATE();
756 CREATE_QUAD_3_NEW(DebugBorderDrawQuad
, visible_rect
, color
, width
);
757 EXPECT_EQ(0, IterateAndCount(quad_new
));
760 TEST_F(DrawQuadIteratorTest
, IOSurfaceDrawQuad
) {
761 gfx::Rect
opaque_rect(33, 47, 10, 12);
762 gfx::Rect
visible_rect(40, 50, 30, 20);
763 gfx::Size
size(58, 95);
764 ResourceProvider::ResourceId resource_id
= 72;
765 IOSurfaceDrawQuad::Orientation orientation
= IOSurfaceDrawQuad::UNFLIPPED
;
767 CREATE_SHARED_STATE();
768 CREATE_QUAD_5_NEW(IOSurfaceDrawQuad
,
774 EXPECT_EQ(resource_id
, quad_new
->io_surface_resource_id
);
775 EXPECT_EQ(1, IterateAndCount(quad_new
));
776 EXPECT_EQ(resource_id
+ 1, quad_new
->io_surface_resource_id
);
779 TEST_F(DrawQuadIteratorTest
, RenderPassDrawQuad
) {
780 gfx::Rect
visible_rect(40, 50, 30, 20);
781 RenderPassId
render_pass_id(22, 64);
782 ResourceProvider::ResourceId mask_resource_id
= 78;
783 gfx::Vector2dF
mask_uv_scale(33.f
, 19.f
);
784 gfx::Size
mask_texture_size(128, 134);
785 FilterOperations filters
;
786 filters
.Append(FilterOperation::CreateBlurFilter(1.f
));
787 gfx::Vector2dF
filters_scale(2.f
, 3.f
);
788 FilterOperations background_filters
;
789 background_filters
.Append(
790 FilterOperation::CreateGrayscaleFilter(1.f
));
792 RenderPassId
copied_render_pass_id(235, 11);
794 CREATE_SHARED_STATE();
795 CREATE_QUAD_NEW_RP(RenderPassDrawQuad
,
804 copied_render_pass_id
);
805 EXPECT_EQ(mask_resource_id
, quad_new
->mask_resource_id
);
806 EXPECT_EQ(1, IterateAndCount(quad_new
));
807 EXPECT_EQ(mask_resource_id
+ 1, quad_new
->mask_resource_id
);
808 quad_new
->mask_resource_id
= 0;
809 EXPECT_EQ(0, IterateAndCount(quad_new
));
810 EXPECT_EQ(0u, quad_new
->mask_resource_id
);
813 TEST_F(DrawQuadIteratorTest
, SolidColorDrawQuad
) {
814 gfx::Rect
visible_rect(40, 50, 30, 20);
815 SkColor color
= 0x49494949;
816 bool force_anti_aliasing_off
= false;
818 CREATE_SHARED_STATE();
820 SolidColorDrawQuad
, visible_rect
, color
, force_anti_aliasing_off
);
821 EXPECT_EQ(0, IterateAndCount(quad_new
));
824 TEST_F(DrawQuadIteratorTest
, StreamVideoDrawQuad
) {
825 gfx::Rect
opaque_rect(33, 47, 10, 12);
826 gfx::Rect
visible_rect(40, 50, 30, 20);
827 ResourceProvider::ResourceId resource_id
= 64;
828 gfx::Transform matrix
= gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
830 CREATE_SHARED_STATE();
832 StreamVideoDrawQuad
, opaque_rect
, visible_rect
, resource_id
, matrix
);
833 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
834 EXPECT_EQ(1, IterateAndCount(quad_new
));
835 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
838 TEST_F(DrawQuadIteratorTest
, SurfaceDrawQuad
) {
839 gfx::Rect
visible_rect(40, 50, 30, 20);
840 SurfaceId
surface_id(4321);
842 CREATE_SHARED_STATE();
843 CREATE_QUAD_2_NEW(SurfaceDrawQuad
, visible_rect
, surface_id
);
844 EXPECT_EQ(0, IterateAndCount(quad_new
));
847 TEST_F(DrawQuadIteratorTest
, TextureDrawQuad
) {
848 gfx::Rect
opaque_rect(33, 47, 10, 12);
849 gfx::Rect
visible_rect(40, 50, 30, 20);
850 unsigned resource_id
= 82;
851 bool premultiplied_alpha
= true;
852 gfx::PointF
uv_top_left(0.5f
, 224.f
);
853 gfx::PointF
uv_bottom_right(51.5f
, 260.f
);
854 const float vertex_opacity
[] = { 1.0f
, 1.0f
, 1.0f
, 1.0f
};
856 bool nearest_neighbor
= true;
858 CREATE_SHARED_STATE();
859 CREATE_QUAD_10_NEW(TextureDrawQuad
,
870 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
871 EXPECT_EQ(1, IterateAndCount(quad_new
));
872 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
875 TEST_F(DrawQuadIteratorTest
, TileDrawQuad
) {
876 gfx::Rect
opaque_rect(33, 44, 22, 33);
877 gfx::Rect
visible_rect(40, 50, 30, 20);
878 unsigned resource_id
= 104;
879 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
880 gfx::Size
texture_size(85, 32);
881 bool swizzle_contents
= true;
882 bool nearest_neighbor
= true;
884 CREATE_SHARED_STATE();
885 CREATE_QUAD_7_NEW(TileDrawQuad
,
893 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
894 EXPECT_EQ(1, IterateAndCount(quad_new
));
895 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
898 TEST_F(DrawQuadIteratorTest
, YUVVideoDrawQuad
) {
899 gfx::Rect
opaque_rect(33, 47, 10, 12);
900 gfx::Rect
visible_rect(40, 50, 30, 20);
901 gfx::RectF
tex_coord_rect(0.0f
, 0.0f
, 0.75f
, 0.5f
);
902 ResourceProvider::ResourceId y_plane_resource_id
= 45;
903 ResourceProvider::ResourceId u_plane_resource_id
= 532;
904 ResourceProvider::ResourceId v_plane_resource_id
= 4;
905 ResourceProvider::ResourceId a_plane_resource_id
= 63;
906 YUVVideoDrawQuad::ColorSpace color_space
= YUVVideoDrawQuad::REC_601_JPEG
;
908 CREATE_SHARED_STATE();
909 CREATE_QUAD_8_NEW(YUVVideoDrawQuad
,
918 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
919 EXPECT_EQ(y_plane_resource_id
, quad_new
->y_plane_resource_id
);
920 EXPECT_EQ(u_plane_resource_id
, quad_new
->u_plane_resource_id
);
921 EXPECT_EQ(v_plane_resource_id
, quad_new
->v_plane_resource_id
);
922 EXPECT_EQ(a_plane_resource_id
, quad_new
->a_plane_resource_id
);
923 EXPECT_EQ(color_space
, quad_new
->color_space
);
924 EXPECT_EQ(4, IterateAndCount(quad_new
));
925 EXPECT_EQ(y_plane_resource_id
+ 1, quad_new
->y_plane_resource_id
);
926 EXPECT_EQ(u_plane_resource_id
+ 1, quad_new
->u_plane_resource_id
);
927 EXPECT_EQ(v_plane_resource_id
+ 1, quad_new
->v_plane_resource_id
);
928 EXPECT_EQ(a_plane_resource_id
+ 1, quad_new
->a_plane_resource_id
);
931 // Disabled until picture draw quad is supported for ubercomp: crbug.com/231715
932 TEST_F(DrawQuadIteratorTest
, DISABLED_PictureDrawQuad
) {
933 gfx::Rect
opaque_rect(33, 44, 22, 33);
934 gfx::Rect
visible_rect(40, 50, 30, 20);
935 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
936 gfx::Size
texture_size(85, 32);
937 bool nearest_neighbor
= true;
938 ResourceFormat texture_format
= RGBA_8888
;
939 gfx::Rect
content_rect(30, 40, 20, 30);
940 float contents_scale
= 3.141592f
;
941 scoped_refptr
<PicturePileImpl
> raster_source
= PicturePileImpl::Create();
943 CREATE_SHARED_STATE();
944 CREATE_QUAD_9_NEW(PictureDrawQuad
, opaque_rect
, visible_rect
, tex_coord_rect
,
945 texture_size
, nearest_neighbor
, texture_format
,
946 content_rect
, contents_scale
, raster_source
);
947 EXPECT_EQ(0, IterateAndCount(quad_new
));
950 TEST(DrawQuadTest
, LargestQuadType
) {
953 for (int i
= 0; i
<= DrawQuad::MATERIAL_LAST
; ++i
) {
954 switch (static_cast<DrawQuad::Material
>(i
)) {
955 case DrawQuad::CHECKERBOARD
:
956 largest
= std::max(largest
, sizeof(CheckerboardDrawQuad
));
958 case DrawQuad::DEBUG_BORDER
:
959 largest
= std::max(largest
, sizeof(DebugBorderDrawQuad
));
961 case DrawQuad::IO_SURFACE_CONTENT
:
962 largest
= std::max(largest
, sizeof(IOSurfaceDrawQuad
));
964 case DrawQuad::PICTURE_CONTENT
:
965 largest
= std::max(largest
, sizeof(PictureDrawQuad
));
967 case DrawQuad::TEXTURE_CONTENT
:
968 largest
= std::max(largest
, sizeof(TextureDrawQuad
));
970 case DrawQuad::RENDER_PASS
:
971 largest
= std::max(largest
, sizeof(RenderPassDrawQuad
));
973 case DrawQuad::SOLID_COLOR
:
974 largest
= std::max(largest
, sizeof(SolidColorDrawQuad
));
976 case DrawQuad::SURFACE_CONTENT
:
977 largest
= std::max(largest
, sizeof(SurfaceDrawQuad
));
979 case DrawQuad::TILED_CONTENT
:
980 largest
= std::max(largest
, sizeof(TileDrawQuad
));
982 case DrawQuad::STREAM_VIDEO_CONTENT
:
983 largest
= std::max(largest
, sizeof(StreamVideoDrawQuad
));
985 case DrawQuad::YUV_VIDEO_CONTENT
:
986 largest
= std::max(largest
, sizeof(YUVVideoDrawQuad
));
988 case DrawQuad::INVALID
:
992 EXPECT_EQ(LargestDrawQuadSize(), largest
);
997 // On failure, output the size of all quads for debugging.
998 LOG(ERROR
) << "largest " << largest
;
999 LOG(ERROR
) << "kLargestDrawQuad " << LargestDrawQuadSize();
1000 for (int i
= 0; i
<= DrawQuad::MATERIAL_LAST
; ++i
) {
1001 switch (static_cast<DrawQuad::Material
>(i
)) {
1002 case DrawQuad::CHECKERBOARD
:
1003 LOG(ERROR
) << "CheckerboardDrawQuad " << sizeof(CheckerboardDrawQuad
);
1005 case DrawQuad::DEBUG_BORDER
:
1006 LOG(ERROR
) << "DebugBorderDrawQuad " << sizeof(DebugBorderDrawQuad
);
1008 case DrawQuad::IO_SURFACE_CONTENT
:
1009 LOG(ERROR
) << "IOSurfaceDrawQuad " << sizeof(IOSurfaceDrawQuad
);
1011 case DrawQuad::PICTURE_CONTENT
:
1012 LOG(ERROR
) << "PictureDrawQuad " << sizeof(PictureDrawQuad
);
1014 case DrawQuad::TEXTURE_CONTENT
:
1015 LOG(ERROR
) << "TextureDrawQuad " << sizeof(TextureDrawQuad
);
1017 case DrawQuad::RENDER_PASS
:
1018 LOG(ERROR
) << "RenderPassDrawQuad " << sizeof(RenderPassDrawQuad
);
1020 case DrawQuad::SOLID_COLOR
:
1021 LOG(ERROR
) << "SolidColorDrawQuad " << sizeof(SolidColorDrawQuad
);
1023 case DrawQuad::SURFACE_CONTENT
:
1024 LOG(ERROR
) << "SurfaceDrawQuad " << sizeof(SurfaceDrawQuad
);
1026 case DrawQuad::TILED_CONTENT
:
1027 LOG(ERROR
) << "TileDrawQuad " << sizeof(TileDrawQuad
);
1029 case DrawQuad::STREAM_VIDEO_CONTENT
:
1030 LOG(ERROR
) << "StreamVideoDrawQuad " << sizeof(StreamVideoDrawQuad
);
1032 case DrawQuad::YUV_VIDEO_CONTENT
:
1033 LOG(ERROR
) << "YUVVideoDrawQuad " << sizeof(YUVVideoDrawQuad
);
1035 case DrawQuad::INVALID
: