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

Unified Diff: cc/output/overlay_renderer.cc

Issue 197223003: Start of hardware overlay support in CC with Ubercompositor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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/output/overlay_renderer.cc
diff --git a/cc/output/overlay_renderer.cc b/cc/output/overlay_renderer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b9b3fcf64441f44bc574441be32516866735e9f5
--- /dev/null
+++ b/cc/output/overlay_renderer.cc
@@ -0,0 +1,124 @@
+// 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/output/overlay_renderer.h"
+
+#include "cc/output/output_surface.h"
+#include "cc/quads/draw_quad.h"
+#include "cc/quads/texture_draw_quad.h"
+#include "ui/gfx/rect_conversions.h"
+#include "ui/gfx/transform.h"
+
+namespace cc {
+
+namespace {
+
+class SingleOverlayOnTop : public OverlayRenderer::Strategy {
+ public:
+ SingleOverlayOnTop(OverlayCandidates* capability_checker,
+ ResourceProvider* resource_provider);
+ virtual bool Attempt(RenderPassList* render_passes_in_draw_order) OVERRIDE;
+
+ private:
+ OverlayCandidates* capability_checker_;
+ ResourceProvider* resource_provider_;
piman 2014/03/14 03:42:34 nit: DISALLOW_COPY_AND_ASSIGN
alexst (slow to review) 2014/03/14 19:54:22 Done.
+};
+
+SingleOverlayOnTop::SingleOverlayOnTop(OverlayCandidates* capability_checker,
+ ResourceProvider* resource_provider)
+ : capability_checker_(capability_checker),
+ resource_provider_(resource_provider) {}
+
+bool SingleOverlayOnTop::Attempt(RenderPassList* render_passes_in_draw_order) {
piman 2014/03/14 03:42:34 I think it would be nice to expose this so that we
alexst (slow to review) 2014/03/14 19:54:22 I was planning to do it as we added more strategie
+ // Only attempt to handle very simple case for now.
+ if (render_passes_in_draw_order->size() != 1 || !capability_checker_)
+ return false;
+
+ RenderPass* root_render_pass = render_passes_in_draw_order->back();
+ DCHECK(root_render_pass);
+
+ QuadList& quad_list = root_render_pass->quad_list;
+ QuadList::BackToFrontIterator candidate_quad = quad_list.BackToFrontEnd();
+ for (QuadList::BackToFrontIterator it = quad_list.BackToFrontBegin();
+ it != quad_list.BackToFrontEnd();
+ ++it) {
+ const DrawQuad& quad = *(*it);
+ // Don't try for multiple surfaces or if something is on top of
+ // our candidate.
+ if (candidate_quad != quad_list.BackToFrontEnd())
+ return false;
piman 2014/03/14 03:42:34 You're only setting candidate_quad right before yo
alexst (slow to review) 2014/03/14 19:54:22 You are right, I was simplifying old test code for
+
+ if (quad.material == DrawQuad::TEXTURE_CONTENT) {
+ ResourceProvider::ResourceId resource_id =
+ TextureDrawQuad::MaterialCast(*it)->resource_id;
+
+ if (!resource_provider_->HasNativeBufferBacking(resource_id))
+ continue;
+
+ candidate_quad = it;
+ break;
+ }
+ }
+
+ // Found nothing useful.
+ if (candidate_quad == quad_list.BackToFrontEnd())
+ return false;
+
+ // Add our primary surface.
+ OverlayCandidates::OverlaySurfaceCandidateList candidates;
+ OverlayCandidates::OverlaySurfaceCandidate main_image;
+ main_image.display_rect = root_render_pass->output_rect;
+ main_image.format = RGBA_8888;
+ candidates.push_back(main_image);
+
+ // Add the overlay.
+ OverlayCandidates::OverlaySurfaceCandidate candidate;
+ const TextureDrawQuad& quad = *TextureDrawQuad::MaterialCast(*candidate_quad);
+ gfx::RectF float_rect(quad.rect);
+ quad.quadTransform().TransformRect(&float_rect);
piman 2014/03/14 03:42:34 This really computes the bounding box of the trans
alexst (slow to review) 2014/03/14 19:54:22 This meant to have a check for identity or transla
+ candidate.display_rect = gfx::ToNearestRect(float_rect);
+ candidate.crop_rect = BoundingRect(quad.uv_top_left, quad.uv_bottom_right);
+ candidate.format = RGBA_8888;
+ candidates.push_back(candidate);
+
+ // Check for support.
+ capability_checker_->CheckOverlaySupport(&candidates);
enne (OOO) 2014/03/14 18:13:41 I'm sure there's a wrinkle I'm not seeing, but why
alexst (slow to review) 2014/03/14 19:54:22 Exactly right. Maybe HW can't handle 4 things, but
+
+ // If the candidate can be handled by an overlay, create a pass for it.
+ if (candidates[1].overlay_handled) {
+ scoped_ptr<RenderPass> overlay_pass = RenderPass::Create();
+ overlay_pass->overlay_state = RenderPass::SIMPLE_OVERLAY;
+
+ scoped_ptr<DrawQuad> overlay_quad =
+ quad_list.take((candidate_quad + 1).base());
piman 2014/03/14 03:42:34 I think it would be clearer if candidate_quad was
+ quad_list.erase((candidate_quad + 1).base());
+ overlay_pass->quad_list.push_back(overlay_quad.PassAs<DrawQuad>());
piman 2014/03/14 03:42:34 nit: just Pass() ?
+ render_passes_in_draw_order->insert(render_passes_in_draw_order->begin(),
+ overlay_pass.PassAs<RenderPass>());
piman 2014/03/14 03:42:34 nit: just Pass()?
+ }
+ return true;
+}
+}
+
+OverlayRenderer::OverlayRenderer(OutputSurface* surface,
+ ResourceProvider* resource_provider) {
+ DCHECK(surface);
+ OverlayCandidates* candidates = surface->overlay_candidates();
+ if (candidates) {
+ strategies_.push_back(scoped_ptr<Strategy>(
+ new SingleOverlayOnTop(candidates, resource_provider)));
+ }
+}
+
+OverlayRenderer::~OverlayRenderer() {}
+
+void OverlayRenderer::ProcessForOverlays(
+ RenderPassList* render_passes_in_draw_order) {
+ for (size_t i = 0; i < strategies_.size(); i++) {
piman 2014/03/14 03:42:34 nit: use iterators and win on the bounds checks.
+ if (strategies_[i]->Attempt(render_passes_in_draw_order))
+ return;
+ }
+}
+
+} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698