Connect PPAPI IPC channels for non-SFI mode.
[chromium-blink-merge.git] / cc / quads / draw_quad_unittest.cc
blob316accdf9d769ca07b9d24ef3aacd3f642e1291c
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;
42 scoped_ptr<SharedQuadState> state(SharedQuadState::Create());
43 state->SetAll(quad_transform,
44 content_bounds,
45 visible_content_rect,
46 clip_rect,
47 is_clipped,
48 opacity,
49 blend_mode);
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;
66 float opacity = 1.f;
67 SkXfermode::Mode blend_mode = SkXfermode::kSrcOver_Mode;
69 scoped_ptr<SharedQuadState> state(SharedQuadState::Create());
70 state->SetAll(quad_transform,
71 content_bounds,
72 visible_content_rect,
73 clip_rect,
74 is_clipped,
75 opacity,
76 blend_mode);
77 return state.Pass();
80 void CompareDrawQuad(DrawQuad* quad,
81 DrawQuad* copy,
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()); \
95 #define QUAD_DATA \
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()); \
124 QUAD_DATA \
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()); \
132 QUAD_DATA \
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()); \
141 QUAD_DATA \
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()); \
149 QUAD_DATA \
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()); \
158 QUAD_DATA \
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()); \
166 QUAD_DATA \
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()); \
175 QUAD_DATA \
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()); \
183 QUAD_DATA \
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()); \
192 QUAD_DATA \
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()); \
200 QUAD_DATA \
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()); \
209 QUAD_DATA \
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()); \
217 QUAD_DATA \
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()); \
226 QUAD_DATA \
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()); \
234 QUAD_DATA \
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()); \
243 QUAD_DATA \
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()); \
251 QUAD_DATA \
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()); \
261 QUAD_DATA \
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()); \
269 QUAD_DATA \
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()); \
279 QUAD_DATA \
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()); \
287 QUAD_DATA \
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()); \
297 QUAD_DATA \
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()); \
305 QUAD_DATA \
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()); \
315 QUAD_DATA \
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()); \
324 QUAD_DATA \
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 SkColor color = 0xfabb0011;
333 CREATE_SHARED_STATE();
335 CREATE_QUAD_1_NEW(CheckerboardDrawQuad, color);
336 EXPECT_EQ(DrawQuad::CHECKERBOARD, copy_quad->material);
337 EXPECT_EQ(color, copy_quad->color);
339 CREATE_QUAD_1_ALL(CheckerboardDrawQuad, color);
340 EXPECT_EQ(DrawQuad::CHECKERBOARD, copy_quad->material);
341 EXPECT_EQ(color, copy_quad->color);
344 TEST(DrawQuadTest, CopyDebugBorderDrawQuad) {
345 SkColor color = 0xfabb0011;
346 int width = 99;
347 CREATE_SHARED_STATE();
349 CREATE_QUAD_2_NEW(DebugBorderDrawQuad, color, width);
350 EXPECT_EQ(DrawQuad::DEBUG_BORDER, copy_quad->material);
351 EXPECT_EQ(color, copy_quad->color);
352 EXPECT_EQ(width, copy_quad->width);
354 CREATE_QUAD_2_ALL(DebugBorderDrawQuad, color, width);
355 EXPECT_EQ(DrawQuad::DEBUG_BORDER, copy_quad->material);
356 EXPECT_EQ(color, copy_quad->color);
357 EXPECT_EQ(width, copy_quad->width);
360 TEST(DrawQuadTest, CopyIOSurfaceDrawQuad) {
361 gfx::Rect opaque_rect(33, 47, 10, 12);
362 gfx::Size size(58, 95);
363 ResourceProvider::ResourceId resource_id = 72;
364 IOSurfaceDrawQuad::Orientation orientation = IOSurfaceDrawQuad::UNFLIPPED;
365 CREATE_SHARED_STATE();
367 CREATE_QUAD_4_NEW(
368 IOSurfaceDrawQuad, opaque_rect, size, resource_id, orientation);
369 EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT, copy_quad->material);
370 EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
371 EXPECT_EQ(size, copy_quad->io_surface_size);
372 EXPECT_EQ(resource_id, copy_quad->io_surface_resource_id);
373 EXPECT_EQ(orientation, copy_quad->orientation);
375 CREATE_QUAD_3_ALL(IOSurfaceDrawQuad, size, resource_id, orientation);
376 EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT, copy_quad->material);
377 EXPECT_EQ(size, copy_quad->io_surface_size);
378 EXPECT_EQ(resource_id, copy_quad->io_surface_resource_id);
379 EXPECT_EQ(orientation, copy_quad->orientation);
382 TEST(DrawQuadTest, CopyRenderPassDrawQuad) {
383 RenderPass::Id render_pass_id(22, 64);
384 bool is_replica = true;
385 ResourceProvider::ResourceId mask_resource_id = 78;
386 gfx::Rect contents_changed_since_last_frame(42, 11, 74, 24);
387 gfx::RectF mask_u_v_rect(-45.f, -21.f, 33.f, 19.f);
388 FilterOperations filters;
389 filters.Append(FilterOperation::CreateBlurFilter(1.f));
390 FilterOperations background_filters;
391 background_filters.Append(
392 FilterOperation::CreateGrayscaleFilter(1.f));
394 RenderPass::Id copied_render_pass_id(235, 11);
395 CREATE_SHARED_STATE();
397 CREATE_QUAD_7_NEW_1(RenderPassDrawQuad,
398 render_pass_id,
399 is_replica,
400 mask_resource_id,
401 contents_changed_since_last_frame,
402 mask_u_v_rect,
403 filters,
404 background_filters,
405 copied_render_pass_id);
406 EXPECT_EQ(DrawQuad::RENDER_PASS, copy_quad->material);
407 EXPECT_EQ(copied_render_pass_id, copy_quad->render_pass_id);
408 EXPECT_EQ(is_replica, copy_quad->is_replica);
409 EXPECT_EQ(mask_resource_id, copy_quad->mask_resource_id);
410 EXPECT_RECT_EQ(contents_changed_since_last_frame,
411 copy_quad->contents_changed_since_last_frame);
412 EXPECT_EQ(mask_u_v_rect.ToString(), copy_quad->mask_uv_rect.ToString());
413 EXPECT_EQ(filters, copy_quad->filters);
414 EXPECT_EQ(background_filters, copy_quad->background_filters);
416 CREATE_QUAD_7_ALL_1(RenderPassDrawQuad,
417 render_pass_id,
418 is_replica,
419 mask_resource_id,
420 contents_changed_since_last_frame,
421 mask_u_v_rect,
422 filters,
423 background_filters,
424 copied_render_pass_id);
425 EXPECT_EQ(DrawQuad::RENDER_PASS, copy_quad->material);
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);
436 TEST(DrawQuadTest, CopySolidColorDrawQuad) {
437 SkColor color = 0x49494949;
438 bool force_anti_aliasing_off = false;
439 CREATE_SHARED_STATE();
441 CREATE_QUAD_2_NEW(SolidColorDrawQuad, color, force_anti_aliasing_off);
442 EXPECT_EQ(DrawQuad::SOLID_COLOR, copy_quad->material);
443 EXPECT_EQ(color, copy_quad->color);
444 EXPECT_EQ(force_anti_aliasing_off, copy_quad->force_anti_aliasing_off);
446 CREATE_QUAD_2_ALL(SolidColorDrawQuad, color, force_anti_aliasing_off);
447 EXPECT_EQ(DrawQuad::SOLID_COLOR, copy_quad->material);
448 EXPECT_EQ(color, copy_quad->color);
449 EXPECT_EQ(force_anti_aliasing_off, copy_quad->force_anti_aliasing_off);
452 TEST(DrawQuadTest, CopyStreamVideoDrawQuad) {
453 gfx::Rect opaque_rect(33, 47, 10, 12);
454 ResourceProvider::ResourceId resource_id = 64;
455 gfx::Transform matrix = gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
456 CREATE_SHARED_STATE();
458 CREATE_QUAD_3_NEW(StreamVideoDrawQuad, opaque_rect, resource_id, matrix);
459 EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT, copy_quad->material);
460 EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
461 EXPECT_EQ(resource_id, copy_quad->resource_id);
462 EXPECT_EQ(matrix, copy_quad->matrix);
464 CREATE_QUAD_2_ALL(StreamVideoDrawQuad, resource_id, matrix);
465 EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT, copy_quad->material);
466 EXPECT_EQ(resource_id, copy_quad->resource_id);
467 EXPECT_EQ(matrix, copy_quad->matrix);
470 TEST(DrawQuadTest, CopySurfaceDrawQuad) {
471 int surface_id = 1234;
472 CREATE_SHARED_STATE();
474 CREATE_QUAD_1_NEW(SurfaceDrawQuad, surface_id);
475 EXPECT_EQ(DrawQuad::SURFACE_CONTENT, copy_quad->material);
476 EXPECT_EQ(surface_id, copy_quad->surface_id);
478 CREATE_QUAD_1_ALL(SurfaceDrawQuad, surface_id);
479 EXPECT_EQ(DrawQuad::SURFACE_CONTENT, copy_quad->material);
480 EXPECT_EQ(surface_id, copy_quad->surface_id);
484 TEST(DrawQuadTest, CopyTextureDrawQuad) {
485 gfx::Rect opaque_rect(33, 47, 10, 12);
486 unsigned resource_id = 82;
487 bool premultiplied_alpha = true;
488 gfx::PointF uv_top_left(0.5f, 224.f);
489 gfx::PointF uv_bottom_right(51.5f, 260.f);
490 const float vertex_opacity[] = { 1.0f, 1.0f, 1.0f, 1.0f };
491 bool flipped = true;
492 CREATE_SHARED_STATE();
494 CREATE_QUAD_8_NEW(TextureDrawQuad,
495 opaque_rect,
496 resource_id,
497 premultiplied_alpha,
498 uv_top_left,
499 uv_bottom_right,
500 SK_ColorTRANSPARENT,
501 vertex_opacity,
502 flipped);
503 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, copy_quad->material);
504 EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
505 EXPECT_EQ(resource_id, copy_quad->resource_id);
506 EXPECT_EQ(premultiplied_alpha, copy_quad->premultiplied_alpha);
507 EXPECT_EQ(uv_top_left, copy_quad->uv_top_left);
508 EXPECT_EQ(uv_bottom_right, copy_quad->uv_bottom_right);
509 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copy_quad->vertex_opacity, 4);
510 EXPECT_EQ(flipped, copy_quad->flipped);
512 CREATE_QUAD_7_ALL(TextureDrawQuad,
513 resource_id,
514 premultiplied_alpha,
515 uv_top_left,
516 uv_bottom_right,
517 SK_ColorTRANSPARENT,
518 vertex_opacity,
519 flipped);
520 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, copy_quad->material);
521 EXPECT_EQ(resource_id, copy_quad->resource_id);
522 EXPECT_EQ(premultiplied_alpha, copy_quad->premultiplied_alpha);
523 EXPECT_EQ(uv_top_left, copy_quad->uv_top_left);
524 EXPECT_EQ(uv_bottom_right, copy_quad->uv_bottom_right);
525 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copy_quad->vertex_opacity, 4);
526 EXPECT_EQ(flipped, copy_quad->flipped);
529 TEST(DrawQuadTest, CopyTileDrawQuad) {
530 gfx::Rect opaque_rect(33, 44, 22, 33);
531 unsigned resource_id = 104;
532 gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
533 gfx::Size texture_size(85, 32);
534 bool swizzle_contents = true;
535 CREATE_SHARED_STATE();
537 CREATE_QUAD_5_NEW(TileDrawQuad,
538 opaque_rect,
539 resource_id,
540 tex_coord_rect,
541 texture_size,
542 swizzle_contents);
543 EXPECT_EQ(DrawQuad::TILED_CONTENT, copy_quad->material);
544 EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
545 EXPECT_EQ(resource_id, copy_quad->resource_id);
546 EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
547 EXPECT_EQ(texture_size, copy_quad->texture_size);
548 EXPECT_EQ(swizzle_contents, copy_quad->swizzle_contents);
550 CREATE_QUAD_4_ALL(TileDrawQuad,
551 resource_id,
552 tex_coord_rect,
553 texture_size,
554 swizzle_contents);
555 EXPECT_EQ(DrawQuad::TILED_CONTENT, copy_quad->material);
556 EXPECT_EQ(resource_id, copy_quad->resource_id);
557 EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
558 EXPECT_EQ(texture_size, copy_quad->texture_size);
559 EXPECT_EQ(swizzle_contents, copy_quad->swizzle_contents);
562 TEST(DrawQuadTest, CopyYUVVideoDrawQuad) {
563 gfx::Rect opaque_rect(33, 47, 10, 12);
564 gfx::SizeF tex_scale(0.75f, 0.5f);
565 ResourceProvider::ResourceId y_plane_resource_id = 45;
566 ResourceProvider::ResourceId u_plane_resource_id = 532;
567 ResourceProvider::ResourceId v_plane_resource_id = 4;
568 ResourceProvider::ResourceId a_plane_resource_id = 63;
569 CREATE_SHARED_STATE();
571 CREATE_QUAD_6_NEW(YUVVideoDrawQuad,
572 opaque_rect,
573 tex_scale,
574 y_plane_resource_id,
575 u_plane_resource_id,
576 v_plane_resource_id,
577 a_plane_resource_id);
578 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copy_quad->material);
579 EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
580 EXPECT_EQ(tex_scale, copy_quad->tex_scale);
581 EXPECT_EQ(y_plane_resource_id, copy_quad->y_plane_resource_id);
582 EXPECT_EQ(u_plane_resource_id, copy_quad->u_plane_resource_id);
583 EXPECT_EQ(v_plane_resource_id, copy_quad->v_plane_resource_id);
584 EXPECT_EQ(a_plane_resource_id, copy_quad->a_plane_resource_id);
586 CREATE_QUAD_5_ALL(YUVVideoDrawQuad,
587 tex_scale,
588 y_plane_resource_id,
589 u_plane_resource_id,
590 v_plane_resource_id,
591 a_plane_resource_id);
592 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copy_quad->material);
593 EXPECT_EQ(tex_scale, copy_quad->tex_scale);
594 EXPECT_EQ(y_plane_resource_id, copy_quad->y_plane_resource_id);
595 EXPECT_EQ(u_plane_resource_id, copy_quad->u_plane_resource_id);
596 EXPECT_EQ(v_plane_resource_id, copy_quad->v_plane_resource_id);
597 EXPECT_EQ(a_plane_resource_id, copy_quad->a_plane_resource_id);
600 TEST(DrawQuadTest, CopyPictureDrawQuad) {
601 gfx::Rect opaque_rect(33, 44, 22, 33);
602 gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
603 gfx::Size texture_size(85, 32);
604 ResourceFormat texture_format = RGBA_8888;
605 gfx::Rect content_rect(30, 40, 20, 30);
606 float contents_scale = 3.141592f;
607 scoped_refptr<PicturePileImpl> picture_pile = PicturePileImpl::Create();
608 CREATE_SHARED_STATE();
610 CREATE_QUAD_7_NEW(PictureDrawQuad,
611 opaque_rect,
612 tex_coord_rect,
613 texture_size,
614 texture_format,
615 content_rect,
616 contents_scale,
617 picture_pile);
618 EXPECT_EQ(DrawQuad::PICTURE_CONTENT, copy_quad->material);
619 EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
620 EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
621 EXPECT_EQ(texture_size, copy_quad->texture_size);
622 EXPECT_EQ(texture_format, copy_quad->texture_format);
623 EXPECT_RECT_EQ(content_rect, copy_quad->content_rect);
624 EXPECT_EQ(contents_scale, copy_quad->contents_scale);
625 EXPECT_EQ(picture_pile, copy_quad->picture_pile);
627 CREATE_QUAD_6_ALL(PictureDrawQuad,
628 tex_coord_rect,
629 texture_size,
630 texture_format,
631 content_rect,
632 contents_scale,
633 picture_pile);
634 EXPECT_EQ(DrawQuad::PICTURE_CONTENT, copy_quad->material);
635 EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
636 EXPECT_EQ(texture_size, copy_quad->texture_size);
637 EXPECT_EQ(texture_format, copy_quad->texture_format);
638 EXPECT_RECT_EQ(content_rect, copy_quad->content_rect);
639 EXPECT_EQ(contents_scale, copy_quad->contents_scale);
640 EXPECT_EQ(picture_pile, copy_quad->picture_pile);
643 class DrawQuadIteratorTest : public testing::Test {
644 protected:
645 ResourceProvider::ResourceId IncrementResourceId(
646 ResourceProvider::ResourceId id) {
647 ++num_resources_;
648 return id + 1;
651 int IterateAndCount(DrawQuad* quad) {
652 num_resources_ = 0;
653 quad->IterateResources(base::Bind(
654 &DrawQuadIteratorTest::IncrementResourceId, base::Unretained(this)));
655 return num_resources_;
658 private:
659 int num_resources_;
662 TEST_F(DrawQuadIteratorTest, CheckerboardDrawQuad) {
663 SkColor color = 0xfabb0011;
665 CREATE_SHARED_STATE();
666 CREATE_QUAD_1_NEW(CheckerboardDrawQuad, color);
667 EXPECT_EQ(0, IterateAndCount(quad_new.get()));
670 TEST_F(DrawQuadIteratorTest, DebugBorderDrawQuad) {
671 SkColor color = 0xfabb0011;
672 int width = 99;
674 CREATE_SHARED_STATE();
675 CREATE_QUAD_2_NEW(DebugBorderDrawQuad, color, width);
676 EXPECT_EQ(0, IterateAndCount(quad_new.get()));
679 TEST_F(DrawQuadIteratorTest, IOSurfaceDrawQuad) {
680 gfx::Rect opaque_rect(33, 47, 10, 12);
681 gfx::Size size(58, 95);
682 ResourceProvider::ResourceId resource_id = 72;
683 IOSurfaceDrawQuad::Orientation orientation = IOSurfaceDrawQuad::UNFLIPPED;
685 CREATE_SHARED_STATE();
686 CREATE_QUAD_4_NEW(
687 IOSurfaceDrawQuad, opaque_rect, size, resource_id, orientation);
688 EXPECT_EQ(resource_id, quad_new->io_surface_resource_id);
689 EXPECT_EQ(1, IterateAndCount(quad_new.get()));
690 EXPECT_EQ(resource_id + 1, quad_new->io_surface_resource_id);
693 TEST_F(DrawQuadIteratorTest, RenderPassDrawQuad) {
694 RenderPass::Id render_pass_id(22, 64);
695 bool is_replica = true;
696 ResourceProvider::ResourceId mask_resource_id = 78;
697 gfx::Rect contents_changed_since_last_frame(42, 11, 74, 24);
698 gfx::RectF mask_u_v_rect(-45.f, -21.f, 33.f, 19.f);
699 FilterOperations filters;
700 filters.Append(FilterOperation::CreateBlurFilter(1.f));
701 FilterOperations background_filters;
702 background_filters.Append(
703 FilterOperation::CreateGrayscaleFilter(1.f));
705 RenderPass::Id copied_render_pass_id(235, 11);
707 CREATE_SHARED_STATE();
708 CREATE_QUAD_7_NEW_1(RenderPassDrawQuad,
709 render_pass_id,
710 is_replica,
711 mask_resource_id,
712 contents_changed_since_last_frame,
713 mask_u_v_rect,
714 filters,
715 background_filters,
716 copied_render_pass_id);
717 EXPECT_EQ(mask_resource_id, quad_new->mask_resource_id);
718 EXPECT_EQ(1, IterateAndCount(quad_new.get()));
719 EXPECT_EQ(mask_resource_id + 1, quad_new->mask_resource_id);
720 quad_new->mask_resource_id = 0;
721 EXPECT_EQ(0, IterateAndCount(quad_new.get()));
722 EXPECT_EQ(0u, quad_new->mask_resource_id);
725 TEST_F(DrawQuadIteratorTest, SolidColorDrawQuad) {
726 SkColor color = 0x49494949;
727 bool force_anti_aliasing_off = false;
729 CREATE_SHARED_STATE();
730 CREATE_QUAD_2_NEW(SolidColorDrawQuad, color, force_anti_aliasing_off);
731 EXPECT_EQ(0, IterateAndCount(quad_new.get()));
734 TEST_F(DrawQuadIteratorTest, StreamVideoDrawQuad) {
735 gfx::Rect opaque_rect(33, 47, 10, 12);
736 ResourceProvider::ResourceId resource_id = 64;
737 gfx::Transform matrix = gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
739 CREATE_SHARED_STATE();
740 CREATE_QUAD_3_NEW(StreamVideoDrawQuad, opaque_rect, resource_id, matrix);
741 EXPECT_EQ(resource_id, quad_new->resource_id);
742 EXPECT_EQ(1, IterateAndCount(quad_new.get()));
743 EXPECT_EQ(resource_id + 1, quad_new->resource_id);
746 TEST_F(DrawQuadIteratorTest, SurfaceDrawQuad) {
747 int surface_id = 4321;
749 CREATE_SHARED_STATE();
750 CREATE_QUAD_1_NEW(SurfaceDrawQuad, surface_id);
751 EXPECT_EQ(0, IterateAndCount(quad_new.get()));
754 TEST_F(DrawQuadIteratorTest, TextureDrawQuad) {
755 gfx::Rect opaque_rect(33, 47, 10, 12);
756 unsigned resource_id = 82;
757 bool premultiplied_alpha = true;
758 gfx::PointF uv_top_left(0.5f, 224.f);
759 gfx::PointF uv_bottom_right(51.5f, 260.f);
760 const float vertex_opacity[] = { 1.0f, 1.0f, 1.0f, 1.0f };
761 bool flipped = true;
763 CREATE_SHARED_STATE();
764 CREATE_QUAD_8_NEW(TextureDrawQuad,
765 opaque_rect,
766 resource_id,
767 premultiplied_alpha,
768 uv_top_left,
769 uv_bottom_right,
770 SK_ColorTRANSPARENT,
771 vertex_opacity,
772 flipped);
773 EXPECT_EQ(resource_id, quad_new->resource_id);
774 EXPECT_EQ(1, IterateAndCount(quad_new.get()));
775 EXPECT_EQ(resource_id + 1, quad_new->resource_id);
778 TEST_F(DrawQuadIteratorTest, TileDrawQuad) {
779 gfx::Rect opaque_rect(33, 44, 22, 33);
780 unsigned resource_id = 104;
781 gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
782 gfx::Size texture_size(85, 32);
783 bool swizzle_contents = true;
785 CREATE_SHARED_STATE();
786 CREATE_QUAD_5_NEW(TileDrawQuad,
787 opaque_rect,
788 resource_id,
789 tex_coord_rect,
790 texture_size,
791 swizzle_contents);
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, YUVVideoDrawQuad) {
798 gfx::Rect opaque_rect(33, 47, 10, 12);
799 gfx::SizeF tex_scale(0.75f, 0.5f);
800 ResourceProvider::ResourceId y_plane_resource_id = 45;
801 ResourceProvider::ResourceId u_plane_resource_id = 532;
802 ResourceProvider::ResourceId v_plane_resource_id = 4;
803 ResourceProvider::ResourceId a_plane_resource_id = 63;
805 CREATE_SHARED_STATE();
806 CREATE_QUAD_6_NEW(YUVVideoDrawQuad,
807 opaque_rect,
808 tex_scale,
809 y_plane_resource_id,
810 u_plane_resource_id,
811 v_plane_resource_id,
812 a_plane_resource_id);
813 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copy_quad->material);
814 EXPECT_EQ(y_plane_resource_id, quad_new->y_plane_resource_id);
815 EXPECT_EQ(u_plane_resource_id, quad_new->u_plane_resource_id);
816 EXPECT_EQ(v_plane_resource_id, quad_new->v_plane_resource_id);
817 EXPECT_EQ(a_plane_resource_id, quad_new->a_plane_resource_id);
818 EXPECT_EQ(4, IterateAndCount(quad_new.get()));
819 EXPECT_EQ(y_plane_resource_id + 1, quad_new->y_plane_resource_id);
820 EXPECT_EQ(u_plane_resource_id + 1, quad_new->u_plane_resource_id);
821 EXPECT_EQ(v_plane_resource_id + 1, quad_new->v_plane_resource_id);
822 EXPECT_EQ(a_plane_resource_id + 1, quad_new->a_plane_resource_id);
825 // Disabled until picture draw quad is supported for ubercomp: crbug.com/231715
826 TEST_F(DrawQuadIteratorTest, DISABLED_PictureDrawQuad) {
827 gfx::Rect opaque_rect(33, 44, 22, 33);
828 gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
829 gfx::Size texture_size(85, 32);
830 ResourceFormat texture_format = RGBA_8888;
831 gfx::Rect content_rect(30, 40, 20, 30);
832 float contents_scale = 3.141592f;
833 scoped_refptr<PicturePileImpl> picture_pile = PicturePileImpl::Create();
835 CREATE_SHARED_STATE();
836 CREATE_QUAD_7_NEW(PictureDrawQuad,
837 opaque_rect,
838 tex_coord_rect,
839 texture_size,
840 texture_format,
841 content_rect,
842 contents_scale,
843 picture_pile);
844 EXPECT_EQ(0, IterateAndCount(quad_new.get()));
847 } // namespace
848 } // namespace cc