Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / cc / quads / draw_quad_unittest.cc
blobf0f77190ffbe7c2d5f07d4b93aaf53f2baf4aa7f
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"
7 #include <algorithm>
9 #include "base/bind.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"
30 namespace cc {
31 namespace {
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,
45 content_bounds,
46 visible_content_rect,
47 clip_rect,
48 is_clipped,
49 opacity,
50 blend_mode,
51 sorting_context_id);
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;
69 float opacity = 1.f;
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,
75 content_bounds,
76 visible_content_rect,
77 clip_rect,
78 is_clipped,
79 opacity,
80 blend_mode,
81 sorting_context_id);
82 return state.Pass();
85 void CompareDrawQuad(DrawQuad* quad,
86 DrawQuad* copy,
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());
101 #define QUAD_DATA \
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()); \
130 QUAD_DATA \
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()); \
138 QUAD_DATA \
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()); \
147 QUAD_DATA \
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()); \
155 QUAD_DATA \
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()); \
164 QUAD_DATA \
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()); \
172 QUAD_DATA \
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()); \
181 QUAD_DATA \
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()); \
189 QUAD_DATA \
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()); \
198 QUAD_DATA \
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()); \
206 QUAD_DATA \
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()); \
215 QUAD_DATA \
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()); \
223 QUAD_DATA \
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()); \
232 QUAD_DATA \
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()); \
240 QUAD_DATA \
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()); \
249 QUAD_DATA \
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()); \
257 QUAD_DATA \
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()); \
267 QUAD_DATA \
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()); \
275 QUAD_DATA \
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()); \
285 QUAD_DATA \
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()); \
293 QUAD_DATA \
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()); \
303 QUAD_DATA \
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()); \
311 QUAD_DATA \
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()); \
321 QUAD_DATA \
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()); \
330 QUAD_DATA \
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;
355 int width = 99;
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,
379 opaque_rect,
380 visible_rect,
381 size,
382 resource_id,
383 orientation);
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,
415 visible_rect,
416 render_pass_id,
417 is_replica,
418 mask_resource_id,
419 contents_changed_since_last_frame,
420 mask_u_v_rect,
421 filters,
422 background_filters,
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,
436 render_pass_id,
437 is_replica,
438 mask_resource_id,
439 contents_changed_since_last_frame,
440 mask_u_v_rect,
441 filters,
442 background_filters,
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();
461 CREATE_QUAD_3_NEW(
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();
481 CREATE_QUAD_4_NEW(
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 };
519 bool flipped = true;
520 CREATE_SHARED_STATE();
522 CREATE_QUAD_9_NEW(TextureDrawQuad,
523 opaque_rect,
524 visible_rect,
525 resource_id,
526 premultiplied_alpha,
527 uv_top_left,
528 uv_bottom_right,
529 SK_ColorTRANSPARENT,
530 vertex_opacity,
531 flipped);
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,
543 resource_id,
544 premultiplied_alpha,
545 uv_top_left,
546 uv_bottom_right,
547 SK_ColorTRANSPARENT,
548 vertex_opacity,
549 flipped);
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,
569 opaque_rect,
570 visible_rect,
571 resource_id,
572 tex_coord_rect,
573 texture_size,
574 swizzle_contents);
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,
584 resource_id,
585 tex_coord_rect,
586 texture_size,
587 swizzle_contents);
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,
607 opaque_rect,
608 visible_rect,
609 tex_coord_rect,
610 y_plane_resource_id,
611 u_plane_resource_id,
612 v_plane_resource_id,
613 a_plane_resource_id,
614 color_space);
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,
626 tex_coord_rect,
627 y_plane_resource_id,
628 u_plane_resource_id,
629 v_plane_resource_id,
630 a_plane_resource_id,
631 color_space);
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,
653 opaque_rect,
654 visible_rect,
655 tex_coord_rect,
656 texture_size,
657 texture_format,
658 content_rect,
659 contents_scale,
660 picture_pile);
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,
672 tex_coord_rect,
673 texture_size,
674 texture_format,
675 content_rect,
676 contents_scale,
677 picture_pile);
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 {
688 protected:
689 ResourceProvider::ResourceId IncrementResourceId(
690 ResourceProvider::ResourceId id) {
691 ++num_resources_;
692 return id + 1;
695 int IterateAndCount(DrawQuad* quad) {
696 num_resources_ = 0;
697 quad->IterateResources(base::Bind(
698 &DrawQuadIteratorTest::IncrementResourceId, base::Unretained(this)));
699 return num_resources_;
702 private:
703 int 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;
718 int width = 99;
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,
734 opaque_rect,
735 visible_rect,
736 size,
737 resource_id,
738 orientation);
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,
761 visible_rect,
762 render_pass_id,
763 is_replica,
764 mask_resource_id,
765 contents_changed_since_last_frame,
766 mask_u_v_rect,
767 filters,
768 background_filters,
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();
784 CREATE_QUAD_3_NEW(
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();
796 CREATE_QUAD_4_NEW(
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 };
820 bool flipped = true;
822 CREATE_SHARED_STATE();
823 CREATE_QUAD_9_NEW(TextureDrawQuad,
824 opaque_rect,
825 visible_rect,
826 resource_id,
827 premultiplied_alpha,
828 uv_top_left,
829 uv_bottom_right,
830 SK_ColorTRANSPARENT,
831 vertex_opacity,
832 flipped);
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,
848 opaque_rect,
849 visible_rect,
850 resource_id,
851 tex_coord_rect,
852 texture_size,
853 swizzle_contents);
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,
871 opaque_rect,
872 visible_rect,
873 tex_coord_rect,
874 y_plane_resource_id,
875 u_plane_resource_id,
876 v_plane_resource_id,
877 a_plane_resource_id,
878 color_space);
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,
905 opaque_rect,
906 visible_rect,
907 tex_coord_rect,
908 texture_size,
909 texture_format,
910 content_rect,
911 contents_scale,
912 picture_pile);
913 EXPECT_EQ(0, IterateAndCount(quad_new.get()));
916 } // namespace
917 } // namespace cc