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/texture_draw_quad.h"
21 #include "cc/quads/tile_draw_quad.h"
22 #include "cc/quads/yuv_video_draw_quad.h"
23 #include "cc/resources/picture_pile_impl.h"
24 #include "cc/test/geometry_test_utils.h"
25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
27 #include "ui/gfx/transform.h"
32 TEST(DrawQuadTest
, CopySharedQuadState
) {
33 gfx::Transform quad_transform
= gfx::Transform(1.0, 0.0, 0.5, 1.0, 0.5, 0.0);
34 gfx::Size
content_bounds(26, 28);
35 gfx::Rect
visible_content_rect(10, 12, 14, 16);
36 gfx::Rect
clip_rect(19, 21, 23, 25);
37 bool is_clipped
= true;
38 float opacity
= 0.25f
;
40 scoped_ptr
<SharedQuadState
> state(SharedQuadState::Create());
41 state
->SetAll(quad_transform
,
48 scoped_ptr
<SharedQuadState
> copy(state
->Copy());
49 EXPECT_EQ(quad_transform
, copy
->content_to_target_transform
);
50 EXPECT_RECT_EQ(visible_content_rect
, copy
->visible_content_rect
);
51 EXPECT_EQ(opacity
, copy
->opacity
);
52 EXPECT_RECT_EQ(clip_rect
, copy
->clip_rect
);
53 EXPECT_EQ(is_clipped
, copy
->is_clipped
);
56 scoped_ptr
<SharedQuadState
> CreateSharedQuadState() {
57 gfx::Transform quad_transform
= gfx::Transform(1.0, 0.0, 0.5, 1.0, 0.5, 0.0);
58 gfx::Size
content_bounds(26, 28);
59 gfx::Rect
visible_content_rect(10, 12, 14, 16);
60 gfx::Rect
clip_rect(19, 21, 23, 25);
61 bool is_clipped
= false;
64 scoped_ptr
<SharedQuadState
> state(SharedQuadState::Create());
65 state
->SetAll(quad_transform
,
74 void CompareDrawQuad(DrawQuad
* quad
,
76 SharedQuadState
* copy_shared_state
) {
77 EXPECT_EQ(quad
->material
, copy
->material
);
78 EXPECT_RECT_EQ(quad
->rect
, copy
->rect
);
79 EXPECT_RECT_EQ(quad
->visible_rect
, copy
->visible_rect
);
80 EXPECT_RECT_EQ(quad
->opaque_rect
, copy
->opaque_rect
);
81 EXPECT_EQ(quad
->needs_blending
, copy
->needs_blending
);
82 EXPECT_EQ(copy_shared_state
, copy
->shared_quad_state
);
85 #define CREATE_SHARED_STATE() \
86 scoped_ptr<SharedQuadState> shared_state(CreateSharedQuadState()); \
87 scoped_ptr<SharedQuadState> copy_shared_state(shared_state->Copy()); \
90 gfx::Rect quad_rect(30, 40, 50, 60); \
91 gfx::Rect quad_visible_rect(40, 50, 30, 20); \
92 gfx::Rect ALLOW_UNUSED quad_opaque_rect(60, 55, 10, 10); \
93 bool ALLOW_UNUSED needs_blending = true;
95 #define SETUP_AND_COPY_QUAD_NEW(Type, quad) \
96 scoped_ptr<DrawQuad> copy_new(quad_new->Copy(copy_shared_state.get())); \
97 CompareDrawQuad(quad_new.get(), copy_new.get(), copy_shared_state.get()); \
98 const Type* ALLOW_UNUSED copy_quad = Type::MaterialCast(copy_new.get());
100 #define SETUP_AND_COPY_QUAD_ALL(Type, quad) \
101 scoped_ptr<DrawQuad> copy_all(quad_all->Copy(copy_shared_state.get())); \
102 CompareDrawQuad(quad_all.get(), copy_all.get(), copy_shared_state.get()); \
103 copy_quad = Type::MaterialCast(copy_all.get());
105 #define SETUP_AND_COPY_QUAD_NEW_1(Type, quad, a) \
106 scoped_ptr<DrawQuad> copy_new(quad_new->Copy(copy_shared_state.get(), a)); \
107 CompareDrawQuad(quad_new.get(), copy_new.get(), copy_shared_state.get()); \
108 const Type* ALLOW_UNUSED copy_quad = Type::MaterialCast(copy_new.get());
110 #define SETUP_AND_COPY_QUAD_ALL_1(Type, quad, a) \
111 scoped_ptr<DrawQuad> copy_all(quad_all->Copy(copy_shared_state.get(), a)); \
112 CompareDrawQuad(quad_all.get(), copy_all.get(), copy_shared_state.get()); \
113 copy_quad = Type::MaterialCast(copy_all.get());
115 #define CREATE_QUAD_1_NEW(Type, a) \
116 scoped_ptr<Type> quad_new(Type::Create()); \
119 quad_new->SetNew(shared_state.get(), quad_rect, a); \
121 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
123 #define CREATE_QUAD_1_ALL(Type, a) \
124 scoped_ptr<Type> quad_all(Type::Create()); \
127 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
128 quad_visible_rect, needs_blending, a); \
130 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
132 #define CREATE_QUAD_2_NEW(Type, a, b) \
133 scoped_ptr<Type> quad_new(Type::Create()); \
136 quad_new->SetNew(shared_state.get(), quad_rect, a, b); \
138 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
140 #define CREATE_QUAD_2_ALL(Type, a, b) \
141 scoped_ptr<Type> quad_all(Type::Create()); \
144 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
145 quad_visible_rect, needs_blending, a, b); \
147 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
149 #define CREATE_QUAD_3_NEW(Type, a, b, c) \
150 scoped_ptr<Type> quad_new(Type::Create()); \
153 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c); \
155 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
157 #define CREATE_QUAD_3_ALL(Type, a, b, c) \
158 scoped_ptr<Type> quad_all(Type::Create()); \
161 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
162 quad_visible_rect, needs_blending, a, b, c); \
164 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
166 #define CREATE_QUAD_4_NEW(Type, a, b, c, d) \
167 scoped_ptr<Type> quad_new(Type::Create()); \
170 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d); \
172 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
174 #define CREATE_QUAD_4_ALL(Type, a, b, c, d) \
175 scoped_ptr<Type> quad_all(Type::Create()); \
178 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
179 quad_visible_rect, needs_blending, a, b, c, d); \
181 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
183 #define CREATE_QUAD_5_NEW(Type, a, b, c, d, e) \
184 scoped_ptr<Type> quad_new(Type::Create()); \
187 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e); \
189 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
191 #define CREATE_QUAD_5_ALL(Type, a, b, c, d, e) \
192 scoped_ptr<Type> quad_all(Type::Create()); \
195 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
196 quad_visible_rect, needs_blending, a, b, c, d, e); \
198 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
200 #define CREATE_QUAD_5_NEW_1(Type, a, b, c, d, e, copy_a) \
201 scoped_ptr<Type> quad_new(Type::Create()); \
204 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e); \
206 SETUP_AND_COPY_QUAD_NEW_1(Type, quad_new, copy_a);
208 #define CREATE_QUAD_5_ALL_1(Type, a, b, c, d, e, copy_a) \
209 scoped_ptr<Type> quad_all(Type::Create()); \
212 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
213 quad_visible_rect, needs_blending, a, b, c, d, e); \
215 SETUP_AND_COPY_QUAD_ALL_1(Type, quad_all, copy_a);
217 #define CREATE_QUAD_6_NEW(Type, a, b, c, d, e, f) \
218 scoped_ptr<Type> quad_new(Type::Create()); \
221 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f); \
223 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
225 #define CREATE_QUAD_6_ALL(Type, a, b, c, d, e, f) \
226 scoped_ptr<Type> quad_all(Type::Create()); \
229 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
230 quad_visible_rect, needs_blending, a, b, c, d, e, f); \
232 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
234 #define CREATE_QUAD_7_NEW(Type, a, b, c, d, e, f, g) \
235 scoped_ptr<Type> quad_new(Type::Create()); \
238 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f, g); \
240 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
242 #define CREATE_QUAD_7_ALL(Type, a, b, c, d, e, f, g) \
243 scoped_ptr<Type> quad_all(Type::Create()); \
246 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
247 quad_visible_rect, needs_blending, \
248 a, b, c, d, e, f, g); \
250 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
252 #define CREATE_QUAD_8_NEW(Type, a, b, c, d, e, f, g, h) \
253 scoped_ptr<Type> quad_new(Type::Create()); \
256 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f, g, h); \
258 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
260 #define CREATE_QUAD_8_ALL(Type, a, b, c, d, e, f, g, h) \
261 scoped_ptr<Type> quad_all(Type::Create()); \
264 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
265 quad_visible_rect, needs_blending, \
266 a, b, c, d, e, f, g, h); \
268 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
270 #define CREATE_QUAD_8_NEW_1(Type, a, b, c, d, e, f, g, h, copy_a) \
271 scoped_ptr<Type> quad_new(Type::Create()); \
274 quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f, g, h); \
276 SETUP_AND_COPY_QUAD_NEW_1(Type, quad_new, copy_a);
278 #define CREATE_QUAD_8_ALL_1(Type, a, b, c, d, e, f, g, h, copy_a) \
279 scoped_ptr<Type> quad_all(Type::Create()); \
282 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
283 quad_visible_rect, needs_blending, \
284 a, b, c, d, e, f, g, h); \
286 SETUP_AND_COPY_QUAD_ALL_1(Type, quad_all, copy_a);
288 #define CREATE_QUAD_9_NEW(Type, a, b, c, d, e, f, g, h, i) \
289 scoped_ptr<Type> quad_new(Type::Create()); \
292 quad_new->SetNew(shared_state.get(), quad_rect, \
293 a, b, c, d, e, f, g, h, i); \
295 SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
297 #define CREATE_QUAD_9_ALL(Type, a, b, c, d, e, f, g, h, i) \
298 scoped_ptr<Type> quad_all(Type::Create()); \
301 quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
302 quad_visible_rect, needs_blending, \
303 a, b, c, d, e, f, g, h, i); \
305 SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
307 TEST(DrawQuadTest
, CopyCheckerboardDrawQuad
) {
308 SkColor color
= 0xfabb0011;
309 CREATE_SHARED_STATE();
311 CREATE_QUAD_1_NEW(CheckerboardDrawQuad
, color
);
312 EXPECT_EQ(DrawQuad::CHECKERBOARD
, copy_quad
->material
);
313 EXPECT_EQ(color
, copy_quad
->color
);
315 CREATE_QUAD_1_ALL(CheckerboardDrawQuad
, color
);
316 EXPECT_EQ(DrawQuad::CHECKERBOARD
, copy_quad
->material
);
317 EXPECT_EQ(color
, copy_quad
->color
);
320 TEST(DrawQuadTest
, CopyDebugBorderDrawQuad
) {
321 SkColor color
= 0xfabb0011;
323 CREATE_SHARED_STATE();
325 CREATE_QUAD_2_NEW(DebugBorderDrawQuad
, color
, width
);
326 EXPECT_EQ(DrawQuad::DEBUG_BORDER
, copy_quad
->material
);
327 EXPECT_EQ(color
, copy_quad
->color
);
328 EXPECT_EQ(width
, copy_quad
->width
);
330 CREATE_QUAD_2_ALL(DebugBorderDrawQuad
, color
, width
);
331 EXPECT_EQ(DrawQuad::DEBUG_BORDER
, copy_quad
->material
);
332 EXPECT_EQ(color
, copy_quad
->color
);
333 EXPECT_EQ(width
, copy_quad
->width
);
336 TEST(DrawQuadTest
, CopyIOSurfaceDrawQuad
) {
337 gfx::Rect
opaque_rect(3, 7, 10, 12);
338 gfx::Size
size(58, 95);
339 ResourceProvider::ResourceId resource_id
= 72;
340 IOSurfaceDrawQuad::Orientation orientation
= IOSurfaceDrawQuad::UNFLIPPED
;
341 CREATE_SHARED_STATE();
344 IOSurfaceDrawQuad
, opaque_rect
, size
, resource_id
, orientation
);
345 EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT
, copy_quad
->material
);
346 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
347 EXPECT_EQ(size
, copy_quad
->io_surface_size
);
348 EXPECT_EQ(resource_id
, copy_quad
->io_surface_resource_id
);
349 EXPECT_EQ(orientation
, copy_quad
->orientation
);
351 CREATE_QUAD_3_ALL(IOSurfaceDrawQuad
, size
, resource_id
, orientation
);
352 EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT
, copy_quad
->material
);
353 EXPECT_EQ(size
, copy_quad
->io_surface_size
);
354 EXPECT_EQ(resource_id
, copy_quad
->io_surface_resource_id
);
355 EXPECT_EQ(orientation
, copy_quad
->orientation
);
358 TEST(DrawQuadTest
, CopyRenderPassDrawQuad
) {
359 RenderPass::Id
render_pass_id(22, 64);
360 bool is_replica
= true;
361 ResourceProvider::ResourceId mask_resource_id
= 78;
362 gfx::Rect
contents_changed_since_last_frame(42, 11, 74, 24);
363 gfx::RectF
mask_u_v_rect(-45.f
, -21.f
, 33.f
, 19.f
);
364 FilterOperations filters
;
365 filters
.Append(FilterOperation::CreateBlurFilter(1.f
));
366 FilterOperations background_filters
;
367 background_filters
.Append(
368 FilterOperation::CreateGrayscaleFilter(1.f
));
369 skia::RefPtr
<SkImageFilter
> filter
=
370 skia::AdoptRef(new SkBlurImageFilter(SK_Scalar1
, SK_Scalar1
));
372 RenderPass::Id
copied_render_pass_id(235, 11);
373 CREATE_SHARED_STATE();
375 CREATE_QUAD_8_NEW_1(RenderPassDrawQuad
,
379 contents_changed_since_last_frame
,
384 copied_render_pass_id
);
385 EXPECT_EQ(DrawQuad::RENDER_PASS
, copy_quad
->material
);
386 EXPECT_EQ(copied_render_pass_id
, copy_quad
->render_pass_id
);
387 EXPECT_EQ(is_replica
, copy_quad
->is_replica
);
388 EXPECT_EQ(mask_resource_id
, copy_quad
->mask_resource_id
);
389 EXPECT_RECT_EQ(contents_changed_since_last_frame
,
390 copy_quad
->contents_changed_since_last_frame
);
391 EXPECT_EQ(mask_u_v_rect
.ToString(), copy_quad
->mask_uv_rect
.ToString());
392 EXPECT_EQ(filters
, copy_quad
->filters
);
393 EXPECT_EQ(filter
, copy_quad
->filter
);
394 EXPECT_EQ(background_filters
, copy_quad
->background_filters
);
396 CREATE_QUAD_8_ALL_1(RenderPassDrawQuad
,
400 contents_changed_since_last_frame
,
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(filter
, copy_quad
->filter
);
415 EXPECT_EQ(background_filters
, copy_quad
->background_filters
);
418 TEST(DrawQuadTest
, CopySolidColorDrawQuad
) {
419 SkColor color
= 0x49494949;
420 bool force_anti_aliasing_off
= false;
421 CREATE_SHARED_STATE();
423 CREATE_QUAD_2_NEW(SolidColorDrawQuad
, color
, force_anti_aliasing_off
);
424 EXPECT_EQ(DrawQuad::SOLID_COLOR
, copy_quad
->material
);
425 EXPECT_EQ(color
, copy_quad
->color
);
426 EXPECT_EQ(force_anti_aliasing_off
, copy_quad
->force_anti_aliasing_off
);
428 CREATE_QUAD_2_ALL(SolidColorDrawQuad
, color
, force_anti_aliasing_off
);
429 EXPECT_EQ(DrawQuad::SOLID_COLOR
, copy_quad
->material
);
430 EXPECT_EQ(color
, copy_quad
->color
);
431 EXPECT_EQ(force_anti_aliasing_off
, copy_quad
->force_anti_aliasing_off
);
434 TEST(DrawQuadTest
, CopyStreamVideoDrawQuad
) {
435 gfx::Rect
opaque_rect(3, 7, 10, 12);
436 ResourceProvider::ResourceId resource_id
= 64;
437 gfx::Transform matrix
= gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
438 CREATE_SHARED_STATE();
440 CREATE_QUAD_3_NEW(StreamVideoDrawQuad
, opaque_rect
, resource_id
, matrix
);
441 EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT
, copy_quad
->material
);
442 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
443 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
444 EXPECT_EQ(matrix
, copy_quad
->matrix
);
446 CREATE_QUAD_2_ALL(StreamVideoDrawQuad
, resource_id
, matrix
);
447 EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT
, copy_quad
->material
);
448 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
449 EXPECT_EQ(matrix
, copy_quad
->matrix
);
452 TEST(DrawQuadTest
, CopyTextureDrawQuad
) {
453 gfx::Rect
opaque_rect(3, 7, 10, 12);
454 unsigned resource_id
= 82;
455 bool premultiplied_alpha
= true;
456 gfx::PointF
uv_top_left(0.5f
, 224.f
);
457 gfx::PointF
uv_bottom_right(51.5f
, 260.f
);
458 const float vertex_opacity
[] = { 1.0f
, 1.0f
, 1.0f
, 1.0f
};
460 CREATE_SHARED_STATE();
462 CREATE_QUAD_8_NEW(TextureDrawQuad
,
471 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT
, copy_quad
->material
);
472 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
473 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
474 EXPECT_EQ(premultiplied_alpha
, copy_quad
->premultiplied_alpha
);
475 EXPECT_EQ(uv_top_left
, copy_quad
->uv_top_left
);
476 EXPECT_EQ(uv_bottom_right
, copy_quad
->uv_bottom_right
);
477 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity
, copy_quad
->vertex_opacity
, 4);
478 EXPECT_EQ(flipped
, copy_quad
->flipped
);
480 CREATE_QUAD_7_ALL(TextureDrawQuad
,
488 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT
, copy_quad
->material
);
489 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
490 EXPECT_EQ(premultiplied_alpha
, copy_quad
->premultiplied_alpha
);
491 EXPECT_EQ(uv_top_left
, copy_quad
->uv_top_left
);
492 EXPECT_EQ(uv_bottom_right
, copy_quad
->uv_bottom_right
);
493 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity
, copy_quad
->vertex_opacity
, 4);
494 EXPECT_EQ(flipped
, copy_quad
->flipped
);
497 TEST(DrawQuadTest
, ClipTextureDrawQuad
) {
498 gfx::Rect
opaque_rect(3, 7, 10, 12);
499 unsigned resource_id
= 82;
500 bool premultiplied_alpha
= true;
502 CREATE_SHARED_STATE();
503 // The original quad position is (30, 40) its size is 50*60.
504 shared_state
->content_to_target_transform
=
505 gfx::Transform(1.f
, 0.f
, 0.f
, 1.f
, 10.f
, 20.f
);
506 // After transformation, the quad position is (40, 60) its size is 50*60.
507 shared_state
->clip_rect
= gfx::Rect(50, 70, 30, 20);
509 // The original quad is 'ABCD', the clipped quad is 'abcd':
517 // UV and vertex opacity are stored per vertex on the parent rectangle 'ABCD'.
519 // This is the UV value for vertex 'B'.
520 gfx::PointF
uv_top_left(0.1f
, 0.2f
);
521 // This is the UV value for vertex 'D'.
522 gfx::PointF
uv_bottom_right(0.9f
, 0.8f
);
523 // This the vertex opacity for the vertices 'ABCD'.
524 const float vertex_opacity
[] = { 0.3f
, 0.4f
, 0.7f
, 0.8f
};
526 CREATE_QUAD_8_NEW(TextureDrawQuad
,
535 CREATE_QUAD_7_ALL(TextureDrawQuad
,
543 EXPECT_TRUE(quad_all
->PerformClipping());
545 // This is the expected UV value for vertex 'b'.
546 // uv(b) = uv(B) + (Bb / BD) * (uv(D) - uv(B))
547 // 0.3 = 0.2 + (10 / 60) * (0.8 - 0.2)
548 gfx::PointF
uv_top_left_clipped(0.26f
, 0.3f
);
549 // This is the expected UV value for vertex 'd'.
550 // uv(d) = uv(B) + (Bd / BD) * (uv(D) - uv(B))
551 gfx::PointF
uv_bottom_right_clipped(0.74f
, 0.5f
);
552 // This the expected vertex opacity for the vertices 'abcd'.
553 // They are computed with a bilinear interpolation of the corner values.
554 const float vertex_opacity_clipped
[] = { 0.43f
, 0.45f
, 0.65f
, 0.67f
};
556 EXPECT_EQ(uv_top_left_clipped
, quad_all
->uv_top_left
);
557 EXPECT_EQ(uv_bottom_right_clipped
, quad_all
->uv_bottom_right
);
558 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity_clipped
, quad_all
->vertex_opacity
, 4);
561 uv_top_left
= gfx::PointF(0.8f
, 0.7f
);
562 uv_bottom_right
= gfx::PointF(0.2f
, 0.1f
);
564 CREATE_QUAD_8_NEW(TextureDrawQuad
,
573 CREATE_QUAD_7_ALL(TextureDrawQuad
,
581 EXPECT_TRUE(quad_all
->PerformClipping());
583 // This is the expected UV value for vertex 'b'.
584 gfx::PointF
uv_top_left_clipped(0.68f
, 0.6f
);
585 // This is the expected UV value for vertex 'd'.
586 gfx::PointF
uv_bottom_right_clipped(0.32f
, 0.4f
);
588 EXPECT_EQ(uv_top_left_clipped
, quad_all
->uv_top_left
);
589 EXPECT_EQ(uv_bottom_right_clipped
, quad_all
->uv_bottom_right
);
593 TEST(DrawQuadTest
, CopyTileDrawQuad
) {
594 gfx::Rect
opaque_rect(33, 44, 22, 33);
595 unsigned resource_id
= 104;
596 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
597 gfx::Size
texture_size(85, 32);
598 bool swizzle_contents
= true;
599 CREATE_SHARED_STATE();
601 CREATE_QUAD_5_NEW(TileDrawQuad
,
607 EXPECT_EQ(DrawQuad::TILED_CONTENT
, copy_quad
->material
);
608 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
609 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
610 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
611 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
612 EXPECT_EQ(swizzle_contents
, copy_quad
->swizzle_contents
);
614 CREATE_QUAD_4_ALL(TileDrawQuad
,
619 EXPECT_EQ(DrawQuad::TILED_CONTENT
, copy_quad
->material
);
620 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
621 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
622 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
623 EXPECT_EQ(swizzle_contents
, copy_quad
->swizzle_contents
);
626 TEST(DrawQuadTest
, CopyYUVVideoDrawQuad
) {
627 gfx::Rect
opaque_rect(3, 7, 10, 12);
628 gfx::SizeF
tex_scale(0.75f
, 0.5f
);
629 ResourceProvider::ResourceId y_plane_resource_id
= 45;
630 ResourceProvider::ResourceId u_plane_resource_id
= 532;
631 ResourceProvider::ResourceId v_plane_resource_id
= 4;
632 ResourceProvider::ResourceId a_plane_resource_id
= 63;
633 CREATE_SHARED_STATE();
635 CREATE_QUAD_6_NEW(YUVVideoDrawQuad
,
641 a_plane_resource_id
);
642 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
643 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
644 EXPECT_EQ(tex_scale
, copy_quad
->tex_scale
);
645 EXPECT_EQ(y_plane_resource_id
, copy_quad
->y_plane_resource_id
);
646 EXPECT_EQ(u_plane_resource_id
, copy_quad
->u_plane_resource_id
);
647 EXPECT_EQ(v_plane_resource_id
, copy_quad
->v_plane_resource_id
);
648 EXPECT_EQ(a_plane_resource_id
, copy_quad
->a_plane_resource_id
);
650 CREATE_QUAD_5_ALL(YUVVideoDrawQuad
,
655 a_plane_resource_id
);
656 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
657 EXPECT_EQ(tex_scale
, copy_quad
->tex_scale
);
658 EXPECT_EQ(y_plane_resource_id
, copy_quad
->y_plane_resource_id
);
659 EXPECT_EQ(u_plane_resource_id
, copy_quad
->u_plane_resource_id
);
660 EXPECT_EQ(v_plane_resource_id
, copy_quad
->v_plane_resource_id
);
661 EXPECT_EQ(a_plane_resource_id
, copy_quad
->a_plane_resource_id
);
664 TEST(DrawQuadTest
, CopyPictureDrawQuad
) {
665 gfx::Rect
opaque_rect(33, 44, 22, 33);
666 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
667 gfx::Size
texture_size(85, 32);
668 bool swizzle_contents
= true;
669 gfx::Rect
content_rect(30, 40, 20, 30);
670 float contents_scale
= 3.141592f
;
671 bool can_draw_direct_to_backbuffer
= true;
672 scoped_refptr
<PicturePileImpl
> picture_pile
= PicturePileImpl::Create();
673 CREATE_SHARED_STATE();
675 CREATE_QUAD_8_NEW(PictureDrawQuad
,
682 can_draw_direct_to_backbuffer
,
684 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
, copy_quad
->material
);
685 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
686 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
687 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
688 EXPECT_EQ(swizzle_contents
, copy_quad
->swizzle_contents
);
689 EXPECT_RECT_EQ(content_rect
, copy_quad
->content_rect
);
690 EXPECT_EQ(contents_scale
, copy_quad
->contents_scale
);
691 EXPECT_EQ(can_draw_direct_to_backbuffer
,
692 copy_quad
->can_draw_direct_to_backbuffer
);
693 EXPECT_EQ(picture_pile
, copy_quad
->picture_pile
);
695 CREATE_QUAD_7_ALL(PictureDrawQuad
,
701 can_draw_direct_to_backbuffer
,
703 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
, copy_quad
->material
);
704 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
705 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
706 EXPECT_EQ(swizzle_contents
, copy_quad
->swizzle_contents
);
707 EXPECT_RECT_EQ(content_rect
, copy_quad
->content_rect
);
708 EXPECT_EQ(contents_scale
, copy_quad
->contents_scale
);
709 EXPECT_EQ(can_draw_direct_to_backbuffer
,
710 copy_quad
->can_draw_direct_to_backbuffer
);
711 EXPECT_EQ(picture_pile
, copy_quad
->picture_pile
);
714 class DrawQuadIteratorTest
: public testing::Test
{
716 ResourceProvider::ResourceId
IncrementResourceId(
717 ResourceProvider::ResourceId id
) {
722 int IterateAndCount(DrawQuad
* quad
) {
724 quad
->IterateResources(base::Bind(
725 &DrawQuadIteratorTest::IncrementResourceId
, base::Unretained(this)));
726 return num_resources_
;
733 TEST_F(DrawQuadIteratorTest
, CheckerboardDrawQuad
) {
734 SkColor color
= 0xfabb0011;
736 CREATE_SHARED_STATE();
737 CREATE_QUAD_1_NEW(CheckerboardDrawQuad
, color
);
738 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
741 TEST_F(DrawQuadIteratorTest
, DebugBorderDrawQuad
) {
742 SkColor color
= 0xfabb0011;
745 CREATE_SHARED_STATE();
746 CREATE_QUAD_2_NEW(DebugBorderDrawQuad
, color
, width
);
747 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
750 TEST_F(DrawQuadIteratorTest
, IOSurfaceDrawQuad
) {
751 gfx::Rect
opaque_rect(3, 7, 10, 12);
752 gfx::Size
size(58, 95);
753 ResourceProvider::ResourceId resource_id
= 72;
754 IOSurfaceDrawQuad::Orientation orientation
= IOSurfaceDrawQuad::UNFLIPPED
;
756 CREATE_SHARED_STATE();
758 IOSurfaceDrawQuad
, opaque_rect
, size
, resource_id
, orientation
);
759 EXPECT_EQ(resource_id
, quad_new
->io_surface_resource_id
);
760 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
761 EXPECT_EQ(resource_id
+ 1, quad_new
->io_surface_resource_id
);
764 TEST_F(DrawQuadIteratorTest
, RenderPassDrawQuad
) {
765 RenderPass::Id
render_pass_id(22, 64);
766 bool is_replica
= true;
767 ResourceProvider::ResourceId mask_resource_id
= 78;
768 gfx::Rect
contents_changed_since_last_frame(42, 11, 74, 24);
769 gfx::RectF
mask_u_v_rect(-45.f
, -21.f
, 33.f
, 19.f
);
770 FilterOperations filters
;
771 filters
.Append(FilterOperation::CreateBlurFilter(1.f
));
772 FilterOperations background_filters
;
773 background_filters
.Append(
774 FilterOperation::CreateGrayscaleFilter(1.f
));
775 skia::RefPtr
<SkImageFilter
> filter
=
776 skia::AdoptRef(new SkBlurImageFilter(SK_Scalar1
, SK_Scalar1
));
778 RenderPass::Id
copied_render_pass_id(235, 11);
780 CREATE_SHARED_STATE();
781 CREATE_QUAD_8_NEW_1(RenderPassDrawQuad
,
785 contents_changed_since_last_frame
,
790 copied_render_pass_id
);
791 EXPECT_EQ(mask_resource_id
, quad_new
->mask_resource_id
);
792 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
793 EXPECT_EQ(mask_resource_id
+ 1, quad_new
->mask_resource_id
);
794 quad_new
->mask_resource_id
= 0;
795 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
796 EXPECT_EQ(0u, quad_new
->mask_resource_id
);
799 TEST_F(DrawQuadIteratorTest
, SolidColorDrawQuad
) {
800 SkColor color
= 0x49494949;
801 bool force_anti_aliasing_off
= false;
803 CREATE_SHARED_STATE();
804 CREATE_QUAD_2_NEW(SolidColorDrawQuad
, color
, force_anti_aliasing_off
);
805 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
808 TEST_F(DrawQuadIteratorTest
, StreamVideoDrawQuad
) {
809 gfx::Rect
opaque_rect(3, 7, 10, 12);
810 ResourceProvider::ResourceId resource_id
= 64;
811 gfx::Transform matrix
= gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
813 CREATE_SHARED_STATE();
814 CREATE_QUAD_3_NEW(StreamVideoDrawQuad
, opaque_rect
, resource_id
, matrix
);
815 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
816 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
817 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
820 TEST_F(DrawQuadIteratorTest
, TextureDrawQuad
) {
821 gfx::Rect
opaque_rect(3, 7, 10, 12);
822 unsigned resource_id
= 82;
823 bool premultiplied_alpha
= true;
824 gfx::PointF
uv_top_left(0.5f
, 224.f
);
825 gfx::PointF
uv_bottom_right(51.5f
, 260.f
);
826 const float vertex_opacity
[] = { 1.0f
, 1.0f
, 1.0f
, 1.0f
};
829 CREATE_SHARED_STATE();
830 CREATE_QUAD_8_NEW(TextureDrawQuad
,
839 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
840 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
841 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
844 TEST_F(DrawQuadIteratorTest
, TileDrawQuad
) {
845 gfx::Rect
opaque_rect(33, 44, 22, 33);
846 unsigned resource_id
= 104;
847 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
848 gfx::Size
texture_size(85, 32);
849 bool swizzle_contents
= true;
851 CREATE_SHARED_STATE();
852 CREATE_QUAD_5_NEW(TileDrawQuad
,
858 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
859 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
860 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
863 TEST_F(DrawQuadIteratorTest
, YUVVideoDrawQuad
) {
864 gfx::Rect
opaque_rect(3, 7, 10, 12);
865 gfx::SizeF
tex_scale(0.75f
, 0.5f
);
866 ResourceProvider::ResourceId y_plane_resource_id
= 45;
867 ResourceProvider::ResourceId u_plane_resource_id
= 532;
868 ResourceProvider::ResourceId v_plane_resource_id
= 4;
869 ResourceProvider::ResourceId a_plane_resource_id
= 63;
871 CREATE_SHARED_STATE();
872 CREATE_QUAD_6_NEW(YUVVideoDrawQuad
,
878 a_plane_resource_id
);
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(4, IterateAndCount(quad_new
.get()));
885 EXPECT_EQ(y_plane_resource_id
+ 1, quad_new
->y_plane_resource_id
);
886 EXPECT_EQ(u_plane_resource_id
+ 1, quad_new
->u_plane_resource_id
);
887 EXPECT_EQ(v_plane_resource_id
+ 1, quad_new
->v_plane_resource_id
);
888 EXPECT_EQ(a_plane_resource_id
+ 1, quad_new
->a_plane_resource_id
);
891 // Disabled until picture draw quad is supported for ubercomp: crbug.com/231715
892 TEST_F(DrawQuadIteratorTest
, DISABLED_PictureDrawQuad
) {
893 gfx::Rect
opaque_rect(33, 44, 22, 33);
894 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
895 gfx::Size
texture_size(85, 32);
896 bool swizzle_contents
= true;
897 gfx::Rect
content_rect(30, 40, 20, 30);
898 float contents_scale
= 3.141592f
;
899 bool can_draw_direct_to_backbuffer
= true;
900 scoped_refptr
<PicturePileImpl
> picture_pile
= PicturePileImpl::Create();
902 CREATE_SHARED_STATE();
903 CREATE_QUAD_8_NEW(PictureDrawQuad
,
910 can_draw_direct_to_backbuffer
,
912 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));