Delete unused downloads page asset.
[chromium-blink-merge.git] / cc / quads / render_pass.cc
blob637f5652d2d810c79bd9b09e7d02962990f4618f
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/numerics/safe_conversions.h"
10 #include "base/trace_event/trace_event_argument.h"
11 #include "base/values.h"
12 #include "cc/base/math_util.h"
13 #include "cc/debug/traced_value.h"
14 #include "cc/output/copy_output_request.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 : has_transparent_background(true),
56 quad_list(kDefaultNumQuadsToReserve),
57 shared_quad_state_list(sizeof(SharedQuadState),
58 kDefaultNumSharedQuadStatesToReserve) {
61 // Each layer usually produces one shared quad state, so the number of layers
62 // is a good hint for what to reserve here.
63 RenderPass::RenderPass(size_t num_layers)
64 : has_transparent_background(true),
65 quad_list(kDefaultNumQuadsToReserve),
66 shared_quad_state_list(sizeof(SharedQuadState), num_layers) {
69 RenderPass::RenderPass(size_t shared_quad_state_list_size,
70 size_t quad_list_size)
71 : has_transparent_background(true),
72 quad_list(quad_list_size),
73 shared_quad_state_list(sizeof(SharedQuadState),
74 shared_quad_state_list_size) {
77 RenderPass::~RenderPass() {
78 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
79 TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"),
80 "cc::RenderPass", id.AsTracingId());
83 scoped_ptr<RenderPass> RenderPass::Copy(RenderPassId new_id) const {
84 scoped_ptr<RenderPass> copy_pass(
85 Create(shared_quad_state_list.size(), quad_list.size()));
86 copy_pass->SetAll(new_id,
87 output_rect,
88 damage_rect,
89 transform_to_root_target,
90 has_transparent_background);
91 return copy_pass.Pass();
94 // static
95 void RenderPass::CopyAll(const ScopedPtrVector<RenderPass>& in,
96 ScopedPtrVector<RenderPass>* out) {
97 for (size_t i = 0; i < in.size(); ++i) {
98 RenderPass* source = in[i];
100 // Since we can't copy these, it's wrong to use CopyAll in a situation where
101 // you may have copy_requests present.
102 DCHECK_EQ(source->copy_requests.size(), 0u);
104 scoped_ptr<RenderPass> copy_pass(Create(
105 source->shared_quad_state_list.size(), source->quad_list.size()));
106 copy_pass->SetAll(source->id,
107 source->output_rect,
108 source->damage_rect,
109 source->transform_to_root_target,
110 source->has_transparent_background);
111 for (const auto& shared_quad_state : source->shared_quad_state_list) {
112 SharedQuadState* copy_shared_quad_state =
113 copy_pass->CreateAndAppendSharedQuadState();
114 copy_shared_quad_state->CopyFrom(shared_quad_state);
116 SharedQuadStateList::Iterator sqs_iter =
117 source->shared_quad_state_list.begin();
118 SharedQuadStateList::Iterator copy_sqs_iter =
119 copy_pass->shared_quad_state_list.begin();
120 for (const auto& quad : source->quad_list) {
121 while (quad->shared_quad_state != *sqs_iter) {
122 ++sqs_iter;
123 ++copy_sqs_iter;
124 DCHECK(sqs_iter != source->shared_quad_state_list.end());
126 DCHECK(quad->shared_quad_state == *sqs_iter);
128 SharedQuadState* copy_shared_quad_state = *copy_sqs_iter;
130 if (quad->material == DrawQuad::RENDER_PASS) {
131 const RenderPassDrawQuad* pass_quad =
132 RenderPassDrawQuad::MaterialCast(quad);
133 copy_pass->CopyFromAndAppendRenderPassDrawQuad(
134 pass_quad, copy_shared_quad_state, pass_quad->render_pass_id);
135 } else {
136 copy_pass->CopyFromAndAppendDrawQuad(quad, copy_shared_quad_state);
139 out->push_back(copy_pass.Pass());
143 void RenderPass::SetNew(RenderPassId id,
144 const gfx::Rect& output_rect,
145 const gfx::Rect& damage_rect,
146 const gfx::Transform& transform_to_root_target) {
147 DCHECK_GT(id.layer_id, 0);
148 DCHECK(damage_rect.IsEmpty() || output_rect.Contains(damage_rect))
149 << "damage_rect: " << damage_rect.ToString()
150 << " output_rect: " << output_rect.ToString();
152 this->id = id;
153 this->output_rect = output_rect;
154 this->damage_rect = damage_rect;
155 this->transform_to_root_target = transform_to_root_target;
157 DCHECK(quad_list.empty());
158 DCHECK(shared_quad_state_list.empty());
161 void RenderPass::SetAll(RenderPassId id,
162 const gfx::Rect& output_rect,
163 const gfx::Rect& damage_rect,
164 const gfx::Transform& transform_to_root_target,
165 bool has_transparent_background) {
166 DCHECK_GT(id.layer_id, 0);
168 this->id = id;
169 this->output_rect = output_rect;
170 this->damage_rect = damage_rect;
171 this->transform_to_root_target = transform_to_root_target;
172 this->has_transparent_background = has_transparent_background;
174 DCHECK(quad_list.empty());
175 DCHECK(shared_quad_state_list.empty());
178 void RenderPass::AsValueInto(base::trace_event::TracedValue* value) const {
179 MathUtil::AddToTracedValue("output_rect", output_rect, value);
180 MathUtil::AddToTracedValue("damage_rect", damage_rect, value);
182 value->SetBoolean("has_transparent_background", has_transparent_background);
183 value->SetInteger("copy_requests",
184 base::saturated_cast<int>(copy_requests.size()));
186 value->BeginArray("shared_quad_state_list");
187 for (const auto& shared_quad_state : shared_quad_state_list) {
188 value->BeginDictionary();
189 shared_quad_state->AsValueInto(value);
190 value->EndDictionary();
192 value->EndArray();
194 value->BeginArray("quad_list");
195 for (const auto& quad : quad_list) {
196 value->BeginDictionary();
197 quad->AsValueInto(value);
198 value->EndDictionary();
200 value->EndArray();
202 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
203 TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"),
204 value,
205 "cc::RenderPass",
206 id.AsTracingId());
209 SharedQuadState* RenderPass::CreateAndAppendSharedQuadState() {
210 return shared_quad_state_list.AllocateAndConstruct<SharedQuadState>();
213 RenderPassDrawQuad* RenderPass::CopyFromAndAppendRenderPassDrawQuad(
214 const RenderPassDrawQuad* quad,
215 const SharedQuadState* shared_quad_state,
216 RenderPassId render_pass_id) {
217 RenderPassDrawQuad* copy_quad =
218 CopyFromAndAppendTypedDrawQuad<RenderPassDrawQuad>(quad);
219 copy_quad->shared_quad_state = shared_quad_state;
220 copy_quad->render_pass_id = render_pass_id;
221 return copy_quad;
224 DrawQuad* RenderPass::CopyFromAndAppendDrawQuad(
225 const DrawQuad* quad,
226 const SharedQuadState* shared_quad_state) {
227 switch (quad->material) {
228 case DrawQuad::DEBUG_BORDER:
229 CopyFromAndAppendTypedDrawQuad<DebugBorderDrawQuad>(quad);
230 break;
231 case DrawQuad::IO_SURFACE_CONTENT:
232 CopyFromAndAppendTypedDrawQuad<IOSurfaceDrawQuad>(quad);
233 break;
234 case DrawQuad::PICTURE_CONTENT:
235 CopyFromAndAppendTypedDrawQuad<PictureDrawQuad>(quad);
236 break;
237 case DrawQuad::TEXTURE_CONTENT:
238 CopyFromAndAppendTypedDrawQuad<TextureDrawQuad>(quad);
239 break;
240 case DrawQuad::SOLID_COLOR:
241 CopyFromAndAppendTypedDrawQuad<SolidColorDrawQuad>(quad);
242 break;
243 case DrawQuad::TILED_CONTENT:
244 CopyFromAndAppendTypedDrawQuad<TileDrawQuad>(quad);
245 break;
246 case DrawQuad::STREAM_VIDEO_CONTENT:
247 CopyFromAndAppendTypedDrawQuad<StreamVideoDrawQuad>(quad);
248 break;
249 case DrawQuad::SURFACE_CONTENT:
250 CopyFromAndAppendTypedDrawQuad<SurfaceDrawQuad>(quad);
251 break;
252 case DrawQuad::YUV_VIDEO_CONTENT:
253 CopyFromAndAppendTypedDrawQuad<YUVVideoDrawQuad>(quad);
254 break;
255 // RenderPass quads need to use specific CopyFrom function.
256 case DrawQuad::RENDER_PASS:
257 case DrawQuad::INVALID:
258 LOG(FATAL) << "Invalid DrawQuad material " << quad->material;
259 break;
261 quad_list.back()->shared_quad_state = shared_quad_state;
262 return quad_list.back();
265 } // namespace cc