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