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/test/fake_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 gfx::Size
tex_size(32, 68);
642 ResourceProvider::ResourceId y_plane_resource_id
= 45;
643 ResourceProvider::ResourceId u_plane_resource_id
= 532;
644 ResourceProvider::ResourceId v_plane_resource_id
= 4;
645 ResourceProvider::ResourceId a_plane_resource_id
= 63;
646 YUVVideoDrawQuad::ColorSpace color_space
= YUVVideoDrawQuad::JPEG
;
647 CREATE_SHARED_STATE();
649 CREATE_QUAD_9_NEW(YUVVideoDrawQuad
, opaque_rect
, visible_rect
, tex_coord_rect
,
650 tex_size
, y_plane_resource_id
, u_plane_resource_id
,
651 v_plane_resource_id
, a_plane_resource_id
, color_space
);
652 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
653 EXPECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
654 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
655 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
656 EXPECT_EQ(tex_size
, copy_quad
->tex_size
);
657 EXPECT_EQ(y_plane_resource_id
, copy_quad
->y_plane_resource_id
);
658 EXPECT_EQ(u_plane_resource_id
, copy_quad
->u_plane_resource_id
);
659 EXPECT_EQ(v_plane_resource_id
, copy_quad
->v_plane_resource_id
);
660 EXPECT_EQ(a_plane_resource_id
, copy_quad
->a_plane_resource_id
);
661 EXPECT_EQ(color_space
, copy_quad
->color_space
);
663 CREATE_QUAD_7_ALL(YUVVideoDrawQuad
, tex_coord_rect
, tex_size
,
664 y_plane_resource_id
, u_plane_resource_id
,
665 v_plane_resource_id
, a_plane_resource_id
, color_space
);
666 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
667 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
668 EXPECT_EQ(tex_size
, copy_quad
->tex_size
);
669 EXPECT_EQ(y_plane_resource_id
, copy_quad
->y_plane_resource_id
);
670 EXPECT_EQ(u_plane_resource_id
, copy_quad
->u_plane_resource_id
);
671 EXPECT_EQ(v_plane_resource_id
, copy_quad
->v_plane_resource_id
);
672 EXPECT_EQ(a_plane_resource_id
, copy_quad
->a_plane_resource_id
);
673 EXPECT_EQ(color_space
, copy_quad
->color_space
);
676 TEST(DrawQuadTest
, CopyPictureDrawQuad
) {
677 gfx::Rect
opaque_rect(33, 44, 22, 33);
678 gfx::Rect
visible_rect(40, 50, 30, 20);
679 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
680 gfx::Size
texture_size(85, 32);
681 bool nearest_neighbor
= true;
682 ResourceFormat texture_format
= RGBA_8888
;
683 gfx::Rect
content_rect(30, 40, 20, 30);
684 float contents_scale
= 3.141592f
;
685 scoped_refptr
<RasterSource
> raster_source
=
686 FakePicturePileImpl::CreateEmptyPile(gfx::Size(100, 100),
687 gfx::Size(100, 100));
688 CREATE_SHARED_STATE();
690 CREATE_QUAD_9_NEW(PictureDrawQuad
, opaque_rect
, visible_rect
, tex_coord_rect
,
691 texture_size
, nearest_neighbor
, texture_format
,
692 content_rect
, contents_scale
, raster_source
);
693 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
, copy_quad
->material
);
694 EXPECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
695 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
696 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
697 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
698 EXPECT_EQ(nearest_neighbor
, copy_quad
->nearest_neighbor
);
699 EXPECT_EQ(texture_format
, copy_quad
->texture_format
);
700 EXPECT_EQ(content_rect
, copy_quad
->content_rect
);
701 EXPECT_EQ(contents_scale
, copy_quad
->contents_scale
);
702 EXPECT_EQ(raster_source
, copy_quad
->raster_source
);
704 CREATE_QUAD_7_ALL(PictureDrawQuad
, tex_coord_rect
, texture_size
,
705 nearest_neighbor
, texture_format
, content_rect
,
706 contents_scale
, raster_source
);
707 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
, copy_quad
->material
);
708 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
709 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
710 EXPECT_EQ(nearest_neighbor
, copy_quad
->nearest_neighbor
);
711 EXPECT_EQ(texture_format
, copy_quad
->texture_format
);
712 EXPECT_EQ(content_rect
, copy_quad
->content_rect
);
713 EXPECT_EQ(contents_scale
, copy_quad
->contents_scale
);
714 EXPECT_EQ(raster_source
, copy_quad
->raster_source
);
717 class DrawQuadIteratorTest
: public testing::Test
{
719 ResourceProvider::ResourceId
IncrementResourceId(
720 ResourceProvider::ResourceId id
) {
725 int IterateAndCount(DrawQuad
* quad
) {
727 quad
->IterateResources(base::Bind(
728 &DrawQuadIteratorTest::IncrementResourceId
, base::Unretained(this)));
729 return num_resources_
;
736 TEST_F(DrawQuadIteratorTest
, CheckerboardDrawQuad
) {
737 gfx::Rect
visible_rect(40, 50, 30, 20);
738 SkColor color
= 0xfabb0011;
740 CREATE_SHARED_STATE();
741 CREATE_QUAD_2_NEW(CheckerboardDrawQuad
, visible_rect
, color
);
742 EXPECT_EQ(0, IterateAndCount(quad_new
));
745 TEST_F(DrawQuadIteratorTest
, DebugBorderDrawQuad
) {
746 gfx::Rect
visible_rect(40, 50, 30, 20);
747 SkColor color
= 0xfabb0011;
750 CREATE_SHARED_STATE();
751 CREATE_QUAD_3_NEW(DebugBorderDrawQuad
, visible_rect
, color
, width
);
752 EXPECT_EQ(0, IterateAndCount(quad_new
));
755 TEST_F(DrawQuadIteratorTest
, IOSurfaceDrawQuad
) {
756 gfx::Rect
opaque_rect(33, 47, 10, 12);
757 gfx::Rect
visible_rect(40, 50, 30, 20);
758 gfx::Size
size(58, 95);
759 ResourceProvider::ResourceId resource_id
= 72;
760 IOSurfaceDrawQuad::Orientation orientation
= IOSurfaceDrawQuad::UNFLIPPED
;
762 CREATE_SHARED_STATE();
763 CREATE_QUAD_5_NEW(IOSurfaceDrawQuad
,
769 EXPECT_EQ(resource_id
, quad_new
->io_surface_resource_id
);
770 EXPECT_EQ(1, IterateAndCount(quad_new
));
771 EXPECT_EQ(resource_id
+ 1, quad_new
->io_surface_resource_id
);
774 TEST_F(DrawQuadIteratorTest
, RenderPassDrawQuad
) {
775 gfx::Rect
visible_rect(40, 50, 30, 20);
776 RenderPassId
render_pass_id(22, 64);
777 ResourceProvider::ResourceId mask_resource_id
= 78;
778 gfx::Vector2dF
mask_uv_scale(33.f
, 19.f
);
779 gfx::Size
mask_texture_size(128, 134);
780 FilterOperations filters
;
781 filters
.Append(FilterOperation::CreateBlurFilter(1.f
));
782 gfx::Vector2dF
filters_scale(2.f
, 3.f
);
783 FilterOperations background_filters
;
784 background_filters
.Append(
785 FilterOperation::CreateGrayscaleFilter(1.f
));
787 RenderPassId
copied_render_pass_id(235, 11);
789 CREATE_SHARED_STATE();
790 CREATE_QUAD_NEW_RP(RenderPassDrawQuad
,
799 copied_render_pass_id
);
800 EXPECT_EQ(mask_resource_id
, quad_new
->mask_resource_id
);
801 EXPECT_EQ(1, IterateAndCount(quad_new
));
802 EXPECT_EQ(mask_resource_id
+ 1, quad_new
->mask_resource_id
);
803 quad_new
->mask_resource_id
= 0;
804 EXPECT_EQ(0, IterateAndCount(quad_new
));
805 EXPECT_EQ(0u, quad_new
->mask_resource_id
);
808 TEST_F(DrawQuadIteratorTest
, SolidColorDrawQuad
) {
809 gfx::Rect
visible_rect(40, 50, 30, 20);
810 SkColor color
= 0x49494949;
811 bool force_anti_aliasing_off
= false;
813 CREATE_SHARED_STATE();
815 SolidColorDrawQuad
, visible_rect
, color
, force_anti_aliasing_off
);
816 EXPECT_EQ(0, IterateAndCount(quad_new
));
819 TEST_F(DrawQuadIteratorTest
, StreamVideoDrawQuad
) {
820 gfx::Rect
opaque_rect(33, 47, 10, 12);
821 gfx::Rect
visible_rect(40, 50, 30, 20);
822 ResourceProvider::ResourceId resource_id
= 64;
823 gfx::Transform matrix
= gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
825 CREATE_SHARED_STATE();
827 StreamVideoDrawQuad
, opaque_rect
, visible_rect
, resource_id
, matrix
);
828 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
829 EXPECT_EQ(1, IterateAndCount(quad_new
));
830 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
833 TEST_F(DrawQuadIteratorTest
, SurfaceDrawQuad
) {
834 gfx::Rect
visible_rect(40, 50, 30, 20);
835 SurfaceId
surface_id(4321);
837 CREATE_SHARED_STATE();
838 CREATE_QUAD_2_NEW(SurfaceDrawQuad
, visible_rect
, surface_id
);
839 EXPECT_EQ(0, IterateAndCount(quad_new
));
842 TEST_F(DrawQuadIteratorTest
, TextureDrawQuad
) {
843 gfx::Rect
opaque_rect(33, 47, 10, 12);
844 gfx::Rect
visible_rect(40, 50, 30, 20);
845 unsigned resource_id
= 82;
846 bool premultiplied_alpha
= true;
847 gfx::PointF
uv_top_left(0.5f
, 224.f
);
848 gfx::PointF
uv_bottom_right(51.5f
, 260.f
);
849 const float vertex_opacity
[] = { 1.0f
, 1.0f
, 1.0f
, 1.0f
};
851 bool nearest_neighbor
= true;
853 CREATE_SHARED_STATE();
854 CREATE_QUAD_10_NEW(TextureDrawQuad
,
865 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
866 EXPECT_EQ(1, IterateAndCount(quad_new
));
867 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
870 TEST_F(DrawQuadIteratorTest
, TileDrawQuad
) {
871 gfx::Rect
opaque_rect(33, 44, 22, 33);
872 gfx::Rect
visible_rect(40, 50, 30, 20);
873 unsigned resource_id
= 104;
874 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
875 gfx::Size
texture_size(85, 32);
876 bool swizzle_contents
= true;
877 bool nearest_neighbor
= true;
879 CREATE_SHARED_STATE();
880 CREATE_QUAD_7_NEW(TileDrawQuad
,
888 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
889 EXPECT_EQ(1, IterateAndCount(quad_new
));
890 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
893 TEST_F(DrawQuadIteratorTest
, YUVVideoDrawQuad
) {
894 gfx::Rect
opaque_rect(33, 47, 10, 12);
895 gfx::Rect
visible_rect(40, 50, 30, 20);
896 gfx::RectF
tex_coord_rect(0.0f
, 0.0f
, 0.75f
, 0.5f
);
897 gfx::Size
tex_size(32, 68);
898 ResourceProvider::ResourceId y_plane_resource_id
= 45;
899 ResourceProvider::ResourceId u_plane_resource_id
= 532;
900 ResourceProvider::ResourceId v_plane_resource_id
= 4;
901 ResourceProvider::ResourceId a_plane_resource_id
= 63;
902 YUVVideoDrawQuad::ColorSpace color_space
= YUVVideoDrawQuad::JPEG
;
904 CREATE_SHARED_STATE();
905 CREATE_QUAD_9_NEW(YUVVideoDrawQuad
, opaque_rect
, visible_rect
, tex_coord_rect
,
906 tex_size
, y_plane_resource_id
, u_plane_resource_id
,
907 v_plane_resource_id
, a_plane_resource_id
, color_space
);
908 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
909 EXPECT_EQ(y_plane_resource_id
, quad_new
->y_plane_resource_id
);
910 EXPECT_EQ(u_plane_resource_id
, quad_new
->u_plane_resource_id
);
911 EXPECT_EQ(v_plane_resource_id
, quad_new
->v_plane_resource_id
);
912 EXPECT_EQ(a_plane_resource_id
, quad_new
->a_plane_resource_id
);
913 EXPECT_EQ(color_space
, quad_new
->color_space
);
914 EXPECT_EQ(4, IterateAndCount(quad_new
));
915 EXPECT_EQ(y_plane_resource_id
+ 1, quad_new
->y_plane_resource_id
);
916 EXPECT_EQ(u_plane_resource_id
+ 1, quad_new
->u_plane_resource_id
);
917 EXPECT_EQ(v_plane_resource_id
+ 1, quad_new
->v_plane_resource_id
);
918 EXPECT_EQ(a_plane_resource_id
+ 1, quad_new
->a_plane_resource_id
);
921 // Disabled until picture draw quad is supported for ubercomp: crbug.com/231715
922 TEST_F(DrawQuadIteratorTest
, DISABLED_PictureDrawQuad
) {
923 gfx::Rect
opaque_rect(33, 44, 22, 33);
924 gfx::Rect
visible_rect(40, 50, 30, 20);
925 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
926 gfx::Size
texture_size(85, 32);
927 bool nearest_neighbor
= true;
928 ResourceFormat texture_format
= RGBA_8888
;
929 gfx::Rect
content_rect(30, 40, 20, 30);
930 float contents_scale
= 3.141592f
;
931 scoped_refptr
<RasterSource
> raster_source
=
932 FakePicturePileImpl::CreateEmptyPile(gfx::Size(100, 100),
933 gfx::Size(100, 100));
935 CREATE_SHARED_STATE();
936 CREATE_QUAD_9_NEW(PictureDrawQuad
, opaque_rect
, visible_rect
, tex_coord_rect
,
937 texture_size
, nearest_neighbor
, texture_format
,
938 content_rect
, contents_scale
, raster_source
);
939 EXPECT_EQ(0, IterateAndCount(quad_new
));
942 TEST(DrawQuadTest
, LargestQuadType
) {
945 for (int i
= 0; i
<= DrawQuad::MATERIAL_LAST
; ++i
) {
946 switch (static_cast<DrawQuad::Material
>(i
)) {
947 case DrawQuad::CHECKERBOARD
:
948 largest
= std::max(largest
, sizeof(CheckerboardDrawQuad
));
950 case DrawQuad::DEBUG_BORDER
:
951 largest
= std::max(largest
, sizeof(DebugBorderDrawQuad
));
953 case DrawQuad::IO_SURFACE_CONTENT
:
954 largest
= std::max(largest
, sizeof(IOSurfaceDrawQuad
));
956 case DrawQuad::PICTURE_CONTENT
:
957 largest
= std::max(largest
, sizeof(PictureDrawQuad
));
959 case DrawQuad::TEXTURE_CONTENT
:
960 largest
= std::max(largest
, sizeof(TextureDrawQuad
));
962 case DrawQuad::RENDER_PASS
:
963 largest
= std::max(largest
, sizeof(RenderPassDrawQuad
));
965 case DrawQuad::SOLID_COLOR
:
966 largest
= std::max(largest
, sizeof(SolidColorDrawQuad
));
968 case DrawQuad::SURFACE_CONTENT
:
969 largest
= std::max(largest
, sizeof(SurfaceDrawQuad
));
971 case DrawQuad::TILED_CONTENT
:
972 largest
= std::max(largest
, sizeof(TileDrawQuad
));
974 case DrawQuad::STREAM_VIDEO_CONTENT
:
975 largest
= std::max(largest
, sizeof(StreamVideoDrawQuad
));
977 case DrawQuad::YUV_VIDEO_CONTENT
:
978 largest
= std::max(largest
, sizeof(YUVVideoDrawQuad
));
980 case DrawQuad::INVALID
:
984 EXPECT_EQ(LargestDrawQuadSize(), largest
);
989 // On failure, output the size of all quads for debugging.
990 LOG(ERROR
) << "largest " << largest
;
991 LOG(ERROR
) << "kLargestDrawQuad " << LargestDrawQuadSize();
992 for (int i
= 0; i
<= DrawQuad::MATERIAL_LAST
; ++i
) {
993 switch (static_cast<DrawQuad::Material
>(i
)) {
994 case DrawQuad::CHECKERBOARD
:
995 LOG(ERROR
) << "CheckerboardDrawQuad " << sizeof(CheckerboardDrawQuad
);
997 case DrawQuad::DEBUG_BORDER
:
998 LOG(ERROR
) << "DebugBorderDrawQuad " << sizeof(DebugBorderDrawQuad
);
1000 case DrawQuad::IO_SURFACE_CONTENT
:
1001 LOG(ERROR
) << "IOSurfaceDrawQuad " << sizeof(IOSurfaceDrawQuad
);
1003 case DrawQuad::PICTURE_CONTENT
:
1004 LOG(ERROR
) << "PictureDrawQuad " << sizeof(PictureDrawQuad
);
1006 case DrawQuad::TEXTURE_CONTENT
:
1007 LOG(ERROR
) << "TextureDrawQuad " << sizeof(TextureDrawQuad
);
1009 case DrawQuad::RENDER_PASS
:
1010 LOG(ERROR
) << "RenderPassDrawQuad " << sizeof(RenderPassDrawQuad
);
1012 case DrawQuad::SOLID_COLOR
:
1013 LOG(ERROR
) << "SolidColorDrawQuad " << sizeof(SolidColorDrawQuad
);
1015 case DrawQuad::SURFACE_CONTENT
:
1016 LOG(ERROR
) << "SurfaceDrawQuad " << sizeof(SurfaceDrawQuad
);
1018 case DrawQuad::TILED_CONTENT
:
1019 LOG(ERROR
) << "TileDrawQuad " << sizeof(TileDrawQuad
);
1021 case DrawQuad::STREAM_VIDEO_CONTENT
:
1022 LOG(ERROR
) << "StreamVideoDrawQuad " << sizeof(StreamVideoDrawQuad
);
1024 case DrawQuad::YUV_VIDEO_CONTENT
:
1025 LOG(ERROR
) << "YUVVideoDrawQuad " << sizeof(YUVVideoDrawQuad
);
1027 case DrawQuad::INVALID
: