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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: cc/surfaces/surface_aggregator.cc
diff --git a/cc/surfaces/surface_aggregator.cc b/cc/surfaces/surface_aggregator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e5e829b7bba9e28b93f1f510fd42269856ee3f15
--- /dev/null
+++ b/cc/surfaces/surface_aggregator.cc
@@ -0,0 +1,176 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/surfaces/surface_aggregator.h"
+
+#include "base/logging.h"
+#include "cc/output/compositor_frame.h"
+#include "cc/output/delegated_frame_data.h"
+#include "cc/quads/draw_quad.h"
+#include "cc/quads/render_pass_draw_quad.h"
+#include "cc/quads/shared_quad_state.h"
+#include "cc/quads/surface_draw_quad.h"
+#include "cc/surfaces/surface.h"
+#include "cc/surfaces/surface_manager.h"
+
+namespace cc {
+
+SurfaceAggregator::SurfaceAggregator(SurfaceManager* manager)
+ : manager_(manager) {
+ DCHECK(manager_);
+}
+
+SurfaceAggregator::~SurfaceAggregator() {}
+
+void SurfaceAggregator::CopyQuadsToPass(
+ const QuadList& source_quad_list,
+ const SharedQuadStateList& source_shared_quad_state_list,
+ RenderPass* dest_pass,
+ RenderPassList* dest_pass_list,
+ std::set<int>* referenced_surfaces) {
+
+ for (size_t j = 0; j < source_shared_quad_state_list.size(); ++j) {
+ dest_pass->shared_quad_state_list.push_back(
+ source_shared_quad_state_list[j]->Copy());
+ }
+
+ for (size_t i = 0, sqs_i = 0; i < source_quad_list.size(); ++i) {
+ DrawQuad* quad = source_quad_list[i];
+
+ while (quad->shared_quad_state != source_shared_quad_state_list[sqs_i]) {
+ ++sqs_i;
+ DCHECK_LT(sqs_i, source_shared_quad_state_list.size());
+ DCHECK_LT(sqs_i, dest_pass->shared_quad_state_list.size());
+ }
+ DCHECK_EQ(quad->shared_quad_state, source_shared_quad_state_list[sqs_i]);
+
+ if (quad->material == DrawQuad::SURFACE_CONTENT) {
+ const SurfaceDrawQuad* surface_quad = SurfaceDrawQuad::MaterialCast(quad);
+ int surface_id = surface_quad->surface_id;
+ // If this surface's id is already in our referenced set then it creates
+ // a cycle in the graph and should be dropped.
+ if (referenced_surfaces->count(surface_id))
+ continue;
+ Surface* referenced_surface = manager_->GetSurfaceForID(surface_id);
+ if (!referenced_surface)
+ continue; // Invalid surface id, skip this quad.
+ // Grab frame from surface, copy stuff in.
+ CompositorFrame* referenced_frame =
+ referenced_surface->GetEligibleFrame();
+ if (!referenced_frame)
+ continue;
+ DelegatedFrameData* referenced_data =
+ referenced_frame->delegated_frame_data.get();
+ DCHECK(referenced_data);
+ std::set<int>::iterator it =
+ referenced_surfaces->insert(surface_id).first;
+
+ // TODO(jamesr): Clean up first pass special casing.
+ const RenderPass& first_pass = *referenced_data->render_pass_list[0];
+ const QuadList& quads = first_pass.quad_list;
+
+ for (size_t j = 0; j < first_pass.shared_quad_state_list.size(); ++j) {
+ dest_pass->shared_quad_state_list.push_back(
+ first_pass.shared_quad_state_list[j]->Copy());
+ }
+ // TODO(jamesr): Map transform correctly for quads in the referenced
+ // surface into this pass's space.
+ // TODO(jamesr): Make sure clipping is enforced.
+ CopyQuadsToPass(quads,
+ first_pass.shared_quad_state_list,
+ dest_pass,
+ dest_pass_list,
+ referenced_surfaces);
+
+ const RenderPassList& referenced_passes =
+ referenced_data->render_pass_list;
+ for (size_t j = 1; j < referenced_passes.size(); ++j) {
+ const RenderPass& source = *referenced_passes[j];
+
+ scoped_ptr<RenderPass> copy_pass(RenderPass::Create());
+
+ copy_pass->SetAll(source.id,
+ source.output_rect,
+ source.damage_rect,
+ source.transform_to_root_target,
+ source.has_transparent_background);
+
+ CopyQuadsToPass(source.quad_list,
+ source.shared_quad_state_list,
+ copy_pass.get(),
+ dest_pass_list,
+ referenced_surfaces);
+
+ dest_pass_list->push_back(copy_pass.Pass());
+ }
+
+ referenced_surfaces->erase(it);
+ } else if (quad->material == DrawQuad::RENDER_PASS) {
+ const RenderPassDrawQuad* pass_quad =
+ RenderPassDrawQuad::MaterialCast(quad);
+ // TODO(jamesr): Map render pass IDs.
+ dest_pass->quad_list.push_back(
+ pass_quad->Copy(dest_pass->shared_quad_state_list[sqs_i],
+ pass_quad->render_pass_id).PassAs<DrawQuad>());
+ } else {
+ dest_pass->quad_list.push_back(
+ quad->Copy(dest_pass->shared_quad_state_list[sqs_i]));
+ }
+ }
+}
+
+void SurfaceAggregator::CopyPasses(const RenderPassList& source_pass_list,
+ RenderPassList* dest_pass_list,
+ std::set<int>* referenced_surfaces) {
+ for (size_t i = 0; i < source_pass_list.size(); ++i) {
+ const RenderPass& source = *source_pass_list[i];
+
+ scoped_ptr<RenderPass> copy_pass(RenderPass::Create());
+
+ copy_pass->SetAll(source.id,
+ source.output_rect,
+ source.damage_rect,
+ source.transform_to_root_target,
+ source.has_transparent_background);
+
+ dest_pass_list->push_back(copy_pass.Pass());
+
+ CopyQuadsToPass(source.quad_list,
+ source.shared_quad_state_list,
+ dest_pass_list->back(),
+ dest_pass_list,
+ referenced_surfaces);
+ }
+}
+
+scoped_ptr<CompositorFrame> SurfaceAggregator::Aggregate(int surface_id) {
+ Surface* surface = manager_->GetSurfaceForID(surface_id);
+ if (!surface)
+ return scoped_ptr<CompositorFrame>();
+ CompositorFrame* root_surface_frame = surface->GetEligibleFrame();
+ if (!root_surface_frame)
+ return scoped_ptr<CompositorFrame>();
+
+ scoped_ptr<CompositorFrame> frame(new CompositorFrame);
+ frame->delegated_frame_data = make_scoped_ptr(new DelegatedFrameData);
+
+ DCHECK(root_surface_frame->delegated_frame_data);
+
+ const RenderPassList& source_pass_list =
+ root_surface_frame->delegated_frame_data->render_pass_list;
+
+ std::set<int> referenced_surfaces;
+ referenced_surfaces.insert(surface_id);
+
+ RenderPassList* dest_pass_list =
+ &frame->delegated_frame_data->render_pass_list;
+ CopyPasses(source_pass_list, dest_pass_list, &referenced_surfaces);
+
+ // TODO(jamesr): Aggregate all resource references into the returned frame's
+ // resource list.
+
+ return frame.Pass();
+}
+
+} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698