| Index: content/browser/android/in_process/synchronous_compositor_impl.cc
|
| diff --git a/content/browser/android/in_process/synchronous_compositor_impl.cc b/content/browser/android/in_process/synchronous_compositor_impl.cc
|
| index 215fdb1a116a2a7b50af1a7a036cde931b8a6b17..cd7633e2bf6909ca31b34e76ec7b957cf1e0f72e 100644
|
| --- a/content/browser/android/in_process/synchronous_compositor_impl.cc
|
| +++ b/content/browser/android/in_process/synchronous_compositor_impl.cc
|
| @@ -14,12 +14,15 @@
|
| #include "content/browser/android/in_process/synchronous_input_event_filter.h"
|
| #include "content/browser/gpu/gpu_process_host.h"
|
| #include "content/browser/renderer_host/render_widget_host_view_android.h"
|
| +#include "content/browser/web_contents/web_contents_android.h"
|
| +#include "content/browser/web_contents/web_contents_impl.h"
|
| #include "content/common/input/did_overscroll_params.h"
|
| #include "content/common/input_messages.h"
|
| #include "content/public/browser/android/synchronous_compositor_client.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/render_process_host.h"
|
| #include "content/public/browser/render_view_host.h"
|
| +#include "content/public/common/child_process_host.h"
|
| #include "ui/gfx/geometry/scroll_offset.h"
|
| #include "ui/gl/gl_surface.h"
|
|
|
| @@ -27,20 +30,7 @@ namespace content {
|
|
|
| namespace {
|
|
|
| -int GetInProcessRendererId() {
|
| - content::RenderProcessHost::iterator it =
|
| - content::RenderProcessHost::AllHostsIterator();
|
| - if (it.IsAtEnd()) {
|
| - // There should always be one RPH in single process mode.
|
| - NOTREACHED();
|
| - return 0;
|
| - }
|
| -
|
| - int id = it.GetCurrentValue()->GetID();
|
| - it.Advance();
|
| - DCHECK(it.IsAtEnd()); // Not multiprocess compatible.
|
| - return id;
|
| -}
|
| +int g_process_id = ChildProcessHost::kInvalidUniqueID;
|
|
|
| base::LazyInstance<SynchronousCompositorFactoryImpl>::Leaky g_factory =
|
| LAZY_INSTANCE_INITIALIZER;
|
| @@ -52,73 +42,70 @@ base::Thread* CreateInProcessGpuThreadForSynchronousCompositor(
|
|
|
| } // namespace
|
|
|
| -DEFINE_WEB_CONTENTS_USER_DATA_KEY(SynchronousCompositorImpl);
|
| -
|
| -// static
|
| -SynchronousCompositorImpl* SynchronousCompositorImpl::FromID(int process_id,
|
| - int routing_id) {
|
| +SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID(
|
| + int routing_id) {
|
| if (g_factory == nullptr)
|
| return nullptr;
|
| - RenderViewHost* rvh = RenderViewHost::FromID(process_id, routing_id);
|
| + if (g_process_id == ChildProcessHost::kInvalidUniqueID)
|
| + return nullptr;
|
| + RenderViewHost* rvh = RenderViewHost::FromID(g_process_id, routing_id);
|
| if (!rvh)
|
| return nullptr;
|
| - WebContents* contents = WebContents::FromRenderViewHost(rvh);
|
| - if (!contents)
|
| + RenderWidgetHostViewAndroid* rwhva =
|
| + static_cast<RenderWidgetHostViewAndroid*>(rvh->GetView());
|
| + if (!rwhva)
|
| return nullptr;
|
| - return FromWebContents(contents);
|
| -}
|
| -
|
| -SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID(
|
| - int routing_id) {
|
| - return FromID(GetInProcessRendererId(), routing_id);
|
| + return rwhva->GetSynchronousCompositorImpl();
|
| }
|
|
|
| -SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents)
|
| - : compositor_client_(nullptr),
|
| +// static
|
| +scoped_ptr<SynchronousCompositorImpl> SynchronousCompositorImpl::Create(
|
| + RenderWidgetHostViewAndroid* rwhva,
|
| + WebContents* web_contents) {
|
| + DCHECK(web_contents);
|
| + WebContentsAndroid* web_contents_android =
|
| + static_cast<WebContentsImpl*>(web_contents)->GetWebContentsAndroid();
|
| + if (!web_contents_android->synchronous_compositor_client())
|
| + return nullptr; // Not using sync compositing.
|
| +
|
| + return make_scoped_ptr(new SynchronousCompositorImpl(
|
| + rwhva, web_contents_android->synchronous_compositor_client()));
|
| +}
|
| +
|
| +SynchronousCompositorImpl::SynchronousCompositorImpl(
|
| + RenderWidgetHostViewAndroid* rwhva,
|
| + SynchronousCompositorClient* client)
|
| + : rwhva_(rwhva),
|
| + routing_id_(rwhva_->GetRenderWidgetHost()->GetRoutingID()),
|
| + compositor_client_(client),
|
| output_surface_(nullptr),
|
| begin_frame_source_(nullptr),
|
| - contents_(contents),
|
| - routing_id_(contents->GetRoutingID()),
|
| synchronous_input_handler_proxy_(nullptr),
|
| registered_with_client_(false),
|
| is_active_(true),
|
| renderer_needs_begin_frames_(false),
|
| need_animate_input_(false),
|
| weak_ptr_factory_(this) {
|
| - DCHECK(contents);
|
| DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
|
| -}
|
| -
|
| -SynchronousCompositorImpl::~SynchronousCompositorImpl() {
|
| - DCHECK(!output_surface_);
|
| - DCHECK(!begin_frame_source_);
|
| - DCHECK(!synchronous_input_handler_proxy_);
|
| -}
|
|
|
| -void SynchronousCompositorImpl::SetClient(
|
| - SynchronousCompositorClient* compositor_client) {
|
| - DCHECK(CalledOnValidThread());
|
| - DCHECK_IMPLIES(compositor_client, !compositor_client_);
|
| - DCHECK_IMPLIES(!compositor_client, compositor_client_);
|
| -
|
| - if (!compositor_client) {
|
| - SynchronousCompositorRegistry::GetInstance()->UnregisterCompositor(
|
| - routing_id_, this);
|
| + int process_id = rwhva_->GetRenderWidgetHost()->GetProcess()->GetID();
|
| + if (g_process_id == ChildProcessHost::kInvalidUniqueID) {
|
| + g_process_id = process_id;
|
| + } else {
|
| + DCHECK_EQ(g_process_id, process_id); // Not multiprocess compatible.
|
| }
|
|
|
| - compositor_client_ = compositor_client;
|
| + SynchronousCompositorRegistry::GetInstance()->RegisterCompositor(
|
| + routing_id_, this);
|
| +}
|
|
|
| - // SetClient is essentially the constructor and destructor of
|
| - // SynchronousCompositorImpl.
|
| - if (compositor_client_) {
|
| - SynchronousCompositorRegistry::GetInstance()->RegisterCompositor(
|
| - routing_id_, this);
|
| - }
|
| +SynchronousCompositorImpl::~SynchronousCompositorImpl() {
|
| + SynchronousCompositorRegistry::GetInstance()->UnregisterCompositor(
|
| + routing_id_, this);
|
| }
|
|
|
| void SynchronousCompositorImpl::RegisterWithClient() {
|
| DCHECK(CalledOnValidThread());
|
| - DCHECK(compositor_client_);
|
| DCHECK(output_surface_);
|
| DCHECK(synchronous_input_handler_proxy_);
|
| DCHECK(!registered_with_client_);
|
| @@ -153,7 +140,6 @@ void SynchronousCompositorImpl::DidInitializeRendererObjects(
|
| DCHECK(!begin_frame_source_);
|
| DCHECK(output_surface);
|
| DCHECK(begin_frame_source);
|
| - DCHECK(compositor_client_);
|
| DCHECK(synchronous_input_handler_proxy);
|
|
|
| output_surface_ = output_surface;
|
| @@ -167,7 +153,6 @@ void SynchronousCompositorImpl::DidInitializeRendererObjects(
|
| void SynchronousCompositorImpl::DidDestroyRendererObjects() {
|
| DCHECK(output_surface_);
|
| DCHECK(begin_frame_source_);
|
| - DCHECK(compositor_client_);
|
|
|
| if (registered_with_client_) {
|
| output_surface_->SetTreeActivationCallback(base::Closure());
|
| @@ -197,7 +182,6 @@ scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw(
|
| const gfx::Transform& transform_for_tile_priority) {
|
| DCHECK(CalledOnValidThread());
|
| DCHECK(output_surface_);
|
| - DCHECK(compositor_client_);
|
| DCHECK(begin_frame_source_);
|
|
|
| scoped_ptr<cc::CompositorFrame> frame =
|
| @@ -223,7 +207,6 @@ void SynchronousCompositorImpl::ReturnResources(
|
| bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) {
|
| DCHECK(CalledOnValidThread());
|
| DCHECK(output_surface_);
|
| - DCHECK(compositor_client_);
|
| DCHECK(begin_frame_source_);
|
|
|
| scoped_ptr<cc::CompositorFrame> frame =
|
| @@ -237,10 +220,7 @@ bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) {
|
|
|
| void SynchronousCompositorImpl::UpdateFrameMetaData(
|
| const cc::CompositorFrameMetadata& frame_metadata) {
|
| - RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>(
|
| - contents_->GetRenderWidgetHostView());
|
| - if (rwhv)
|
| - rwhv->SynchronousFrameMetadata(frame_metadata);
|
| + rwhva_->SynchronousFrameMetadata(frame_metadata);
|
| DeliverMessages();
|
| }
|
|
|
| @@ -260,7 +240,6 @@ void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) {
|
|
|
| void SynchronousCompositorImpl::PostInvalidate() {
|
| DCHECK(CalledOnValidThread());
|
| - DCHECK(compositor_client_);
|
| if (registered_with_client_)
|
| compositor_client_->PostInvalidate();
|
| }
|
| @@ -307,15 +286,11 @@ void SynchronousCompositorImpl::BeginFrame(const cc::BeginFrameArgs& args) {
|
| }
|
|
|
| void SynchronousCompositorImpl::UpdateNeedsBeginFrames() {
|
| - RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>(
|
| - contents_->GetRenderWidgetHostView());
|
| - if (rwhv)
|
| - rwhv->OnSetNeedsBeginFrames(is_active_ && renderer_needs_begin_frames_);
|
| + rwhva_->OnSetNeedsBeginFrames(is_active_ && renderer_needs_begin_frames_);
|
| }
|
|
|
| void SynchronousCompositorImpl::DidOverscroll(
|
| const DidOverscrollParams& params) {
|
| - DCHECK(compositor_client_);
|
| if (registered_with_client_) {
|
| compositor_client_->DidOverscroll(params.accumulated_overscroll,
|
| params.latest_overscroll_delta,
|
| @@ -327,7 +302,7 @@ void SynchronousCompositorImpl::DidStopFlinging() {
|
| // It's important that the fling-end notification follow the same path as it
|
| // takes on other platforms (using an IPC). This ensures consistent
|
| // bookkeeping at all stages of the input pipeline.
|
| - contents_->GetRenderProcessHost()->OnMessageReceived(
|
| + rwhva_->GetRenderWidgetHost()->GetProcess()->OnMessageReceived(
|
| InputHostMsg_DidStopFlinging(routing_id_));
|
| }
|
|
|
| @@ -335,13 +310,13 @@ InputEventAckState SynchronousCompositorImpl::HandleInputEvent(
|
| const blink::WebInputEvent& input_event) {
|
| DCHECK(CalledOnValidThread());
|
| return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent(
|
| - contents_->GetRoutingID(), input_event);
|
| + routing_id_, input_event);
|
| }
|
|
|
| void SynchronousCompositorImpl::DeliverMessages() {
|
| ScopedVector<IPC::Message> messages;
|
| output_surface_->GetMessagesToDeliver(&messages);
|
| - RenderProcessHost* rph = contents_->GetRenderProcessHost();
|
| + RenderProcessHost* rph = rwhva_->GetRenderWidgetHost()->GetProcess();
|
| for (ScopedVector<IPC::Message>::const_iterator i = messages.begin();
|
| i != messages.end();
|
| ++i) {
|
| @@ -350,7 +325,6 @@ void SynchronousCompositorImpl::DeliverMessages() {
|
| }
|
|
|
| void SynchronousCompositorImpl::DidActivatePendingTree() {
|
| - DCHECK(compositor_client_);
|
| if (registered_with_client_)
|
| compositor_client_->DidUpdateContent();
|
| DeliverMessages();
|
| @@ -358,7 +332,6 @@ void SynchronousCompositorImpl::DidActivatePendingTree() {
|
|
|
| void SynchronousCompositorImpl::SetNeedsSynchronousAnimateInput() {
|
| DCHECK(CalledOnValidThread());
|
| - DCHECK(compositor_client_);
|
| if (!registered_with_client_)
|
| return;
|
| need_animate_input_ = true;
|
| @@ -373,7 +346,6 @@ void SynchronousCompositorImpl::UpdateRootLayerState(
|
| float min_page_scale_factor,
|
| float max_page_scale_factor) {
|
| DCHECK(CalledOnValidThread());
|
| - DCHECK(compositor_client_);
|
|
|
| if (registered_with_client_) {
|
| // TODO(miletus): Pass in ScrollOffset. crbug.com/414283.
|
| @@ -398,14 +370,12 @@ void SynchronousCompositor::SetClientForWebContents(
|
| WebContents* contents,
|
| SynchronousCompositorClient* client) {
|
| DCHECK(contents);
|
| - if (client) {
|
| - g_factory.Get(); // Ensure it's initialized.
|
| - SynchronousCompositorImpl::CreateForWebContents(contents);
|
| - }
|
| - SynchronousCompositorImpl* instance =
|
| - SynchronousCompositorImpl::FromWebContents(contents);
|
| - DCHECK(instance);
|
| - instance->SetClient(client);
|
| + DCHECK(client);
|
| + g_factory.Get(); // Ensure it's initialized.
|
| + WebContentsAndroid* web_contents_android =
|
| + static_cast<WebContentsImpl*>(contents)->GetWebContentsAndroid();
|
| + DCHECK(!web_contents_android->synchronous_compositor_client());
|
| + web_contents_android->set_synchronous_compositor_client(client);
|
| }
|
|
|
| } // namespace content
|
|
|