Cleanup: Only build extensions renderer code when extensions are enabled.
[chromium-blink-merge.git] / cc / test / render_pass_test_common.cc
blobdd5bb901fd556ec68ed0dee2553b81640aeff6a4
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_common.h"
7 #include "base/bind.h"
8 #include "cc/quads/checkerboard_draw_quad.h"
9 #include "cc/quads/debug_border_draw_quad.h"
10 #include "cc/quads/io_surface_draw_quad.h"
11 #include "cc/quads/render_pass_draw_quad.h"
12 #include "cc/quads/shared_quad_state.h"
13 #include "cc/quads/solid_color_draw_quad.h"
14 #include "cc/quads/stream_video_draw_quad.h"
15 #include "cc/quads/texture_draw_quad.h"
16 #include "cc/quads/tile_draw_quad.h"
17 #include "cc/quads/yuv_video_draw_quad.h"
18 #include "cc/resources/resource_provider.h"
19 #include "cc/trees/blocking_task_runner.h"
20 #include "ui/gfx/transform.h"
22 namespace cc {
24 static void EmptyReleaseCallback(uint32 sync_point,
25 bool lost_resource,
26 BlockingTaskRunner* main_thread_task_runner) {
29 void TestRenderPass::AppendOneOfEveryQuadType(
30 ResourceProvider* resource_provider,
31 RenderPassId child_pass) {
32 gfx::Rect rect(0, 0, 100, 100);
33 gfx::Rect opaque_rect(10, 10, 80, 80);
34 gfx::Rect visible_rect(0, 0, 100, 100);
35 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
37 ResourceProvider::ResourceId resource1 = resource_provider->CreateResource(
38 gfx::Size(45, 5),
39 GL_CLAMP_TO_EDGE,
40 ResourceProvider::TextureHintImmutable,
41 resource_provider->best_texture_format());
42 resource_provider->AllocateForTesting(resource1);
43 ResourceProvider::ResourceId resource2 = resource_provider->CreateResource(
44 gfx::Size(346, 61),
45 GL_CLAMP_TO_EDGE,
46 ResourceProvider::TextureHintImmutable,
47 resource_provider->best_texture_format());
48 resource_provider->AllocateForTesting(resource2);
49 ResourceProvider::ResourceId resource3 = resource_provider->CreateResource(
50 gfx::Size(12, 134),
51 GL_CLAMP_TO_EDGE,
52 ResourceProvider::TextureHintImmutable,
53 resource_provider->best_texture_format());
54 resource_provider->AllocateForTesting(resource3);
55 ResourceProvider::ResourceId resource4 = resource_provider->CreateResource(
56 gfx::Size(56, 12),
57 GL_CLAMP_TO_EDGE,
58 ResourceProvider::TextureHintImmutable,
59 resource_provider->best_texture_format());
60 resource_provider->AllocateForTesting(resource4);
61 ResourceProvider::ResourceId resource5 = resource_provider->CreateResource(
62 gfx::Size(73, 26),
63 GL_CLAMP_TO_EDGE,
64 ResourceProvider::TextureHintImmutable,
65 resource_provider->best_texture_format());
66 resource_provider->AllocateForTesting(resource5);
67 ResourceProvider::ResourceId resource6 = resource_provider->CreateResource(
68 gfx::Size(64, 92),
69 GL_CLAMP_TO_EDGE,
70 ResourceProvider::TextureHintImmutable,
71 resource_provider->best_texture_format());
72 resource_provider->AllocateForTesting(resource6);
73 ResourceProvider::ResourceId resource7 = resource_provider->CreateResource(
74 gfx::Size(9, 14),
75 GL_CLAMP_TO_EDGE,
76 ResourceProvider::TextureHintImmutable,
77 resource_provider->best_texture_format());
78 resource_provider->AllocateForTesting(resource7);
80 unsigned target = GL_TEXTURE_2D;
81 gpu::Mailbox gpu_mailbox;
82 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1);
83 scoped_ptr<SingleReleaseCallbackImpl> callback =
84 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback));
85 TextureMailbox mailbox(gpu_mailbox, target, kSyncPointForMailboxTextureQuad);
86 ResourceProvider::ResourceId resource8 =
87 resource_provider->CreateResourceFromTextureMailbox(mailbox,
88 callback.Pass());
89 resource_provider->AllocateForTesting(resource8);
91 SharedQuadState* shared_state = this->CreateAndAppendSharedQuadState();
92 shared_state->SetAll(gfx::Transform(),
93 rect.size(),
94 rect,
95 rect,
96 false,
98 SkXfermode::kSrcOver_Mode,
99 0);
101 CheckerboardDrawQuad* checkerboard_quad =
102 this->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
103 checkerboard_quad->SetNew(shared_state, rect, visible_rect, SK_ColorRED);
105 DebugBorderDrawQuad* debug_border_quad =
106 this->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
107 debug_border_quad->SetNew(shared_state, rect, visible_rect, SK_ColorRED, 1);
109 IOSurfaceDrawQuad* io_surface_quad =
110 this->CreateAndAppendDrawQuad<IOSurfaceDrawQuad>();
111 io_surface_quad->SetNew(shared_state,
112 rect,
113 opaque_rect,
114 visible_rect,
115 gfx::Size(50, 50),
116 resource7,
117 IOSurfaceDrawQuad::FLIPPED);
119 if (child_pass.layer_id) {
120 RenderPassDrawQuad* render_pass_quad =
121 this->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
122 render_pass_quad->SetNew(shared_state,
123 rect,
124 visible_rect,
125 child_pass,
126 resource5,
127 gfx::RectF(),
128 FilterOperations(),
129 gfx::Vector2dF(),
130 FilterOperations());
132 RenderPassDrawQuad* render_pass_replica_quad =
133 this->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
134 render_pass_replica_quad->SetNew(shared_state,
135 rect,
136 visible_rect,
137 child_pass,
138 resource5,
139 gfx::RectF(),
140 FilterOperations(),
141 gfx::Vector2dF(),
142 FilterOperations());
145 SolidColorDrawQuad* solid_color_quad =
146 this->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
147 solid_color_quad->SetNew(
148 shared_state, rect, visible_rect, SK_ColorRED, false);
150 StreamVideoDrawQuad* stream_video_quad =
151 this->CreateAndAppendDrawQuad<StreamVideoDrawQuad>();
152 stream_video_quad->SetNew(shared_state,
153 rect,
154 opaque_rect,
155 visible_rect,
156 resource6,
157 gfx::Transform());
159 TextureDrawQuad* texture_quad =
160 this->CreateAndAppendDrawQuad<TextureDrawQuad>();
161 texture_quad->SetNew(shared_state,
162 rect,
163 opaque_rect,
164 visible_rect,
165 resource1,
166 false,
167 gfx::PointF(0.f, 0.f),
168 gfx::PointF(1.f, 1.f),
169 SK_ColorTRANSPARENT,
170 vertex_opacity,
171 false);
173 TextureDrawQuad* mailbox_texture_quad =
174 this->CreateAndAppendDrawQuad<TextureDrawQuad>();
175 mailbox_texture_quad->SetNew(shared_state,
176 rect,
177 opaque_rect,
178 visible_rect,
179 resource8,
180 false,
181 gfx::PointF(0.f, 0.f),
182 gfx::PointF(1.f, 1.f),
183 SK_ColorTRANSPARENT,
184 vertex_opacity,
185 false);
187 TileDrawQuad* scaled_tile_quad =
188 this->CreateAndAppendDrawQuad<TileDrawQuad>();
189 scaled_tile_quad->SetNew(shared_state,
190 rect,
191 opaque_rect,
192 visible_rect,
193 resource2,
194 gfx::RectF(0, 0, 50, 50),
195 gfx::Size(50, 50),
196 false);
198 SharedQuadState* transformed_state = this->CreateAndAppendSharedQuadState();
199 transformed_state->CopyFrom(shared_state);
200 gfx::Transform rotation;
201 rotation.Rotate(45);
202 transformed_state->content_to_target_transform =
203 transformed_state->content_to_target_transform * rotation;
204 TileDrawQuad* transformed_tile_quad =
205 this->CreateAndAppendDrawQuad<TileDrawQuad>();
206 transformed_tile_quad->SetNew(transformed_state,
207 rect,
208 opaque_rect,
209 visible_rect,
210 resource3,
211 gfx::RectF(0, 0, 100, 100),
212 gfx::Size(100, 100),
213 false);
215 SharedQuadState* shared_state2 = this->CreateAndAppendSharedQuadState();
216 shared_state->SetAll(gfx::Transform(),
217 rect.size(),
218 rect,
219 rect,
220 false,
222 SkXfermode::kSrcOver_Mode,
225 TileDrawQuad* tile_quad = this->CreateAndAppendDrawQuad<TileDrawQuad>();
226 tile_quad->SetNew(shared_state2,
227 rect,
228 opaque_rect,
229 visible_rect,
230 resource4,
231 gfx::RectF(0, 0, 100, 100),
232 gfx::Size(100, 100),
233 false);
235 ResourceProvider::ResourceId plane_resources[4];
236 for (int i = 0; i < 4; ++i) {
237 plane_resources[i] = resource_provider->CreateResource(
238 gfx::Size(20, 12),
239 GL_CLAMP_TO_EDGE,
240 ResourceProvider::TextureHintImmutable,
241 resource_provider->best_texture_format());
242 resource_provider->AllocateForTesting(plane_resources[i]);
244 YUVVideoDrawQuad::ColorSpace color_space = YUVVideoDrawQuad::REC_601;
245 YUVVideoDrawQuad* yuv_quad =
246 this->CreateAndAppendDrawQuad<YUVVideoDrawQuad>();
247 yuv_quad->SetNew(shared_state2,
248 rect,
249 opaque_rect,
250 visible_rect,
251 gfx::RectF(0, 0, 100, 100),
252 plane_resources[0],
253 plane_resources[1],
254 plane_resources[2],
255 plane_resources[3],
256 color_space);
259 } // namespace cc