Home | History | Annotate | Download | only in test
      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/test/render_pass_test_utils.h"
      6 
      7 #include "cc/layers/append_quads_data.h"
      8 #include "cc/layers/quad_sink.h"
      9 #include "cc/quads/render_pass_draw_quad.h"
     10 #include "cc/quads/shared_quad_state.h"
     11 #include "cc/quads/solid_color_draw_quad.h"
     12 #include "cc/resources/resource_provider.h"
     13 #include "cc/test/mock_quad_culler.h"
     14 #include "cc/test/render_pass_test_common.h"
     15 #include "third_party/skia/include/core/SkColor.h"
     16 #include "third_party/skia/include/core/SkImageFilter.h"
     17 #include "ui/gfx/rect.h"
     18 
     19 namespace cc {
     20 
     21 TestRenderPass* AddRenderPass(RenderPassList* pass_list,
     22                               RenderPass::Id id,
     23                               gfx::Rect output_rect,
     24                               const gfx::Transform& root_transform) {
     25   scoped_ptr<TestRenderPass> pass(TestRenderPass::Create());
     26   pass->SetNew(id, output_rect, output_rect, root_transform);
     27   TestRenderPass* saved = pass.get();
     28   pass_list->push_back(pass.PassAs<RenderPass>());
     29   return saved;
     30 }
     31 
     32 SolidColorDrawQuad* AddQuad(TestRenderPass* pass,
     33                             gfx::Rect rect,
     34                             SkColor color) {
     35   MockQuadCuller quad_sink(&pass->quad_list, &pass->shared_quad_state_list);
     36   AppendQuadsData data(pass->id);
     37   SharedQuadState* shared_state =
     38       quad_sink.UseSharedQuadState(SharedQuadState::Create());
     39   shared_state->SetAll(gfx::Transform(),
     40                        rect.size(),
     41                        rect,
     42                        rect,
     43                        false,
     44                        1,
     45                        SkXfermode::kSrcOver_Mode);
     46   scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create();
     47   quad->SetNew(shared_state, rect, color, false);
     48   SolidColorDrawQuad* quad_ptr = quad.get();
     49   quad_sink.Append(quad.PassAs<DrawQuad>(), &data);
     50   return quad_ptr;
     51 }
     52 
     53 SolidColorDrawQuad* AddClippedQuad(TestRenderPass* pass,
     54                                    gfx::Rect rect,
     55                                    SkColor color) {
     56   MockQuadCuller quad_sink(&pass->quad_list, &pass->shared_quad_state_list);
     57   AppendQuadsData data(pass->id);
     58   SharedQuadState* shared_state =
     59       quad_sink.UseSharedQuadState(SharedQuadState::Create());
     60   shared_state->SetAll(gfx::Transform(),
     61                        rect.size(),
     62                        rect,
     63                        rect,
     64                        true,
     65                        1,
     66                        SkXfermode::kSrcOver_Mode);
     67   scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create();
     68   quad->SetNew(shared_state, rect, color, false);
     69   SolidColorDrawQuad* quad_ptr = quad.get();
     70   quad_sink.Append(quad.PassAs<DrawQuad>(), &data);
     71   return quad_ptr;
     72 }
     73 
     74 SolidColorDrawQuad* AddTransformedQuad(TestRenderPass* pass,
     75                                        gfx::Rect rect,
     76                                        SkColor color,
     77                                        const gfx::Transform& transform) {
     78   MockQuadCuller quad_sink(&pass->quad_list, &pass->shared_quad_state_list);
     79   AppendQuadsData data(pass->id);
     80   SharedQuadState* shared_state =
     81       quad_sink.UseSharedQuadState(SharedQuadState::Create());
     82   shared_state->SetAll(
     83       transform, rect.size(), rect, rect, false, 1, SkXfermode::kSrcOver_Mode);
     84   scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create();
     85   quad->SetNew(shared_state, rect, color, false);
     86   SolidColorDrawQuad* quad_ptr = quad.get();
     87   quad_sink.Append(quad.PassAs<DrawQuad>(), &data);
     88   return quad_ptr;
     89 }
     90 
     91 void AddRenderPassQuad(TestRenderPass* to_pass,
     92                        TestRenderPass* contributing_pass) {
     93   MockQuadCuller quad_sink(&to_pass->quad_list,
     94                            &to_pass->shared_quad_state_list);
     95   AppendQuadsData data(to_pass->id);
     96   gfx::Rect output_rect = contributing_pass->output_rect;
     97   SharedQuadState* shared_state =
     98       quad_sink.UseSharedQuadState(SharedQuadState::Create());
     99   shared_state->SetAll(gfx::Transform(),
    100                        output_rect.size(),
    101                        output_rect,
    102                        output_rect,
    103                        false,
    104                        1,
    105                        SkXfermode::kSrcOver_Mode);
    106   scoped_ptr<RenderPassDrawQuad> quad = RenderPassDrawQuad::Create();
    107   quad->SetNew(shared_state, output_rect, contributing_pass->id, false, 0,
    108                output_rect, gfx::RectF(), FilterOperations(),
    109                FilterOperations());
    110   quad_sink.Append(quad.PassAs<DrawQuad>(), &data);
    111 }
    112 
    113 void AddRenderPassQuad(TestRenderPass* to_pass,
    114                        TestRenderPass* contributing_pass,
    115                        ResourceProvider::ResourceId mask_resource_id,
    116                        const FilterOperations& filters,
    117                        gfx::Transform transform) {
    118   MockQuadCuller quad_sink(&to_pass->quad_list,
    119                            &to_pass->shared_quad_state_list);
    120   AppendQuadsData data(to_pass->id);
    121   gfx::Rect output_rect = contributing_pass->output_rect;
    122   SharedQuadState* shared_state =
    123       quad_sink.UseSharedQuadState(SharedQuadState::Create());
    124   shared_state->SetAll(transform,
    125                        output_rect.size(),
    126                        output_rect,
    127                        output_rect,
    128                        false,
    129                        1,
    130                        SkXfermode::kSrcOver_Mode);
    131   scoped_ptr<RenderPassDrawQuad> quad = RenderPassDrawQuad::Create();
    132   quad->SetNew(shared_state, output_rect, contributing_pass->id, false,
    133                mask_resource_id, output_rect, gfx::RectF(), filters,
    134                FilterOperations());
    135   quad_sink.Append(quad.PassAs<DrawQuad>(), &data);
    136 }
    137 
    138 }  // namespace cc
    139