[Android] Introduce new UMA action for when user copies Image URL from context menu
[chromium-blink-merge.git] / cc / test / render_pass_test_common.cc
blob6fda53660c036793c8f810413cb4bf2e3ff87ace
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 ResourceId resource1 = resource_provider->CreateResource(
38 gfx::Size(45, 5), GL_CLAMP_TO_EDGE,
39 ResourceProvider::TEXTURE_HINT_IMMUTABLE,
40 resource_provider->best_texture_format());
41 resource_provider->AllocateForTesting(resource1);
42 ResourceId resource2 = resource_provider->CreateResource(
43 gfx::Size(346, 61), GL_CLAMP_TO_EDGE,
44 ResourceProvider::TEXTURE_HINT_IMMUTABLE,
45 resource_provider->best_texture_format());
46 resource_provider->AllocateForTesting(resource2);
47 ResourceId resource3 = resource_provider->CreateResource(
48 gfx::Size(12, 134), GL_CLAMP_TO_EDGE,
49 ResourceProvider::TEXTURE_HINT_IMMUTABLE,
50 resource_provider->best_texture_format());
51 resource_provider->AllocateForTesting(resource3);
52 ResourceId resource4 = resource_provider->CreateResource(
53 gfx::Size(56, 12), GL_CLAMP_TO_EDGE,
54 ResourceProvider::TEXTURE_HINT_IMMUTABLE,
55 resource_provider->best_texture_format());
56 resource_provider->AllocateForTesting(resource4);
57 gfx::Size resource5_size(73, 26);
58 ResourceId resource5 = resource_provider->CreateResource(
59 resource5_size, GL_CLAMP_TO_EDGE,
60 ResourceProvider::TEXTURE_HINT_IMMUTABLE,
61 resource_provider->best_texture_format());
62 resource_provider->AllocateForTesting(resource5);
63 ResourceId resource6 = resource_provider->CreateResource(
64 gfx::Size(64, 92), GL_CLAMP_TO_EDGE,
65 ResourceProvider::TEXTURE_HINT_IMMUTABLE,
66 resource_provider->best_texture_format());
67 resource_provider->AllocateForTesting(resource6);
68 ResourceId resource7 = resource_provider->CreateResource(
69 gfx::Size(9, 14), GL_CLAMP_TO_EDGE,
70 ResourceProvider::TEXTURE_HINT_IMMUTABLE,
71 resource_provider->best_texture_format());
72 resource_provider->AllocateForTesting(resource7);
74 unsigned target = GL_TEXTURE_2D;
75 gpu::Mailbox gpu_mailbox;
76 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1);
77 scoped_ptr<SingleReleaseCallbackImpl> callback =
78 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback));
79 TextureMailbox mailbox(gpu_mailbox, target, kSyncPointForMailboxTextureQuad);
80 ResourceId resource8 = resource_provider->CreateResourceFromTextureMailbox(
81 mailbox, callback.Pass());
82 resource_provider->AllocateForTesting(resource8);
84 SharedQuadState* shared_state = this->CreateAndAppendSharedQuadState();
85 shared_state->SetAll(gfx::Transform(),
86 rect.size(),
87 rect,
88 rect,
89 false,
91 SkXfermode::kSrcOver_Mode,
92 0);
94 CheckerboardDrawQuad* checkerboard_quad =
95 this->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
96 checkerboard_quad->SetNew(shared_state, rect, visible_rect, SK_ColorRED, 1.f);
98 DebugBorderDrawQuad* debug_border_quad =
99 this->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
100 debug_border_quad->SetNew(shared_state, rect, visible_rect, SK_ColorRED, 1);
102 IOSurfaceDrawQuad* io_surface_quad =
103 this->CreateAndAppendDrawQuad<IOSurfaceDrawQuad>();
104 io_surface_quad->SetNew(shared_state,
105 rect,
106 opaque_rect,
107 visible_rect,
108 gfx::Size(50, 50),
109 resource7,
110 IOSurfaceDrawQuad::FLIPPED);
112 if (child_pass.layer_id) {
113 RenderPassDrawQuad* render_pass_quad =
114 this->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
115 render_pass_quad->SetNew(shared_state,
116 rect,
117 visible_rect,
118 child_pass,
119 resource5,
120 gfx::Vector2dF(1.f, 1.f),
121 resource5_size,
122 FilterOperations(),
123 gfx::Vector2dF(),
124 FilterOperations());
126 RenderPassDrawQuad* render_pass_replica_quad =
127 this->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
128 render_pass_replica_quad->SetNew(shared_state,
129 rect,
130 visible_rect,
131 child_pass,
132 resource5,
133 gfx::Vector2dF(1.f, 1.f),
134 resource5_size,
135 FilterOperations(),
136 gfx::Vector2dF(),
137 FilterOperations());
140 SolidColorDrawQuad* solid_color_quad =
141 this->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
142 solid_color_quad->SetNew(
143 shared_state, rect, visible_rect, SK_ColorRED, false);
145 StreamVideoDrawQuad* stream_video_quad =
146 this->CreateAndAppendDrawQuad<StreamVideoDrawQuad>();
147 stream_video_quad->SetNew(shared_state, rect, opaque_rect, visible_rect,
148 resource6, gfx::Size(), false, gfx::Transform());
150 TextureDrawQuad* texture_quad =
151 this->CreateAndAppendDrawQuad<TextureDrawQuad>();
152 texture_quad->SetNew(shared_state,
153 rect,
154 opaque_rect,
155 visible_rect,
156 resource1,
157 false,
158 gfx::PointF(0.f, 0.f),
159 gfx::PointF(1.f, 1.f),
160 SK_ColorTRANSPARENT,
161 vertex_opacity,
162 false,
163 false);
165 TextureDrawQuad* mailbox_texture_quad =
166 this->CreateAndAppendDrawQuad<TextureDrawQuad>();
167 mailbox_texture_quad->SetNew(shared_state,
168 rect,
169 opaque_rect,
170 visible_rect,
171 resource8,
172 false,
173 gfx::PointF(0.f, 0.f),
174 gfx::PointF(1.f, 1.f),
175 SK_ColorTRANSPARENT,
176 vertex_opacity,
177 false,
178 false);
180 TileDrawQuad* scaled_tile_quad =
181 this->CreateAndAppendDrawQuad<TileDrawQuad>();
182 scaled_tile_quad->SetNew(shared_state,
183 rect,
184 opaque_rect,
185 visible_rect,
186 resource2,
187 gfx::RectF(0, 0, 50, 50),
188 gfx::Size(50, 50),
189 false,
190 false);
192 SharedQuadState* transformed_state = this->CreateAndAppendSharedQuadState();
193 transformed_state->CopyFrom(shared_state);
194 gfx::Transform rotation;
195 rotation.Rotate(45);
196 transformed_state->quad_to_target_transform =
197 transformed_state->quad_to_target_transform * rotation;
198 TileDrawQuad* transformed_tile_quad =
199 this->CreateAndAppendDrawQuad<TileDrawQuad>();
200 transformed_tile_quad->SetNew(transformed_state,
201 rect,
202 opaque_rect,
203 visible_rect,
204 resource3,
205 gfx::RectF(0, 0, 100, 100),
206 gfx::Size(100, 100),
207 false,
208 false);
210 SharedQuadState* shared_state2 = this->CreateAndAppendSharedQuadState();
211 shared_state->SetAll(gfx::Transform(),
212 rect.size(),
213 rect,
214 rect,
215 false,
217 SkXfermode::kSrcOver_Mode,
220 TileDrawQuad* tile_quad = this->CreateAndAppendDrawQuad<TileDrawQuad>();
221 tile_quad->SetNew(shared_state2,
222 rect,
223 opaque_rect,
224 visible_rect,
225 resource4,
226 gfx::RectF(0, 0, 100, 100),
227 gfx::Size(100, 100),
228 false,
229 false);
231 ResourceId plane_resources[4];
232 for (int i = 0; i < 4; ++i) {
233 plane_resources[i] = resource_provider->CreateResource(
234 gfx::Size(20, 12), GL_CLAMP_TO_EDGE,
235 ResourceProvider::TEXTURE_HINT_IMMUTABLE,
236 resource_provider->best_texture_format());
237 resource_provider->AllocateForTesting(plane_resources[i]);
239 YUVVideoDrawQuad::ColorSpace color_space = YUVVideoDrawQuad::REC_601;
240 YUVVideoDrawQuad* yuv_quad =
241 this->CreateAndAppendDrawQuad<YUVVideoDrawQuad>();
242 yuv_quad->SetNew(shared_state2, rect, opaque_rect, visible_rect,
243 gfx::RectF(.0f, .0f, 100.0f, 100.0f),
244 gfx::RectF(.0f, .0f, 50.0f, 50.0f), gfx::Size(100, 100),
245 gfx::Size(50, 50), plane_resources[0], plane_resources[1],
246 plane_resources[2], plane_resources[3], color_space);
249 } // namespace cc