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

Unified Diff: ui/android/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: ui/android/delegated_frame_host_android.cc
diff --git a/ui/android/delegated_frame_host_android.cc b/ui/android/delegated_frame_host_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..50364c51dcd1b0dc9d8c19c61b341247553b0a19
--- /dev/null
+++ b/ui/android/delegated_frame_host_android.cc
@@ -0,0 +1,197 @@
+// 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 "ui/android/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/output/copy_output_request.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 "ui/android/context_provider_factory.h"
+#include "ui/android/view_android.h"
+
+namespace ui {
+
+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());
+
+ surface_manager_ =
+ ui::ContextProviderFactory::GetInstance()->GetSurfaceManager();
+ surface_id_allocator_.reset(new cc::SurfaceIdAllocator(
+ ui::ContextProviderFactory::GetInstance()->AllocateSurfaceClientId()));
+ surface_manager_->RegisterSurfaceClientId(surface_id_allocator_->client_id());
+
+ background_layer_->SetBackgroundColor(background_color);
+ view_->GetLayer()->AddChild(background_layer_);
+ UpdateBackgroundLayer();
+}
+
+DelegatedFrameHostAndroid::~DelegatedFrameHostAndroid() {
David Trainor- moved to gerrit 2016/08/04 16:05:46 We should make sure to remove all layers we build
Khushal 2016/08/09 20:54:06 Yup. Done.
+ 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_);
David Trainor- moved to gerrit 2016/08/04 16:05:46 might as well DCHECK(surface_id_.is_null()) also i
Khushal 2016/08/09 20:54:07 Done.
+
+ surface_id_ = surface_id_allocator_->GenerateId();
David Trainor- moved to gerrit 2016/08/04 16:05:46 Not necessarily for this CL, but it would be nice
Khushal 2016/08/09 20:54:06 Looked around the code a little bit, and looks lik
+ 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()));
David Trainor- moved to gerrit 2016/08/04 16:05:46 Do we need to pass in the layer or can we just cre
Khushal 2016/08/09 20:54:06 Good idea. Collapsed it into CreateContentLayer an
+ }
+
+ surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame),
+ draw_callback);
+}
+
+uint32_t DelegatedFrameHostAndroid::GetSurfaceClientId() const {
+ return surface_id_allocator_->client_id();
+}
+
+void DelegatedFrameHostAndroid::RequestCopyOfSurface(
+ std::unique_ptr<cc::CopyOutputRequest> copy_output_request) {
+ DCHECK(!surface_id_.is_null());
+ surface_factory_->RequestCopyOfSurface(surface_id_,
+ std::move(copy_output_request));
+}
+
+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) {
+ desired_content_size_ = desired_content_size;
+ background_layer_->SetBounds(desired_content_size);
+ UpdateBackgroundLayer();
+}
+
+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_);
David Trainor- moved to gerrit 2016/08/04 16:05:46 Is there a reason we don't set the new surface id
Khushal 2016/08/09 20:54:06 Good question. Doesn't look like the Surface Layer
Khushal 2016/08/12 01:49:48 So we can keep a single content layer around and j
+ 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) {
+ if (content_layer)
+ content_layer->RemoveFromParent();
+
+ content_layer_ = std::move(content_layer);
+
+ if (content_layer_)
+ view_->GetLayer()->AddChild(content_layer_);
+
+ UpdateBackgroundLayer();
+}
+
+void DelegatedFrameHostAndroid::UpdateBackgroundLayer() {
+ // The background layer draws in 2 cases:
+ // 1) When we don't have any content from the renderer.
+ // 2) When the bounds of the content received from the renderer does not match
+ // the desired content bounds.
+ bool background_is_drawable =
+ content_layer_.get() == nullptr ||
+ content_layer_->bounds() != desired_content_size_;
+ background_layer_->SetIsDrawable(background_is_drawable);
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698