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
;
41 int sorting_context_id
= 65536;
43 scoped_ptr
<SharedQuadState
> state(new SharedQuadState
);
44 state
->SetAll(quad_transform
,
53 scoped_ptr
<SharedQuadState
> copy(new SharedQuadState
);
54 copy
->CopyFrom(state
.get());
55 EXPECT_EQ(quad_transform
, copy
->content_to_target_transform
);
56 EXPECT_RECT_EQ(visible_content_rect
, copy
->visible_content_rect
);
57 EXPECT_EQ(opacity
, copy
->opacity
);
58 EXPECT_RECT_EQ(clip_rect
, copy
->clip_rect
);
59 EXPECT_EQ(is_clipped
, copy
->is_clipped
);
60 EXPECT_EQ(blend_mode
, copy
->blend_mode
);
63 scoped_ptr
<SharedQuadState
> CreateSharedQuadState() {
64 gfx::Transform quad_transform
= gfx::Transform(1.0, 0.0, 0.5, 1.0, 0.5, 0.0);
65 gfx::Size
content_bounds(26, 28);
66 gfx::Rect
visible_content_rect(10, 12, 14, 16);
67 gfx::Rect
clip_rect(19, 21, 23, 25);
68 bool is_clipped
= false;
70 int sorting_context_id
= 65536;
71 SkXfermode::Mode blend_mode
= SkXfermode::kSrcOver_Mode
;
73 scoped_ptr
<SharedQuadState
> state(new SharedQuadState
);
74 state
->SetAll(quad_transform
,
85 void CompareDrawQuad(DrawQuad
* quad
,
87 SharedQuadState
* copy_shared_state
) {
88 EXPECT_EQ(quad
->material
, copy
->material
);
89 EXPECT_RECT_EQ(quad
->rect
, copy
->rect
);
90 EXPECT_RECT_EQ(quad
->visible_rect
, copy
->visible_rect
);
91 EXPECT_RECT_EQ(quad
->opaque_rect
, copy
->opaque_rect
);
92 EXPECT_EQ(quad
->needs_blending
, copy
->needs_blending
);
93 EXPECT_EQ(copy_shared_state
, copy
->shared_quad_state
);
96 #define CREATE_SHARED_STATE() \
97 scoped_ptr<SharedQuadState> shared_state(CreateSharedQuadState()); \
98 scoped_ptr<SharedQuadState> copy_shared_state(new SharedQuadState); \
99 copy_shared_state->CopyFrom(shared_state.get());
102 gfx::Rect quad_rect(30, 40, 50, 60); \
103 gfx::Rect quad_visible_rect(40, 50, 30, 20); \
104 gfx::Rect ALLOW_UNUSED quad_opaque_rect(60, 55, 10, 10); \
105 bool ALLOW_UNUSED needs_blending = true;
107 #define SETUP_AND_COPY_QUAD_NEW(Type, quad) \
108 scoped_ptr<DrawQuad> copy_new(quad_new->Copy(copy_shared_state.get())); \
109 CompareDrawQuad(quad_new.get(), copy_new.get(), copy_shared_state.get()); \
110 const Type* ALLOW_UNUSED copy_quad = Type::MaterialCast(copy_new.get());
112 #define SETUP_AND_COPY_QUAD_ALL(Type, quad) \
113 scoped_ptr<DrawQuad> copy_all(quad_all->Copy(copy_shared_state.get())); \
114 CompareDrawQuad(quad_all.get(), copy_all.get(), copy_shared_state.get()); \
115 copy_quad = Type::MaterialCast(copy_all.get());
117 #define SETUP_AND_COPY_QUAD_NEW_1(Type, quad, a) \
118 scoped_ptr<DrawQuad> copy_new(quad_new->Copy(copy_shared_state.get(), a)); \
119 CompareDrawQuad(quad_new.get(), copy_new.get(), copy_shared_state.get()); \
120 const Type* ALLOW_UNUSED copy_quad = Type::MaterialCast(copy_new.get());
122 #define SETUP_AND_COPY_QUAD_ALL_1(Type, quad, a) \
123 scoped_ptr<DrawQuad> copy_all(quad_all->Copy(copy_shared_state.get(), a)); \
124 CompareDrawQuad(quad_all.get(), copy_all.get(), copy_shared_state.get()); \
125 copy_quad = Type::MaterialCast(copy_all.get());
127 #define CREATE_QUAD_1_NEW(Type, a) \
128 scoped_ptr<Type> quad_new(Type::Create()); \
131 quad_new->SetNew(shared_state.get(), quad_rect, a); \
133 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
135 #define CREATE_QUAD_1_ALL(Type, a) \
136 scoped_ptr<Type> quad_all(Type::Create()); \
139 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
140 quad_visible_rect, needs_blending, a); \
142 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
144 #define CREATE_QUAD_2_NEW(Type, a, b) \
145 scoped_ptr<Type> quad_new(Type::Create()); \
148 quad_new->SetNew(shared_state.get(), quad_rect, a, b); \
150 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
152 #define CREATE_QUAD_2_ALL(Type, a, b) \
153 scoped_ptr<Type> quad_all(Type::Create()); \
156 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
157 quad_visible_rect, needs_blending, a, b); \
159 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
161 #define CREATE_QUAD_3_NEW(Type, a, b, c) \
162 scoped_ptr<Type> quad_new(Type::Create()); \
165 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c); \
167 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
169 #define CREATE_QUAD_3_ALL(Type, a, b, c) \
170 scoped_ptr<Type> quad_all(Type::Create()); \
173 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
174 quad_visible_rect, needs_blending, a, b, c); \
176 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
178 #define CREATE_QUAD_4_NEW(Type, a, b, c, d) \
179 scoped_ptr<Type> quad_new(Type::Create()); \
182 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d); \
184 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
186 #define CREATE_QUAD_4_ALL(Type, a, b, c, d) \
187 scoped_ptr<Type> quad_all(Type::Create()); \
190 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
191 quad_visible_rect, needs_blending, a, b, c, d); \
193 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
195 #define CREATE_QUAD_5_NEW(Type, a, b, c, d, e) \
196 scoped_ptr<Type> quad_new(Type::Create()); \
199 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e); \
201 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
203 #define CREATE_QUAD_5_ALL(Type, a, b, c, d, e) \
204 scoped_ptr<Type> quad_all(Type::Create()); \
207 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
208 quad_visible_rect, needs_blending, a, b, c, d, e); \
210 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
212 #define CREATE_QUAD_5_NEW_1(Type, a, b, c, d, e, copy_a) \
213 scoped_ptr<Type> quad_new(Type::Create()); \
216 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e); \
218 SETUP_AND_COPY_QUAD_NEW_1(Type, quad_new, copy_a);
220 #define CREATE_QUAD_5_ALL_1(Type, a, b, c, d, e, copy_a) \
221 scoped_ptr<Type> quad_all(Type::Create()); \
224 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
225 quad_visible_rect, needs_blending, a, b, c, d, e); \
227 SETUP_AND_COPY_QUAD_ALL_1(Type, quad_all, copy_a);
229 #define CREATE_QUAD_6_NEW(Type, a, b, c, d, e, f) \
230 scoped_ptr<Type> quad_new(Type::Create()); \
233 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f); \
235 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
237 #define CREATE_QUAD_6_ALL(Type, a, b, c, d, e, f) \
238 scoped_ptr<Type> quad_all(Type::Create()); \
241 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
242 quad_visible_rect, needs_blending, a, b, c, d, e, f); \
244 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
246 #define CREATE_QUAD_7_NEW(Type, a, b, c, d, e, f, g) \
247 scoped_ptr<Type> quad_new(Type::Create()); \
250 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f, g); \
252 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
254 #define CREATE_QUAD_7_ALL(Type, a, b, c, d, e, f, g) \
255 scoped_ptr<Type> quad_all(Type::Create()); \
258 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
259 quad_visible_rect, needs_blending, \
260 a, b, c, d, e, f, g); \
262 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
264 #define CREATE_QUAD_7_NEW_1(Type, a, b, c, d, e, f, g, copy_a) \
265 scoped_ptr<Type> quad_new(Type::Create()); \
268 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f, g); \
270 SETUP_AND_COPY_QUAD_NEW_1(Type, quad_new, copy_a);
272 #define CREATE_QUAD_7_ALL_1(Type, a, b, c, d, e, f, g, copy_a) \
273 scoped_ptr<Type> quad_all(Type::Create()); \
276 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
277 quad_visible_rect, needs_blending, \
278 a, b, c, d, e, f, g); \
280 SETUP_AND_COPY_QUAD_ALL_1(Type, quad_all, copy_a);
282 #define CREATE_QUAD_8_NEW(Type, a, b, c, d, e, f, g, h) \
283 scoped_ptr<Type> quad_new(Type::Create()); \
286 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f, g, h); \
288 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
290 #define CREATE_QUAD_8_ALL(Type, a, b, c, d, e, f, g, h) \
291 scoped_ptr<Type> quad_all(Type::Create()); \
294 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
295 quad_visible_rect, needs_blending, \
296 a, b, c, d, e, f, g, h); \
298 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
300 #define CREATE_QUAD_8_NEW_1(Type, a, b, c, d, e, f, g, h, copy_a) \
301 scoped_ptr<Type> quad_new(Type::Create()); \
304 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f, g, h); \
306 SETUP_AND_COPY_QUAD_NEW_1(Type, quad_new, copy_a);
308 #define CREATE_QUAD_8_ALL_1(Type, a, b, c, d, e, f, g, h, copy_a) \
309 scoped_ptr<Type> quad_all(Type::Create()); \
312 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
313 quad_visible_rect, needs_blending, \
314 a, b, c, d, e, f, g, h); \
316 SETUP_AND_COPY_QUAD_ALL_1(Type, quad_all, copy_a);
318 #define CREATE_QUAD_9_NEW(Type, a, b, c, d, e, f, g, h, i) \
319 scoped_ptr<Type> quad_new(Type::Create()); \
322 quad_new->SetNew(shared_state.get(), quad_rect, \
323 a, b, c, d, e, f, g, h, i); \
325 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
327 #define CREATE_QUAD_9_ALL(Type, a, b, c, d, e, f, g, h, i) \
328 scoped_ptr<Type> quad_all(Type::Create()); \
331 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
332 quad_visible_rect, needs_blending, \
333 a, b, c, d, e, f, g, h, i); \
335 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
337 TEST(DrawQuadTest
, CopyCheckerboardDrawQuad
) {
338 gfx::Rect
visible_rect(40, 50, 30, 20);
339 SkColor color
= 0xfabb0011;
340 CREATE_SHARED_STATE();
342 CREATE_QUAD_2_NEW(CheckerboardDrawQuad
, visible_rect
, color
);
343 EXPECT_EQ(DrawQuad::CHECKERBOARD
, copy_quad
->material
);
344 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
345 EXPECT_EQ(color
, copy_quad
->color
);
347 CREATE_QUAD_1_ALL(CheckerboardDrawQuad
, color
);
348 EXPECT_EQ(DrawQuad::CHECKERBOARD
, copy_quad
->material
);
349 EXPECT_EQ(color
, copy_quad
->color
);
352 TEST(DrawQuadTest
, CopyDebugBorderDrawQuad
) {
353 gfx::Rect
visible_rect(40, 50, 30, 20);
354 SkColor color
= 0xfabb0011;
356 CREATE_SHARED_STATE();
358 CREATE_QUAD_3_NEW(DebugBorderDrawQuad
, visible_rect
, color
, width
);
359 EXPECT_EQ(DrawQuad::DEBUG_BORDER
, copy_quad
->material
);
360 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
361 EXPECT_EQ(color
, copy_quad
->color
);
362 EXPECT_EQ(width
, copy_quad
->width
);
364 CREATE_QUAD_2_ALL(DebugBorderDrawQuad
, color
, width
);
365 EXPECT_EQ(DrawQuad::DEBUG_BORDER
, copy_quad
->material
);
366 EXPECT_EQ(color
, copy_quad
->color
);
367 EXPECT_EQ(width
, copy_quad
->width
);
370 TEST(DrawQuadTest
, CopyIOSurfaceDrawQuad
) {
371 gfx::Rect
opaque_rect(33, 47, 10, 12);
372 gfx::Rect
visible_rect(40, 50, 30, 20);
373 gfx::Size
size(58, 95);
374 ResourceProvider::ResourceId resource_id
= 72;
375 IOSurfaceDrawQuad::Orientation orientation
= IOSurfaceDrawQuad::UNFLIPPED
;
376 CREATE_SHARED_STATE();
378 CREATE_QUAD_5_NEW(IOSurfaceDrawQuad
,
384 EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT
, copy_quad
->material
);
385 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
386 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
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
);
391 CREATE_QUAD_3_ALL(IOSurfaceDrawQuad
, size
, resource_id
, orientation
);
392 EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT
, copy_quad
->material
);
393 EXPECT_EQ(size
, copy_quad
->io_surface_size
);
394 EXPECT_EQ(resource_id
, copy_quad
->io_surface_resource_id
);
395 EXPECT_EQ(orientation
, copy_quad
->orientation
);
398 TEST(DrawQuadTest
, CopyRenderPassDrawQuad
) {
399 gfx::Rect
visible_rect(40, 50, 30, 20);
400 RenderPass::Id
render_pass_id(22, 64);
401 bool is_replica
= true;
402 ResourceProvider::ResourceId mask_resource_id
= 78;
403 gfx::Rect
contents_changed_since_last_frame(42, 11, 74, 24);
404 gfx::RectF
mask_u_v_rect(-45.f
, -21.f
, 33.f
, 19.f
);
405 FilterOperations filters
;
406 filters
.Append(FilterOperation::CreateBlurFilter(1.f
));
407 FilterOperations background_filters
;
408 background_filters
.Append(
409 FilterOperation::CreateGrayscaleFilter(1.f
));
411 RenderPass::Id
copied_render_pass_id(235, 11);
412 CREATE_SHARED_STATE();
414 CREATE_QUAD_8_NEW_1(RenderPassDrawQuad
,
419 contents_changed_since_last_frame
,
423 copied_render_pass_id
);
424 EXPECT_EQ(DrawQuad::RENDER_PASS
, copy_quad
->material
);
425 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
426 EXPECT_EQ(copied_render_pass_id
, copy_quad
->render_pass_id
);
427 EXPECT_EQ(is_replica
, copy_quad
->is_replica
);
428 EXPECT_EQ(mask_resource_id
, copy_quad
->mask_resource_id
);
429 EXPECT_RECT_EQ(contents_changed_since_last_frame
,
430 copy_quad
->contents_changed_since_last_frame
);
431 EXPECT_EQ(mask_u_v_rect
.ToString(), copy_quad
->mask_uv_rect
.ToString());
432 EXPECT_EQ(filters
, copy_quad
->filters
);
433 EXPECT_EQ(background_filters
, copy_quad
->background_filters
);
435 CREATE_QUAD_7_ALL_1(RenderPassDrawQuad
,
439 contents_changed_since_last_frame
,
443 copied_render_pass_id
);
444 EXPECT_EQ(DrawQuad::RENDER_PASS
, copy_quad
->material
);
445 EXPECT_EQ(copied_render_pass_id
, copy_quad
->render_pass_id
);
446 EXPECT_EQ(is_replica
, copy_quad
->is_replica
);
447 EXPECT_EQ(mask_resource_id
, copy_quad
->mask_resource_id
);
448 EXPECT_RECT_EQ(contents_changed_since_last_frame
,
449 copy_quad
->contents_changed_since_last_frame
);
450 EXPECT_EQ(mask_u_v_rect
.ToString(), copy_quad
->mask_uv_rect
.ToString());
451 EXPECT_EQ(filters
, copy_quad
->filters
);
452 EXPECT_EQ(background_filters
, copy_quad
->background_filters
);
455 TEST(DrawQuadTest
, CopySolidColorDrawQuad
) {
456 gfx::Rect
visible_rect(40, 50, 30, 20);
457 SkColor color
= 0x49494949;
458 bool force_anti_aliasing_off
= false;
459 CREATE_SHARED_STATE();
462 SolidColorDrawQuad
, visible_rect
, color
, force_anti_aliasing_off
);
463 EXPECT_EQ(DrawQuad::SOLID_COLOR
, copy_quad
->material
);
464 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
465 EXPECT_EQ(color
, copy_quad
->color
);
466 EXPECT_EQ(force_anti_aliasing_off
, copy_quad
->force_anti_aliasing_off
);
468 CREATE_QUAD_2_ALL(SolidColorDrawQuad
, color
, force_anti_aliasing_off
);
469 EXPECT_EQ(DrawQuad::SOLID_COLOR
, copy_quad
->material
);
470 EXPECT_EQ(color
, copy_quad
->color
);
471 EXPECT_EQ(force_anti_aliasing_off
, copy_quad
->force_anti_aliasing_off
);
474 TEST(DrawQuadTest
, CopyStreamVideoDrawQuad
) {
475 gfx::Rect
opaque_rect(33, 47, 10, 12);
476 gfx::Rect
visible_rect(40, 50, 30, 20);
477 ResourceProvider::ResourceId resource_id
= 64;
478 gfx::Transform matrix
= gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
479 CREATE_SHARED_STATE();
482 StreamVideoDrawQuad
, opaque_rect
, visible_rect
, resource_id
, matrix
);
483 EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT
, copy_quad
->material
);
484 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
485 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
486 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
487 EXPECT_EQ(matrix
, copy_quad
->matrix
);
489 CREATE_QUAD_2_ALL(StreamVideoDrawQuad
, resource_id
, matrix
);
490 EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT
, copy_quad
->material
);
491 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
492 EXPECT_EQ(matrix
, copy_quad
->matrix
);
495 TEST(DrawQuadTest
, CopySurfaceDrawQuad
) {
496 gfx::Rect
visible_rect(40, 50, 30, 20);
497 SurfaceId
surface_id(1234);
498 CREATE_SHARED_STATE();
500 CREATE_QUAD_2_NEW(SurfaceDrawQuad
, visible_rect
, surface_id
);
501 EXPECT_EQ(DrawQuad::SURFACE_CONTENT
, copy_quad
->material
);
502 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
503 EXPECT_EQ(surface_id
, copy_quad
->surface_id
);
505 CREATE_QUAD_1_ALL(SurfaceDrawQuad
, surface_id
);
506 EXPECT_EQ(DrawQuad::SURFACE_CONTENT
, copy_quad
->material
);
507 EXPECT_EQ(surface_id
, copy_quad
->surface_id
);
511 TEST(DrawQuadTest
, CopyTextureDrawQuad
) {
512 gfx::Rect
opaque_rect(33, 47, 10, 12);
513 gfx::Rect
visible_rect(40, 50, 30, 20);
514 unsigned resource_id
= 82;
515 bool premultiplied_alpha
= true;
516 gfx::PointF
uv_top_left(0.5f
, 224.f
);
517 gfx::PointF
uv_bottom_right(51.5f
, 260.f
);
518 const float vertex_opacity
[] = { 1.0f
, 1.0f
, 1.0f
, 1.0f
};
520 CREATE_SHARED_STATE();
522 CREATE_QUAD_9_NEW(TextureDrawQuad
,
532 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT
, copy_quad
->material
);
533 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
534 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
535 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
536 EXPECT_EQ(premultiplied_alpha
, copy_quad
->premultiplied_alpha
);
537 EXPECT_EQ(uv_top_left
, copy_quad
->uv_top_left
);
538 EXPECT_EQ(uv_bottom_right
, copy_quad
->uv_bottom_right
);
539 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity
, copy_quad
->vertex_opacity
, 4);
540 EXPECT_EQ(flipped
, copy_quad
->flipped
);
542 CREATE_QUAD_7_ALL(TextureDrawQuad
,
550 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT
, copy_quad
->material
);
551 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
552 EXPECT_EQ(premultiplied_alpha
, copy_quad
->premultiplied_alpha
);
553 EXPECT_EQ(uv_top_left
, copy_quad
->uv_top_left
);
554 EXPECT_EQ(uv_bottom_right
, copy_quad
->uv_bottom_right
);
555 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity
, copy_quad
->vertex_opacity
, 4);
556 EXPECT_EQ(flipped
, copy_quad
->flipped
);
559 TEST(DrawQuadTest
, CopyTileDrawQuad
) {
560 gfx::Rect
opaque_rect(33, 44, 22, 33);
561 gfx::Rect
visible_rect(40, 50, 30, 20);
562 unsigned resource_id
= 104;
563 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
564 gfx::Size
texture_size(85, 32);
565 bool swizzle_contents
= true;
566 CREATE_SHARED_STATE();
568 CREATE_QUAD_6_NEW(TileDrawQuad
,
575 EXPECT_EQ(DrawQuad::TILED_CONTENT
, copy_quad
->material
);
576 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
577 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
578 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
579 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
580 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
581 EXPECT_EQ(swizzle_contents
, copy_quad
->swizzle_contents
);
583 CREATE_QUAD_4_ALL(TileDrawQuad
,
588 EXPECT_EQ(DrawQuad::TILED_CONTENT
, copy_quad
->material
);
589 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
590 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
591 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
592 EXPECT_EQ(swizzle_contents
, copy_quad
->swizzle_contents
);
595 TEST(DrawQuadTest
, CopyYUVVideoDrawQuad
) {
596 gfx::Rect
opaque_rect(33, 47, 10, 12);
597 gfx::Rect
visible_rect(40, 50, 30, 20);
598 gfx::RectF
tex_coord_rect(0.0f
, 0.0f
, 0.75f
, 0.5f
);
599 ResourceProvider::ResourceId y_plane_resource_id
= 45;
600 ResourceProvider::ResourceId u_plane_resource_id
= 532;
601 ResourceProvider::ResourceId v_plane_resource_id
= 4;
602 ResourceProvider::ResourceId a_plane_resource_id
= 63;
603 YUVVideoDrawQuad::ColorSpace color_space
= YUVVideoDrawQuad::REC_601_JPEG
;
604 CREATE_SHARED_STATE();
606 CREATE_QUAD_8_NEW(YUVVideoDrawQuad
,
615 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
616 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
617 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
618 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
619 EXPECT_EQ(y_plane_resource_id
, copy_quad
->y_plane_resource_id
);
620 EXPECT_EQ(u_plane_resource_id
, copy_quad
->u_plane_resource_id
);
621 EXPECT_EQ(v_plane_resource_id
, copy_quad
->v_plane_resource_id
);
622 EXPECT_EQ(a_plane_resource_id
, copy_quad
->a_plane_resource_id
);
623 EXPECT_EQ(color_space
, copy_quad
->color_space
);
625 CREATE_QUAD_6_ALL(YUVVideoDrawQuad
,
632 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
633 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
634 EXPECT_EQ(y_plane_resource_id
, copy_quad
->y_plane_resource_id
);
635 EXPECT_EQ(u_plane_resource_id
, copy_quad
->u_plane_resource_id
);
636 EXPECT_EQ(v_plane_resource_id
, copy_quad
->v_plane_resource_id
);
637 EXPECT_EQ(a_plane_resource_id
, copy_quad
->a_plane_resource_id
);
638 EXPECT_EQ(color_space
, copy_quad
->color_space
);
641 TEST(DrawQuadTest
, CopyPictureDrawQuad
) {
642 gfx::Rect
opaque_rect(33, 44, 22, 33);
643 gfx::Rect
visible_rect(40, 50, 30, 20);
644 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
645 gfx::Size
texture_size(85, 32);
646 ResourceFormat texture_format
= RGBA_8888
;
647 gfx::Rect
content_rect(30, 40, 20, 30);
648 float contents_scale
= 3.141592f
;
649 scoped_refptr
<PicturePileImpl
> picture_pile
= PicturePileImpl::Create();
650 CREATE_SHARED_STATE();
652 CREATE_QUAD_8_NEW(PictureDrawQuad
,
661 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
, copy_quad
->material
);
662 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
663 EXPECT_RECT_EQ(visible_rect
, copy_quad
->visible_rect
);
664 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
665 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
666 EXPECT_EQ(texture_format
, copy_quad
->texture_format
);
667 EXPECT_RECT_EQ(content_rect
, copy_quad
->content_rect
);
668 EXPECT_EQ(contents_scale
, copy_quad
->contents_scale
);
669 EXPECT_EQ(picture_pile
, copy_quad
->picture_pile
);
671 CREATE_QUAD_6_ALL(PictureDrawQuad
,
678 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
, copy_quad
->material
);
679 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
680 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
681 EXPECT_EQ(texture_format
, copy_quad
->texture_format
);
682 EXPECT_RECT_EQ(content_rect
, copy_quad
->content_rect
);
683 EXPECT_EQ(contents_scale
, copy_quad
->contents_scale
);
684 EXPECT_EQ(picture_pile
, copy_quad
->picture_pile
);
687 class DrawQuadIteratorTest
: public testing::Test
{
689 ResourceProvider::ResourceId
IncrementResourceId(
690 ResourceProvider::ResourceId id
) {
695 int IterateAndCount(DrawQuad
* quad
) {
697 quad
->IterateResources(base::Bind(
698 &DrawQuadIteratorTest::IncrementResourceId
, base::Unretained(this)));
699 return num_resources_
;
706 TEST_F(DrawQuadIteratorTest
, CheckerboardDrawQuad
) {
707 gfx::Rect
visible_rect(40, 50, 30, 20);
708 SkColor color
= 0xfabb0011;
710 CREATE_SHARED_STATE();
711 CREATE_QUAD_2_NEW(CheckerboardDrawQuad
, visible_rect
, color
);
712 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
715 TEST_F(DrawQuadIteratorTest
, DebugBorderDrawQuad
) {
716 gfx::Rect
visible_rect(40, 50, 30, 20);
717 SkColor color
= 0xfabb0011;
720 CREATE_SHARED_STATE();
721 CREATE_QUAD_3_NEW(DebugBorderDrawQuad
, visible_rect
, color
, width
);
722 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
725 TEST_F(DrawQuadIteratorTest
, IOSurfaceDrawQuad
) {
726 gfx::Rect
opaque_rect(33, 47, 10, 12);
727 gfx::Rect
visible_rect(40, 50, 30, 20);
728 gfx::Size
size(58, 95);
729 ResourceProvider::ResourceId resource_id
= 72;
730 IOSurfaceDrawQuad::Orientation orientation
= IOSurfaceDrawQuad::UNFLIPPED
;
732 CREATE_SHARED_STATE();
733 CREATE_QUAD_5_NEW(IOSurfaceDrawQuad
,
739 EXPECT_EQ(resource_id
, quad_new
->io_surface_resource_id
);
740 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
741 EXPECT_EQ(resource_id
+ 1, quad_new
->io_surface_resource_id
);
744 TEST_F(DrawQuadIteratorTest
, RenderPassDrawQuad
) {
745 gfx::Rect
visible_rect(40, 50, 30, 20);
746 RenderPass::Id
render_pass_id(22, 64);
747 bool is_replica
= true;
748 ResourceProvider::ResourceId mask_resource_id
= 78;
749 gfx::Rect
contents_changed_since_last_frame(42, 11, 74, 24);
750 gfx::RectF
mask_u_v_rect(-45.f
, -21.f
, 33.f
, 19.f
);
751 FilterOperations filters
;
752 filters
.Append(FilterOperation::CreateBlurFilter(1.f
));
753 FilterOperations background_filters
;
754 background_filters
.Append(
755 FilterOperation::CreateGrayscaleFilter(1.f
));
757 RenderPass::Id
copied_render_pass_id(235, 11);
759 CREATE_SHARED_STATE();
760 CREATE_QUAD_8_NEW_1(RenderPassDrawQuad
,
765 contents_changed_since_last_frame
,
769 copied_render_pass_id
);
770 EXPECT_EQ(mask_resource_id
, quad_new
->mask_resource_id
);
771 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
772 EXPECT_EQ(mask_resource_id
+ 1, quad_new
->mask_resource_id
);
773 quad_new
->mask_resource_id
= 0;
774 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
775 EXPECT_EQ(0u, quad_new
->mask_resource_id
);
778 TEST_F(DrawQuadIteratorTest
, SolidColorDrawQuad
) {
779 gfx::Rect
visible_rect(40, 50, 30, 20);
780 SkColor color
= 0x49494949;
781 bool force_anti_aliasing_off
= false;
783 CREATE_SHARED_STATE();
785 SolidColorDrawQuad
, visible_rect
, color
, force_anti_aliasing_off
);
786 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
789 TEST_F(DrawQuadIteratorTest
, StreamVideoDrawQuad
) {
790 gfx::Rect
opaque_rect(33, 47, 10, 12);
791 gfx::Rect
visible_rect(40, 50, 30, 20);
792 ResourceProvider::ResourceId resource_id
= 64;
793 gfx::Transform matrix
= gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
795 CREATE_SHARED_STATE();
797 StreamVideoDrawQuad
, opaque_rect
, visible_rect
, resource_id
, matrix
);
798 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
799 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
800 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
803 TEST_F(DrawQuadIteratorTest
, SurfaceDrawQuad
) {
804 gfx::Rect
visible_rect(40, 50, 30, 20);
805 SurfaceId
surface_id(4321);
807 CREATE_SHARED_STATE();
808 CREATE_QUAD_2_NEW(SurfaceDrawQuad
, visible_rect
, surface_id
);
809 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
812 TEST_F(DrawQuadIteratorTest
, TextureDrawQuad
) {
813 gfx::Rect
opaque_rect(33, 47, 10, 12);
814 gfx::Rect
visible_rect(40, 50, 30, 20);
815 unsigned resource_id
= 82;
816 bool premultiplied_alpha
= true;
817 gfx::PointF
uv_top_left(0.5f
, 224.f
);
818 gfx::PointF
uv_bottom_right(51.5f
, 260.f
);
819 const float vertex_opacity
[] = { 1.0f
, 1.0f
, 1.0f
, 1.0f
};
822 CREATE_SHARED_STATE();
823 CREATE_QUAD_9_NEW(TextureDrawQuad
,
833 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
834 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
835 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
838 TEST_F(DrawQuadIteratorTest
, TileDrawQuad
) {
839 gfx::Rect
opaque_rect(33, 44, 22, 33);
840 gfx::Rect
visible_rect(40, 50, 30, 20);
841 unsigned resource_id
= 104;
842 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
843 gfx::Size
texture_size(85, 32);
844 bool swizzle_contents
= true;
846 CREATE_SHARED_STATE();
847 CREATE_QUAD_6_NEW(TileDrawQuad
,
854 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
855 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
856 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
859 TEST_F(DrawQuadIteratorTest
, YUVVideoDrawQuad
) {
860 gfx::Rect
opaque_rect(33, 47, 10, 12);
861 gfx::Rect
visible_rect(40, 50, 30, 20);
862 gfx::RectF
tex_coord_rect(0.0f
, 0.0f
, 0.75f
, 0.5f
);
863 ResourceProvider::ResourceId y_plane_resource_id
= 45;
864 ResourceProvider::ResourceId u_plane_resource_id
= 532;
865 ResourceProvider::ResourceId v_plane_resource_id
= 4;
866 ResourceProvider::ResourceId a_plane_resource_id
= 63;
867 YUVVideoDrawQuad::ColorSpace color_space
= YUVVideoDrawQuad::REC_601_JPEG
;
869 CREATE_SHARED_STATE();
870 CREATE_QUAD_8_NEW(YUVVideoDrawQuad
,
879 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
880 EXPECT_EQ(y_plane_resource_id
, quad_new
->y_plane_resource_id
);
881 EXPECT_EQ(u_plane_resource_id
, quad_new
->u_plane_resource_id
);
882 EXPECT_EQ(v_plane_resource_id
, quad_new
->v_plane_resource_id
);
883 EXPECT_EQ(a_plane_resource_id
, quad_new
->a_plane_resource_id
);
884 EXPECT_EQ(color_space
, quad_new
->color_space
);
885 EXPECT_EQ(4, IterateAndCount(quad_new
.get()));
886 EXPECT_EQ(y_plane_resource_id
+ 1, quad_new
->y_plane_resource_id
);
887 EXPECT_EQ(u_plane_resource_id
+ 1, quad_new
->u_plane_resource_id
);
888 EXPECT_EQ(v_plane_resource_id
+ 1, quad_new
->v_plane_resource_id
);
889 EXPECT_EQ(a_plane_resource_id
+ 1, quad_new
->a_plane_resource_id
);
892 // Disabled until picture draw quad is supported for ubercomp: crbug.com/231715
893 TEST_F(DrawQuadIteratorTest
, DISABLED_PictureDrawQuad
) {
894 gfx::Rect
opaque_rect(33, 44, 22, 33);
895 gfx::Rect
visible_rect(40, 50, 30, 20);
896 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
897 gfx::Size
texture_size(85, 32);
898 ResourceFormat texture_format
= RGBA_8888
;
899 gfx::Rect
content_rect(30, 40, 20, 30);
900 float contents_scale
= 3.141592f
;
901 scoped_refptr
<PicturePileImpl
> picture_pile
= PicturePileImpl::Create();
903 CREATE_SHARED_STATE();
904 CREATE_QUAD_8_NEW(PictureDrawQuad
,
913 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));