Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: cc/surfaces/surface_aggregator.cc

Issue 139763003: Initial surface aggregator implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add comment to SharedQuadState Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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.
4
5 #include "cc/surfaces/surface_aggregator.h"
6
7 #include "base/logging.h"
8 #include "cc/output/compositor_frame.h"
9 #include "cc/output/delegated_frame_data.h"
10 #include "cc/quads/draw_quad.h"
11 #include "cc/quads/render_pass_draw_quad.h"
12 #include "cc/quads/shared_quad_state.h"
13 #include "cc/quads/surface_draw_quad.h"
14 #include "cc/surfaces/surface.h"
15 #include "cc/surfaces/surface_manager.h"
16
17 namespace cc {
18
19 SurfaceAggregator::SurfaceAggregator(SurfaceManager* manager)
20 : manager_(manager) {
21 DCHECK(manager_);
22 }
23
24 SurfaceAggregator::~SurfaceAggregator() {}
25
26 void SurfaceAggregator::CopyQuadsToPass(
27 const QuadList& source_quad_list,
28 const SharedQuadStateList& source_shared_quad_state_list,
29 RenderPass* dest_pass,
30 RenderPassList* dest_pass_list,
31 std::set<int>* referenced_surfaces) {
32
33 for (size_t j = 0; j < source_shared_quad_state_list.size(); ++j) {
34 dest_pass->shared_quad_state_list.push_back(
35 source_shared_quad_state_list[j]->Copy());
36 }
37
38 for (size_t i = 0, sqs_i = 0; i < source_quad_list.size(); ++i) {
39 DrawQuad* quad = source_quad_list[i];
40
41 while (quad->shared_quad_state != source_shared_quad_state_list[sqs_i]) {
42 ++sqs_i;
43 DCHECK_LT(sqs_i, source_shared_quad_state_list.size());
44 DCHECK_LT(sqs_i, dest_pass->shared_quad_state_list.size());
45 }
46 DCHECK_EQ(quad->shared_quad_state, source_shared_quad_state_list[sqs_i]);
47
48 if (quad->material == DrawQuad::SURFACE_CONTENT) {
49 const SurfaceDrawQuad* surface_quad = SurfaceDrawQuad::MaterialCast(quad);
50 int surface_id = surface_quad->surface_id;
51 // If this surface's id is already in our referenced set then it creates
52 // a cycle in the graph and should be dropped.
53 if (referenced_surfaces->count(surface_id))
54 continue;
55 Surface* referenced_surface = manager_->GetSurfaceForID(surface_id);
56 if (!referenced_surface)
57 continue; // Invalid surface id, skip this quad.
58 // Grab frame from surface, copy stuff in.
59 CompositorFrame* referenced_frame =
60 referenced_surface->GetEligibleFrame();
61 if (!referenced_frame)
62 continue;
63 DelegatedFrameData* referenced_data =
64 referenced_frame->delegated_frame_data.get();
65 DCHECK(referenced_data);
66 std::set<int>::iterator it =
67 referenced_surfaces->insert(surface_id).first;
68
69 // TODO(jamesr): Clean up first pass special casing.
70 const RenderPass& first_pass = *referenced_data->render_pass_list[0];
71 const QuadList& quads = first_pass.quad_list;
72
73 for (size_t j = 0; j < first_pass.shared_quad_state_list.size(); ++j) {
74 dest_pass->shared_quad_state_list.push_back(
75 first_pass.shared_quad_state_list[j]->Copy());
76 }
77 // TODO(jamesr): Map transform correctly for quads in the referenced
78 // surface into this pass's space.
79 // TODO(jamesr): Make sure clipping is enforced.
80 CopyQuadsToPass(quads,
81 first_pass.shared_quad_state_list,
82 dest_pass,
83 dest_pass_list,
84 referenced_surfaces);
85
86 const RenderPassList& referenced_passes =
87 referenced_data->render_pass_list;
88 for (size_t j = 1; j < referenced_passes.size(); ++j) {
89 const RenderPass& source = *referenced_passes[j];
90
91 scoped_ptr<RenderPass> copy_pass(RenderPass::Create());
92
93 copy_pass->SetAll(source.id,
94 source.output_rect,
95 source.damage_rect,
96 source.transform_to_root_target,
97 source.has_transparent_background);
98
99 CopyQuadsToPass(source.quad_list,
100 source.shared_quad_state_list,
101 copy_pass.get(),
102 dest_pass_list,
103 referenced_surfaces);
104
105 dest_pass_list->push_back(copy_pass.Pass());
106 }
107
108 referenced_surfaces->erase(it);
109 } else if (quad->material == DrawQuad::RENDER_PASS) {
110 const RenderPassDrawQuad* pass_quad =
111 RenderPassDrawQuad::MaterialCast(quad);
112 // TODO(jamesr): Map render pass IDs.
113 dest_pass->quad_list.push_back(
114 pass_quad->Copy(dest_pass->shared_quad_state_list[sqs_i],
115 pass_quad->render_pass_id).PassAs<DrawQuad>());
116 } else {
117 dest_pass->quad_list.push_back(
118 quad->Copy(dest_pass->shared_quad_state_list[sqs_i]));
119 }
120 }
121 }
122
123 void SurfaceAggregator::CopyPasses(const RenderPassList& source_pass_list,
124 RenderPassList* dest_pass_list,
125 std::set<int>* referenced_surfaces) {
126 for (size_t i = 0; i < source_pass_list.size(); ++i) {
127 const RenderPass& source = *source_pass_list[i];
128
129 scoped_ptr<RenderPass> copy_pass(RenderPass::Create());
130
131 copy_pass->SetAll(source.id,
132 source.output_rect,
133 source.damage_rect,
134 source.transform_to_root_target,
135 source.has_transparent_background);
136
137 dest_pass_list->push_back(copy_pass.Pass());
138
139 CopyQuadsToPass(source.quad_list,
140 source.shared_quad_state_list,
141 dest_pass_list->back(),
142 dest_pass_list,
143 referenced_surfaces);
144 }
145 }
146
147 scoped_ptr<CompositorFrame> SurfaceAggregator::Aggregate(int surface_id) {
148 Surface* surface = manager_->GetSurfaceForID(surface_id);
149 if (!surface)
150 return scoped_ptr<CompositorFrame>();
151 CompositorFrame* root_surface_frame = surface->GetEligibleFrame();
152 if (!root_surface_frame)
153 return scoped_ptr<CompositorFrame>();
154
155 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
156 frame->delegated_frame_data = make_scoped_ptr(new DelegatedFrameData);
157
158 DCHECK(root_surface_frame->delegated_frame_data);
159
160 const RenderPassList& source_pass_list =
161 root_surface_frame->delegated_frame_data->render_pass_list;
162
163 std::set<int> referenced_surfaces;
164 referenced_surfaces.insert(surface_id);
165
166 RenderPassList* dest_pass_list =
167 &frame->delegated_frame_data->render_pass_list;
168 CopyPasses(source_pass_list, dest_pass_list, &referenced_surfaces);
169
170 // TODO(jamesr): Aggregate all resource references into the returned frame's
171 // resource list.
172
173 return frame.Pass();
174 }
175
176 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698