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