| OLD | NEW |
| 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 "base/supports_user_data.h" |
| 11 #include "content/browser/android/in_process/synchronous_compositor_external_beg
in_frame_source.h" | 12 #include "content/browser/android/in_process/synchronous_compositor_external_beg
in_frame_source.h" |
| 12 #include "content/browser/android/in_process/synchronous_compositor_factory_impl
.h" | 13 #include "content/browser/android/in_process/synchronous_compositor_factory_impl
.h" |
| 13 #include "content/browser/android/in_process/synchronous_compositor_registry.h" | 14 #include "content/browser/android/in_process/synchronous_compositor_registry.h" |
| 14 #include "content/browser/android/in_process/synchronous_input_event_filter.h" | 15 #include "content/browser/android/in_process/synchronous_input_event_filter.h" |
| 15 #include "content/browser/gpu/gpu_process_host.h" | 16 #include "content/browser/gpu/gpu_process_host.h" |
| 16 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 17 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 17 #include "content/common/input/did_overscroll_params.h" | 18 #include "content/common/input/did_overscroll_params.h" |
| 18 #include "content/common/input_messages.h" | 19 #include "content/common/input_messages.h" |
| 19 #include "content/public/browser/android/synchronous_compositor_client.h" | 20 #include "content/public/browser/android/synchronous_compositor_client.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| 22 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
| 24 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/common/child_process_host.h" |
| 23 #include "ui/gfx/geometry/scroll_offset.h" | 26 #include "ui/gfx/geometry/scroll_offset.h" |
| 24 #include "ui/gl/gl_surface.h" | 27 #include "ui/gl/gl_surface.h" |
| 25 | 28 |
| 26 namespace content { | 29 namespace content { |
| 27 | 30 |
| 28 namespace { | 31 namespace { |
| 29 | 32 |
| 30 int GetInProcessRendererId() { | 33 const int kClientHolderLocatorKey = 0; |
| 31 content::RenderProcessHost::iterator it = | 34 |
| 32 content::RenderProcessHost::AllHostsIterator(); | 35 class ClientHolder : public base::SupportsUserData::Data { |
| 33 if (it.IsAtEnd()) { | 36 public: |
| 34 // There should always be one RPH in single process mode. | 37 static void CreateForWebContents(WebContents* contents, |
| 35 NOTREACHED(); | 38 SynchronousCompositorClient* client) { |
| 36 return 0; | 39 DCHECK(contents); |
| 40 DCHECK(!FromWebContents(contents)); |
| 41 contents->SetUserData(&kClientHolderLocatorKey, new ClientHolder(client)); |
| 37 } | 42 } |
| 38 | 43 |
| 39 int id = it.GetCurrentValue()->GetID(); | 44 static ClientHolder* FromWebContents(WebContents* contents) { |
| 40 it.Advance(); | 45 DCHECK(contents); |
| 41 DCHECK(it.IsAtEnd()); // Not multiprocess compatible. | 46 return static_cast<ClientHolder*>( |
| 42 return id; | 47 contents->GetUserData(&kClientHolderLocatorKey)); |
| 43 } | 48 } |
| 49 |
| 50 SynchronousCompositorClient* client() const { return client_; } |
| 51 |
| 52 private: |
| 53 explicit ClientHolder(SynchronousCompositorClient* client) |
| 54 : client_(client) {} |
| 55 ~ClientHolder() override {} |
| 56 |
| 57 SynchronousCompositorClient* const client_; // Non-owning. |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(ClientHolder); |
| 60 }; |
| 61 |
| 62 int g_process_id = ChildProcessHost::kInvalidUniqueID; |
| 44 | 63 |
| 45 base::LazyInstance<SynchronousCompositorFactoryImpl>::Leaky g_factory = | 64 base::LazyInstance<SynchronousCompositorFactoryImpl>::Leaky g_factory = |
| 46 LAZY_INSTANCE_INITIALIZER; | 65 LAZY_INSTANCE_INITIALIZER; |
| 47 | 66 |
| 48 base::Thread* CreateInProcessGpuThreadForSynchronousCompositor( | 67 base::Thread* CreateInProcessGpuThreadForSynchronousCompositor( |
| 49 const InProcessChildThreadParams& params) { | 68 const InProcessChildThreadParams& params) { |
| 50 return g_factory.Get().CreateInProcessGpuThread(params); | 69 return g_factory.Get().CreateInProcessGpuThread(params); |
| 51 } | 70 } |
| 52 | 71 |
| 53 } // namespace | 72 } // namespace |
| 54 | 73 |
| 55 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SynchronousCompositorImpl); | 74 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID( |
| 75 int routing_id) { |
| 76 if (g_factory == nullptr) |
| 77 return nullptr; |
| 78 if (g_process_id == ChildProcessHost::kInvalidUniqueID) |
| 79 return nullptr; |
| 80 RenderViewHost* rvh = RenderViewHost::FromID(g_process_id, routing_id); |
| 81 if (!rvh) |
| 82 return nullptr; |
| 83 RenderWidgetHostViewAndroid* rwhva = |
| 84 static_cast<RenderWidgetHostViewAndroid*>(rvh->GetView()); |
| 85 if (!rwhva) |
| 86 return nullptr; |
| 87 return rwhva->GetSynchronousCompositorImpl(); |
| 88 } |
| 56 | 89 |
| 57 // static | 90 // static |
| 58 SynchronousCompositorImpl* SynchronousCompositorImpl::FromID(int process_id, | 91 scoped_ptr<SynchronousCompositorImpl> SynchronousCompositorImpl::Create( |
| 59 int routing_id) { | 92 RenderWidgetHostViewAndroid* rwhva, |
| 60 if (g_factory == nullptr) | 93 WebContents* web_contents) { |
| 61 return nullptr; | 94 DCHECK(web_contents); |
| 62 RenderViewHost* rvh = RenderViewHost::FromID(process_id, routing_id); | 95 ClientHolder* holder = ClientHolder::FromWebContents(web_contents); |
| 63 if (!rvh) | 96 if (!holder) |
| 64 return nullptr; | 97 return nullptr; // Temporary until multiprocess is implemented. |
| 65 WebContents* contents = WebContents::FromRenderViewHost(rvh); | 98 DCHECK(holder->client()); |
| 66 if (!contents) | 99 return make_scoped_ptr( |
| 67 return nullptr; | 100 new SynchronousCompositorImpl(rwhva, holder->client())); |
| 68 return FromWebContents(contents); | |
| 69 } | 101 } |
| 70 | 102 |
| 71 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID( | 103 SynchronousCompositorImpl::SynchronousCompositorImpl( |
| 72 int routing_id) { | 104 RenderWidgetHostViewAndroid* rwhva, |
| 73 return FromID(GetInProcessRendererId(), routing_id); | 105 SynchronousCompositorClient* client) |
| 74 } | 106 : rwhva_(rwhva), |
| 75 | 107 routing_id_(rwhva_->GetRenderWidgetHost()->GetRoutingID()), |
| 76 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) | 108 compositor_client_(client), |
| 77 : compositor_client_(nullptr), | |
| 78 output_surface_(nullptr), | 109 output_surface_(nullptr), |
| 79 begin_frame_source_(nullptr), | 110 begin_frame_source_(nullptr), |
| 80 contents_(contents), | |
| 81 routing_id_(contents->GetRoutingID()), | |
| 82 synchronous_input_handler_proxy_(nullptr), | 111 synchronous_input_handler_proxy_(nullptr), |
| 83 registered_with_client_(false), | 112 registered_with_client_(false), |
| 84 is_active_(true), | 113 is_active_(true), |
| 85 renderer_needs_begin_frames_(false), | 114 renderer_needs_begin_frames_(false), |
| 86 need_animate_input_(false), | 115 need_animate_input_(false), |
| 87 weak_ptr_factory_(this) { | 116 weak_ptr_factory_(this) { |
| 88 DCHECK(contents); | |
| 89 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); | 117 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); |
| 118 |
| 119 int process_id = rwhva_->GetRenderWidgetHost()->GetProcess()->GetID(); |
| 120 if (g_process_id == ChildProcessHost::kInvalidUniqueID) { |
| 121 g_process_id = process_id; |
| 122 } else { |
| 123 DCHECK_EQ(g_process_id, process_id); // Not multiprocess compatible. |
| 124 } |
| 125 |
| 126 SynchronousCompositorRegistry::GetInstance()->RegisterCompositor( |
| 127 routing_id_, this); |
| 90 } | 128 } |
| 91 | 129 |
| 92 SynchronousCompositorImpl::~SynchronousCompositorImpl() { | 130 SynchronousCompositorImpl::~SynchronousCompositorImpl() { |
| 93 DCHECK(!output_surface_); | 131 SynchronousCompositorRegistry::GetInstance()->UnregisterCompositor( |
| 94 DCHECK(!begin_frame_source_); | 132 routing_id_, this); |
| 95 DCHECK(!synchronous_input_handler_proxy_); | |
| 96 } | |
| 97 | |
| 98 void SynchronousCompositorImpl::SetClient( | |
| 99 SynchronousCompositorClient* compositor_client) { | |
| 100 DCHECK(CalledOnValidThread()); | |
| 101 DCHECK_IMPLIES(compositor_client, !compositor_client_); | |
| 102 DCHECK_IMPLIES(!compositor_client, compositor_client_); | |
| 103 | |
| 104 if (!compositor_client) { | |
| 105 SynchronousCompositorRegistry::GetInstance()->UnregisterCompositor( | |
| 106 routing_id_, this); | |
| 107 } | |
| 108 | |
| 109 compositor_client_ = compositor_client; | |
| 110 | |
| 111 // SetClient is essentially the constructor and destructor of | |
| 112 // SynchronousCompositorImpl. | |
| 113 if (compositor_client_) { | |
| 114 SynchronousCompositorRegistry::GetInstance()->RegisterCompositor( | |
| 115 routing_id_, this); | |
| 116 } | |
| 117 } | 133 } |
| 118 | 134 |
| 119 void SynchronousCompositorImpl::RegisterWithClient() { | 135 void SynchronousCompositorImpl::RegisterWithClient() { |
| 120 DCHECK(CalledOnValidThread()); | 136 DCHECK(CalledOnValidThread()); |
| 121 DCHECK(compositor_client_); | |
| 122 DCHECK(output_surface_); | 137 DCHECK(output_surface_); |
| 123 DCHECK(synchronous_input_handler_proxy_); | 138 DCHECK(synchronous_input_handler_proxy_); |
| 124 DCHECK(!registered_with_client_); | 139 DCHECK(!registered_with_client_); |
| 125 registered_with_client_ = true; | 140 registered_with_client_ = true; |
| 126 | 141 |
| 127 compositor_client_->DidInitializeCompositor(this); | 142 compositor_client_->DidInitializeCompositor(this); |
| 128 | 143 |
| 129 output_surface_->SetTreeActivationCallback( | 144 output_surface_->SetTreeActivationCallback( |
| 130 base::Bind(&SynchronousCompositorImpl::DidActivatePendingTree, | 145 base::Bind(&SynchronousCompositorImpl::DidActivatePendingTree, |
| 131 weak_ptr_factory_.GetWeakPtr())); | 146 weak_ptr_factory_.GetWeakPtr())); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 146 } | 161 } |
| 147 | 162 |
| 148 void SynchronousCompositorImpl::DidInitializeRendererObjects( | 163 void SynchronousCompositorImpl::DidInitializeRendererObjects( |
| 149 SynchronousCompositorOutputSurface* output_surface, | 164 SynchronousCompositorOutputSurface* output_surface, |
| 150 SynchronousCompositorExternalBeginFrameSource* begin_frame_source, | 165 SynchronousCompositorExternalBeginFrameSource* begin_frame_source, |
| 151 SynchronousInputHandlerProxy* synchronous_input_handler_proxy) { | 166 SynchronousInputHandlerProxy* synchronous_input_handler_proxy) { |
| 152 DCHECK(!output_surface_); | 167 DCHECK(!output_surface_); |
| 153 DCHECK(!begin_frame_source_); | 168 DCHECK(!begin_frame_source_); |
| 154 DCHECK(output_surface); | 169 DCHECK(output_surface); |
| 155 DCHECK(begin_frame_source); | 170 DCHECK(begin_frame_source); |
| 156 DCHECK(compositor_client_); | |
| 157 DCHECK(synchronous_input_handler_proxy); | 171 DCHECK(synchronous_input_handler_proxy); |
| 158 | 172 |
| 159 output_surface_ = output_surface; | 173 output_surface_ = output_surface; |
| 160 begin_frame_source_ = begin_frame_source; | 174 begin_frame_source_ = begin_frame_source; |
| 161 synchronous_input_handler_proxy_ = synchronous_input_handler_proxy; | 175 synchronous_input_handler_proxy_ = synchronous_input_handler_proxy; |
| 162 | 176 |
| 163 output_surface_->SetCompositor(this); | 177 output_surface_->SetCompositor(this); |
| 164 begin_frame_source_->SetCompositor(this); | 178 begin_frame_source_->SetCompositor(this); |
| 165 } | 179 } |
| 166 | 180 |
| 167 void SynchronousCompositorImpl::DidDestroyRendererObjects() { | 181 void SynchronousCompositorImpl::DidDestroyRendererObjects() { |
| 168 DCHECK(output_surface_); | 182 DCHECK(output_surface_); |
| 169 DCHECK(begin_frame_source_); | 183 DCHECK(begin_frame_source_); |
| 170 DCHECK(compositor_client_); | |
| 171 | 184 |
| 172 if (registered_with_client_) { | 185 if (registered_with_client_) { |
| 173 output_surface_->SetTreeActivationCallback(base::Closure()); | 186 output_surface_->SetTreeActivationCallback(base::Closure()); |
| 174 compositor_client_->DidDestroyCompositor(this); | 187 compositor_client_->DidDestroyCompositor(this); |
| 175 registered_with_client_ = false; | 188 registered_with_client_ = false; |
| 176 } | 189 } |
| 177 | 190 |
| 178 // This object is being destroyed, so remove pointers to it. | 191 // This object is being destroyed, so remove pointers to it. |
| 179 begin_frame_source_->SetCompositor(nullptr); | 192 begin_frame_source_->SetCompositor(nullptr); |
| 180 output_surface_->SetCompositor(nullptr); | 193 output_surface_->SetCompositor(nullptr); |
| 181 synchronous_input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings( | 194 synchronous_input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings( |
| 182 nullptr); | 195 nullptr); |
| 183 | 196 |
| 184 synchronous_input_handler_proxy_ = nullptr; | 197 synchronous_input_handler_proxy_ = nullptr; |
| 185 begin_frame_source_ = nullptr; | 198 begin_frame_source_ = nullptr; |
| 186 output_surface_ = nullptr; | 199 output_surface_ = nullptr; |
| 187 // Don't propogate this signal from one renderer to the next. | 200 // Don't propogate this signal from one renderer to the next. |
| 188 need_animate_input_ = false; | 201 need_animate_input_ = false; |
| 189 } | 202 } |
| 190 | 203 |
| 191 scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw( | 204 scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw( |
| 192 gfx::Size surface_size, | 205 gfx::Size surface_size, |
| 193 const gfx::Transform& transform, | 206 const gfx::Transform& transform, |
| 194 gfx::Rect viewport, | 207 gfx::Rect viewport, |
| 195 gfx::Rect clip, | 208 gfx::Rect clip, |
| 196 gfx::Rect viewport_rect_for_tile_priority, | 209 gfx::Rect viewport_rect_for_tile_priority, |
| 197 const gfx::Transform& transform_for_tile_priority) { | 210 const gfx::Transform& transform_for_tile_priority) { |
| 198 DCHECK(CalledOnValidThread()); | 211 DCHECK(CalledOnValidThread()); |
| 199 DCHECK(output_surface_); | 212 DCHECK(output_surface_); |
| 200 DCHECK(compositor_client_); | |
| 201 DCHECK(begin_frame_source_); | 213 DCHECK(begin_frame_source_); |
| 202 | 214 |
| 203 scoped_ptr<cc::CompositorFrame> frame = | 215 scoped_ptr<cc::CompositorFrame> frame = |
| 204 output_surface_->DemandDrawHw(surface_size, | 216 output_surface_->DemandDrawHw(surface_size, |
| 205 transform, | 217 transform, |
| 206 viewport, | 218 viewport, |
| 207 clip, | 219 clip, |
| 208 viewport_rect_for_tile_priority, | 220 viewport_rect_for_tile_priority, |
| 209 transform_for_tile_priority); | 221 transform_for_tile_priority); |
| 210 | 222 |
| 211 if (frame.get()) | 223 if (frame.get()) |
| 212 UpdateFrameMetaData(frame->metadata); | 224 UpdateFrameMetaData(frame->metadata); |
| 213 | 225 |
| 214 return frame.Pass(); | 226 return frame.Pass(); |
| 215 } | 227 } |
| 216 | 228 |
| 217 void SynchronousCompositorImpl::ReturnResources( | 229 void SynchronousCompositorImpl::ReturnResources( |
| 218 const cc::CompositorFrameAck& frame_ack) { | 230 const cc::CompositorFrameAck& frame_ack) { |
| 219 DCHECK(CalledOnValidThread()); | 231 DCHECK(CalledOnValidThread()); |
| 220 output_surface_->ReturnResources(frame_ack); | 232 output_surface_->ReturnResources(frame_ack); |
| 221 } | 233 } |
| 222 | 234 |
| 223 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { | 235 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { |
| 224 DCHECK(CalledOnValidThread()); | 236 DCHECK(CalledOnValidThread()); |
| 225 DCHECK(output_surface_); | 237 DCHECK(output_surface_); |
| 226 DCHECK(compositor_client_); | |
| 227 DCHECK(begin_frame_source_); | 238 DCHECK(begin_frame_source_); |
| 228 | 239 |
| 229 scoped_ptr<cc::CompositorFrame> frame = | 240 scoped_ptr<cc::CompositorFrame> frame = |
| 230 output_surface_->DemandDrawSw(canvas); | 241 output_surface_->DemandDrawSw(canvas); |
| 231 | 242 |
| 232 if (frame.get()) | 243 if (frame.get()) |
| 233 UpdateFrameMetaData(frame->metadata); | 244 UpdateFrameMetaData(frame->metadata); |
| 234 | 245 |
| 235 return !!frame.get(); | 246 return !!frame.get(); |
| 236 } | 247 } |
| 237 | 248 |
| 238 void SynchronousCompositorImpl::UpdateFrameMetaData( | 249 void SynchronousCompositorImpl::UpdateFrameMetaData( |
| 239 const cc::CompositorFrameMetadata& frame_metadata) { | 250 const cc::CompositorFrameMetadata& frame_metadata) { |
| 240 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 251 rwhva_->SynchronousFrameMetadata(frame_metadata); |
| 241 contents_->GetRenderWidgetHostView()); | |
| 242 if (rwhv) | |
| 243 rwhv->SynchronousFrameMetadata(frame_metadata); | |
| 244 DeliverMessages(); | 252 DeliverMessages(); |
| 245 } | 253 } |
| 246 | 254 |
| 247 void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) { | 255 void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) { |
| 248 DCHECK(CalledOnValidThread()); | 256 DCHECK(CalledOnValidThread()); |
| 249 DCHECK(output_surface_); | 257 DCHECK(output_surface_); |
| 250 | 258 |
| 251 size_t current_bytes_limit = output_surface_->GetMemoryPolicy(); | 259 size_t current_bytes_limit = output_surface_->GetMemoryPolicy(); |
| 252 output_surface_->SetMemoryPolicy(bytes_limit); | 260 output_surface_->SetMemoryPolicy(bytes_limit); |
| 253 | 261 |
| 254 if (bytes_limit && !current_bytes_limit) { | 262 if (bytes_limit && !current_bytes_limit) { |
| 255 g_factory.Get().CompositorInitializedHardwareDraw(); | 263 g_factory.Get().CompositorInitializedHardwareDraw(); |
| 256 } else if (!bytes_limit && current_bytes_limit) { | 264 } else if (!bytes_limit && current_bytes_limit) { |
| 257 g_factory.Get().CompositorReleasedHardwareDraw(); | 265 g_factory.Get().CompositorReleasedHardwareDraw(); |
| 258 } | 266 } |
| 259 } | 267 } |
| 260 | 268 |
| 261 void SynchronousCompositorImpl::PostInvalidate() { | 269 void SynchronousCompositorImpl::PostInvalidate() { |
| 262 DCHECK(CalledOnValidThread()); | 270 DCHECK(CalledOnValidThread()); |
| 263 DCHECK(compositor_client_); | |
| 264 if (registered_with_client_) | 271 if (registered_with_client_) |
| 265 compositor_client_->PostInvalidate(); | 272 compositor_client_->PostInvalidate(); |
| 266 } | 273 } |
| 267 | 274 |
| 268 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset( | 275 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset( |
| 269 const gfx::ScrollOffset& root_offset) { | 276 const gfx::ScrollOffset& root_offset) { |
| 270 DCHECK(CalledOnValidThread()); | 277 DCHECK(CalledOnValidThread()); |
| 271 if (!synchronous_input_handler_proxy_) | 278 if (!synchronous_input_handler_proxy_) |
| 272 return; | 279 return; |
| 273 synchronous_input_handler_proxy_->SynchronouslySetRootScrollOffset( | 280 synchronous_input_handler_proxy_->SynchronouslySetRootScrollOffset( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 300 // Make sure this is a BeginFrame that renderer side explicitly requested. | 307 // Make sure this is a BeginFrame that renderer side explicitly requested. |
| 301 // Otherwise it is possible renderer objects not initialized. | 308 // Otherwise it is possible renderer objects not initialized. |
| 302 RegisterWithClient(); | 309 RegisterWithClient(); |
| 303 DCHECK(registered_with_client_); | 310 DCHECK(registered_with_client_); |
| 304 } | 311 } |
| 305 if (begin_frame_source_) | 312 if (begin_frame_source_) |
| 306 begin_frame_source_->BeginFrame(args); | 313 begin_frame_source_->BeginFrame(args); |
| 307 } | 314 } |
| 308 | 315 |
| 309 void SynchronousCompositorImpl::UpdateNeedsBeginFrames() { | 316 void SynchronousCompositorImpl::UpdateNeedsBeginFrames() { |
| 310 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 317 rwhva_->OnSetNeedsBeginFrames(is_active_ && renderer_needs_begin_frames_); |
| 311 contents_->GetRenderWidgetHostView()); | |
| 312 if (rwhv) | |
| 313 rwhv->OnSetNeedsBeginFrames(is_active_ && renderer_needs_begin_frames_); | |
| 314 } | 318 } |
| 315 | 319 |
| 316 void SynchronousCompositorImpl::DidOverscroll( | 320 void SynchronousCompositorImpl::DidOverscroll( |
| 317 const DidOverscrollParams& params) { | 321 const DidOverscrollParams& params) { |
| 318 DCHECK(compositor_client_); | |
| 319 if (registered_with_client_) { | 322 if (registered_with_client_) { |
| 320 compositor_client_->DidOverscroll(params.accumulated_overscroll, | 323 compositor_client_->DidOverscroll(params.accumulated_overscroll, |
| 321 params.latest_overscroll_delta, | 324 params.latest_overscroll_delta, |
| 322 params.current_fling_velocity); | 325 params.current_fling_velocity); |
| 323 } | 326 } |
| 324 } | 327 } |
| 325 | 328 |
| 326 void SynchronousCompositorImpl::DidStopFlinging() { | 329 void SynchronousCompositorImpl::DidStopFlinging() { |
| 327 // It's important that the fling-end notification follow the same path as it | 330 // It's important that the fling-end notification follow the same path as it |
| 328 // takes on other platforms (using an IPC). This ensures consistent | 331 // takes on other platforms (using an IPC). This ensures consistent |
| 329 // bookkeeping at all stages of the input pipeline. | 332 // bookkeeping at all stages of the input pipeline. |
| 330 contents_->GetRenderProcessHost()->OnMessageReceived( | 333 rwhva_->GetRenderWidgetHost()->GetProcess()->OnMessageReceived( |
| 331 InputHostMsg_DidStopFlinging(routing_id_)); | 334 InputHostMsg_DidStopFlinging(routing_id_)); |
| 332 } | 335 } |
| 333 | 336 |
| 334 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( | 337 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( |
| 335 const blink::WebInputEvent& input_event) { | 338 const blink::WebInputEvent& input_event) { |
| 336 DCHECK(CalledOnValidThread()); | 339 DCHECK(CalledOnValidThread()); |
| 337 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( | 340 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( |
| 338 contents_->GetRoutingID(), input_event); | 341 routing_id_, input_event); |
| 339 } | 342 } |
| 340 | 343 |
| 341 void SynchronousCompositorImpl::DeliverMessages() { | 344 void SynchronousCompositorImpl::DeliverMessages() { |
| 342 ScopedVector<IPC::Message> messages; | 345 ScopedVector<IPC::Message> messages; |
| 343 output_surface_->GetMessagesToDeliver(&messages); | 346 output_surface_->GetMessagesToDeliver(&messages); |
| 344 RenderProcessHost* rph = contents_->GetRenderProcessHost(); | 347 RenderProcessHost* rph = rwhva_->GetRenderWidgetHost()->GetProcess(); |
| 345 for (ScopedVector<IPC::Message>::const_iterator i = messages.begin(); | 348 for (ScopedVector<IPC::Message>::const_iterator i = messages.begin(); |
| 346 i != messages.end(); | 349 i != messages.end(); |
| 347 ++i) { | 350 ++i) { |
| 348 rph->OnMessageReceived(**i); | 351 rph->OnMessageReceived(**i); |
| 349 } | 352 } |
| 350 } | 353 } |
| 351 | 354 |
| 352 void SynchronousCompositorImpl::DidActivatePendingTree() { | 355 void SynchronousCompositorImpl::DidActivatePendingTree() { |
| 353 DCHECK(compositor_client_); | |
| 354 if (registered_with_client_) | 356 if (registered_with_client_) |
| 355 compositor_client_->DidUpdateContent(); | 357 compositor_client_->DidUpdateContent(); |
| 356 DeliverMessages(); | 358 DeliverMessages(); |
| 357 } | 359 } |
| 358 | 360 |
| 359 void SynchronousCompositorImpl::SetNeedsSynchronousAnimateInput() { | 361 void SynchronousCompositorImpl::SetNeedsSynchronousAnimateInput() { |
| 360 DCHECK(CalledOnValidThread()); | 362 DCHECK(CalledOnValidThread()); |
| 361 DCHECK(compositor_client_); | |
| 362 if (!registered_with_client_) | 363 if (!registered_with_client_) |
| 363 return; | 364 return; |
| 364 need_animate_input_ = true; | 365 need_animate_input_ = true; |
| 365 compositor_client_->PostInvalidate(); | 366 compositor_client_->PostInvalidate(); |
| 366 } | 367 } |
| 367 | 368 |
| 368 void SynchronousCompositorImpl::UpdateRootLayerState( | 369 void SynchronousCompositorImpl::UpdateRootLayerState( |
| 369 const gfx::ScrollOffset& total_scroll_offset, | 370 const gfx::ScrollOffset& total_scroll_offset, |
| 370 const gfx::ScrollOffset& max_scroll_offset, | 371 const gfx::ScrollOffset& max_scroll_offset, |
| 371 const gfx::SizeF& scrollable_size, | 372 const gfx::SizeF& scrollable_size, |
| 372 float page_scale_factor, | 373 float page_scale_factor, |
| 373 float min_page_scale_factor, | 374 float min_page_scale_factor, |
| 374 float max_page_scale_factor) { | 375 float max_page_scale_factor) { |
| 375 DCHECK(CalledOnValidThread()); | 376 DCHECK(CalledOnValidThread()); |
| 376 DCHECK(compositor_client_); | |
| 377 | 377 |
| 378 if (registered_with_client_) { | 378 if (registered_with_client_) { |
| 379 // TODO(miletus): Pass in ScrollOffset. crbug.com/414283. | 379 // TODO(miletus): Pass in ScrollOffset. crbug.com/414283. |
| 380 compositor_client_->UpdateRootLayerState( | 380 compositor_client_->UpdateRootLayerState( |
| 381 gfx::ScrollOffsetToVector2dF(total_scroll_offset), | 381 gfx::ScrollOffsetToVector2dF(total_scroll_offset), |
| 382 gfx::ScrollOffsetToVector2dF(max_scroll_offset), | 382 gfx::ScrollOffsetToVector2dF(max_scroll_offset), |
| 383 scrollable_size, | 383 scrollable_size, |
| 384 page_scale_factor, | 384 page_scale_factor, |
| 385 min_page_scale_factor, | 385 min_page_scale_factor, |
| 386 max_page_scale_factor); | 386 max_page_scale_factor); |
| 387 } | 387 } |
| 388 } | 388 } |
| 389 | 389 |
| 390 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 390 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| 391 // requirement: SynchronousCompositorImpl() must only be used on the UI thread. | 391 // requirement: SynchronousCompositorImpl() must only be used on the UI thread. |
| 392 bool SynchronousCompositorImpl::CalledOnValidThread() const { | 392 bool SynchronousCompositorImpl::CalledOnValidThread() const { |
| 393 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 393 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 394 } | 394 } |
| 395 | 395 |
| 396 // static | 396 // static |
| 397 void SynchronousCompositor::SetClientForWebContents( | 397 void SynchronousCompositor::SetClientForWebContents( |
| 398 WebContents* contents, | 398 WebContents* contents, |
| 399 SynchronousCompositorClient* client) { | 399 SynchronousCompositorClient* client) { |
| 400 DCHECK(contents); | 400 DCHECK(contents); |
| 401 if (client) { | 401 DCHECK(client); |
| 402 g_factory.Get(); // Ensure it's initialized. | 402 g_factory.Get(); // Ensure it's initialized. |
| 403 SynchronousCompositorImpl::CreateForWebContents(contents); | 403 DCHECK(!ClientHolder::FromWebContents(contents)); |
| 404 } | 404 ClientHolder::CreateForWebContents(contents, client); |
| 405 SynchronousCompositorImpl* instance = | |
| 406 SynchronousCompositorImpl::FromWebContents(contents); | |
| 407 DCHECK(instance); | |
| 408 instance->SetClient(client); | |
| 409 } | 405 } |
| 410 | 406 |
| 411 } // namespace content | 407 } // namespace content |
| OLD | NEW |