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

Unified Diff: content/browser/frame_host/render_widget_host_view_guest.cc

Issue 1169983006: Convert BrowserPlugin to render using cc::Surfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update test to always call UpdateGuestSizeIfNecessary(). Created 5 years, 6 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/frame_host/render_widget_host_view_guest.cc
diff --git a/content/browser/frame_host/render_widget_host_view_guest.cc b/content/browser/frame_host/render_widget_host_view_guest.cc
index c1a3419de0d08501c36c7fd81414c990d32ee03a..27a2c716a1222800c22ab39efd98275ce2bb3b11 100644
--- a/content/browser/frame_host/render_widget_host_view_guest.cc
+++ b/content/browser/frame_host/render_widget_host_view_guest.cc
@@ -6,7 +6,12 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
+#include "cc/surfaces/surface.h"
+#include "cc/surfaces/surface_factory.h"
+#include "cc/surfaces/surface_manager.h"
+#include "cc/surfaces/surface_sequence.h"
#include "content/browser/browser_plugin/browser_plugin_guest.h"
+#include "content/browser/compositor/surface_utils.h"
#include "content/browser/frame_host/render_widget_host_view_guest.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/common/browser_plugin/browser_plugin_messages.h"
@@ -206,10 +211,68 @@ void RenderWidgetHostViewGuest::OnSwapCompositorFrame(
return;
last_scroll_offset_ = frame->metadata.root_scroll_offset;
- guest_->SwapCompositorFrame(output_surface_id,
- host_->GetProcess()->GetID(),
- host_->GetRoutingID(),
- frame.Pass());
+ // When not using surfaces, the frame just gets proxied to
+ // the embedder's renderer to be composited.
+ if (!frame->delegated_frame_data || !use_surfaces_) {
+ guest_->SwapCompositorFrame(output_surface_id,
+ host_->GetProcess()->GetID(),
+ host_->GetRoutingID(),
+ frame.Pass());
+ return;
+ }
+
+ cc::RenderPass* root_pass =
+ frame->delegated_frame_data->render_pass_list.back();
+
+ gfx::Size frame_size = root_pass->output_rect.size();
+ float scale_factor = frame->metadata.device_scale_factor;
+
+ guest_->UpdateGuestSizeIfNecessary(frame_size, scale_factor);
+
+ // Check whether we need to recreate the cc::Surface, which means the child
+ // frame renderer has changed its output surface, or size, or scale factor.
+ if (output_surface_id != last_output_surface_id_ && surface_factory_) {
+ surface_factory_->Destroy(surface_id_);
+ surface_factory_.reset();
+ }
+ if (output_surface_id != last_output_surface_id_ ||
+ frame_size != current_surface_size_ ||
+ scale_factor != current_surface_scale_factor_) {
+ if (surface_factory_ && !surface_id_.is_null())
+ surface_factory_->Destroy(surface_id_);
+ surface_id_ = cc::SurfaceId();
+ last_output_surface_id_ = output_surface_id;
+ current_surface_size_ = frame_size;
+ current_surface_scale_factor_ = scale_factor;
+ }
+
+ if (!surface_factory_) {
+ cc::SurfaceManager* manager = GetSurfaceManager();
+ surface_factory_ = make_scoped_ptr(new cc::SurfaceFactory(manager, this));
+ }
+
+ if (surface_id_.is_null()) {
+ surface_id_ = id_allocator_->GenerateId();
+ // wjm: Next line makes destructor unhappy ...
+ surface_factory_->Create(surface_id_);
+
+ cc::SurfaceSequence sequence = cc::SurfaceSequence(
+ id_allocator_->id_namespace(), next_surface_sequence_++);
+ // The renderer process will satisfy this dependency when it creates a
+ // SurfaceLayer.
+ cc::SurfaceManager* manager = GetSurfaceManager();
+ manager->GetSurfaceForId(surface_id_)->AddDestructionDependency(sequence);
+ guest_->SetChildFrameSurface(surface_id_, frame_size, scale_factor,
+ sequence);
+ }
+
+ cc::SurfaceFactory::DrawCallback ack_callback = base::Bind(
+ &RenderWidgetHostViewChildFrame::SurfaceDrawn,
+ RenderWidgetHostViewChildFrame::AsWeakPtr(), output_surface_id);
+ ack_pending_count_++;
+ // If this value grows very large, something is going wrong.
+ DCHECK(ack_pending_count_ < 1000);
+ surface_factory_->SubmitFrame(surface_id_, frame.Pass(), ack_callback);
}
bool RenderWidgetHostViewGuest::OnMessageReceived(const IPC::Message& msg) {
@@ -389,11 +452,6 @@ void RenderWidgetHostViewGuest::GetScreenInfo(blink::WebScreenInfo* results) {
embedder_view->GetScreenInfo(results);
}
-uint32_t RenderWidgetHostViewGuest::GetSurfaceIdNamespace() {
- // Compositing surfaces not supported.
- return 0;
-}
-
#if defined(OS_MACOSX)
void RenderWidgetHostViewGuest::SetActive(bool active) {
platform_view_->SetActive(active);

Powered by Google App Engine
This is Rietveld 408576698