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

Unified Diff: content/browser/renderer_host/delegated_frame_host_android.cc

Issue 2133873004: content: Move Surfaces related code out of RWHVA. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: .. Created 4 years, 5 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: content/browser/renderer_host/delegated_frame_host_android.cc
diff --git a/content/browser/renderer_host/delegated_frame_host_android.cc b/content/browser/renderer_host/delegated_frame_host_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..12edca10f351ebc317943922c297726d52c35721
--- /dev/null
+++ b/content/browser/renderer_host/delegated_frame_host_android.cc
@@ -0,0 +1,176 @@
+// Copyright 2016 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 "content/browser/renderer_host/delegated_frame_host_android.h"
+
+#include "base/logging.h"
+#include "cc/layers/solid_color_layer.h"
+#include "cc/layers/surface_layer.h"
+#include "cc/output/compositor_frame.h"
+#include "cc/surfaces/surface.h"
+#include "cc/surfaces/surface_id.h"
+#include "cc/surfaces/surface_id_allocator.h"
+#include "cc/surfaces/surface_manager.h"
+#include "content/browser/renderer_host/compositor_impl_android.h"
+
+namespace content {
+
+namespace {
+
+void SatisfyCallback(cc::SurfaceManager* manager,
+ const cc::SurfaceSequence& sequence) {
+ std::vector<uint32_t> sequences;
+ sequences.push_back(sequence.sequence);
+ manager->DidSatisfySequences(sequence.client_id, &sequences);
+}
+
+void RequireCallback(cc::SurfaceManager* manager,
+ const cc::SurfaceId& id,
+ const cc::SurfaceSequence& sequence) {
+ cc::Surface* surface = manager->GetSurfaceForId(id);
+ if (!surface) {
+ LOG(ERROR) << "Attempting to require callback on nonexistent surface";
+ return;
+ }
+ surface->AddDestructionDependency(sequence);
+}
+
+} // namespace
+
+DelegatedFrameHostAndroid::DelegatedFrameHostAndroid(
+ ui::ViewAndroid* view,
+ SkColor background_color,
+ ReturnResourcesCallback return_resources_callback)
+ : view_(view),
+ return_resources_callback_(return_resources_callback),
+ background_layer_(cc::SolidColorLayer::Create()) {
+ DCHECK(view_);
+ DCHECK(!return_resources_callback_.is_null());
+
+ // TODO(khushalsagar): These CompositorImpl dependencies should move to ui?
+ surface_manager_ = CompositorImpl::GetSurfaceManager();
Khushal 2016/07/27 21:58:38 Was talking to David about this. Should we move th
+ surface_id_allocator_.reset(
+ new cc::SurfaceIdAllocator(CompositorImpl::AllocateSurfaceClientId()));
+ surface_manager_->RegisterSurfaceClientId(surface_id_allocator_->client_id());
+
+ background_layer_->SetIsDrawable(true);
+ background_layer_->SetBackgroundColor(background_color);
+ view_->GetLayer()->AddChild(background_layer_);
+}
+
+DelegatedFrameHostAndroid::~DelegatedFrameHostAndroid() {
+ DestroyDelegatedContent();
+ surface_factory_.reset();
+ surface_manager_->InvalidateSurfaceClientId(
+ surface_id_allocator_->client_id());
+}
+
+void DelegatedFrameHostAndroid::SubmitCompositorFrame(
+ cc::CompositorFrame frame,
+ cc::SurfaceFactory::DrawCallback draw_callback) {
+ if (!surface_factory_) {
+ surface_factory_ =
+ base::WrapUnique(new cc::SurfaceFactory(surface_manager_, this));
+ }
+
+ cc::RenderPass* root_pass =
+ frame.delegated_frame_data->render_pass_list.back().get();
+ gfx::Size texture_size_in_layer = root_pass->output_rect.size();
+
+ if (surface_id_.is_null() || texture_size_in_layer != current_surface_size_ ||
+ location_bar_content_translation_ !=
+ frame.metadata.location_bar_content_translation ||
+ current_viewport_selection_ != frame.metadata.selection) {
+ DestroyDelegatedContent();
+ DCHECK(!content_layer_);
+
+ surface_id_ = surface_id_allocator_->GenerateId();
+ surface_factory_->Create(surface_id_);
+
+ current_surface_size_ = texture_size_in_layer;
+ location_bar_content_translation_ =
+ frame.metadata.location_bar_content_translation;
+ current_viewport_selection_ = frame.metadata.selection;
+ UpdateContentLayer(std::move(CreateSurfaceLayer()));
+ }
+
+ surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame),
+ draw_callback);
+}
+
+uint32_t DelegatedFrameHostAndroid::GetSurfaceClientId() const {
+ return surface_id_allocator_->client_id();
+}
+
+void DelegatedFrameHostAndroid::DestroyDelegatedContent() {
+ if (surface_id_.is_null())
+ return;
+
+ DCHECK(surface_factory_.get());
+ DCHECK(content_layer_);
+
+ UpdateContentLayer(nullptr);
+ surface_factory_->Destroy(surface_id_);
+ surface_id_ = cc::SurfaceId();
+}
+
+void DelegatedFrameHostAndroid::OutputSurfaceChanged() {
+ DestroyDelegatedContent();
+ surface_factory_.reset();
+}
+
+void DelegatedFrameHostAndroid::UpdateBackgroundColor(SkColor color) {
+ background_layer_->SetBackgroundColor(color);
+}
+
+void DelegatedFrameHostAndroid::UpdateSize(
+ const gfx::Size& desired_content_size) {
+ // TODO(khushalsagar): The gutter logic for when the desired content size
+ // doesn't match the size of the renderer frame should go here.
+ background_layer_->SetBounds(desired_content_size);
+}
+
+cc::Layer* DelegatedFrameHostAndroid::GetContentLayer() const {
+ return content_layer_.get();
+}
+
+void DelegatedFrameHostAndroid::ReturnResources(
+ const cc::ReturnedResourceArray& resources) {
+ return_resources_callback_.Run(resources);
+}
+
+void DelegatedFrameHostAndroid::SetBeginFrameSource(
+ cc::BeginFrameSource* begin_frame_source) {
+ // TODO(tansell): Hook this up.
+}
+
+scoped_refptr<cc::SurfaceLayer>
+DelegatedFrameHostAndroid::CreateSurfaceLayer() {
+ DCHECK(!surface_id_.is_null());
+
+ // manager must outlive compositors using it.
+ scoped_refptr<cc::SurfaceLayer> surface_layer = cc::SurfaceLayer::Create(
+ base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)),
+ base::Bind(&RequireCallback, base::Unretained(surface_manager_)));
+ surface_layer->SetSurfaceId(surface_id_, 1.f, current_surface_size_);
+ surface_layer->SetBounds(current_surface_size_);
+ surface_layer->SetIsDrawable(true);
+ surface_layer->SetContentsOpaque(true);
+
+ return surface_layer;
+}
+
+void DelegatedFrameHostAndroid::UpdateContentLayer(
+ scoped_refptr<cc::Layer> content_layer) {
+ view_->GetLayer()->RemoveAllChildren();
+ content_layer_ = std::move(content_layer);
+
+ if (content_layer_) {
+ view_->GetLayer()->AddChild(content_layer_);
+ } else {
+ view_->GetLayer()->AddChild(background_layer_);
+ }
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698