Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / cc / quads / render_pass.cc
bloba1426f5341654cbdc88504048f8685921f305626
1 // Copyright 2011 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/quads/render_pass.h"
7 #include <algorithm>
9 #include "base/debug/trace_event_argument.h"
10 #include "base/values.h"
11 #include "cc/base/math_util.h"
12 #include "cc/debug/traced_value.h"
13 #include "cc/output/copy_output_request.h"
14 #include "cc/quads/checkerboard_draw_quad.h"
15 #include "cc/quads/debug_border_draw_quad.h"
16 #include "cc/quads/draw_quad.h"
17 #include "cc/quads/io_surface_draw_quad.h"
18 #include "cc/quads/largest_draw_quad.h"
19 #include "cc/quads/picture_draw_quad.h"
20 #include "cc/quads/render_pass_draw_quad.h"
21 #include "cc/quads/shared_quad_state.h"
22 #include "cc/quads/solid_color_draw_quad.h"
23 #include "cc/quads/stream_video_draw_quad.h"
24 #include "cc/quads/surface_draw_quad.h"
25 #include "cc/quads/texture_draw_quad.h"
26 #include "cc/quads/tile_draw_quad.h"
27 #include "cc/quads/yuv_video_draw_quad.h"
29 namespace {
30 const size_t kDefaultNumSharedQuadStatesToReserve = 32;
31 const size_t kDefaultNumQuadsToReserve = 128;
34 namespace cc {
36 QuadList::QuadList(size_t default_size_to_reserve)
37 : ListContainer<DrawQuad>(LargestDrawQuadSize(), default_size_to_reserve) {
40 scoped_ptr<RenderPass> RenderPass::Create() {
41 return make_scoped_ptr(new RenderPass());
44 scoped_ptr<RenderPass> RenderPass::Create(size_t num_layers) {
45 return make_scoped_ptr(new RenderPass(num_layers));
48 scoped_ptr<RenderPass> RenderPass::Create(size_t shared_quad_state_list_size,
49 size_t quad_list_size) {
50 return make_scoped_ptr(
51 new RenderPass(shared_quad_state_list_size, quad_list_size));
54 RenderPass::RenderPass()
55 : id(RenderPassId(-1, -1)),
56 has_transparent_background(true),
57 quad_list(kDefaultNumQuadsToReserve),
58 shared_quad_state_list(sizeof(SharedQuadState),
59 kDefaultNumSharedQuadStatesToReserve) {
62 // Each layer usually produces one shared quad state, so the number of layers
63 // is a good hint for what to reserve here.
64 RenderPass::RenderPass(size_t num_layers)
65 : id(RenderPassId(-1, -1)),
66 has_transparent_background(true),
67 quad_list(kDefaultNumQuadsToReserve),
68 shared_quad_state_list(sizeof(SharedQuadState), num_layers) {
71 RenderPass::RenderPass(size_t shared_quad_state_list_size,
72 size_t quad_list_size)
73 : id(RenderPassId(-1, -1)),
74 has_transparent_background(true),
75 quad_list(quad_list_size),
76 shared_quad_state_list(sizeof(SharedQuadState),
77 shared_quad_state_list_size) {
80 RenderPass::~RenderPass() {
81 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
82 TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"),
83 "cc::RenderPass", id.AsTracingId());
86 scoped_ptr<RenderPass> RenderPass::Copy(RenderPassId new_id) const {
87 scoped_ptr<RenderPass> copy_pass(
88 Create(shared_quad_state_list.size(), quad_list.size()));
89 copy_pass->SetAll(new_id,
90 output_rect,
91 damage_rect,
92 transform_to_root_target,
93 has_transparent_background);
94 return copy_pass.Pass();
97 // static
98 void RenderPass::CopyAll(const ScopedPtrVector<RenderPass>& in,
99 ScopedPtrVector<RenderPass>* out) {
100 for (size_t i = 0; i < in.size(); ++i) {
101 RenderPass* source = in[i];
103 // Since we can't copy these, it's wrong to use CopyAll in a situation where
104 // you may have copy_requests present.
105 DCHECK_EQ(source->copy_requests.size(), 0u);
107 scoped_ptr<RenderPass> copy_pass(Create(
108 source->shared_quad_state_list.size(), source->quad_list.size()));
109 copy_pass->SetAll(source->id,
110 source->output_rect,
111 source->damage_rect,
112 source->transform_to_root_target,
113 source->has_transparent_background);
114 for (const auto& shared_quad_state : source->shared_quad_state_list) {
115 SharedQuadState* copy_shared_quad_state =
116 copy_pass->CreateAndAppendSharedQuadState();
117 copy_shared_quad_state->CopyFrom(shared_quad_state);
119 SharedQuadStateList::Iterator sqs_iter =
120 source->shared_quad_state_list.begin();
121 SharedQuadStateList::Iterator copy_sqs_iter =
122 copy_pass->shared_quad_state_list.begin();
123 for (const auto& quad : source->quad_list) {
124 while (quad->shared_quad_state != *sqs_iter) {
125 ++sqs_iter;
126 ++copy_sqs_iter;
127 DCHECK(sqs_iter != source->shared_quad_state_list.end());
129 DCHECK(quad->shared_quad_state == *sqs_iter);
131 SharedQuadState* copy_shared_quad_state = *copy_sqs_iter;
133 if (quad->material == DrawQuad::RENDER_PASS) {
134 const RenderPassDrawQuad* pass_quad =
135 RenderPassDrawQuad::MaterialCast(quad);
136 copy_pass->CopyFromAndAppendRenderPassDrawQuad(
137 pass_quad, copy_shared_quad_state, pass_quad->render_pass_id);
138 } else {
139 copy_pass->CopyFromAndAppendDrawQuad(quad, copy_shared_quad_state);
142 out->push_back(copy_pass.Pass());
146 void RenderPass::SetNew(RenderPassId id,
147 const gfx::Rect& output_rect,
148 const gfx::Rect& damage_rect,
149 const gfx::Transform& transform_to_root_target) {
150 DCHECK_GT(id.layer_id, 0);
151 DCHECK_GE(id.index, 0);
152 DCHECK(damage_rect.IsEmpty() || output_rect.Contains(damage_rect))
153 << "damage_rect: " << damage_rect.ToString()
154 << " output_rect: " << output_rect.ToString();
156 this->id = id;
157 this->output_rect = output_rect;
158 this->damage_rect = damage_rect;
159 this->transform_to_root_target = transform_to_root_target;
161 DCHECK(quad_list.empty());
162 DCHECK(shared_quad_state_list.empty());
165 void RenderPass::SetAll(RenderPassId id,
166 const gfx::Rect& output_rect,
167 const gfx::Rect& damage_rect,
168 const gfx::Transform& transform_to_root_target,
169 bool has_transparent_background) {
170 DCHECK_GT(id.layer_id, 0);
171 DCHECK_GE(id.index, 0);
173 this->id = id;
174 this->output_rect = output_rect;
175 this->damage_rect = damage_rect;
176 this->transform_to_root_target = transform_to_root_target;
177 this->has_transparent_background = has_transparent_background;
179 DCHECK(quad_list.empty());
180 DCHECK(shared_quad_state_list.empty());
183 void RenderPass::AsValueInto(base::debug::TracedValue* value) const {
184 value->BeginArray("output_rect");
185 MathUtil::AddToTracedValue(output_rect, value);
186 value->EndArray();
188 value->BeginArray("damage_rect");
189 MathUtil::AddToTracedValue(damage_rect, value);
190 value->EndArray();
192 value->SetBoolean("has_transparent_background", has_transparent_background);
193 value->SetInteger("copy_requests", copy_requests.size());
195 value->BeginArray("shared_quad_state_list");
196 for (const auto& shared_quad_state : shared_quad_state_list) {
197 value->BeginDictionary();
198 shared_quad_state->AsValueInto(value);
199 value->EndDictionary();
201 value->EndArray();
203 value->BeginArray("quad_list");
204 for (const auto& quad : quad_list) {
205 value->BeginDictionary();
206 quad->AsValueInto(value);
207 value->EndDictionary();
209 value->EndArray();
211 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
212 TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"),
213 value,
214 "cc::RenderPass",
215 id.AsTracingId());
218 SharedQuadState* RenderPass::CreateAndAppendSharedQuadState() {
219 return shared_quad_state_list.AllocateAndConstruct<SharedQuadState>();
222 RenderPassDrawQuad* RenderPass::CopyFromAndAppendRenderPassDrawQuad(
223 const RenderPassDrawQuad* quad,
224 const SharedQuadState* shared_quad_state,
225 RenderPassId render_pass_id) {
226 RenderPassDrawQuad* copy_quad =
227 CopyFromAndAppendTypedDrawQuad<RenderPassDrawQuad>(quad);
228 copy_quad->shared_quad_state = shared_quad_state;
229 copy_quad->render_pass_id = render_pass_id;
230 return copy_quad;
233 DrawQuad* RenderPass::CopyFromAndAppendDrawQuad(
234 const DrawQuad* quad,
235 const SharedQuadState* shared_quad_state) {
236 switch (quad->material) {
237 case DrawQuad::CHECKERBOARD:
238 CopyFromAndAppendTypedDrawQuad<CheckerboardDrawQuad>(quad);
239 break;
240 case DrawQuad::DEBUG_BORDER:
241 CopyFromAndAppendTypedDrawQuad<DebugBorderDrawQuad>(quad);
242 break;
243 case DrawQuad::IO_SURFACE_CONTENT:
244 CopyFromAndAppendTypedDrawQuad<IOSurfaceDrawQuad>(quad);
245 break;
246 case DrawQuad::PICTURE_CONTENT:
247 CopyFromAndAppendTypedDrawQuad<PictureDrawQuad>(quad);
248 break;
249 case DrawQuad::TEXTURE_CONTENT:
250 CopyFromAndAppendTypedDrawQuad<TextureDrawQuad>(quad);
251 break;
252 case DrawQuad::SOLID_COLOR:
253 CopyFromAndAppendTypedDrawQuad<SolidColorDrawQuad>(quad);
254 break;
255 case DrawQuad::TILED_CONTENT:
256 CopyFromAndAppendTypedDrawQuad<TileDrawQuad>(quad);
257 break;
258 case DrawQuad::STREAM_VIDEO_CONTENT:
259 CopyFromAndAppendTypedDrawQuad<StreamVideoDrawQuad>(quad);
260 break;
261 case DrawQuad::SURFACE_CONTENT:
262 CopyFromAndAppendTypedDrawQuad<SurfaceDrawQuad>(quad);
263 break;
264 case DrawQuad::YUV_VIDEO_CONTENT:
265 CopyFromAndAppendTypedDrawQuad<YUVVideoDrawQuad>(quad);
266 break;
267 // RenderPass quads need to use specific CopyFrom function.
268 case DrawQuad::RENDER_PASS:
269 case DrawQuad::INVALID:
270 LOG(FATAL) << "Invalid DrawQuad material " << quad->material;
271 break;
273 quad_list.back()->shared_quad_state = shared_quad_state;
274 return quad_list.back();
277 } // namespace cc