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

Side by Side Diff: content/browser/android/in_process/synchronous_compositor_impl.cc

Issue 1408123005: Android Webview IPC-based sync compositing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/android/in_process/synchronous_compositor_impl.h" 5 #include "content/browser/android/in_process/synchronous_compositor_impl.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "content/browser/android/in_process/synchronous_compositor_factory_impl .h" 11 #include "content/browser/android/in_process/synchronous_compositor_factory_impl .h"
12 #include "content/browser/android/in_process/synchronous_compositor_registry_in_ proc.h" 12 #include "content/browser/android/in_process/synchronous_compositor_registry_in_ proc.h"
13 #include "content/browser/android/in_process/synchronous_input_event_filter.h" 13 #include "content/browser/android/in_process/synchronous_input_event_filter.h"
14 #include "content/browser/gpu/gpu_process_host.h" 14 #include "content/browser/gpu/gpu_process_host.h"
15 #include "content/browser/renderer_host/render_widget_host_view_android.h" 15 #include "content/browser/renderer_host/render_widget_host_view_android.h"
16 #include "content/browser/web_contents/web_contents_android.h"
17 #include "content/browser/web_contents/web_contents_impl.h"
18 #include "content/common/input/did_overscroll_params.h" 16 #include "content/common/input/did_overscroll_params.h"
19 #include "content/common/input_messages.h" 17 #include "content/common/input_messages.h"
20 #include "content/public/browser/android/synchronous_compositor_client.h" 18 #include "content/public/browser/android/synchronous_compositor_client.h"
21 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/render_process_host.h" 20 #include "content/public/browser/render_process_host.h"
23 #include "content/public/browser/render_view_host.h" 21 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/render_widget_host.h" 22 #include "content/public/browser/render_widget_host.h"
25 #include "content/public/common/child_process_host.h" 23 #include "content/public/common/child_process_host.h"
26 #include "ui/gfx/geometry/scroll_offset.h" 24 #include "ui/gfx/geometry/scroll_offset.h"
27 #include "ui/gl/gl_surface.h" 25 #include "ui/gl/gl_surface.h"
28 26
29 namespace content { 27 namespace content {
30 28
31 namespace { 29 namespace {
32 30
33 int g_process_id = ChildProcessHost::kInvalidUniqueID; 31 int g_process_id = ChildProcessHost::kInvalidUniqueID;
34 32
35 base::LazyInstance<SynchronousCompositorFactoryImpl>::Leaky g_factory = 33 base::LazyInstance<SynchronousCompositorFactoryImpl>::Leaky g_factory =
36 LAZY_INSTANCE_INITIALIZER; 34 LAZY_INSTANCE_INITIALIZER;
37 35
38 base::Thread* CreateInProcessGpuThreadForSynchronousCompositor(
39 const InProcessChildThreadParams& params) {
40 return g_factory.Get().CreateInProcessGpuThread(params);
41 }
42
43 } // namespace 36 } // namespace
44 37
45 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID( 38 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID(
46 int routing_id) { 39 int routing_id) {
47 if (g_factory == nullptr) 40 if (g_factory == nullptr)
48 return nullptr; 41 return nullptr;
49 if (g_process_id == ChildProcessHost::kInvalidUniqueID) 42 if (g_process_id == ChildProcessHost::kInvalidUniqueID)
50 return nullptr; 43 return nullptr;
51 RenderViewHost* rvh = RenderViewHost::FromID(g_process_id, routing_id); 44 RenderViewHost* rvh = RenderViewHost::FromID(g_process_id, routing_id);
52 if (!rvh) 45 if (!rvh)
53 return nullptr; 46 return nullptr;
54 RenderWidgetHostViewAndroid* rwhva = 47 RenderWidgetHostViewAndroid* rwhva =
55 static_cast<RenderWidgetHostViewAndroid*>(rvh->GetWidget()->GetView()); 48 static_cast<RenderWidgetHostViewAndroid*>(rvh->GetWidget()->GetView());
56 if (!rwhva) 49 if (!rwhva)
57 return nullptr; 50 return nullptr;
58 return rwhva->GetSynchronousCompositorImpl(); 51 return static_cast<SynchronousCompositorImpl*>(
59 } 52 rwhva->GetSynchronousCompositor());
60
61 // static
62 scoped_ptr<SynchronousCompositorImpl> SynchronousCompositorImpl::Create(
63 RenderWidgetHostViewAndroid* rwhva,
64 WebContents* web_contents) {
65 DCHECK(web_contents);
66 WebContentsAndroid* web_contents_android =
67 static_cast<WebContentsImpl*>(web_contents)->GetWebContentsAndroid();
68 if (!web_contents_android->synchronous_compositor_client())
69 return nullptr; // Not using sync compositing.
70
71 return make_scoped_ptr(new SynchronousCompositorImpl(
72 rwhva, web_contents_android->synchronous_compositor_client()));
73 } 53 }
74 54
75 SynchronousCompositorImpl::SynchronousCompositorImpl( 55 SynchronousCompositorImpl::SynchronousCompositorImpl(
76 RenderWidgetHostViewAndroid* rwhva, 56 RenderWidgetHostViewAndroid* rwhva,
77 SynchronousCompositorClient* client) 57 SynchronousCompositorClient* client)
78 : rwhva_(rwhva), 58 : rwhva_(rwhva),
79 routing_id_(rwhva_->GetRenderWidgetHost()->GetRoutingID()), 59 routing_id_(rwhva_->GetRenderWidgetHost()->GetRoutingID()),
80 compositor_client_(client), 60 compositor_client_(client),
81 output_surface_(nullptr), 61 output_surface_(nullptr),
82 begin_frame_source_(nullptr), 62 begin_frame_source_(nullptr),
83 synchronous_input_handler_proxy_(nullptr), 63 synchronous_input_handler_proxy_(nullptr),
84 registered_with_client_(false), 64 registered_with_client_(false),
85 is_active_(true), 65 is_active_(true),
86 renderer_needs_begin_frames_(false), 66 renderer_needs_begin_frames_(false),
87 need_animate_input_(false), 67 need_animate_input_(false),
88 weak_ptr_factory_(this) { 68 weak_ptr_factory_(this) {
89 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); 69 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
70 g_factory.Get(); // Ensure it's initialized.
90 71
91 int process_id = rwhva_->GetRenderWidgetHost()->GetProcess()->GetID(); 72 int process_id = rwhva_->GetRenderWidgetHost()->GetProcess()->GetID();
92 if (g_process_id == ChildProcessHost::kInvalidUniqueID) { 73 if (g_process_id == ChildProcessHost::kInvalidUniqueID) {
93 g_process_id = process_id; 74 g_process_id = process_id;
94 } else { 75 } else {
95 DCHECK_EQ(g_process_id, process_id); // Not multiprocess compatible. 76 DCHECK_EQ(g_process_id, process_id); // Not multiprocess compatible.
96 } 77 }
97 78
98 SynchronousCompositorRegistryInProc::GetInstance()->RegisterCompositor( 79 SynchronousCompositorRegistryInProc::GetInstance()->RegisterCompositor(
99 routing_id_, this); 80 routing_id_, this);
(...skipping 18 matching lines...) Expand all
118 weak_ptr_factory_.GetWeakPtr())); 99 weak_ptr_factory_.GetWeakPtr()));
119 100
120 // This disables the input system from animating inputs autonomously, instead 101 // This disables the input system from animating inputs autonomously, instead
121 // routing all input animations through the SynchronousInputHandler, which is 102 // routing all input animations through the SynchronousInputHandler, which is
122 // |this| class. Calling this causes an UpdateRootLayerState() immediately so, 103 // |this| class. Calling this causes an UpdateRootLayerState() immediately so,
123 // do it after setting the client. 104 // do it after setting the client.
124 synchronous_input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings(this); 105 synchronous_input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings(this);
125 } 106 }
126 107
127 // static 108 // static
128 void SynchronousCompositor::SetGpuService( 109 void SynchronousCompositorImpl::SetGpuServiceInProc(
129 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { 110 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) {
130 g_factory.Get().SetDeferredGpuService(service); 111 g_factory.Get().SetDeferredGpuService(service);
131 GpuProcessHost::RegisterGpuMainThreadFactory(
132 CreateInProcessGpuThreadForSynchronousCompositor);
133 } 112 }
134 113
135 void SynchronousCompositorImpl::DidInitializeRendererObjects( 114 void SynchronousCompositorImpl::DidInitializeRendererObjects(
136 SynchronousCompositorOutputSurface* output_surface, 115 SynchronousCompositorOutputSurface* output_surface,
137 SynchronousCompositorExternalBeginFrameSource* begin_frame_source, 116 SynchronousCompositorExternalBeginFrameSource* begin_frame_source,
138 SynchronousInputHandlerProxy* synchronous_input_handler_proxy) { 117 SynchronousInputHandlerProxy* synchronous_input_handler_proxy) {
139 DCHECK(!output_surface_); 118 DCHECK(!output_surface_);
140 DCHECK(!begin_frame_source_); 119 DCHECK(!begin_frame_source_);
141 DCHECK(output_surface); 120 DCHECK(output_surface);
142 DCHECK(begin_frame_source); 121 DCHECK(begin_frame_source);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 InputHostMsg_DidStopFlinging(routing_id_)); 285 InputHostMsg_DidStopFlinging(routing_id_));
307 } 286 }
308 287
309 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( 288 InputEventAckState SynchronousCompositorImpl::HandleInputEvent(
310 const blink::WebInputEvent& input_event) { 289 const blink::WebInputEvent& input_event) {
311 DCHECK(CalledOnValidThread()); 290 DCHECK(CalledOnValidThread());
312 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( 291 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent(
313 routing_id_, input_event); 292 routing_id_, input_event);
314 } 293 }
315 294
295 bool SynchronousCompositorImpl::OnMessageReceived(const IPC::Message& message) {
296 return false;
no sievers 2015/10/29 01:37:00 ideally NOTREACHED(), or some comment '// not hand
boliu 2015/10/29 04:24:43 NOTREACHED is good.
297 }
298
316 void SynchronousCompositorImpl::DeliverMessages() { 299 void SynchronousCompositorImpl::DeliverMessages() {
317 ScopedVector<IPC::Message> messages; 300 ScopedVector<IPC::Message> messages;
318 output_surface_->GetMessagesToDeliver(&messages); 301 output_surface_->GetMessagesToDeliver(&messages);
319 RenderProcessHost* rph = rwhva_->GetRenderWidgetHost()->GetProcess(); 302 RenderProcessHost* rph = rwhva_->GetRenderWidgetHost()->GetProcess();
320 for (ScopedVector<IPC::Message>::const_iterator i = messages.begin(); 303 for (ScopedVector<IPC::Message>::const_iterator i = messages.begin();
321 i != messages.end(); 304 i != messages.end();
322 ++i) { 305 ++i) {
323 rph->OnMessageReceived(**i); 306 rph->OnMessageReceived(**i);
324 } 307 }
325 } 308 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 max_page_scale_factor); 341 max_page_scale_factor);
359 } 342 }
360 } 343 }
361 344
362 // Not using base::NonThreadSafe as we want to enforce a more exacting threading 345 // Not using base::NonThreadSafe as we want to enforce a more exacting threading
363 // requirement: SynchronousCompositorImpl() must only be used on the UI thread. 346 // requirement: SynchronousCompositorImpl() must only be used on the UI thread.
364 bool SynchronousCompositorImpl::CalledOnValidThread() const { 347 bool SynchronousCompositorImpl::CalledOnValidThread() const {
365 return BrowserThread::CurrentlyOn(BrowserThread::UI); 348 return BrowserThread::CurrentlyOn(BrowserThread::UI);
366 } 349 }
367 350
368 // static
369 void SynchronousCompositor::SetClientForWebContents(
370 WebContents* contents,
371 SynchronousCompositorClient* client) {
372 DCHECK(contents);
373 DCHECK(client);
374 g_factory.Get(); // Ensure it's initialized.
375 WebContentsAndroid* web_contents_android =
376 static_cast<WebContentsImpl*>(contents)->GetWebContentsAndroid();
377 DCHECK(!web_contents_android->synchronous_compositor_client());
378 web_contents_android->set_synchronous_compositor_client(client);
379 }
380
381 } // namespace content 351 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698