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/quads/checkerboard_draw_quad.h"
13 #include "cc/quads/debug_border_draw_quad.h"
14 #include "cc/quads/io_surface_draw_quad.h"
15 #include "cc/quads/picture_draw_quad.h"
16 #include "cc/quads/render_pass_draw_quad.h"
17 #include "cc/quads/solid_color_draw_quad.h"
18 #include "cc/quads/stream_video_draw_quad.h"
19 #include "cc/quads/texture_draw_quad.h"
20 #include "cc/quads/tile_draw_quad.h"
21 #include "cc/quads/yuv_video_draw_quad.h"
22 #include "cc/resources/picture_pile_impl.h"
23 #include "cc/test/geometry_test_utils.h"
24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations.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 WebKit::WebFilterOperations filters
;
365 filters
.append(WebKit::WebFilterOperation::createBlurFilter(1.f
));
366 WebKit::WebFilterOperations background_filters
;
367 background_filters
.append(
368 WebKit::WebFilterOperation::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_7_NEW(TextureDrawQuad
,
470 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT
, copy_quad
->material
);
471 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
472 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
473 EXPECT_EQ(premultiplied_alpha
, copy_quad
->premultiplied_alpha
);
474 EXPECT_EQ(uv_top_left
, copy_quad
->uv_top_left
);
475 EXPECT_EQ(uv_bottom_right
, copy_quad
->uv_bottom_right
);
476 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity
, copy_quad
->vertex_opacity
, 4);
477 EXPECT_EQ(flipped
, copy_quad
->flipped
);
479 CREATE_QUAD_6_ALL(TextureDrawQuad
,
486 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT
, copy_quad
->material
);
487 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
488 EXPECT_EQ(premultiplied_alpha
, copy_quad
->premultiplied_alpha
);
489 EXPECT_EQ(uv_top_left
, copy_quad
->uv_top_left
);
490 EXPECT_EQ(uv_bottom_right
, copy_quad
->uv_bottom_right
);
491 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity
, copy_quad
->vertex_opacity
, 4);
492 EXPECT_EQ(flipped
, copy_quad
->flipped
);
495 TEST(DrawQuadTest
, ClipTextureDrawQuad
) {
496 gfx::Rect
opaque_rect(3, 7, 10, 12);
497 unsigned resource_id
= 82;
498 bool premultiplied_alpha
= true;
500 CREATE_SHARED_STATE();
501 // The original quad position is (30, 40) its size is 50*60.
502 shared_state
->content_to_target_transform
=
503 gfx::Transform(1.f
, 0.f
, 0.f
, 1.f
, 10.f
, 20.f
);
504 // After transformation, the quad position is (40, 60) its size is 50*60.
505 shared_state
->clip_rect
= gfx::Rect(50, 70, 30, 20);
507 // The original quad is 'ABCD', the clipped quad is 'abcd':
515 // UV and vertex opacity are stored per vertex on the parent rectangle 'ABCD'.
517 // This is the UV value for vertex 'B'.
518 gfx::PointF
uv_top_left(0.1f
, 0.2f
);
519 // This is the UV value for vertex 'D'.
520 gfx::PointF
uv_bottom_right(0.9f
, 0.8f
);
521 // This the vertex opacity for the vertices 'ABCD'.
522 const float vertex_opacity
[] = { 0.3f
, 0.4f
, 0.7f
, 0.8f
};
524 CREATE_QUAD_7_NEW(TextureDrawQuad
,
532 CREATE_QUAD_6_ALL(TextureDrawQuad
,
539 EXPECT_TRUE(quad_all
->PerformClipping());
541 // This is the expected UV value for vertex 'b'.
542 // uv(b) = uv(B) + (Bb / BD) * (uv(D) - uv(B))
543 // 0.3 = 0.2 + (10 / 60) * (0.8 - 0.2)
544 gfx::PointF
uv_top_left_clipped(0.26f
, 0.3f
);
545 // This is the expected UV value for vertex 'd'.
546 // uv(d) = uv(B) + (Bd / BD) * (uv(D) - uv(B))
547 gfx::PointF
uv_bottom_right_clipped(0.74f
, 0.5f
);
548 // This the expected vertex opacity for the vertices 'abcd'.
549 // They are computed with a bilinear interpolation of the corner values.
550 const float vertex_opacity_clipped
[] = { 0.43f
, 0.45f
, 0.65f
, 0.67f
};
552 EXPECT_EQ(uv_top_left_clipped
, quad_all
->uv_top_left
);
553 EXPECT_EQ(uv_bottom_right_clipped
, quad_all
->uv_bottom_right
);
554 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity_clipped
, quad_all
->vertex_opacity
, 4);
557 uv_top_left
= gfx::PointF(0.8f
, 0.7f
);
558 uv_bottom_right
= gfx::PointF(0.2f
, 0.1f
);
560 CREATE_QUAD_7_NEW(TextureDrawQuad
,
568 CREATE_QUAD_6_ALL(TextureDrawQuad
,
575 EXPECT_TRUE(quad_all
->PerformClipping());
577 // This is the expected UV value for vertex 'b'.
578 gfx::PointF
uv_top_left_clipped(0.68f
, 0.6f
);
579 // This is the expected UV value for vertex 'd'.
580 gfx::PointF
uv_bottom_right_clipped(0.32f
, 0.4f
);
582 EXPECT_EQ(uv_top_left_clipped
, quad_all
->uv_top_left
);
583 EXPECT_EQ(uv_bottom_right_clipped
, quad_all
->uv_bottom_right
);
587 TEST(DrawQuadTest
, CopyTileDrawQuad
) {
588 gfx::Rect
opaque_rect(33, 44, 22, 33);
589 unsigned resource_id
= 104;
590 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
591 gfx::Size
texture_size(85, 32);
592 bool swizzle_contents
= true;
593 CREATE_SHARED_STATE();
595 CREATE_QUAD_5_NEW(TileDrawQuad
,
601 EXPECT_EQ(DrawQuad::TILED_CONTENT
, copy_quad
->material
);
602 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
603 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
604 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
605 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
606 EXPECT_EQ(swizzle_contents
, copy_quad
->swizzle_contents
);
608 CREATE_QUAD_4_ALL(TileDrawQuad
,
613 EXPECT_EQ(DrawQuad::TILED_CONTENT
, copy_quad
->material
);
614 EXPECT_EQ(resource_id
, copy_quad
->resource_id
);
615 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
616 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
617 EXPECT_EQ(swizzle_contents
, copy_quad
->swizzle_contents
);
620 TEST(DrawQuadTest
, CopyYUVVideoDrawQuad
) {
621 gfx::Rect
opaque_rect(3, 7, 10, 12);
622 gfx::SizeF
tex_scale(0.75f
, 0.5f
);
623 ResourceProvider::ResourceId y_plane_resource_id
= 45;
624 ResourceProvider::ResourceId u_plane_resource_id
= 532;
625 ResourceProvider::ResourceId v_plane_resource_id
= 4;
626 CREATE_SHARED_STATE();
628 CREATE_QUAD_5_NEW(YUVVideoDrawQuad
,
633 v_plane_resource_id
);
634 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
635 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
636 EXPECT_EQ(tex_scale
, copy_quad
->tex_scale
);
637 EXPECT_EQ(y_plane_resource_id
, copy_quad
->y_plane_resource_id
);
638 EXPECT_EQ(u_plane_resource_id
, copy_quad
->u_plane_resource_id
);
639 EXPECT_EQ(v_plane_resource_id
, copy_quad
->v_plane_resource_id
);
641 CREATE_QUAD_4_ALL(YUVVideoDrawQuad
,
645 v_plane_resource_id
);
646 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
647 EXPECT_EQ(tex_scale
, copy_quad
->tex_scale
);
648 EXPECT_EQ(y_plane_resource_id
, copy_quad
->y_plane_resource_id
);
649 EXPECT_EQ(u_plane_resource_id
, copy_quad
->u_plane_resource_id
);
650 EXPECT_EQ(v_plane_resource_id
, copy_quad
->v_plane_resource_id
);
653 TEST(DrawQuadTest
, CopyPictureDrawQuad
) {
654 gfx::Rect
opaque_rect(33, 44, 22, 33);
655 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
656 gfx::Size
texture_size(85, 32);
657 bool swizzle_contents
= true;
658 gfx::Rect
content_rect(30, 40, 20, 30);
659 float contents_scale
= 3.141592f
;
660 bool can_draw_direct_to_backbuffer
= true;
661 scoped_refptr
<PicturePileImpl
> picture_pile
= PicturePileImpl::Create(false);
662 CREATE_SHARED_STATE();
664 CREATE_QUAD_8_NEW(PictureDrawQuad
,
671 can_draw_direct_to_backbuffer
,
673 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
, copy_quad
->material
);
674 EXPECT_RECT_EQ(opaque_rect
, copy_quad
->opaque_rect
);
675 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
676 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
677 EXPECT_EQ(swizzle_contents
, copy_quad
->swizzle_contents
);
678 EXPECT_RECT_EQ(content_rect
, copy_quad
->content_rect
);
679 EXPECT_EQ(contents_scale
, copy_quad
->contents_scale
);
680 EXPECT_EQ(can_draw_direct_to_backbuffer
,
681 copy_quad
->can_draw_direct_to_backbuffer
);
682 EXPECT_EQ(picture_pile
, copy_quad
->picture_pile
);
684 CREATE_QUAD_7_ALL(PictureDrawQuad
,
690 can_draw_direct_to_backbuffer
,
692 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
, copy_quad
->material
);
693 EXPECT_EQ(tex_coord_rect
, copy_quad
->tex_coord_rect
);
694 EXPECT_EQ(texture_size
, copy_quad
->texture_size
);
695 EXPECT_EQ(swizzle_contents
, copy_quad
->swizzle_contents
);
696 EXPECT_RECT_EQ(content_rect
, copy_quad
->content_rect
);
697 EXPECT_EQ(contents_scale
, copy_quad
->contents_scale
);
698 EXPECT_EQ(can_draw_direct_to_backbuffer
,
699 copy_quad
->can_draw_direct_to_backbuffer
);
700 EXPECT_EQ(picture_pile
, copy_quad
->picture_pile
);
703 class DrawQuadIteratorTest
: public testing::Test
{
705 ResourceProvider::ResourceId
IncrementResourceId(
706 ResourceProvider::ResourceId id
) {
711 int IterateAndCount(DrawQuad
* quad
) {
713 quad
->IterateResources(base::Bind(
714 &DrawQuadIteratorTest::IncrementResourceId
, base::Unretained(this)));
715 return num_resources_
;
722 TEST_F(DrawQuadIteratorTest
, CheckerboardDrawQuad
) {
723 SkColor color
= 0xfabb0011;
725 CREATE_SHARED_STATE();
726 CREATE_QUAD_1_NEW(CheckerboardDrawQuad
, color
);
727 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
730 TEST_F(DrawQuadIteratorTest
, DebugBorderDrawQuad
) {
731 SkColor color
= 0xfabb0011;
734 CREATE_SHARED_STATE();
735 CREATE_QUAD_2_NEW(DebugBorderDrawQuad
, color
, width
);
736 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
739 TEST_F(DrawQuadIteratorTest
, IOSurfaceDrawQuad
) {
740 gfx::Rect
opaque_rect(3, 7, 10, 12);
741 gfx::Size
size(58, 95);
742 ResourceProvider::ResourceId resource_id
= 72;
743 IOSurfaceDrawQuad::Orientation orientation
= IOSurfaceDrawQuad::UNFLIPPED
;
745 CREATE_SHARED_STATE();
747 IOSurfaceDrawQuad
, opaque_rect
, size
, resource_id
, orientation
);
748 EXPECT_EQ(resource_id
, quad_new
->io_surface_resource_id
);
749 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
750 EXPECT_EQ(resource_id
+ 1, quad_new
->io_surface_resource_id
);
753 TEST_F(DrawQuadIteratorTest
, RenderPassDrawQuad
) {
754 RenderPass::Id
render_pass_id(22, 64);
755 bool is_replica
= true;
756 ResourceProvider::ResourceId mask_resource_id
= 78;
757 gfx::Rect
contents_changed_since_last_frame(42, 11, 74, 24);
758 gfx::RectF
mask_u_v_rect(-45.f
, -21.f
, 33.f
, 19.f
);
759 WebKit::WebFilterOperations filters
;
760 filters
.append(WebKit::WebFilterOperation::createBlurFilter(1.f
));
761 WebKit::WebFilterOperations background_filters
;
762 background_filters
.append(
763 WebKit::WebFilterOperation::createGrayscaleFilter(1.f
));
764 skia::RefPtr
<SkImageFilter
> filter
=
765 skia::AdoptRef(new SkBlurImageFilter(SK_Scalar1
, SK_Scalar1
));
767 RenderPass::Id
copied_render_pass_id(235, 11);
769 CREATE_SHARED_STATE();
770 CREATE_QUAD_8_NEW_1(RenderPassDrawQuad
,
774 contents_changed_since_last_frame
,
779 copied_render_pass_id
);
780 EXPECT_EQ(mask_resource_id
, quad_new
->mask_resource_id
);
781 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
782 EXPECT_EQ(mask_resource_id
+ 1, quad_new
->mask_resource_id
);
783 quad_new
->mask_resource_id
= 0;
784 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
785 EXPECT_EQ(0u, quad_new
->mask_resource_id
);
788 TEST_F(DrawQuadIteratorTest
, SolidColorDrawQuad
) {
789 SkColor color
= 0x49494949;
790 bool force_anti_aliasing_off
= false;
792 CREATE_SHARED_STATE();
793 CREATE_QUAD_2_NEW(SolidColorDrawQuad
, color
, force_anti_aliasing_off
);
794 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));
797 TEST_F(DrawQuadIteratorTest
, StreamVideoDrawQuad
) {
798 gfx::Rect
opaque_rect(3, 7, 10, 12);
799 ResourceProvider::ResourceId resource_id
= 64;
800 gfx::Transform matrix
= gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
802 CREATE_SHARED_STATE();
803 CREATE_QUAD_3_NEW(StreamVideoDrawQuad
, opaque_rect
, resource_id
, matrix
);
804 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
805 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
806 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
809 TEST_F(DrawQuadIteratorTest
, TextureDrawQuad
) {
810 gfx::Rect
opaque_rect(3, 7, 10, 12);
811 unsigned resource_id
= 82;
812 bool premultiplied_alpha
= true;
813 gfx::PointF
uv_top_left(0.5f
, 224.f
);
814 gfx::PointF
uv_bottom_right(51.5f
, 260.f
);
815 const float vertex_opacity
[] = { 1.0f
, 1.0f
, 1.0f
, 1.0f
};
818 CREATE_SHARED_STATE();
819 CREATE_QUAD_7_NEW(TextureDrawQuad
,
827 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
828 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
829 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
832 TEST_F(DrawQuadIteratorTest
, TileDrawQuad
) {
833 gfx::Rect
opaque_rect(33, 44, 22, 33);
834 unsigned resource_id
= 104;
835 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
836 gfx::Size
texture_size(85, 32);
837 bool swizzle_contents
= true;
839 CREATE_SHARED_STATE();
840 CREATE_QUAD_5_NEW(TileDrawQuad
,
846 EXPECT_EQ(resource_id
, quad_new
->resource_id
);
847 EXPECT_EQ(1, IterateAndCount(quad_new
.get()));
848 EXPECT_EQ(resource_id
+ 1, quad_new
->resource_id
);
851 TEST_F(DrawQuadIteratorTest
, YUVVideoDrawQuad
) {
852 gfx::Rect
opaque_rect(3, 7, 10, 12);
853 gfx::SizeF
tex_scale(0.75f
, 0.5f
);
854 ResourceProvider::ResourceId y_plane_resource_id
= 45;
855 ResourceProvider::ResourceId u_plane_resource_id
= 532;
856 ResourceProvider::ResourceId v_plane_resource_id
= 4;
858 CREATE_SHARED_STATE();
859 CREATE_QUAD_5_NEW(YUVVideoDrawQuad
,
864 v_plane_resource_id
);
865 EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT
, copy_quad
->material
);
866 EXPECT_EQ(y_plane_resource_id
, quad_new
->y_plane_resource_id
);
867 EXPECT_EQ(u_plane_resource_id
, quad_new
->u_plane_resource_id
);
868 EXPECT_EQ(v_plane_resource_id
, quad_new
->v_plane_resource_id
);
869 EXPECT_EQ(3, IterateAndCount(quad_new
.get()));
870 EXPECT_EQ(y_plane_resource_id
+ 1, quad_new
->y_plane_resource_id
);
871 EXPECT_EQ(u_plane_resource_id
+ 1, quad_new
->u_plane_resource_id
);
872 EXPECT_EQ(v_plane_resource_id
+ 1, quad_new
->v_plane_resource_id
);
875 // Disabled until picture draw quad is supported for ubercomp: crbug.com/231715
876 TEST_F(DrawQuadIteratorTest
, DISABLED_PictureDrawQuad
) {
877 gfx::Rect
opaque_rect(33, 44, 22, 33);
878 gfx::RectF
tex_coord_rect(31.f
, 12.f
, 54.f
, 20.f
);
879 gfx::Size
texture_size(85, 32);
880 bool swizzle_contents
= true;
881 gfx::Rect
content_rect(30, 40, 20, 30);
882 float contents_scale
= 3.141592f
;
883 bool can_draw_direct_to_backbuffer
= true;
884 scoped_refptr
<PicturePileImpl
> picture_pile
= PicturePileImpl::Create(false);
886 CREATE_SHARED_STATE();
887 CREATE_QUAD_8_NEW(PictureDrawQuad
,
894 can_draw_direct_to_backbuffer
,
896 EXPECT_EQ(0, IterateAndCount(quad_new
.get()));