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/picture_draw_quad.h"
17 #include "cc/quads/render_pass_draw_quad.h"
18 #include "cc/quads/solid_color_draw_quad.h"
19 #include "cc/quads/stream_video_draw_quad.h"
20 #include "cc/quads/surface_draw_quad.h"
21 #include "cc/quads/texture_draw_quad.h"
22 #include "cc/quads/tile_draw_quad.h"
23 #include "cc/quads/yuv_video_draw_quad.h"
24 #include "cc/resources/picture_pile_impl.h"
25 #include "cc/test/geometry_test_utils.h"
26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
28 #include "ui/gfx/transform.h"
33 TEST(DrawQuadTest
, CopySharedQuadState
) {
34 gfx::Transform quad_transform
= gfx::Transform(1.0, 0.0, 0.5, 1.0, 0.5, 0.0);
35 gfx::Size
content_bounds(26, 28);
36 gfx::Rect
visible_content_rect(10, 12, 14, 16);
37 gfx::Rect
clip_rect(19, 21, 23, 25);
38 bool is_clipped
= true;
39 float opacity
= 0.25f
;
40 SkXfermode::Mode blend_mode
= SkXfermode::kMultiply_Mode
;
42 scoped_ptr
<SharedQuadState
> state(SharedQuadState::Create());
43 state
->SetAll(quad_transform
,
51 scoped_ptr
<SharedQuadState
> copy(state
->Copy());
52 EXPECT_EQ(quad_transform
, copy
->content_to_target_transform
);
53 EXPECT_RECT_EQ(visible_content_rect
, copy
->visible_content_rect
);
54 EXPECT_EQ(opacity
, copy
->opacity
);
55 EXPECT_RECT_EQ(clip_rect
, copy
->clip_rect
);
56 EXPECT_EQ(is_clipped
, copy
->is_clipped
);
57 EXPECT_EQ(blend_mode
, copy
->blend_mode
);
60 scoped_ptr
<SharedQuadState
> CreateSharedQuadState() {
61 gfx::Transform quad_transform
= gfx::Transform(1.0, 0.0, 0.5, 1.0, 0.5, 0.0);
62 gfx::Size
content_bounds(26, 28);
63 gfx::Rect
visible_content_rect(10, 12, 14, 16);
64 gfx::Rect
clip_rect(19, 21, 23, 25);
65 bool is_clipped
= false;
67 SkXfermode::Mode blend_mode
= SkXfermode::kSrcOver_Mode
;
69 scoped_ptr
<SharedQuadState
> state(SharedQuadState::Create());
70 state
->SetAll(quad_transform
,
80 void CompareDrawQuad(DrawQuad
* quad
,
82 SharedQuadState
* copy_shared_state
) {
83 EXPECT_EQ(quad
->material
, copy
->material
);
84 EXPECT_RECT_EQ(quad
->rect
, copy
->rect
);
85 EXPECT_RECT_EQ(quad
->visible_rect
, copy
->visible_rect
);
86 EXPECT_RECT_EQ(quad
->opaque_rect
, copy
->opaque_rect
);
87 EXPECT_EQ(quad
->needs_blending
, copy
->needs_blending
);
88 EXPECT_EQ(copy_shared_state
, copy
->shared_quad_state
);
91 #define CREATE_SHARED_STATE() \
92 scoped_ptr<SharedQuadState> shared_state(CreateSharedQuadState()); \
93 scoped_ptr<SharedQuadState> copy_shared_state(shared_state->Copy()); \
96 gfx::Rect quad_rect(30, 40, 50, 60); \
97 gfx::Rect quad_visible_rect(40, 50, 30, 20); \
98 gfx::Rect ALLOW_UNUSED quad_opaque_rect(60, 55, 10, 10); \
99 bool ALLOW_UNUSED needs_blending = true;
101 #define SETUP_AND_COPY_QUAD_NEW(Type, quad) \
102 scoped_ptr<DrawQuad> copy_new(quad_new->Copy(copy_shared_state.get())); \
103 CompareDrawQuad(quad_new.get(), copy_new.get(), copy_shared_state.get()); \
104 const Type* ALLOW_UNUSED copy_quad = Type::MaterialCast(copy_new.get());
106 #define SETUP_AND_COPY_QUAD_ALL(Type, quad) \
107 scoped_ptr<DrawQuad> copy_all(quad_all->Copy(copy_shared_state.get())); \
108 CompareDrawQuad(quad_all.get(), copy_all.get(), copy_shared_state.get()); \
109 copy_quad = Type::MaterialCast(copy_all.get());
111 #define SETUP_AND_COPY_QUAD_NEW_1(Type, quad, a) \
112 scoped_ptr<DrawQuad> copy_new(quad_new->Copy(copy_shared_state.get(), a)); \
113 CompareDrawQuad(quad_new.get(), copy_new.get(), copy_shared_state.get()); \
114 const Type* ALLOW_UNUSED copy_quad = Type::MaterialCast(copy_new.get());
116 #define SETUP_AND_COPY_QUAD_ALL_1(Type, quad, a) \
117 scoped_ptr<DrawQuad> copy_all(quad_all->Copy(copy_shared_state.get(), a)); \
118 CompareDrawQuad(quad_all.get(), copy_all.get(), copy_shared_state.get()); \
119 copy_quad = Type::MaterialCast(copy_all.get());
121 #define CREATE_QUAD_1_NEW(Type, a) \
122 scoped_ptr<Type> quad_new(Type::Create()); \
125 quad_new->SetNew(shared_state.get(), quad_rect, a); \
127 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
129 #define CREATE_QUAD_1_ALL(Type, a) \
130 scoped_ptr<Type> quad_all(Type::Create()); \
133 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
134 quad_visible_rect, needs_blending, a); \
136 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
138 #define CREATE_QUAD_2_NEW(Type, a, b) \
139 scoped_ptr<Type> quad_new(Type::Create()); \
142 quad_new->SetNew(shared_state.get(), quad_rect, a, b); \
144 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
146 #define CREATE_QUAD_2_ALL(Type, a, b) \
147 scoped_ptr<Type> quad_all(Type::Create()); \
150 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
151 quad_visible_rect, needs_blending, a, b); \
153 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
155 #define CREATE_QUAD_3_NEW(Type, a, b, c) \
156 scoped_ptr<Type> quad_new(Type::Create()); \
159 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c); \
161 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
163 #define CREATE_QUAD_3_ALL(Type, a, b, c) \
164 scoped_ptr<Type> quad_all(Type::Create()); \
167 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
168 quad_visible_rect, needs_blending, a, b, c); \
170 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
172 #define CREATE_QUAD_4_NEW(Type, a, b, c, d) \
173 scoped_ptr<Type> quad_new(Type::Create()); \
176 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d); \
178 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
180 #define CREATE_QUAD_4_ALL(Type, a, b, c, d) \
181 scoped_ptr<Type> quad_all(Type::Create()); \
184 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
185 quad_visible_rect, needs_blending, a, b, c, d); \
187 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
189 #define CREATE_QUAD_5_NEW(Type, a, b, c, d, e) \
190 scoped_ptr<Type> quad_new(Type::Create()); \
193 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e); \
195 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
197 #define CREATE_QUAD_5_ALL(Type, a, b, c, d, e) \
198 scoped_ptr<Type> quad_all(Type::Create()); \
201 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
202 quad_visible_rect, needs_blending, a, b, c, d, e); \
204 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
206 #define CREATE_QUAD_5_NEW_1(Type, a, b, c, d, e, copy_a) \
207 scoped_ptr<Type> quad_new(Type::Create()); \
210 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e); \
212 SETUP_AND_COPY_QUAD_NEW_1(Type, quad_new, copy_a);
214 #define CREATE_QUAD_5_ALL_1(Type, a, b, c, d, e, copy_a) \
215 scoped_ptr<Type> quad_all(Type::Create()); \
218 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
219 quad_visible_rect, needs_blending, a, b, c, d, e); \
221 SETUP_AND_COPY_QUAD_ALL_1(Type, quad_all, copy_a);
223 #define CREATE_QUAD_6_NEW(Type, a, b, c, d, e, f) \
224 scoped_ptr<Type> quad_new(Type::Create()); \
227 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f); \
229 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
231 #define CREATE_QUAD_6_ALL(Type, a, b, c, d, e, f) \
232 scoped_ptr<Type> quad_all(Type::Create()); \
235 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
236 quad_visible_rect, needs_blending, a, b, c, d, e, f); \
238 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
240 #define CREATE_QUAD_7_NEW(Type, a, b, c, d, e, f, g) \
241 scoped_ptr<Type> quad_new(Type::Create()); \
244 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f, g); \
246 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
248 #define CREATE_QUAD_7_ALL(Type, a, b, c, d, e, f, g) \
249 scoped_ptr<Type> quad_all(Type::Create()); \
252 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
253 quad_visible_rect, needs_blending, \
254 a, b, c, d, e, f, g); \
256 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
258 #define CREATE_QUAD_7_NEW_1(Type, a, b, c, d, e, f, g, copy_a) \
259 scoped_ptr<Type> quad_new(Type::Create()); \
262 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f, g); \
264 SETUP_AND_COPY_QUAD_NEW_1(Type, quad_new, copy_a);
266 #define CREATE_QUAD_7_ALL_1(Type, a, b, c, d, e, f, g, copy_a) \
267 scoped_ptr<Type> quad_all(Type::Create()); \
270 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
271 quad_visible_rect, needs_blending, \
272 a, b, c, d, e, f, g); \
274 SETUP_AND_COPY_QUAD_ALL_1(Type, quad_all, copy_a);
276 #define CREATE_QUAD_8_NEW(Type, a, b, c, d, e, f, g, h) \
277 scoped_ptr<Type> quad_new(Type::Create()); \
280 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f, g, h); \
282 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
284 #define CREATE_QUAD_8_ALL(Type, a, b, c, d, e, f, g, h) \
285 scoped_ptr<Type> quad_all(Type::Create()); \
288 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
289 quad_visible_rect, needs_blending, \
290 a, b, c, d, e, f, g, h); \
292 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
294 #define CREATE_QUAD_8_NEW_1(Type, a, b, c, d, e, f, g, h, copy_a) \
295 scoped_ptr<Type> quad_new(Type::Create()); \
298 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f, g, h); \
300 SETUP_AND_COPY_QUAD_NEW_1(Type, quad_new, copy_a);
302 #define CREATE_QUAD_8_ALL_1(Type, a, b, c, d, e, f, g, h, copy_a) \
303 scoped_ptr<Type> quad_all(Type::Create()); \
306 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
307 quad_visible_rect, needs_blending, \
308 a, b, c, d, e, f, g, h); \
310 SETUP_AND_COPY_QUAD_ALL_1(Type, quad_all, copy_a);
312 #define CREATE_QUAD_9_NEW(Type, a, b, c, d, e, f, g, h, i) \
313 scoped_ptr<Type> quad_new(Type::Create()); \
316 quad_new->SetNew(shared_state.get(), quad_rect, \
317 a, b, c, d, e, f, g, h, i); \
319 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
321 #define CREATE_QUAD_9_ALL(Type, a, b, c, d, e, f, g, h, i) \
322 scoped_ptr<Type> quad_all(Type::Create()); \
325 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
326 quad_visible_rect, needs_blending, \
327 a, b, c, d, e, f, g, h, i); \
329 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
331 TEST(DrawQuadTest
, CopyCheckerboardDrawQuad
) {
332 gfx::Rect
visible_rect(40, 50, 30, 20);
333 SkColor color
= 0xfabb0011;
334 CREATE_SHARED_STATE();
336 CREATE_QUAD_2_NEW(CheckerboardDrawQuad
, visible_rect
, color
);
337 EXPECT_EQ(DrawQuad::CHECKERBOARD
, copy_quad
->material
);
338 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
339 EXPECT_EQ(color
, copy_quad
->color
);
341 CREATE_QUAD_1_ALL(CheckerboardDrawQuad
, color
);
342 EXPECT_EQ(DrawQuad::CHECKERBOARD
, copy_quad
->material
);
343 EXPECT_EQ(color
, copy_quad
->color
);
346 TEST(DrawQuadTest
, CopyDebugBorderDrawQuad
) {
347 gfx::Rect
visible_rect(40, 50, 30, 20);
348 SkColor color
= 0xfabb0011;
350 CREATE_SHARED_STATE();
352 CREATE_QUAD_3_NEW(DebugBorderDrawQuad
, visible_rect
, color
, width
);
353 EXPECT_EQ(DrawQuad::DEBUG_BORDER
, copy_quad
->material
);
354 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
355 EXPECT_EQ(color
, copy_quad
->color
);
356 EXPECT_EQ(width
, copy_quad
->width
);
358 CREATE_QUAD_2_ALL(DebugBorderDrawQuad
, color
, width
);
359 EXPECT_EQ(DrawQuad::DEBUG_BORDER
, copy_quad
->material
);
360 EXPECT_EQ(color
, copy_quad
->color
);
361 EXPECT_EQ(width
, copy_quad
->width
);
364 TEST(DrawQuadTest
, CopyIOSurfaceDrawQuad
) {
365 gfx::Rect
opaque_rect(33, 47, 10, 12);
366 gfx::Rect
visible_rect(40, 50, 30, 20);
367 gfx::Size
size(58, 95);
368 ResourceProvider::ResourceId resource_id
= 72;
369 IOSurfaceDrawQuad::Orientation orientation
= IOSurfaceDrawQuad::UNFLIPPED
;
370 CREATE_SHARED_STATE();
372 CREATE_QUAD_5_NEW(IOSurfaceDrawQuad
,
378 EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT
, copy_quad
->material
);
379 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
380 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
381 EXPECT_EQ(size
, copy_quad
->io_surface_size
);
382 EXPECT_EQ(resource_id
, copy_quad
->io_surface_resource_id
);
383 EXPECT_EQ(orientation
, copy_quad
->orientation
);
385 CREATE_QUAD_3_ALL(IOSurfaceDrawQuad
, size
, resource_id
, orientation
);
386 EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT
, copy_quad
->material
);
387 EXPECT_EQ(size
, copy_quad
->io_surface_size
);
388 EXPECT_EQ(resource_id
, copy_quad
->io_surface_resource_id
);
389 EXPECT_EQ(orientation
, copy_quad
->orientation
);
392 TEST(DrawQuadTest
, CopyRenderPassDrawQuad
) {
393 gfx::Rect
visible_rect(40, 50, 30, 20);
394 RenderPass::Id
render_pass_id(22, 64);
395 bool is_replica
= true;
396 ResourceProvider::ResourceId mask_resource_id
= 78;
397 gfx::Rect
contents_changed_since_last_frame(42, 11, 74, 24);
398 gfx::RectF
mask_u_v_rect(-45.f
, -21.f
, 33.f
, 19.f
);
399 FilterOperations filters
;
400 filters
.Append(FilterOperation::CreateBlurFilter(1.f
));
401 FilterOperations background_filters
;
402 background_filters
.Append(
403 FilterOperation::CreateGrayscaleFilter(1.f
));
405 RenderPass::Id
copied_render_pass_id(235, 11);
406 CREATE_SHARED_STATE();
408 CREATE_QUAD_8_NEW_1(RenderPassDrawQuad
,
413 contents_changed_since_last_frame
,
417 copied_render_pass_id
);
418 EXPECT_EQ(DrawQuad::RENDER_PASS
, copy_quad
->material
);
419 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
420 EXPECT_EQ(copied_render_pass_id
, copy_quad
->render_pass_id
);
421 EXPECT_EQ(is_replica
, copy_quad
->is_replica
);
422 EXPECT_EQ(mask_resource_id
, copy_quad
->mask_resource_id
);
423 EXPECT_RECT_EQ(contents_changed_since_last_frame
,
424 copy_quad
->contents_changed_since_last_frame
);
425 EXPECT_EQ(mask_u_v_rect
.ToString(), copy_quad
->mask_uv_rect
.ToString());
426 EXPECT_EQ(filters
, copy_quad
->filters
);
427 EXPECT_EQ(background_filters
, copy_quad
->background_filters
);
429 CREATE_QUAD_7_ALL_1(RenderPassDrawQuad
,
433 contents_changed_since_last_frame
,
437 copied_render_pass_id
);
438 EXPECT_EQ(DrawQuad::RENDER_PASS
, copy_quad
->material
);
439 EXPECT_EQ(copied_render_pass_id
, copy_quad
->render_pass_id
);
440 EXPECT_EQ(is_replica
, copy_quad
->is_replica
);
441 EXPECT_EQ(mask_resource_id
, copy_quad
->mask_resource_id
);
442 EXPECT_RECT_EQ(contents_changed_since_last_frame
,
443 copy_quad
->contents_changed_since_last_frame
);
444 EXPECT_EQ(mask_u_v_rect
.ToString(), copy_quad
->mask_uv_rect
.ToString());
445 EXPECT_EQ(filters
, copy_quad
->filters
);
446 EXPECT_EQ(background_filters
, copy_quad
->background_filters
);
449 TEST(DrawQuadTest
, CopySolidColorDrawQuad
) {
450 gfx::Rect
visible_rect(40, 50, 30, 20);
451 SkColor color
= 0x49494949;
452 bool force_anti_aliasing_off
= false;
453 CREATE_SHARED_STATE();
456 SolidColorDrawQuad
, visible_rect
, color
, force_anti_aliasing_off
);
457 EXPECT_EQ(DrawQuad::SOLID_COLOR
, copy_quad
->material
);
458 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
459 EXPECT_EQ(color
, copy_quad
->color
);
460 EXPECT_EQ(force_anti_aliasing_off
, copy_quad
->force_anti_aliasing_off
);
462 CREATE_QUAD_2_ALL(SolidColorDrawQuad
, color
, force_anti_aliasing_off
);
463 EXPECT_EQ(DrawQuad::SOLID_COLOR
, copy_quad
->material
);
464 EXPECT_EQ(color
, copy_quad
->color
);
465 EXPECT_EQ(force_anti_aliasing_off
, copy_quad
->force_anti_aliasing_off
);
468 TEST(DrawQuadTest
, CopyStreamVideoDrawQuad
) {
469 gfx::Rect
opaque_rect(33, 47, 10, 12);
470 gfx::Rect
visible_rect(40, 50, 30, 20);
471 ResourceProvider::ResourceId resource_id
= 64;
472 gfx::Transform matrix
= gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
473 CREATE_SHARED_STATE();
476 StreamVideoDrawQuad
, opaque_rect
, visible_rect
, resource_id
, matrix
);
477 EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT
, copy_quad
->material
);
478 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
479 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
480 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
481 EXPECT_EQ(matrix
, copy_quad
->matrix
);
483 CREATE_QUAD_2_ALL(StreamVideoDrawQuad
, resource_id
, matrix
);
484 EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT
, copy_quad
->material
);
485 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
486 EXPECT_EQ(matrix
, copy_quad
->matrix
);
489 TEST(DrawQuadTest
, CopySurfaceDrawQuad
) {
490 gfx::Rect
visible_rect(40, 50, 30, 20);
491 int surface_id
= 1234;
492 CREATE_SHARED_STATE();
494 CREATE_QUAD_2_NEW(SurfaceDrawQuad
, visible_rect
, surface_id
);
495 EXPECT_EQ(DrawQuad::SURFACE_CONTENT
, copy_quad
->material
);
496 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
497 EXPECT_EQ(surface_id
, copy_quad
->surface_id
);
499 CREATE_QUAD_1_ALL(SurfaceDrawQuad
, surface_id
);
500 EXPECT_EQ(DrawQuad::SURFACE_CONTENT
, copy_quad
->material
);
501 EXPECT_EQ(surface_id
, copy_quad
->surface_id
);
505 TEST(DrawQuadTest
, CopyTextureDrawQuad
) {
506 gfx::Rect
opaque_rect(33, 47, 10, 12);
507 gfx::Rect
visible_rect(40, 50, 30, 20);
508 unsigned resource_id
= 82;
509 bool premultiplied_alpha
= true;
510 gfx::PointF
uv_top_left(0.5f
, 224.f
);
511 gfx::PointF
uv_bottom_right(51.5f
, 260.f
);
512 const float vertex_opacity
[] = { 1.0f
, 1.0f
, 1.0f
, 1.0f
};
514 CREATE_SHARED_STATE();
516 CREATE_QUAD_9_NEW(TextureDrawQuad
,
526 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT
, copy_quad
->material
);
527 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
528 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
529 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
530 EXPECT_EQ(premultiplied_alpha
, copy_quad
->premultiplied_alpha
);
531 EXPECT_EQ(uv_top_left
, copy_quad
->uv_top_left
);
532 EXPECT_EQ(uv_bottom_right
, copy_quad
->uv_bottom_right
);
533 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity
, copy_quad
->vertex_opacity
, 4);
534 EXPECT_EQ(flipped
, copy_quad
->flipped
);
536 CREATE_QUAD_7_ALL(TextureDrawQuad
,
544 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT
, copy_quad
->material
);
545 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
546 EXPECT_EQ(premultiplied_alpha
, copy_quad
->premultiplied_alpha
);
547 EXPECT_EQ(uv_top_left
, copy_quad
->uv_top_left
);
548 EXPECT_EQ(uv_bottom_right
, copy_quad
->uv_bottom_right
);
549 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity
, copy_quad
->vertex_opacity
, 4);
550 EXPECT_EQ(flipped
, copy_quad
->flipped
);
553 TEST(DrawQuadTest
, CopyTileDrawQuad
) {
554 gfx::Rect
opaque_rect(33, 44, 22, 33);
555 gfx::Rect
visible_rect(40, 50, 30, 20);
556 unsigned resource_id
= 104;
557 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
558 gfx::Size
texture_size(85, 32);
559 bool swizzle_contents
= true;
560 CREATE_SHARED_STATE();
562 CREATE_QUAD_6_NEW(TileDrawQuad
,
569 EXPECT_EQ(DrawQuad::TILED_CONTENT
, copy_quad
->material
);
570 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
571 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
572 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
573 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
574 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
575 EXPECT_EQ(swizzle_contents
, copy_quad
->swizzle_contents
);
577 CREATE_QUAD_4_ALL(TileDrawQuad
,
582 EXPECT_EQ(DrawQuad::TILED_CONTENT
, copy_quad
->material
);
583 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
584 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
585 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
586 EXPECT_EQ(swizzle_contents
, copy_quad
->swizzle_contents
);
589 TEST(DrawQuadTest
, CopyYUVVideoDrawQuad
) {
590 gfx::Rect
opaque_rect(33, 47, 10, 12);
591 gfx::Rect
visible_rect(40, 50, 30, 20);
592 gfx::RectF
tex_coord_rect(0.0f
, 0.0f
, 0.75f
, 0.5f
);
593 ResourceProvider::ResourceId y_plane_resource_id
= 45;
594 ResourceProvider::ResourceId u_plane_resource_id
= 532;
595 ResourceProvider::ResourceId v_plane_resource_id
= 4;
596 ResourceProvider::ResourceId a_plane_resource_id
= 63;
597 YUVVideoDrawQuad::ColorSpace color_space
= YUVVideoDrawQuad::REC_601_JPEG
;
598 CREATE_SHARED_STATE();
600 CREATE_QUAD_8_NEW(YUVVideoDrawQuad
,
609 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
610 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
611 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
612 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
613 EXPECT_EQ(y_plane_resource_id
, copy_quad
->y_plane_resource_id
);
614 EXPECT_EQ(u_plane_resource_id
, copy_quad
->u_plane_resource_id
);
615 EXPECT_EQ(v_plane_resource_id
, copy_quad
->v_plane_resource_id
);
616 EXPECT_EQ(a_plane_resource_id
, copy_quad
->a_plane_resource_id
);
617 EXPECT_EQ(color_space
, copy_quad
->color_space
);
619 CREATE_QUAD_6_ALL(YUVVideoDrawQuad
,
626 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
627 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
628 EXPECT_EQ(y_plane_resource_id
, copy_quad
->y_plane_resource_id
);
629 EXPECT_EQ(u_plane_resource_id
, copy_quad
->u_plane_resource_id
);
630 EXPECT_EQ(v_plane_resource_id
, copy_quad
->v_plane_resource_id
);
631 EXPECT_EQ(a_plane_resource_id
, copy_quad
->a_plane_resource_id
);
632 EXPECT_EQ(color_space
, copy_quad
->color_space
);
635 TEST(DrawQuadTest
, CopyPictureDrawQuad
) {
636 gfx::Rect
opaque_rect(33, 44, 22, 33);
637 gfx::Rect
visible_rect(40, 50, 30, 20);
638 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
639 gfx::Size
texture_size(85, 32);
640 ResourceFormat texture_format
= RGBA_8888
;
641 gfx::Rect
content_rect(30, 40, 20, 30);
642 float contents_scale
= 3.141592f
;
643 scoped_refptr
<PicturePileImpl
> picture_pile
= PicturePileImpl::Create();
644 CREATE_SHARED_STATE();
646 CREATE_QUAD_8_NEW(PictureDrawQuad
,
655 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
, copy_quad
->material
);
656 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
657 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
658 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
659 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
660 EXPECT_EQ(texture_format
, copy_quad
->texture_format
);
661 EXPECT_RECT_EQ(content_rect
, copy_quad
->content_rect
);
662 EXPECT_EQ(contents_scale
, copy_quad
->contents_scale
);
663 EXPECT_EQ(picture_pile
, copy_quad
->picture_pile
);
665 CREATE_QUAD_6_ALL(PictureDrawQuad
,
672 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
, copy_quad
->material
);
673 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
674 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
675 EXPECT_EQ(texture_format
, copy_quad
->texture_format
);
676 EXPECT_RECT_EQ(content_rect
, copy_quad
->content_rect
);
677 EXPECT_EQ(contents_scale
, copy_quad
->contents_scale
);
678 EXPECT_EQ(picture_pile
, copy_quad
->picture_pile
);
681 class DrawQuadIteratorTest
: public testing::Test
{
683 ResourceProvider::ResourceId
IncrementResourceId(
684 ResourceProvider::ResourceId id
) {
689 int IterateAndCount(DrawQuad
* quad
) {
691 quad
->IterateResources(base::Bind(
692 &DrawQuadIteratorTest::IncrementResourceId
, base::Unretained(this)));
693 return num_resources_
;
700 TEST_F(DrawQuadIteratorTest
, CheckerboardDrawQuad
) {
701 gfx::Rect
visible_rect(40, 50, 30, 20);
702 SkColor color
= 0xfabb0011;
704 CREATE_SHARED_STATE();
705 CREATE_QUAD_2_NEW(CheckerboardDrawQuad
, visible_rect
, color
);
706 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
709 TEST_F(DrawQuadIteratorTest
, DebugBorderDrawQuad
) {
710 gfx::Rect
visible_rect(40, 50, 30, 20);
711 SkColor color
= 0xfabb0011;
714 CREATE_SHARED_STATE();
715 CREATE_QUAD_3_NEW(DebugBorderDrawQuad
, visible_rect
, color
, width
);
716 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
719 TEST_F(DrawQuadIteratorTest
, IOSurfaceDrawQuad
) {
720 gfx::Rect
opaque_rect(33, 47, 10, 12);
721 gfx::Rect
visible_rect(40, 50, 30, 20);
722 gfx::Size
size(58, 95);
723 ResourceProvider::ResourceId resource_id
= 72;
724 IOSurfaceDrawQuad::Orientation orientation
= IOSurfaceDrawQuad::UNFLIPPED
;
726 CREATE_SHARED_STATE();
727 CREATE_QUAD_5_NEW(IOSurfaceDrawQuad
,
733 EXPECT_EQ(resource_id
, quad_new
->io_surface_resource_id
);
734 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
735 EXPECT_EQ(resource_id
+ 1, quad_new
->io_surface_resource_id
);
738 TEST_F(DrawQuadIteratorTest
, RenderPassDrawQuad
) {
739 gfx::Rect
visible_rect(40, 50, 30, 20);
740 RenderPass::Id
render_pass_id(22, 64);
741 bool is_replica
= true;
742 ResourceProvider::ResourceId mask_resource_id
= 78;
743 gfx::Rect
contents_changed_since_last_frame(42, 11, 74, 24);
744 gfx::RectF
mask_u_v_rect(-45.f
, -21.f
, 33.f
, 19.f
);
745 FilterOperations filters
;
746 filters
.Append(FilterOperation::CreateBlurFilter(1.f
));
747 FilterOperations background_filters
;
748 background_filters
.Append(
749 FilterOperation::CreateGrayscaleFilter(1.f
));
751 RenderPass::Id
copied_render_pass_id(235, 11);
753 CREATE_SHARED_STATE();
754 CREATE_QUAD_8_NEW_1(RenderPassDrawQuad
,
759 contents_changed_since_last_frame
,
763 copied_render_pass_id
);
764 EXPECT_EQ(mask_resource_id
, quad_new
->mask_resource_id
);
765 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
766 EXPECT_EQ(mask_resource_id
+ 1, quad_new
->mask_resource_id
);
767 quad_new
->mask_resource_id
= 0;
768 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
769 EXPECT_EQ(0u, quad_new
->mask_resource_id
);
772 TEST_F(DrawQuadIteratorTest
, SolidColorDrawQuad
) {
773 gfx::Rect
visible_rect(40, 50, 30, 20);
774 SkColor color
= 0x49494949;
775 bool force_anti_aliasing_off
= false;
777 CREATE_SHARED_STATE();
779 SolidColorDrawQuad
, visible_rect
, color
, force_anti_aliasing_off
);
780 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
783 TEST_F(DrawQuadIteratorTest
, StreamVideoDrawQuad
) {
784 gfx::Rect
opaque_rect(33, 47, 10, 12);
785 gfx::Rect
visible_rect(40, 50, 30, 20);
786 ResourceProvider::ResourceId resource_id
= 64;
787 gfx::Transform matrix
= gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
789 CREATE_SHARED_STATE();
791 StreamVideoDrawQuad
, opaque_rect
, visible_rect
, resource_id
, matrix
);
792 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
793 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
794 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
797 TEST_F(DrawQuadIteratorTest
, SurfaceDrawQuad
) {
798 gfx::Rect
visible_rect(40, 50, 30, 20);
799 int surface_id
= 4321;
801 CREATE_SHARED_STATE();
802 CREATE_QUAD_2_NEW(SurfaceDrawQuad
, visible_rect
, surface_id
);
803 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
806 TEST_F(DrawQuadIteratorTest
, TextureDrawQuad
) {
807 gfx::Rect
opaque_rect(33, 47, 10, 12);
808 gfx::Rect
visible_rect(40, 50, 30, 20);
809 unsigned resource_id
= 82;
810 bool premultiplied_alpha
= true;
811 gfx::PointF
uv_top_left(0.5f
, 224.f
);
812 gfx::PointF
uv_bottom_right(51.5f
, 260.f
);
813 const float vertex_opacity
[] = { 1.0f
, 1.0f
, 1.0f
, 1.0f
};
816 CREATE_SHARED_STATE();
817 CREATE_QUAD_9_NEW(TextureDrawQuad
,
827 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
828 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
829 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
832 TEST_F(DrawQuadIteratorTest
, TileDrawQuad
) {
833 gfx::Rect
opaque_rect(33, 44, 22, 33);
834 gfx::Rect
visible_rect(40, 50, 30, 20);
835 unsigned resource_id
= 104;
836 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
837 gfx::Size
texture_size(85, 32);
838 bool swizzle_contents
= true;
840 CREATE_SHARED_STATE();
841 CREATE_QUAD_6_NEW(TileDrawQuad
,
848 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
849 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
850 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
853 TEST_F(DrawQuadIteratorTest
, YUVVideoDrawQuad
) {
854 gfx::Rect
opaque_rect(33, 47, 10, 12);
855 gfx::Rect
visible_rect(40, 50, 30, 20);
856 gfx::RectF
tex_coord_rect(0.0f
, 0.0f
, 0.75f
, 0.5f
);
857 ResourceProvider::ResourceId y_plane_resource_id
= 45;
858 ResourceProvider::ResourceId u_plane_resource_id
= 532;
859 ResourceProvider::ResourceId v_plane_resource_id
= 4;
860 ResourceProvider::ResourceId a_plane_resource_id
= 63;
861 YUVVideoDrawQuad::ColorSpace color_space
= YUVVideoDrawQuad::REC_601_JPEG
;
863 CREATE_SHARED_STATE();
864 CREATE_QUAD_8_NEW(YUVVideoDrawQuad
,
873 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
874 EXPECT_EQ(y_plane_resource_id
, quad_new
->y_plane_resource_id
);
875 EXPECT_EQ(u_plane_resource_id
, quad_new
->u_plane_resource_id
);
876 EXPECT_EQ(v_plane_resource_id
, quad_new
->v_plane_resource_id
);
877 EXPECT_EQ(a_plane_resource_id
, quad_new
->a_plane_resource_id
);
878 EXPECT_EQ(color_space
, quad_new
->color_space
);
879 EXPECT_EQ(4, IterateAndCount(quad_new
.get()));
880 EXPECT_EQ(y_plane_resource_id
+ 1, quad_new
->y_plane_resource_id
);
881 EXPECT_EQ(u_plane_resource_id
+ 1, quad_new
->u_plane_resource_id
);
882 EXPECT_EQ(v_plane_resource_id
+ 1, quad_new
->v_plane_resource_id
);
883 EXPECT_EQ(a_plane_resource_id
+ 1, quad_new
->a_plane_resource_id
);
886 // Disabled until picture draw quad is supported for ubercomp: crbug.com/231715
887 TEST_F(DrawQuadIteratorTest
, DISABLED_PictureDrawQuad
) {
888 gfx::Rect
opaque_rect(33, 44, 22, 33);
889 gfx::Rect
visible_rect(40, 50, 30, 20);
890 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
891 gfx::Size
texture_size(85, 32);
892 ResourceFormat texture_format
= RGBA_8888
;
893 gfx::Rect
content_rect(30, 40, 20, 30);
894 float contents_scale
= 3.141592f
;
895 scoped_refptr
<PicturePileImpl
> picture_pile
= PicturePileImpl::Create();
897 CREATE_SHARED_STATE();
898 CREATE_QUAD_8_NEW(PictureDrawQuad
,
907 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));