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/test/render_pass_test_utils.h"
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 "ui/gfx/rect.h"
19 TestRenderPass
* AddRenderPass(RenderPassList
* pass_list
,
21 gfx::Rect output_rect
,
22 const gfx::Transform
& root_transform
) {
23 scoped_ptr
<TestRenderPass
> pass(TestRenderPass::Create());
24 pass
->SetNew(id
, output_rect
, output_rect
, root_transform
);
25 TestRenderPass
* saved
= pass
.get();
26 pass_list
->push_back(pass
.PassAs
<RenderPass
>());
30 SolidColorDrawQuad
* AddQuad(TestRenderPass
* pass
,
33 MockQuadCuller
quad_sink(&pass
->quad_list
, &pass
->shared_quad_state_list
);
34 AppendQuadsData
data(pass
->id
);
35 SharedQuadState
* shared_state
=
36 quad_sink
.UseSharedQuadState(SharedQuadState::Create());
37 shared_state
->SetAll(gfx::Transform(), rect
.size(), rect
, rect
, false, 1);
38 scoped_ptr
<SolidColorDrawQuad
> quad
= SolidColorDrawQuad::Create();
39 quad
->SetNew(shared_state
, rect
, color
, false);
40 SolidColorDrawQuad
* quad_ptr
= quad
.get();
41 quad_sink
.Append(quad
.PassAs
<DrawQuad
>(), &data
);
45 SolidColorDrawQuad
* AddClippedQuad(TestRenderPass
* pass
,
48 MockQuadCuller
quad_sink(&pass
->quad_list
, &pass
->shared_quad_state_list
);
49 AppendQuadsData
data(pass
->id
);
50 SharedQuadState
* shared_state
=
51 quad_sink
.UseSharedQuadState(SharedQuadState::Create());
52 shared_state
->SetAll(gfx::Transform(), rect
.size(), rect
, rect
, true, 1);
53 scoped_ptr
<SolidColorDrawQuad
> quad
= SolidColorDrawQuad::Create();
54 quad
->SetNew(shared_state
, rect
, color
, false);
55 SolidColorDrawQuad
* quad_ptr
= quad
.get();
56 quad_sink
.Append(quad
.PassAs
<DrawQuad
>(), &data
);
60 SolidColorDrawQuad
* AddTransformedQuad(TestRenderPass
* pass
,
63 const gfx::Transform
& transform
) {
64 MockQuadCuller
quad_sink(&pass
->quad_list
, &pass
->shared_quad_state_list
);
65 AppendQuadsData
data(pass
->id
);
66 SharedQuadState
* shared_state
=
67 quad_sink
.UseSharedQuadState(SharedQuadState::Create());
68 shared_state
->SetAll(transform
, rect
.size(), rect
, rect
, false, 1);
69 scoped_ptr
<SolidColorDrawQuad
> quad
= SolidColorDrawQuad::Create();
70 quad
->SetNew(shared_state
, rect
, color
, false);
71 SolidColorDrawQuad
* quad_ptr
= quad
.get();
72 quad_sink
.Append(quad
.PassAs
<DrawQuad
>(), &data
);
76 void AddRenderPassQuad(TestRenderPass
* to_pass
,
77 TestRenderPass
* contributing_pass
) {
78 MockQuadCuller
quad_sink(&to_pass
->quad_list
,
79 &to_pass
->shared_quad_state_list
);
80 AppendQuadsData
data(to_pass
->id
);
81 gfx::Rect output_rect
= contributing_pass
->output_rect
;
82 SharedQuadState
* shared_state
=
83 quad_sink
.UseSharedQuadState(SharedQuadState::Create());
85 gfx::Transform(), output_rect
.size(), output_rect
, output_rect
, false, 1);
86 scoped_ptr
<RenderPassDrawQuad
> quad
= RenderPassDrawQuad::Create();
87 quad
->SetNew(shared_state
, output_rect
, contributing_pass
->id
, false, 0,
88 output_rect
, gfx::RectF(), WebKit::WebFilterOperations(),
89 skia::RefPtr
<SkImageFilter
>(), WebKit::WebFilterOperations());
90 quad_sink
.Append(quad
.PassAs
<DrawQuad
>(), &data
);
93 void AddRenderPassQuad(TestRenderPass
* to_pass
,
94 TestRenderPass
* contributing_pass
,
95 ResourceProvider::ResourceId mask_resource_id
,
96 skia::RefPtr
<SkImageFilter
> filter
,
97 gfx::Transform transform
) {
98 MockQuadCuller
quad_sink(&to_pass
->quad_list
,
99 &to_pass
->shared_quad_state_list
);
100 AppendQuadsData
data(to_pass
->id
);
101 gfx::Rect output_rect
= contributing_pass
->output_rect
;
102 SharedQuadState
* shared_state
=
103 quad_sink
.UseSharedQuadState(SharedQuadState::Create());
104 shared_state
->SetAll(
105 transform
, output_rect
.size(), output_rect
, output_rect
, false, 1);
106 scoped_ptr
<RenderPassDrawQuad
> quad
= RenderPassDrawQuad::Create();
107 quad
->SetNew(shared_state
, output_rect
, contributing_pass
->id
, false,
108 mask_resource_id
, output_rect
, gfx::RectF(),
109 WebKit::WebFilterOperations(),
110 filter
, WebKit::WebFilterOperations());
111 quad_sink
.Append(quad
.PassAs
<DrawQuad
>(), &data
);