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;
373 CREATE_SHARED_STATE();
375 CREATE_QUAD_3_NEW(CheckerboardDrawQuad
, visible_rect
, color
, scale
);
376 EXPECT_EQ(DrawQuad::CHECKERBOARD
, copy_quad
->material
);
377 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
378 EXPECT_EQ(color
, copy_quad
->color
);
379 EXPECT_EQ(scale
, copy_quad
->scale
);
381 CREATE_QUAD_2_ALL(CheckerboardDrawQuad
, color
, scale
);
382 EXPECT_EQ(DrawQuad::CHECKERBOARD
, copy_quad
->material
);
383 EXPECT_EQ(color
, copy_quad
->color
);
384 EXPECT_EQ(scale
, copy_quad
->scale
);
387 TEST(DrawQuadTest
, CopyDebugBorderDrawQuad
) {
388 gfx::Rect
visible_rect(40, 50, 30, 20);
389 SkColor color
= 0xfabb0011;
391 CREATE_SHARED_STATE();
393 CREATE_QUAD_3_NEW(DebugBorderDrawQuad
, visible_rect
, color
, width
);
394 EXPECT_EQ(DrawQuad::DEBUG_BORDER
, copy_quad
->material
);
395 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
396 EXPECT_EQ(color
, copy_quad
->color
);
397 EXPECT_EQ(width
, copy_quad
->width
);
399 CREATE_QUAD_2_ALL(DebugBorderDrawQuad
, color
, width
);
400 EXPECT_EQ(DrawQuad::DEBUG_BORDER
, copy_quad
->material
);
401 EXPECT_EQ(color
, copy_quad
->color
);
402 EXPECT_EQ(width
, copy_quad
->width
);
405 TEST(DrawQuadTest
, CopyIOSurfaceDrawQuad
) {
406 gfx::Rect
opaque_rect(33, 47, 10, 12);
407 gfx::Rect
visible_rect(40, 50, 30, 20);
408 gfx::Size
size(58, 95);
409 ResourceProvider::ResourceId resource_id
= 72;
410 IOSurfaceDrawQuad::Orientation orientation
= IOSurfaceDrawQuad::UNFLIPPED
;
411 CREATE_SHARED_STATE();
413 CREATE_QUAD_5_NEW(IOSurfaceDrawQuad
,
419 EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT
, copy_quad
->material
);
420 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
421 EXPECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
422 EXPECT_EQ(size
, copy_quad
->io_surface_size
);
423 EXPECT_EQ(resource_id
, copy_quad
->io_surface_resource_id
);
424 EXPECT_EQ(orientation
, copy_quad
->orientation
);
426 CREATE_QUAD_3_ALL(IOSurfaceDrawQuad
, size
, resource_id
, orientation
);
427 EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT
, copy_quad
->material
);
428 EXPECT_EQ(size
, copy_quad
->io_surface_size
);
429 EXPECT_EQ(resource_id
, copy_quad
->io_surface_resource_id
);
430 EXPECT_EQ(orientation
, copy_quad
->orientation
);
433 TEST(DrawQuadTest
, CopyRenderPassDrawQuad
) {
434 gfx::Rect
visible_rect(40, 50, 30, 20);
435 RenderPassId
render_pass_id(22, 64);
436 ResourceProvider::ResourceId mask_resource_id
= 78;
437 gfx::Vector2dF
mask_uv_scale(33.f
, 19.f
);
438 gfx::Size
mask_texture_size(128, 134);
439 FilterOperations filters
;
440 filters
.Append(FilterOperation::CreateBlurFilter(1.f
));
441 gfx::Vector2dF filters_scale
;
442 FilterOperations background_filters
;
443 background_filters
.Append(
444 FilterOperation::CreateGrayscaleFilter(1.f
));
446 RenderPassId
copied_render_pass_id(235, 11);
447 CREATE_SHARED_STATE();
449 CREATE_QUAD_NEW_RP(RenderPassDrawQuad
,
458 copied_render_pass_id
);
459 EXPECT_EQ(DrawQuad::RENDER_PASS
, copy_quad
->material
);
460 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
461 EXPECT_EQ(copied_render_pass_id
, copy_quad
->render_pass_id
);
462 EXPECT_EQ(mask_resource_id
, copy_quad
->mask_resource_id
);
463 EXPECT_EQ(mask_uv_scale
.ToString(), copy_quad
->mask_uv_scale
.ToString());
464 EXPECT_EQ(mask_texture_size
.ToString(),
465 copy_quad
->mask_texture_size
.ToString());
466 EXPECT_EQ(filters
, copy_quad
->filters
);
467 EXPECT_EQ(filters_scale
, copy_quad
->filters_scale
);
468 EXPECT_EQ(background_filters
, copy_quad
->background_filters
);
470 CREATE_QUAD_ALL_RP(RenderPassDrawQuad
,
478 copied_render_pass_id
);
479 EXPECT_EQ(DrawQuad::RENDER_PASS
, copy_quad
->material
);
480 EXPECT_EQ(copied_render_pass_id
, copy_quad
->render_pass_id
);
481 EXPECT_EQ(mask_resource_id
, copy_quad
->mask_resource_id
);
482 EXPECT_EQ(mask_uv_scale
.ToString(), copy_quad
->mask_uv_scale
.ToString());
483 EXPECT_EQ(mask_texture_size
.ToString(),
484 copy_quad
->mask_texture_size
.ToString());
485 EXPECT_EQ(filters
, copy_quad
->filters
);
486 EXPECT_EQ(filters_scale
, copy_quad
->filters_scale
);
487 EXPECT_EQ(background_filters
, copy_quad
->background_filters
);
490 TEST(DrawQuadTest
, CopySolidColorDrawQuad
) {
491 gfx::Rect
visible_rect(40, 50, 30, 20);
492 SkColor color
= 0x49494949;
493 bool force_anti_aliasing_off
= false;
494 CREATE_SHARED_STATE();
497 SolidColorDrawQuad
, visible_rect
, color
, force_anti_aliasing_off
);
498 EXPECT_EQ(DrawQuad::SOLID_COLOR
, copy_quad
->material
);
499 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
500 EXPECT_EQ(color
, copy_quad
->color
);
501 EXPECT_EQ(force_anti_aliasing_off
, copy_quad
->force_anti_aliasing_off
);
503 CREATE_QUAD_2_ALL(SolidColorDrawQuad
, color
, force_anti_aliasing_off
);
504 EXPECT_EQ(DrawQuad::SOLID_COLOR
, copy_quad
->material
);
505 EXPECT_EQ(color
, copy_quad
->color
);
506 EXPECT_EQ(force_anti_aliasing_off
, copy_quad
->force_anti_aliasing_off
);
509 TEST(DrawQuadTest
, CopyStreamVideoDrawQuad
) {
510 gfx::Rect
opaque_rect(33, 47, 10, 12);
511 gfx::Rect
visible_rect(40, 50, 30, 20);
512 ResourceProvider::ResourceId resource_id
= 64;
513 gfx::Transform matrix
= gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
514 CREATE_SHARED_STATE();
517 StreamVideoDrawQuad
, opaque_rect
, visible_rect
, resource_id
, matrix
);
518 EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT
, copy_quad
->material
);
519 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
520 EXPECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
521 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
522 EXPECT_EQ(matrix
, copy_quad
->matrix
);
524 CREATE_QUAD_2_ALL(StreamVideoDrawQuad
, resource_id
, matrix
);
525 EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT
, copy_quad
->material
);
526 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
527 EXPECT_EQ(matrix
, copy_quad
->matrix
);
530 TEST(DrawQuadTest
, CopySurfaceDrawQuad
) {
531 gfx::Rect
visible_rect(40, 50, 30, 20);
532 SurfaceId
surface_id(1234);
533 CREATE_SHARED_STATE();
535 CREATE_QUAD_2_NEW(SurfaceDrawQuad
, visible_rect
, surface_id
);
536 EXPECT_EQ(DrawQuad::SURFACE_CONTENT
, copy_quad
->material
);
537 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
538 EXPECT_EQ(surface_id
, copy_quad
->surface_id
);
540 CREATE_QUAD_1_ALL(SurfaceDrawQuad
, surface_id
);
541 EXPECT_EQ(DrawQuad::SURFACE_CONTENT
, copy_quad
->material
);
542 EXPECT_EQ(surface_id
, copy_quad
->surface_id
);
546 TEST(DrawQuadTest
, CopyTextureDrawQuad
) {
547 gfx::Rect
opaque_rect(33, 47, 10, 12);
548 gfx::Rect
visible_rect(40, 50, 30, 20);
549 unsigned resource_id
= 82;
550 bool premultiplied_alpha
= true;
551 gfx::PointF
uv_top_left(0.5f
, 224.f
);
552 gfx::PointF
uv_bottom_right(51.5f
, 260.f
);
553 const float vertex_opacity
[] = { 1.0f
, 1.0f
, 1.0f
, 1.0f
};
555 bool nearest_neighbor
= true;
556 CREATE_SHARED_STATE();
558 CREATE_QUAD_10_NEW(TextureDrawQuad
,
569 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT
, copy_quad
->material
);
570 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
571 EXPECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
572 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
573 EXPECT_EQ(premultiplied_alpha
, copy_quad
->premultiplied_alpha
);
574 EXPECT_EQ(uv_top_left
, copy_quad
->uv_top_left
);
575 EXPECT_EQ(uv_bottom_right
, copy_quad
->uv_bottom_right
);
576 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity
, copy_quad
->vertex_opacity
, 4);
577 EXPECT_EQ(flipped
, copy_quad
->flipped
);
578 EXPECT_EQ(nearest_neighbor
, copy_quad
->nearest_neighbor
);
580 CREATE_QUAD_8_ALL(TextureDrawQuad
,
589 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT
, copy_quad
->material
);
590 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
591 EXPECT_EQ(premultiplied_alpha
, copy_quad
->premultiplied_alpha
);
592 EXPECT_EQ(uv_top_left
, copy_quad
->uv_top_left
);
593 EXPECT_EQ(uv_bottom_right
, copy_quad
->uv_bottom_right
);
594 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity
, copy_quad
->vertex_opacity
, 4);
595 EXPECT_EQ(flipped
, copy_quad
->flipped
);
596 EXPECT_EQ(nearest_neighbor
, copy_quad
->nearest_neighbor
);
599 TEST(DrawQuadTest
, CopyTileDrawQuad
) {
600 gfx::Rect
opaque_rect(33, 44, 22, 33);
601 gfx::Rect
visible_rect(40, 50, 30, 20);
602 unsigned resource_id
= 104;
603 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
604 gfx::Size
texture_size(85, 32);
605 bool swizzle_contents
= true;
606 bool nearest_neighbor
= true;
607 CREATE_SHARED_STATE();
609 CREATE_QUAD_7_NEW(TileDrawQuad
,
617 EXPECT_EQ(DrawQuad::TILED_CONTENT
, copy_quad
->material
);
618 EXPECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
619 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
620 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
621 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
622 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
623 EXPECT_EQ(swizzle_contents
, copy_quad
->swizzle_contents
);
624 EXPECT_EQ(nearest_neighbor
, copy_quad
->nearest_neighbor
);
626 CREATE_QUAD_5_ALL(TileDrawQuad
,
632 EXPECT_EQ(DrawQuad::TILED_CONTENT
, copy_quad
->material
);
633 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
634 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
635 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
636 EXPECT_EQ(swizzle_contents
, copy_quad
->swizzle_contents
);
637 EXPECT_EQ(nearest_neighbor
, copy_quad
->nearest_neighbor
);
640 TEST(DrawQuadTest
, CopyYUVVideoDrawQuad
) {
641 gfx::Rect
opaque_rect(33, 47, 10, 12);
642 gfx::Rect
visible_rect(40, 50, 30, 20);
643 gfx::RectF
tex_coord_rect(0.0f
, 0.0f
, 0.75f
, 0.5f
);
644 gfx::Size
ya_tex_size(32, 68);
645 gfx::Size
uv_tex_size(41, 51);
646 ResourceProvider::ResourceId y_plane_resource_id
= 45;
647 ResourceProvider::ResourceId u_plane_resource_id
= 532;
648 ResourceProvider::ResourceId v_plane_resource_id
= 4;
649 ResourceProvider::ResourceId a_plane_resource_id
= 63;
650 YUVVideoDrawQuad::ColorSpace color_space
= YUVVideoDrawQuad::JPEG
;
651 CREATE_SHARED_STATE();
653 CREATE_QUAD_10_NEW(YUVVideoDrawQuad
, opaque_rect
, visible_rect
,
654 tex_coord_rect
, ya_tex_size
, uv_tex_size
,
655 y_plane_resource_id
, u_plane_resource_id
,
656 v_plane_resource_id
, a_plane_resource_id
, color_space
);
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(ya_tex_size
, copy_quad
->ya_tex_size
);
662 EXPECT_EQ(uv_tex_size
, copy_quad
->uv_tex_size
);
663 EXPECT_EQ(y_plane_resource_id
, copy_quad
->y_plane_resource_id
);
664 EXPECT_EQ(u_plane_resource_id
, copy_quad
->u_plane_resource_id
);
665 EXPECT_EQ(v_plane_resource_id
, copy_quad
->v_plane_resource_id
);
666 EXPECT_EQ(a_plane_resource_id
, copy_quad
->a_plane_resource_id
);
667 EXPECT_EQ(color_space
, copy_quad
->color_space
);
669 CREATE_QUAD_8_ALL(YUVVideoDrawQuad
, tex_coord_rect
, ya_tex_size
, uv_tex_size
,
670 y_plane_resource_id
, u_plane_resource_id
,
671 v_plane_resource_id
, a_plane_resource_id
, color_space
);
672 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
673 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
674 EXPECT_EQ(ya_tex_size
, copy_quad
->ya_tex_size
);
675 EXPECT_EQ(uv_tex_size
, copy_quad
->uv_tex_size
);
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
=
693 FakePicturePileImpl::CreateEmptyPile(gfx::Size(100, 100),
694 gfx::Size(100, 100));
695 CREATE_SHARED_STATE();
697 CREATE_QUAD_9_NEW(PictureDrawQuad
, opaque_rect
, visible_rect
, tex_coord_rect
,
698 texture_size
, nearest_neighbor
, texture_format
,
699 content_rect
, contents_scale
, raster_source
);
700 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
, copy_quad
->material
);
701 EXPECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
702 EXPECT_EQ(visible_rect
, copy_quad
->visible_rect
);
703 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
704 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
705 EXPECT_EQ(nearest_neighbor
, copy_quad
->nearest_neighbor
);
706 EXPECT_EQ(texture_format
, copy_quad
->texture_format
);
707 EXPECT_EQ(content_rect
, copy_quad
->content_rect
);
708 EXPECT_EQ(contents_scale
, copy_quad
->contents_scale
);
709 EXPECT_EQ(raster_source
, copy_quad
->raster_source
);
711 CREATE_QUAD_7_ALL(PictureDrawQuad
, tex_coord_rect
, texture_size
,
712 nearest_neighbor
, texture_format
, content_rect
,
713 contents_scale
, raster_source
);
714 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
, copy_quad
->material
);
715 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
716 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
717 EXPECT_EQ(nearest_neighbor
, copy_quad
->nearest_neighbor
);
718 EXPECT_EQ(texture_format
, copy_quad
->texture_format
);
719 EXPECT_EQ(content_rect
, copy_quad
->content_rect
);
720 EXPECT_EQ(contents_scale
, copy_quad
->contents_scale
);
721 EXPECT_EQ(raster_source
, copy_quad
->raster_source
);
724 class DrawQuadIteratorTest
: public testing::Test
{
726 ResourceProvider::ResourceId
IncrementResourceId(
727 ResourceProvider::ResourceId id
) {
732 int IterateAndCount(DrawQuad
* quad
) {
734 quad
->IterateResources(base::Bind(
735 &DrawQuadIteratorTest::IncrementResourceId
, base::Unretained(this)));
736 return num_resources_
;
743 TEST_F(DrawQuadIteratorTest
, CheckerboardDrawQuad
) {
744 gfx::Rect
visible_rect(40, 50, 30, 20);
745 SkColor color
= 0xfabb0011;
748 CREATE_SHARED_STATE();
749 CREATE_QUAD_3_NEW(CheckerboardDrawQuad
, visible_rect
, color
, scale
);
750 EXPECT_EQ(0, IterateAndCount(quad_new
));
753 TEST_F(DrawQuadIteratorTest
, DebugBorderDrawQuad
) {
754 gfx::Rect
visible_rect(40, 50, 30, 20);
755 SkColor color
= 0xfabb0011;
758 CREATE_SHARED_STATE();
759 CREATE_QUAD_3_NEW(DebugBorderDrawQuad
, visible_rect
, color
, width
);
760 EXPECT_EQ(0, IterateAndCount(quad_new
));
763 TEST_F(DrawQuadIteratorTest
, IOSurfaceDrawQuad
) {
764 gfx::Rect
opaque_rect(33, 47, 10, 12);
765 gfx::Rect
visible_rect(40, 50, 30, 20);
766 gfx::Size
size(58, 95);
767 ResourceProvider::ResourceId resource_id
= 72;
768 IOSurfaceDrawQuad::Orientation orientation
= IOSurfaceDrawQuad::UNFLIPPED
;
770 CREATE_SHARED_STATE();
771 CREATE_QUAD_5_NEW(IOSurfaceDrawQuad
,
777 EXPECT_EQ(resource_id
, quad_new
->io_surface_resource_id
);
778 EXPECT_EQ(1, IterateAndCount(quad_new
));
779 EXPECT_EQ(resource_id
+ 1, quad_new
->io_surface_resource_id
);
782 TEST_F(DrawQuadIteratorTest
, RenderPassDrawQuad
) {
783 gfx::Rect
visible_rect(40, 50, 30, 20);
784 RenderPassId
render_pass_id(22, 64);
785 ResourceProvider::ResourceId mask_resource_id
= 78;
786 gfx::Vector2dF
mask_uv_scale(33.f
, 19.f
);
787 gfx::Size
mask_texture_size(128, 134);
788 FilterOperations filters
;
789 filters
.Append(FilterOperation::CreateBlurFilter(1.f
));
790 gfx::Vector2dF
filters_scale(2.f
, 3.f
);
791 FilterOperations background_filters
;
792 background_filters
.Append(
793 FilterOperation::CreateGrayscaleFilter(1.f
));
795 RenderPassId
copied_render_pass_id(235, 11);
797 CREATE_SHARED_STATE();
798 CREATE_QUAD_NEW_RP(RenderPassDrawQuad
,
807 copied_render_pass_id
);
808 EXPECT_EQ(mask_resource_id
, quad_new
->mask_resource_id
);
809 EXPECT_EQ(1, IterateAndCount(quad_new
));
810 EXPECT_EQ(mask_resource_id
+ 1, quad_new
->mask_resource_id
);
811 quad_new
->mask_resource_id
= 0;
812 EXPECT_EQ(0, IterateAndCount(quad_new
));
813 EXPECT_EQ(0u, quad_new
->mask_resource_id
);
816 TEST_F(DrawQuadIteratorTest
, SolidColorDrawQuad
) {
817 gfx::Rect
visible_rect(40, 50, 30, 20);
818 SkColor color
= 0x49494949;
819 bool force_anti_aliasing_off
= false;
821 CREATE_SHARED_STATE();
823 SolidColorDrawQuad
, visible_rect
, color
, force_anti_aliasing_off
);
824 EXPECT_EQ(0, IterateAndCount(quad_new
));
827 TEST_F(DrawQuadIteratorTest
, StreamVideoDrawQuad
) {
828 gfx::Rect
opaque_rect(33, 47, 10, 12);
829 gfx::Rect
visible_rect(40, 50, 30, 20);
830 ResourceProvider::ResourceId resource_id
= 64;
831 gfx::Transform matrix
= gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
833 CREATE_SHARED_STATE();
835 StreamVideoDrawQuad
, opaque_rect
, visible_rect
, resource_id
, matrix
);
836 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
837 EXPECT_EQ(1, IterateAndCount(quad_new
));
838 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
841 TEST_F(DrawQuadIteratorTest
, SurfaceDrawQuad
) {
842 gfx::Rect
visible_rect(40, 50, 30, 20);
843 SurfaceId
surface_id(4321);
845 CREATE_SHARED_STATE();
846 CREATE_QUAD_2_NEW(SurfaceDrawQuad
, visible_rect
, surface_id
);
847 EXPECT_EQ(0, IterateAndCount(quad_new
));
850 TEST_F(DrawQuadIteratorTest
, TextureDrawQuad
) {
851 gfx::Rect
opaque_rect(33, 47, 10, 12);
852 gfx::Rect
visible_rect(40, 50, 30, 20);
853 unsigned resource_id
= 82;
854 bool premultiplied_alpha
= true;
855 gfx::PointF
uv_top_left(0.5f
, 224.f
);
856 gfx::PointF
uv_bottom_right(51.5f
, 260.f
);
857 const float vertex_opacity
[] = { 1.0f
, 1.0f
, 1.0f
, 1.0f
};
859 bool nearest_neighbor
= true;
861 CREATE_SHARED_STATE();
862 CREATE_QUAD_10_NEW(TextureDrawQuad
,
873 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
874 EXPECT_EQ(1, IterateAndCount(quad_new
));
875 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
878 TEST_F(DrawQuadIteratorTest
, TileDrawQuad
) {
879 gfx::Rect
opaque_rect(33, 44, 22, 33);
880 gfx::Rect
visible_rect(40, 50, 30, 20);
881 unsigned resource_id
= 104;
882 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
883 gfx::Size
texture_size(85, 32);
884 bool swizzle_contents
= true;
885 bool nearest_neighbor
= true;
887 CREATE_SHARED_STATE();
888 CREATE_QUAD_7_NEW(TileDrawQuad
,
896 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
897 EXPECT_EQ(1, IterateAndCount(quad_new
));
898 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
901 TEST_F(DrawQuadIteratorTest
, YUVVideoDrawQuad
) {
902 gfx::Rect
opaque_rect(33, 47, 10, 12);
903 gfx::Rect
visible_rect(40, 50, 30, 20);
904 gfx::RectF
tex_coord_rect(0.0f
, 0.0f
, 0.75f
, 0.5f
);
905 gfx::Size
ya_tex_size(32, 68);
906 gfx::Size
uv_tex_size(41, 51);
907 ResourceProvider::ResourceId y_plane_resource_id
= 45;
908 ResourceProvider::ResourceId u_plane_resource_id
= 532;
909 ResourceProvider::ResourceId v_plane_resource_id
= 4;
910 ResourceProvider::ResourceId a_plane_resource_id
= 63;
911 YUVVideoDrawQuad::ColorSpace color_space
= YUVVideoDrawQuad::JPEG
;
913 CREATE_SHARED_STATE();
914 CREATE_QUAD_10_NEW(YUVVideoDrawQuad
, opaque_rect
, visible_rect
,
915 tex_coord_rect
, ya_tex_size
, uv_tex_size
,
916 y_plane_resource_id
, u_plane_resource_id
,
917 v_plane_resource_id
, a_plane_resource_id
, color_space
);
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
<RasterSource
> raster_source
=
942 FakePicturePileImpl::CreateEmptyPile(gfx::Size(100, 100),
943 gfx::Size(100, 100));
945 CREATE_SHARED_STATE();
946 CREATE_QUAD_9_NEW(PictureDrawQuad
, opaque_rect
, visible_rect
, tex_coord_rect
,
947 texture_size
, nearest_neighbor
, texture_format
,
948 content_rect
, contents_scale
, raster_source
);
949 EXPECT_EQ(0, IterateAndCount(quad_new
));
952 TEST(DrawQuadTest
, LargestQuadType
) {
955 for (int i
= 0; i
<= DrawQuad::MATERIAL_LAST
; ++i
) {
956 switch (static_cast<DrawQuad::Material
>(i
)) {
957 case DrawQuad::CHECKERBOARD
:
958 largest
= std::max(largest
, sizeof(CheckerboardDrawQuad
));
960 case DrawQuad::DEBUG_BORDER
:
961 largest
= std::max(largest
, sizeof(DebugBorderDrawQuad
));
963 case DrawQuad::IO_SURFACE_CONTENT
:
964 largest
= std::max(largest
, sizeof(IOSurfaceDrawQuad
));
966 case DrawQuad::PICTURE_CONTENT
:
967 largest
= std::max(largest
, sizeof(PictureDrawQuad
));
969 case DrawQuad::TEXTURE_CONTENT
:
970 largest
= std::max(largest
, sizeof(TextureDrawQuad
));
972 case DrawQuad::RENDER_PASS
:
973 largest
= std::max(largest
, sizeof(RenderPassDrawQuad
));
975 case DrawQuad::SOLID_COLOR
:
976 largest
= std::max(largest
, sizeof(SolidColorDrawQuad
));
978 case DrawQuad::SURFACE_CONTENT
:
979 largest
= std::max(largest
, sizeof(SurfaceDrawQuad
));
981 case DrawQuad::TILED_CONTENT
:
982 largest
= std::max(largest
, sizeof(TileDrawQuad
));
984 case DrawQuad::STREAM_VIDEO_CONTENT
:
985 largest
= std::max(largest
, sizeof(StreamVideoDrawQuad
));
987 case DrawQuad::YUV_VIDEO_CONTENT
:
988 largest
= std::max(largest
, sizeof(YUVVideoDrawQuad
));
990 case DrawQuad::INVALID
:
994 EXPECT_EQ(LargestDrawQuadSize(), largest
);
999 // On failure, output the size of all quads for debugging.
1000 LOG(ERROR
) << "largest " << largest
;
1001 LOG(ERROR
) << "kLargestDrawQuad " << LargestDrawQuadSize();
1002 for (int i
= 0; i
<= DrawQuad::MATERIAL_LAST
; ++i
) {
1003 switch (static_cast<DrawQuad::Material
>(i
)) {
1004 case DrawQuad::CHECKERBOARD
:
1005 LOG(ERROR
) << "CheckerboardDrawQuad " << sizeof(CheckerboardDrawQuad
);
1007 case DrawQuad::DEBUG_BORDER
:
1008 LOG(ERROR
) << "DebugBorderDrawQuad " << sizeof(DebugBorderDrawQuad
);
1010 case DrawQuad::IO_SURFACE_CONTENT
:
1011 LOG(ERROR
) << "IOSurfaceDrawQuad " << sizeof(IOSurfaceDrawQuad
);
1013 case DrawQuad::PICTURE_CONTENT
:
1014 LOG(ERROR
) << "PictureDrawQuad " << sizeof(PictureDrawQuad
);
1016 case DrawQuad::TEXTURE_CONTENT
:
1017 LOG(ERROR
) << "TextureDrawQuad " << sizeof(TextureDrawQuad
);
1019 case DrawQuad::RENDER_PASS
:
1020 LOG(ERROR
) << "RenderPassDrawQuad " << sizeof(RenderPassDrawQuad
);
1022 case DrawQuad::SOLID_COLOR
:
1023 LOG(ERROR
) << "SolidColorDrawQuad " << sizeof(SolidColorDrawQuad
);
1025 case DrawQuad::SURFACE_CONTENT
:
1026 LOG(ERROR
) << "SurfaceDrawQuad " << sizeof(SurfaceDrawQuad
);
1028 case DrawQuad::TILED_CONTENT
:
1029 LOG(ERROR
) << "TileDrawQuad " << sizeof(TileDrawQuad
);
1031 case DrawQuad::STREAM_VIDEO_CONTENT
:
1032 LOG(ERROR
) << "StreamVideoDrawQuad " << sizeof(StreamVideoDrawQuad
);
1034 case DrawQuad::YUV_VIDEO_CONTENT
:
1035 LOG(ERROR
) << "YUVVideoDrawQuad " << sizeof(YUVVideoDrawQuad
);
1037 case DrawQuad::INVALID
: