Home | History | Annotate | Download | only in quads
      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.
      4 
      5 #include "cc/quads/draw_quad.h"
      6 
      7 #include <algorithm>
      8 
      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/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"
     28 
     29 namespace cc {
     30 namespace {
     31 
     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;
     39   SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode;
     40 
     41   scoped_ptr<SharedQuadState> state(SharedQuadState::Create());
     42   state->SetAll(quad_transform,
     43                 content_bounds,
     44                 visible_content_rect,
     45                 clip_rect,
     46                 is_clipped,
     47                 opacity,
     48                 blend_mode);
     49 
     50   scoped_ptr<SharedQuadState> copy(state->Copy());
     51   EXPECT_EQ(quad_transform, copy->content_to_target_transform);
     52   EXPECT_RECT_EQ(visible_content_rect, copy->visible_content_rect);
     53   EXPECT_EQ(opacity, copy->opacity);
     54   EXPECT_RECT_EQ(clip_rect, copy->clip_rect);
     55   EXPECT_EQ(is_clipped, copy->is_clipped);
     56   EXPECT_EQ(blend_mode, copy->blend_mode);
     57 }
     58 
     59 scoped_ptr<SharedQuadState> CreateSharedQuadState() {
     60   gfx::Transform quad_transform = gfx::Transform(1.0, 0.0, 0.5, 1.0, 0.5, 0.0);
     61   gfx::Size content_bounds(26, 28);
     62   gfx::Rect visible_content_rect(10, 12, 14, 16);
     63   gfx::Rect clip_rect(19, 21, 23, 25);
     64   bool is_clipped = false;
     65   float opacity = 1.f;
     66   SkXfermode::Mode blend_mode = SkXfermode::kSrcOver_Mode;
     67 
     68   scoped_ptr<SharedQuadState> state(SharedQuadState::Create());
     69   state->SetAll(quad_transform,
     70                 content_bounds,
     71                 visible_content_rect,
     72                 clip_rect,
     73                 is_clipped,
     74                 opacity,
     75                 blend_mode);
     76   return state.Pass();
     77 }
     78 
     79 void CompareDrawQuad(DrawQuad* quad,
     80                      DrawQuad* copy,
     81                      SharedQuadState* copy_shared_state) {
     82   EXPECT_EQ(quad->material, copy->material);
     83   EXPECT_RECT_EQ(quad->rect, copy->rect);
     84   EXPECT_RECT_EQ(quad->visible_rect, copy->visible_rect);
     85   EXPECT_RECT_EQ(quad->opaque_rect, copy->opaque_rect);
     86   EXPECT_EQ(quad->needs_blending, copy->needs_blending);
     87   EXPECT_EQ(copy_shared_state, copy->shared_quad_state);
     88 }
     89 
     90 #define CREATE_SHARED_STATE() \
     91     scoped_ptr<SharedQuadState> shared_state(CreateSharedQuadState()); \
     92     scoped_ptr<SharedQuadState> copy_shared_state(shared_state->Copy()); \
     93 
     94 #define QUAD_DATA \
     95     gfx::Rect quad_rect(30, 40, 50, 60); \
     96     gfx::Rect quad_visible_rect(40, 50, 30, 20); \
     97     gfx::Rect ALLOW_UNUSED quad_opaque_rect(60, 55, 10, 10); \
     98     bool ALLOW_UNUSED needs_blending = true;
     99 
    100 #define SETUP_AND_COPY_QUAD_NEW(Type, quad) \
    101     scoped_ptr<DrawQuad> copy_new(quad_new->Copy(copy_shared_state.get())); \
    102     CompareDrawQuad(quad_new.get(), copy_new.get(), copy_shared_state.get()); \
    103     const Type* ALLOW_UNUSED copy_quad = Type::MaterialCast(copy_new.get());
    104 
    105 #define SETUP_AND_COPY_QUAD_ALL(Type, quad) \
    106     scoped_ptr<DrawQuad> copy_all(quad_all->Copy(copy_shared_state.get())); \
    107     CompareDrawQuad(quad_all.get(), copy_all.get(), copy_shared_state.get()); \
    108     copy_quad = Type::MaterialCast(copy_all.get());
    109 
    110 #define SETUP_AND_COPY_QUAD_NEW_1(Type, quad, a) \
    111     scoped_ptr<DrawQuad> copy_new(quad_new->Copy(copy_shared_state.get(), a)); \
    112     CompareDrawQuad(quad_new.get(), copy_new.get(), copy_shared_state.get()); \
    113     const Type* ALLOW_UNUSED copy_quad = Type::MaterialCast(copy_new.get());
    114 
    115 #define SETUP_AND_COPY_QUAD_ALL_1(Type, quad, a) \
    116     scoped_ptr<DrawQuad> copy_all(quad_all->Copy(copy_shared_state.get(), a)); \
    117     CompareDrawQuad(quad_all.get(), copy_all.get(), copy_shared_state.get()); \
    118     copy_quad = Type::MaterialCast(copy_all.get());
    119 
    120 #define CREATE_QUAD_1_NEW(Type, a) \
    121     scoped_ptr<Type> quad_new(Type::Create()); \
    122     { \
    123       QUAD_DATA \
    124       quad_new->SetNew(shared_state.get(), quad_rect, a); \
    125     } \
    126     SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
    127 
    128 #define CREATE_QUAD_1_ALL(Type, a) \
    129     scoped_ptr<Type> quad_all(Type::Create()); \
    130     { \
    131       QUAD_DATA \
    132       quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
    133                        quad_visible_rect, needs_blending, a); \
    134     } \
    135     SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
    136 
    137 #define CREATE_QUAD_2_NEW(Type, a, b) \
    138     scoped_ptr<Type> quad_new(Type::Create()); \
    139     { \
    140       QUAD_DATA \
    141       quad_new->SetNew(shared_state.get(), quad_rect, a, b); \
    142     } \
    143     SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
    144 
    145 #define CREATE_QUAD_2_ALL(Type, a, b) \
    146     scoped_ptr<Type> quad_all(Type::Create()); \
    147     { \
    148       QUAD_DATA \
    149       quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
    150                        quad_visible_rect, needs_blending, a, b); \
    151     } \
    152     SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
    153 
    154 #define CREATE_QUAD_3_NEW(Type, a, b, c) \
    155     scoped_ptr<Type> quad_new(Type::Create()); \
    156     { \
    157       QUAD_DATA \
    158       quad_new->SetNew(shared_state.get(), quad_rect, a, b, c); \
    159     } \
    160     SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
    161 
    162 #define CREATE_QUAD_3_ALL(Type, a, b, c) \
    163     scoped_ptr<Type> quad_all(Type::Create()); \
    164     { \
    165       QUAD_DATA \
    166       quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
    167                        quad_visible_rect, needs_blending, a, b, c); \
    168     } \
    169     SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
    170 
    171 #define CREATE_QUAD_4_NEW(Type, a, b, c, d) \
    172     scoped_ptr<Type> quad_new(Type::Create()); \
    173     { \
    174       QUAD_DATA \
    175       quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d); \
    176     } \
    177     SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
    178 
    179 #define CREATE_QUAD_4_ALL(Type, a, b, c, d) \
    180     scoped_ptr<Type> quad_all(Type::Create()); \
    181     { \
    182       QUAD_DATA \
    183       quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
    184                        quad_visible_rect, needs_blending, a, b, c, d); \
    185     } \
    186     SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
    187 
    188 #define CREATE_QUAD_5_NEW(Type, a, b, c, d, e) \
    189     scoped_ptr<Type> quad_new(Type::Create()); \
    190     { \
    191       QUAD_DATA \
    192       quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e); \
    193     } \
    194     SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
    195 
    196 #define CREATE_QUAD_5_ALL(Type, a, b, c, d, e) \
    197     scoped_ptr<Type> quad_all(Type::Create()); \
    198     { \
    199       QUAD_DATA \
    200       quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
    201                        quad_visible_rect, needs_blending, a, b, c, d, e); \
    202     } \
    203     SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
    204 
    205 #define CREATE_QUAD_5_NEW_1(Type, a, b, c, d, e, copy_a) \
    206     scoped_ptr<Type> quad_new(Type::Create()); \
    207     { \
    208       QUAD_DATA \
    209       quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e); \
    210     } \
    211     SETUP_AND_COPY_QUAD_NEW_1(Type, quad_new, copy_a);
    212 
    213 #define CREATE_QUAD_5_ALL_1(Type, a, b, c, d, e, copy_a) \
    214     scoped_ptr<Type> quad_all(Type::Create()); \
    215     { \
    216       QUAD_DATA \
    217       quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
    218                        quad_visible_rect, needs_blending, a, b, c, d, e); \
    219     } \
    220     SETUP_AND_COPY_QUAD_ALL_1(Type, quad_all, copy_a);
    221 
    222 #define CREATE_QUAD_6_NEW(Type, a, b, c, d, e, f) \
    223     scoped_ptr<Type> quad_new(Type::Create()); \
    224     { \
    225       QUAD_DATA \
    226       quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f); \
    227     } \
    228     SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
    229 
    230 #define CREATE_QUAD_6_ALL(Type, a, b, c, d, e, f) \
    231     scoped_ptr<Type> quad_all(Type::Create()); \
    232     { \
    233       QUAD_DATA \
    234       quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
    235                        quad_visible_rect, needs_blending, a, b, c, d, e, f); \
    236     } \
    237     SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
    238 
    239 #define CREATE_QUAD_7_NEW(Type, a, b, c, d, e, f, g) \
    240     scoped_ptr<Type> quad_new(Type::Create()); \
    241     { \
    242       QUAD_DATA \
    243       quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f, g); \
    244     } \
    245     SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
    246 
    247 #define CREATE_QUAD_7_ALL(Type, a, b, c, d, e, f, g) \
    248     scoped_ptr<Type> quad_all(Type::Create()); \
    249     { \
    250       QUAD_DATA \
    251       quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
    252                        quad_visible_rect, needs_blending, \
    253                        a, b, c, d, e, f, g); \
    254     } \
    255     SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
    256 
    257 #define CREATE_QUAD_7_NEW_1(Type, a, b, c, d, e, f, g, copy_a) \
    258     scoped_ptr<Type> quad_new(Type::Create()); \
    259     { \
    260       QUAD_DATA \
    261       quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f, g); \
    262     } \
    263     SETUP_AND_COPY_QUAD_NEW_1(Type, quad_new, copy_a);
    264 
    265 #define CREATE_QUAD_7_ALL_1(Type, a, b, c, d, e, f, g, copy_a) \
    266     scoped_ptr<Type> quad_all(Type::Create()); \
    267     { \
    268       QUAD_DATA \
    269       quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
    270                        quad_visible_rect, needs_blending, \
    271                        a, b, c, d, e, f, g); \
    272     } \
    273     SETUP_AND_COPY_QUAD_ALL_1(Type, quad_all, copy_a);
    274 
    275 #define CREATE_QUAD_8_NEW(Type, a, b, c, d, e, f, g, h) \
    276     scoped_ptr<Type> quad_new(Type::Create()); \
    277     { \
    278       QUAD_DATA \
    279       quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f, g, h); \
    280     } \
    281     SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
    282 
    283 #define CREATE_QUAD_8_ALL(Type, a, b, c, d, e, f, g, h) \
    284     scoped_ptr<Type> quad_all(Type::Create()); \
    285     { \
    286       QUAD_DATA \
    287       quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
    288                        quad_visible_rect, needs_blending, \
    289                        a, b, c, d, e, f, g, h); \
    290     } \
    291     SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
    292 
    293 #define CREATE_QUAD_8_NEW_1(Type, a, b, c, d, e, f, g, h, copy_a) \
    294     scoped_ptr<Type> quad_new(Type::Create()); \
    295     { \
    296       QUAD_DATA \
    297       quad_new->SetNew(shared_state.get(), quad_rect, a, b, c, d, e, f, g, h); \
    298     } \
    299     SETUP_AND_COPY_QUAD_NEW_1(Type, quad_new, copy_a);
    300 
    301 #define CREATE_QUAD_8_ALL_1(Type, a, b, c, d, e, f, g, h, copy_a) \
    302     scoped_ptr<Type> quad_all(Type::Create()); \
    303     { \
    304       QUAD_DATA \
    305       quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
    306                        quad_visible_rect, needs_blending, \
    307                        a, b, c, d, e, f, g, h); \
    308     } \
    309     SETUP_AND_COPY_QUAD_ALL_1(Type, quad_all, copy_a);
    310 
    311 #define CREATE_QUAD_9_NEW(Type, a, b, c, d, e, f, g, h, i) \
    312     scoped_ptr<Type> quad_new(Type::Create()); \
    313     { \
    314       QUAD_DATA \
    315       quad_new->SetNew(shared_state.get(), quad_rect, \
    316                        a, b, c, d, e, f, g, h, i); \
    317     } \
    318     SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
    319 
    320 #define CREATE_QUAD_9_ALL(Type, a, b, c, d, e, f, g, h, i) \
    321     scoped_ptr<Type> quad_all(Type::Create()); \
    322     { \
    323       QUAD_DATA \
    324       quad_all->SetAll(shared_state.get(), quad_rect, quad_opaque_rect, \
    325                        quad_visible_rect, needs_blending, \
    326                        a, b, c, d, e, f, g, h, i); \
    327     } \
    328     SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
    329 
    330 TEST(DrawQuadTest, CopyCheckerboardDrawQuad) {
    331   SkColor color = 0xfabb0011;
    332   CREATE_SHARED_STATE();
    333 
    334   CREATE_QUAD_1_NEW(CheckerboardDrawQuad, color);
    335   EXPECT_EQ(DrawQuad::CHECKERBOARD, copy_quad->material);
    336   EXPECT_EQ(color, copy_quad->color);
    337 
    338   CREATE_QUAD_1_ALL(CheckerboardDrawQuad, color);
    339   EXPECT_EQ(DrawQuad::CHECKERBOARD, copy_quad->material);
    340   EXPECT_EQ(color, copy_quad->color);
    341 }
    342 
    343 TEST(DrawQuadTest, CopyDebugBorderDrawQuad) {
    344   SkColor color = 0xfabb0011;
    345   int width = 99;
    346   CREATE_SHARED_STATE();
    347 
    348   CREATE_QUAD_2_NEW(DebugBorderDrawQuad, color, width);
    349   EXPECT_EQ(DrawQuad::DEBUG_BORDER, copy_quad->material);
    350   EXPECT_EQ(color, copy_quad->color);
    351   EXPECT_EQ(width, copy_quad->width);
    352 
    353   CREATE_QUAD_2_ALL(DebugBorderDrawQuad, color, width);
    354   EXPECT_EQ(DrawQuad::DEBUG_BORDER, copy_quad->material);
    355   EXPECT_EQ(color, copy_quad->color);
    356   EXPECT_EQ(width, copy_quad->width);
    357 }
    358 
    359 TEST(DrawQuadTest, CopyIOSurfaceDrawQuad) {
    360   gfx::Rect opaque_rect(33, 47, 10, 12);
    361   gfx::Size size(58, 95);
    362   ResourceProvider::ResourceId resource_id = 72;
    363   IOSurfaceDrawQuad::Orientation orientation = IOSurfaceDrawQuad::UNFLIPPED;
    364   CREATE_SHARED_STATE();
    365 
    366   CREATE_QUAD_4_NEW(
    367       IOSurfaceDrawQuad, opaque_rect, size, resource_id, orientation);
    368   EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT, copy_quad->material);
    369   EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
    370   EXPECT_EQ(size, copy_quad->io_surface_size);
    371   EXPECT_EQ(resource_id, copy_quad->io_surface_resource_id);
    372   EXPECT_EQ(orientation, copy_quad->orientation);
    373 
    374   CREATE_QUAD_3_ALL(IOSurfaceDrawQuad, size, resource_id, orientation);
    375   EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT, copy_quad->material);
    376   EXPECT_EQ(size, copy_quad->io_surface_size);
    377   EXPECT_EQ(resource_id, copy_quad->io_surface_resource_id);
    378   EXPECT_EQ(orientation, copy_quad->orientation);
    379 }
    380 
    381 TEST(DrawQuadTest, CopyRenderPassDrawQuad) {
    382   RenderPass::Id render_pass_id(22, 64);
    383   bool is_replica = true;
    384   ResourceProvider::ResourceId mask_resource_id = 78;
    385   gfx::Rect contents_changed_since_last_frame(42, 11, 74, 24);
    386   gfx::RectF mask_u_v_rect(-45.f, -21.f, 33.f, 19.f);
    387   FilterOperations filters;
    388   filters.Append(FilterOperation::CreateBlurFilter(1.f));
    389   FilterOperations background_filters;
    390   background_filters.Append(
    391       FilterOperation::CreateGrayscaleFilter(1.f));
    392 
    393   RenderPass::Id copied_render_pass_id(235, 11);
    394   CREATE_SHARED_STATE();
    395 
    396   CREATE_QUAD_7_NEW_1(RenderPassDrawQuad,
    397                       render_pass_id,
    398                       is_replica,
    399                       mask_resource_id,
    400                       contents_changed_since_last_frame,
    401                       mask_u_v_rect,
    402                       filters,
    403                       background_filters,
    404                       copied_render_pass_id);
    405   EXPECT_EQ(DrawQuad::RENDER_PASS, copy_quad->material);
    406   EXPECT_EQ(copied_render_pass_id, copy_quad->render_pass_id);
    407   EXPECT_EQ(is_replica, copy_quad->is_replica);
    408   EXPECT_EQ(mask_resource_id, copy_quad->mask_resource_id);
    409   EXPECT_RECT_EQ(contents_changed_since_last_frame,
    410                  copy_quad->contents_changed_since_last_frame);
    411   EXPECT_EQ(mask_u_v_rect.ToString(), copy_quad->mask_uv_rect.ToString());
    412   EXPECT_EQ(filters, copy_quad->filters);
    413   EXPECT_EQ(background_filters, copy_quad->background_filters);
    414 
    415   CREATE_QUAD_7_ALL_1(RenderPassDrawQuad,
    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_EQ(copied_render_pass_id, copy_quad->render_pass_id);
    426   EXPECT_EQ(is_replica, copy_quad->is_replica);
    427   EXPECT_EQ(mask_resource_id, copy_quad->mask_resource_id);
    428   EXPECT_RECT_EQ(contents_changed_since_last_frame,
    429                  copy_quad->contents_changed_since_last_frame);
    430   EXPECT_EQ(mask_u_v_rect.ToString(), copy_quad->mask_uv_rect.ToString());
    431   EXPECT_EQ(filters, copy_quad->filters);
    432   EXPECT_EQ(background_filters, copy_quad->background_filters);
    433 }
    434 
    435 TEST(DrawQuadTest, CopySolidColorDrawQuad) {
    436   SkColor color = 0x49494949;
    437   bool force_anti_aliasing_off = false;
    438   CREATE_SHARED_STATE();
    439 
    440   CREATE_QUAD_2_NEW(SolidColorDrawQuad, color, force_anti_aliasing_off);
    441   EXPECT_EQ(DrawQuad::SOLID_COLOR, copy_quad->material);
    442   EXPECT_EQ(color, copy_quad->color);
    443   EXPECT_EQ(force_anti_aliasing_off, copy_quad->force_anti_aliasing_off);
    444 
    445   CREATE_QUAD_2_ALL(SolidColorDrawQuad, color, force_anti_aliasing_off);
    446   EXPECT_EQ(DrawQuad::SOLID_COLOR, copy_quad->material);
    447   EXPECT_EQ(color, copy_quad->color);
    448   EXPECT_EQ(force_anti_aliasing_off, copy_quad->force_anti_aliasing_off);
    449 }
    450 
    451 TEST(DrawQuadTest, CopyStreamVideoDrawQuad) {
    452   gfx::Rect opaque_rect(33, 47, 10, 12);
    453   ResourceProvider::ResourceId resource_id = 64;
    454   gfx::Transform matrix = gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
    455   CREATE_SHARED_STATE();
    456 
    457   CREATE_QUAD_3_NEW(StreamVideoDrawQuad, opaque_rect, resource_id, matrix);
    458   EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT, copy_quad->material);
    459   EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
    460   EXPECT_EQ(resource_id, copy_quad->resource_id);
    461   EXPECT_EQ(matrix, copy_quad->matrix);
    462 
    463   CREATE_QUAD_2_ALL(StreamVideoDrawQuad, resource_id, matrix);
    464   EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT, copy_quad->material);
    465   EXPECT_EQ(resource_id, copy_quad->resource_id);
    466   EXPECT_EQ(matrix, copy_quad->matrix);
    467 }
    468 
    469 TEST(DrawQuadTest, CopyTextureDrawQuad) {
    470   gfx::Rect opaque_rect(33, 47, 10, 12);
    471   unsigned resource_id = 82;
    472   bool premultiplied_alpha = true;
    473   gfx::PointF uv_top_left(0.5f, 224.f);
    474   gfx::PointF uv_bottom_right(51.5f, 260.f);
    475   const float vertex_opacity[] = { 1.0f, 1.0f, 1.0f, 1.0f };
    476   bool flipped = true;
    477   CREATE_SHARED_STATE();
    478 
    479   CREATE_QUAD_8_NEW(TextureDrawQuad,
    480                     opaque_rect,
    481                     resource_id,
    482                     premultiplied_alpha,
    483                     uv_top_left,
    484                     uv_bottom_right,
    485                     SK_ColorTRANSPARENT,
    486                     vertex_opacity,
    487                     flipped);
    488   EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, copy_quad->material);
    489   EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
    490   EXPECT_EQ(resource_id, copy_quad->resource_id);
    491   EXPECT_EQ(premultiplied_alpha, copy_quad->premultiplied_alpha);
    492   EXPECT_EQ(uv_top_left, copy_quad->uv_top_left);
    493   EXPECT_EQ(uv_bottom_right, copy_quad->uv_bottom_right);
    494   EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copy_quad->vertex_opacity, 4);
    495   EXPECT_EQ(flipped, copy_quad->flipped);
    496 
    497   CREATE_QUAD_7_ALL(TextureDrawQuad,
    498                     resource_id,
    499                     premultiplied_alpha,
    500                     uv_top_left,
    501                     uv_bottom_right,
    502                     SK_ColorTRANSPARENT,
    503                     vertex_opacity,
    504                     flipped);
    505   EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, copy_quad->material);
    506   EXPECT_EQ(resource_id, copy_quad->resource_id);
    507   EXPECT_EQ(premultiplied_alpha, copy_quad->premultiplied_alpha);
    508   EXPECT_EQ(uv_top_left, copy_quad->uv_top_left);
    509   EXPECT_EQ(uv_bottom_right, copy_quad->uv_bottom_right);
    510   EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copy_quad->vertex_opacity, 4);
    511   EXPECT_EQ(flipped, copy_quad->flipped);
    512 }
    513 
    514 TEST(DrawQuadTest, CopyTileDrawQuad) {
    515   gfx::Rect opaque_rect(33, 44, 22, 33);
    516   unsigned resource_id = 104;
    517   gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
    518   gfx::Size texture_size(85, 32);
    519   bool swizzle_contents = true;
    520   CREATE_SHARED_STATE();
    521 
    522   CREATE_QUAD_5_NEW(TileDrawQuad,
    523                     opaque_rect,
    524                     resource_id,
    525                     tex_coord_rect,
    526                     texture_size,
    527                     swizzle_contents);
    528   EXPECT_EQ(DrawQuad::TILED_CONTENT, copy_quad->material);
    529   EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
    530   EXPECT_EQ(resource_id, copy_quad->resource_id);
    531   EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
    532   EXPECT_EQ(texture_size, copy_quad->texture_size);
    533   EXPECT_EQ(swizzle_contents, copy_quad->swizzle_contents);
    534 
    535   CREATE_QUAD_4_ALL(TileDrawQuad,
    536                     resource_id,
    537                     tex_coord_rect,
    538                     texture_size,
    539                     swizzle_contents);
    540   EXPECT_EQ(DrawQuad::TILED_CONTENT, copy_quad->material);
    541   EXPECT_EQ(resource_id, copy_quad->resource_id);
    542   EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
    543   EXPECT_EQ(texture_size, copy_quad->texture_size);
    544   EXPECT_EQ(swizzle_contents, copy_quad->swizzle_contents);
    545 }
    546 
    547 TEST(DrawQuadTest, CopyYUVVideoDrawQuad) {
    548   gfx::Rect opaque_rect(33, 47, 10, 12);
    549   gfx::SizeF tex_scale(0.75f, 0.5f);
    550   ResourceProvider::ResourceId y_plane_resource_id = 45;
    551   ResourceProvider::ResourceId u_plane_resource_id = 532;
    552   ResourceProvider::ResourceId v_plane_resource_id = 4;
    553   ResourceProvider::ResourceId a_plane_resource_id = 63;
    554   CREATE_SHARED_STATE();
    555 
    556   CREATE_QUAD_6_NEW(YUVVideoDrawQuad,
    557                     opaque_rect,
    558                     tex_scale,
    559                     y_plane_resource_id,
    560                     u_plane_resource_id,
    561                     v_plane_resource_id,
    562                     a_plane_resource_id);
    563   EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copy_quad->material);
    564   EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
    565   EXPECT_EQ(tex_scale, copy_quad->tex_scale);
    566   EXPECT_EQ(y_plane_resource_id, copy_quad->y_plane_resource_id);
    567   EXPECT_EQ(u_plane_resource_id, copy_quad->u_plane_resource_id);
    568   EXPECT_EQ(v_plane_resource_id, copy_quad->v_plane_resource_id);
    569   EXPECT_EQ(a_plane_resource_id, copy_quad->a_plane_resource_id);
    570 
    571   CREATE_QUAD_5_ALL(YUVVideoDrawQuad,
    572                     tex_scale,
    573                     y_plane_resource_id,
    574                     u_plane_resource_id,
    575                     v_plane_resource_id,
    576                     a_plane_resource_id);
    577   EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copy_quad->material);
    578   EXPECT_EQ(tex_scale, copy_quad->tex_scale);
    579   EXPECT_EQ(y_plane_resource_id, copy_quad->y_plane_resource_id);
    580   EXPECT_EQ(u_plane_resource_id, copy_quad->u_plane_resource_id);
    581   EXPECT_EQ(v_plane_resource_id, copy_quad->v_plane_resource_id);
    582   EXPECT_EQ(a_plane_resource_id, copy_quad->a_plane_resource_id);
    583 }
    584 
    585 TEST(DrawQuadTest, CopyPictureDrawQuad) {
    586   gfx::Rect opaque_rect(33, 44, 22, 33);
    587   gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
    588   gfx::Size texture_size(85, 32);
    589   ResourceFormat texture_format = RGBA_8888;
    590   gfx::Rect content_rect(30, 40, 20, 30);
    591   float contents_scale = 3.141592f;
    592   scoped_refptr<PicturePileImpl> picture_pile = PicturePileImpl::Create();
    593   CREATE_SHARED_STATE();
    594 
    595   CREATE_QUAD_7_NEW(PictureDrawQuad,
    596                     opaque_rect,
    597                     tex_coord_rect,
    598                     texture_size,
    599                     texture_format,
    600                     content_rect,
    601                     contents_scale,
    602                     picture_pile);
    603   EXPECT_EQ(DrawQuad::PICTURE_CONTENT, copy_quad->material);
    604   EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
    605   EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
    606   EXPECT_EQ(texture_size, copy_quad->texture_size);
    607   EXPECT_EQ(texture_format, copy_quad->texture_format);
    608   EXPECT_RECT_EQ(content_rect, copy_quad->content_rect);
    609   EXPECT_EQ(contents_scale, copy_quad->contents_scale);
    610   EXPECT_EQ(picture_pile, copy_quad->picture_pile);
    611 
    612   CREATE_QUAD_6_ALL(PictureDrawQuad,
    613                     tex_coord_rect,
    614                     texture_size,
    615                     texture_format,
    616                     content_rect,
    617                     contents_scale,
    618                     picture_pile);
    619   EXPECT_EQ(DrawQuad::PICTURE_CONTENT, copy_quad->material);
    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);
    626 }
    627 
    628 class DrawQuadIteratorTest : public testing::Test {
    629  protected:
    630   ResourceProvider::ResourceId IncrementResourceId(
    631       ResourceProvider::ResourceId id) {
    632     ++num_resources_;
    633     return id + 1;
    634   }
    635 
    636   int IterateAndCount(DrawQuad* quad) {
    637     num_resources_ = 0;
    638     quad->IterateResources(base::Bind(
    639         &DrawQuadIteratorTest::IncrementResourceId, base::Unretained(this)));
    640     return num_resources_;
    641   }
    642 
    643  private:
    644   int num_resources_;
    645 };
    646 
    647 TEST_F(DrawQuadIteratorTest, CheckerboardDrawQuad) {
    648   SkColor color = 0xfabb0011;
    649 
    650   CREATE_SHARED_STATE();
    651   CREATE_QUAD_1_NEW(CheckerboardDrawQuad, color);
    652   EXPECT_EQ(0, IterateAndCount(quad_new.get()));
    653 }
    654 
    655 TEST_F(DrawQuadIteratorTest, DebugBorderDrawQuad) {
    656   SkColor color = 0xfabb0011;
    657   int width = 99;
    658 
    659   CREATE_SHARED_STATE();
    660   CREATE_QUAD_2_NEW(DebugBorderDrawQuad, color, width);
    661   EXPECT_EQ(0, IterateAndCount(quad_new.get()));
    662 }
    663 
    664 TEST_F(DrawQuadIteratorTest, IOSurfaceDrawQuad) {
    665   gfx::Rect opaque_rect(33, 47, 10, 12);
    666   gfx::Size size(58, 95);
    667   ResourceProvider::ResourceId resource_id = 72;
    668   IOSurfaceDrawQuad::Orientation orientation = IOSurfaceDrawQuad::UNFLIPPED;
    669 
    670   CREATE_SHARED_STATE();
    671   CREATE_QUAD_4_NEW(
    672       IOSurfaceDrawQuad, opaque_rect, size, resource_id, orientation);
    673   EXPECT_EQ(resource_id, quad_new->io_surface_resource_id);
    674   EXPECT_EQ(1, IterateAndCount(quad_new.get()));
    675   EXPECT_EQ(resource_id + 1, quad_new->io_surface_resource_id);
    676 }
    677 
    678 TEST_F(DrawQuadIteratorTest, RenderPassDrawQuad) {
    679   RenderPass::Id render_pass_id(22, 64);
    680   bool is_replica = true;
    681   ResourceProvider::ResourceId mask_resource_id = 78;
    682   gfx::Rect contents_changed_since_last_frame(42, 11, 74, 24);
    683   gfx::RectF mask_u_v_rect(-45.f, -21.f, 33.f, 19.f);
    684   FilterOperations filters;
    685   filters.Append(FilterOperation::CreateBlurFilter(1.f));
    686   FilterOperations background_filters;
    687   background_filters.Append(
    688       FilterOperation::CreateGrayscaleFilter(1.f));
    689 
    690   RenderPass::Id copied_render_pass_id(235, 11);
    691 
    692   CREATE_SHARED_STATE();
    693   CREATE_QUAD_7_NEW_1(RenderPassDrawQuad,
    694                       render_pass_id,
    695                       is_replica,
    696                       mask_resource_id,
    697                       contents_changed_since_last_frame,
    698                       mask_u_v_rect,
    699                       filters,
    700                       background_filters,
    701                       copied_render_pass_id);
    702   EXPECT_EQ(mask_resource_id, quad_new->mask_resource_id);
    703   EXPECT_EQ(1, IterateAndCount(quad_new.get()));
    704   EXPECT_EQ(mask_resource_id + 1, quad_new->mask_resource_id);
    705   quad_new->mask_resource_id = 0;
    706   EXPECT_EQ(0, IterateAndCount(quad_new.get()));
    707   EXPECT_EQ(0u, quad_new->mask_resource_id);
    708 }
    709 
    710 TEST_F(DrawQuadIteratorTest, SolidColorDrawQuad) {
    711   SkColor color = 0x49494949;
    712   bool force_anti_aliasing_off = false;
    713 
    714   CREATE_SHARED_STATE();
    715   CREATE_QUAD_2_NEW(SolidColorDrawQuad, color, force_anti_aliasing_off);
    716   EXPECT_EQ(0, IterateAndCount(quad_new.get()));
    717 }
    718 
    719 TEST_F(DrawQuadIteratorTest, StreamVideoDrawQuad) {
    720   gfx::Rect opaque_rect(33, 47, 10, 12);
    721   ResourceProvider::ResourceId resource_id = 64;
    722   gfx::Transform matrix = gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
    723 
    724   CREATE_SHARED_STATE();
    725   CREATE_QUAD_3_NEW(StreamVideoDrawQuad, opaque_rect, resource_id, matrix);
    726   EXPECT_EQ(resource_id, quad_new->resource_id);
    727   EXPECT_EQ(1, IterateAndCount(quad_new.get()));
    728   EXPECT_EQ(resource_id + 1, quad_new->resource_id);
    729 }
    730 
    731 TEST_F(DrawQuadIteratorTest, TextureDrawQuad) {
    732   gfx::Rect opaque_rect(33, 47, 10, 12);
    733   unsigned resource_id = 82;
    734   bool premultiplied_alpha = true;
    735   gfx::PointF uv_top_left(0.5f, 224.f);
    736   gfx::PointF uv_bottom_right(51.5f, 260.f);
    737   const float vertex_opacity[] = { 1.0f, 1.0f, 1.0f, 1.0f };
    738   bool flipped = true;
    739 
    740   CREATE_SHARED_STATE();
    741   CREATE_QUAD_8_NEW(TextureDrawQuad,
    742                     opaque_rect,
    743                     resource_id,
    744                     premultiplied_alpha,
    745                     uv_top_left,
    746                     uv_bottom_right,
    747                     SK_ColorTRANSPARENT,
    748                     vertex_opacity,
    749                     flipped);
    750   EXPECT_EQ(resource_id, quad_new->resource_id);
    751   EXPECT_EQ(1, IterateAndCount(quad_new.get()));
    752   EXPECT_EQ(resource_id + 1, quad_new->resource_id);
    753 }
    754 
    755 TEST_F(DrawQuadIteratorTest, TileDrawQuad) {
    756   gfx::Rect opaque_rect(33, 44, 22, 33);
    757   unsigned resource_id = 104;
    758   gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
    759   gfx::Size texture_size(85, 32);
    760   bool swizzle_contents = true;
    761 
    762   CREATE_SHARED_STATE();
    763   CREATE_QUAD_5_NEW(TileDrawQuad,
    764                     opaque_rect,
    765                     resource_id,
    766                     tex_coord_rect,
    767                     texture_size,
    768                     swizzle_contents);
    769   EXPECT_EQ(resource_id, quad_new->resource_id);
    770   EXPECT_EQ(1, IterateAndCount(quad_new.get()));
    771   EXPECT_EQ(resource_id + 1, quad_new->resource_id);
    772 }
    773 
    774 TEST_F(DrawQuadIteratorTest, YUVVideoDrawQuad) {
    775   gfx::Rect opaque_rect(33, 47, 10, 12);
    776   gfx::SizeF tex_scale(0.75f, 0.5f);
    777   ResourceProvider::ResourceId y_plane_resource_id = 45;
    778   ResourceProvider::ResourceId u_plane_resource_id = 532;
    779   ResourceProvider::ResourceId v_plane_resource_id = 4;
    780   ResourceProvider::ResourceId a_plane_resource_id = 63;
    781 
    782   CREATE_SHARED_STATE();
    783   CREATE_QUAD_6_NEW(YUVVideoDrawQuad,
    784                     opaque_rect,
    785                     tex_scale,
    786                     y_plane_resource_id,
    787                     u_plane_resource_id,
    788                     v_plane_resource_id,
    789                     a_plane_resource_id);
    790   EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copy_quad->material);
    791   EXPECT_EQ(y_plane_resource_id, quad_new->y_plane_resource_id);
    792   EXPECT_EQ(u_plane_resource_id, quad_new->u_plane_resource_id);
    793   EXPECT_EQ(v_plane_resource_id, quad_new->v_plane_resource_id);
    794   EXPECT_EQ(a_plane_resource_id, quad_new->a_plane_resource_id);
    795   EXPECT_EQ(4, IterateAndCount(quad_new.get()));
    796   EXPECT_EQ(y_plane_resource_id + 1, quad_new->y_plane_resource_id);
    797   EXPECT_EQ(u_plane_resource_id + 1, quad_new->u_plane_resource_id);
    798   EXPECT_EQ(v_plane_resource_id + 1, quad_new->v_plane_resource_id);
    799   EXPECT_EQ(a_plane_resource_id + 1, quad_new->a_plane_resource_id);
    800 }
    801 
    802 // Disabled until picture draw quad is supported for ubercomp: crbug.com/231715
    803 TEST_F(DrawQuadIteratorTest, DISABLED_PictureDrawQuad) {
    804   gfx::Rect opaque_rect(33, 44, 22, 33);
    805   gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
    806   gfx::Size texture_size(85, 32);
    807   ResourceFormat texture_format = RGBA_8888;
    808   gfx::Rect content_rect(30, 40, 20, 30);
    809   float contents_scale = 3.141592f;
    810   scoped_refptr<PicturePileImpl> picture_pile = PicturePileImpl::Create();
    811 
    812   CREATE_SHARED_STATE();
    813   CREATE_QUAD_7_NEW(PictureDrawQuad,
    814                     opaque_rect,
    815                     tex_coord_rect,
    816                     texture_size,
    817                     texture_format,
    818                     content_rect,
    819                     contents_scale,
    820                     picture_pile);
    821   EXPECT_EQ(0, IterateAndCount(quad_new.get()));
    822 }
    823 
    824 }  // namespace
    825 }  // namespace cc
    826