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/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
8 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
9 #include "cc/input/input_handler.h" | 10 #include "cc/input/input_handler.h" |
| 11 #include "content/browser/android/in_process/synchronous_compositor_external_beg
in_frame_source.h" |
10 #include "content/browser/android/in_process/synchronous_compositor_factory_impl
.h" | 12 #include "content/browser/android/in_process/synchronous_compositor_factory_impl
.h" |
11 #include "content/browser/android/in_process/synchronous_input_event_filter.h" | 13 #include "content/browser/android/in_process/synchronous_input_event_filter.h" |
12 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 14 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
13 #include "content/common/input/did_overscroll_params.h" | 15 #include "content/common/input/did_overscroll_params.h" |
14 #include "content/public/browser/android/synchronous_compositor_client.h" | 16 #include "content/public/browser/android/synchronous_compositor_client.h" |
15 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
17 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
18 #include "ui/gl/gl_surface.h" | 20 #include "ui/gl/gl_surface.h" |
19 | 21 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 } | 60 } |
59 | 61 |
60 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID( | 62 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID( |
61 int routing_id) { | 63 int routing_id) { |
62 return FromID(GetInProcessRendererId(), routing_id); | 64 return FromID(GetInProcessRendererId(), routing_id); |
63 } | 65 } |
64 | 66 |
65 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) | 67 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) |
66 : compositor_client_(NULL), | 68 : compositor_client_(NULL), |
67 output_surface_(NULL), | 69 output_surface_(NULL), |
| 70 begin_frame_source_(nullptr), |
68 contents_(contents), | 71 contents_(contents), |
69 input_handler_(NULL), | 72 input_handler_(NULL), |
| 73 invoking_composite_(false), |
70 weak_ptr_factory_(this) { | 74 weak_ptr_factory_(this) { |
71 DCHECK(contents); | 75 DCHECK(contents); |
72 } | 76 } |
73 | 77 |
74 SynchronousCompositorImpl::~SynchronousCompositorImpl() { | 78 SynchronousCompositorImpl::~SynchronousCompositorImpl() { |
75 if (compositor_client_) | 79 NotifyDidDestroyCompositorToClient(); |
76 compositor_client_->DidDestroyCompositor(this); | 80 if (begin_frame_source_) |
| 81 begin_frame_source_->SetCompositor(nullptr); |
77 SetInputHandler(NULL); | 82 SetInputHandler(NULL); |
78 } | 83 } |
79 | 84 |
80 void SynchronousCompositorImpl::SetClient( | 85 void SynchronousCompositorImpl::SetClient( |
81 SynchronousCompositorClient* compositor_client) { | 86 SynchronousCompositorClient* compositor_client) { |
82 DCHECK(CalledOnValidThread()); | 87 DCHECK(CalledOnValidThread()); |
83 compositor_client_ = compositor_client; | 88 compositor_client_ = compositor_client; |
84 } | 89 } |
85 | 90 |
86 // static | 91 // static |
87 void SynchronousCompositor::SetGpuService( | 92 void SynchronousCompositor::SetGpuService( |
88 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { | 93 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { |
89 g_factory.Get().SetDeferredGpuService(service); | 94 g_factory.Get().SetDeferredGpuService(service); |
90 } | 95 } |
91 | 96 |
92 // static | 97 // static |
93 void SynchronousCompositor::SetRecordFullDocument(bool record_full_document) { | 98 void SynchronousCompositor::SetRecordFullDocument(bool record_full_document) { |
94 g_factory.Get().SetRecordFullDocument(record_full_document); | 99 g_factory.Get().SetRecordFullDocument(record_full_document); |
95 } | 100 } |
96 | 101 |
| 102 void SynchronousCompositorImpl::DidInitializeExternalBeginFrameSource( |
| 103 SynchronousCompositorExternalBeginFrameSource* begin_frame_source) { |
| 104 DCHECK(!begin_frame_source_); |
| 105 DCHECK(!output_surface_); |
| 106 DCHECK(begin_frame_source); |
| 107 begin_frame_source_ = begin_frame_source; |
| 108 begin_frame_source_->SetCompositor(this); |
| 109 } |
| 110 |
| 111 void SynchronousCompositorImpl::DidDestroyExternalBeginFrameSource( |
| 112 SynchronousCompositorExternalBeginFrameSource* begin_frame_source) { |
| 113 DCHECK(begin_frame_source_); |
| 114 DCHECK_EQ(begin_frame_source_, begin_frame_source); |
| 115 begin_frame_source_->SetCompositor(nullptr); |
| 116 begin_frame_source_ = nullptr; |
| 117 |
| 118 if (output_surface_) |
| 119 output_surface_->set_external_begin_frame_source(nullptr); |
| 120 |
| 121 NotifyDidDestroyCompositorToClient(); |
| 122 } |
| 123 |
| 124 void SynchronousCompositorImpl::NotifyDidDestroyCompositorToClient() { |
| 125 if (compositor_client_) |
| 126 compositor_client_->DidDestroyCompositor(this); |
| 127 compositor_client_ = nullptr; |
| 128 } |
| 129 |
97 bool SynchronousCompositorImpl::InitializeHwDraw() { | 130 bool SynchronousCompositorImpl::InitializeHwDraw() { |
98 DCHECK(CalledOnValidThread()); | 131 DCHECK(CalledOnValidThread()); |
99 DCHECK(output_surface_); | 132 DCHECK(output_surface_); |
100 | 133 |
101 scoped_refptr<cc::ContextProvider> onscreen_context = | 134 scoped_refptr<cc::ContextProvider> onscreen_context = |
102 g_factory.Get().CreateOnscreenContextProviderForCompositorThread(); | 135 g_factory.Get().CreateOnscreenContextProviderForCompositorThread(); |
103 | 136 |
104 bool success = output_surface_->InitializeHwDraw(onscreen_context); | 137 bool success = output_surface_->InitializeHwDraw(onscreen_context); |
105 | 138 |
106 if (success) | 139 if (success) |
(...skipping 10 matching lines...) Expand all Loading... |
117 | 150 |
118 scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw( | 151 scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw( |
119 gfx::Size surface_size, | 152 gfx::Size surface_size, |
120 const gfx::Transform& transform, | 153 const gfx::Transform& transform, |
121 gfx::Rect viewport, | 154 gfx::Rect viewport, |
122 gfx::Rect clip, | 155 gfx::Rect clip, |
123 gfx::Rect viewport_rect_for_tile_priority, | 156 gfx::Rect viewport_rect_for_tile_priority, |
124 const gfx::Transform& transform_for_tile_priority) { | 157 const gfx::Transform& transform_for_tile_priority) { |
125 DCHECK(CalledOnValidThread()); | 158 DCHECK(CalledOnValidThread()); |
126 DCHECK(output_surface_); | 159 DCHECK(output_surface_); |
| 160 DCHECK(!invoking_composite_); |
| 161 DCHECK(compositor_client_); |
| 162 DCHECK(begin_frame_source_); |
127 | 163 |
| 164 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, |
| 165 true); |
128 scoped_ptr<cc::CompositorFrame> frame = | 166 scoped_ptr<cc::CompositorFrame> frame = |
129 output_surface_->DemandDrawHw(surface_size, | 167 output_surface_->DemandDrawHw(surface_size, |
130 transform, | 168 transform, |
131 viewport, | 169 viewport, |
132 clip, | 170 clip, |
133 viewport_rect_for_tile_priority, | 171 viewport_rect_for_tile_priority, |
134 transform_for_tile_priority); | 172 transform_for_tile_priority); |
135 if (frame.get()) | 173 if (frame.get()) |
136 UpdateFrameMetaData(frame->metadata); | 174 UpdateFrameMetaData(frame->metadata); |
137 | 175 |
| 176 compositor_client_->SetContinuousInvalidate( |
| 177 begin_frame_source_->NeedsBeginFrames()); |
| 178 |
138 return frame.Pass(); | 179 return frame.Pass(); |
139 } | 180 } |
140 | 181 |
141 void SynchronousCompositorImpl::ReturnResources( | 182 void SynchronousCompositorImpl::ReturnResources( |
142 const cc::CompositorFrameAck& frame_ack) { | 183 const cc::CompositorFrameAck& frame_ack) { |
143 DCHECK(CalledOnValidThread()); | 184 DCHECK(CalledOnValidThread()); |
144 output_surface_->ReturnResources(frame_ack); | 185 output_surface_->ReturnResources(frame_ack); |
145 } | 186 } |
146 | 187 |
147 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { | 188 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { |
148 DCHECK(CalledOnValidThread()); | 189 DCHECK(CalledOnValidThread()); |
149 DCHECK(output_surface_); | 190 DCHECK(output_surface_); |
| 191 DCHECK(!invoking_composite_); |
| 192 DCHECK(compositor_client_); |
| 193 DCHECK(begin_frame_source_); |
150 | 194 |
151 scoped_ptr<cc::CompositorFrame> frame = output_surface_->DemandDrawSw(canvas); | 195 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, |
| 196 true); |
| 197 scoped_ptr<cc::CompositorFrame> frame = |
| 198 output_surface_->DemandDrawSw(canvas); |
152 if (frame.get()) | 199 if (frame.get()) |
153 UpdateFrameMetaData(frame->metadata); | 200 UpdateFrameMetaData(frame->metadata); |
| 201 |
| 202 compositor_client_->SetContinuousInvalidate( |
| 203 begin_frame_source_->NeedsBeginFrames()); |
| 204 |
154 return !!frame.get(); | 205 return !!frame.get(); |
155 } | 206 } |
156 | 207 |
157 void SynchronousCompositorImpl::UpdateFrameMetaData( | 208 void SynchronousCompositorImpl::UpdateFrameMetaData( |
158 const cc::CompositorFrameMetadata& frame_metadata) { | 209 const cc::CompositorFrameMetadata& frame_metadata) { |
159 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 210 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
160 contents_->GetRenderWidgetHostView()); | 211 contents_->GetRenderWidgetHostView()); |
161 if (rwhv) | 212 if (rwhv) |
162 rwhv->SynchronousFrameMetadata(frame_metadata); | 213 rwhv->SynchronousFrameMetadata(frame_metadata); |
163 DeliverMessages(); | 214 DeliverMessages(); |
164 } | 215 } |
165 | 216 |
166 void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) { | 217 void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) { |
167 DCHECK(CalledOnValidThread()); | 218 DCHECK(CalledOnValidThread()); |
168 DCHECK(output_surface_); | 219 DCHECK(output_surface_); |
169 | 220 |
170 output_surface_->SetMemoryPolicy(bytes_limit); | 221 output_surface_->SetMemoryPolicy(bytes_limit); |
171 } | 222 } |
172 | 223 |
173 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() { | 224 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() { |
174 if (input_handler_) | 225 if (input_handler_) |
175 input_handler_->OnRootLayerDelegatedScrollOffsetChanged(); | 226 input_handler_->OnRootLayerDelegatedScrollOffsetChanged(); |
176 } | 227 } |
177 | 228 |
178 void SynchronousCompositorImpl::DidBindOutputSurface( | 229 void SynchronousCompositorImpl::DidBindOutputSurface( |
179 SynchronousCompositorOutputSurface* output_surface) { | 230 SynchronousCompositorOutputSurface* output_surface) { |
180 DCHECK(CalledOnValidThread()); | 231 DCHECK(CalledOnValidThread()); |
| 232 DCHECK(begin_frame_source_); |
| 233 DCHECK(output_surface); |
181 output_surface_ = output_surface; | 234 output_surface_ = output_surface; |
182 if (compositor_client_) | 235 if (compositor_client_) |
183 compositor_client_->DidInitializeCompositor(this); | 236 compositor_client_->DidInitializeCompositor(this); |
| 237 |
| 238 output_surface_->set_external_begin_frame_source(begin_frame_source_); |
184 } | 239 } |
185 | 240 |
186 void SynchronousCompositorImpl::DidDestroySynchronousOutputSurface( | 241 void SynchronousCompositorImpl::DidDestroySynchronousOutputSurface( |
187 SynchronousCompositorOutputSurface* output_surface) { | 242 SynchronousCompositorOutputSurface* output_surface) { |
188 DCHECK(CalledOnValidThread()); | 243 DCHECK(CalledOnValidThread()); |
189 | 244 |
190 // Allow for transient hand-over when two output surfaces may refer to | 245 // Allow for transient hand-over when two output surfaces may refer to |
191 // a single delegate. | 246 // a single delegate. |
192 if (output_surface_ == output_surface) { | 247 if (output_surface_ == output_surface) { |
| 248 output_surface_->set_external_begin_frame_source(nullptr); |
193 output_surface_ = NULL; | 249 output_surface_ = NULL; |
194 if (compositor_client_) | 250 NotifyDidDestroyCompositorToClient(); |
195 compositor_client_->DidDestroyCompositor(this); | |
196 compositor_client_ = NULL; | |
197 } | 251 } |
198 } | 252 } |
199 | 253 |
200 void SynchronousCompositorImpl::SetInputHandler( | 254 void SynchronousCompositorImpl::SetInputHandler( |
201 cc::InputHandler* input_handler) { | 255 cc::InputHandler* input_handler) { |
202 DCHECK(CalledOnValidThread()); | 256 DCHECK(CalledOnValidThread()); |
203 | 257 |
204 if (input_handler_) | 258 if (input_handler_) |
205 input_handler_->SetRootLayerScrollOffsetDelegate(NULL); | 259 input_handler_->SetRootLayerScrollOffsetDelegate(NULL); |
206 | 260 |
(...skipping 12 matching lines...) Expand all Loading... |
219 } | 273 } |
220 } | 274 } |
221 | 275 |
222 void SynchronousCompositorImpl::DidStopFlinging() { | 276 void SynchronousCompositorImpl::DidStopFlinging() { |
223 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 277 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
224 contents_->GetRenderWidgetHostView()); | 278 contents_->GetRenderWidgetHostView()); |
225 if (rwhv) | 279 if (rwhv) |
226 rwhv->DidStopFlinging(); | 280 rwhv->DidStopFlinging(); |
227 } | 281 } |
228 | 282 |
229 void SynchronousCompositorImpl::SetContinuousInvalidate(bool enable) { | 283 void SynchronousCompositorImpl::NeedsBeginFramesChanged() const { |
230 DCHECK(CalledOnValidThread()); | 284 DCHECK(CalledOnValidThread()); |
231 if (compositor_client_) | 285 DCHECK(begin_frame_source_); |
232 compositor_client_->SetContinuousInvalidate(enable); | 286 if (invoking_composite_) |
| 287 return; |
| 288 |
| 289 if (compositor_client_) { |
| 290 compositor_client_->SetContinuousInvalidate( |
| 291 begin_frame_source_->NeedsBeginFrames()); |
| 292 } |
233 } | 293 } |
234 | 294 |
235 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( | 295 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( |
236 const blink::WebInputEvent& input_event) { | 296 const blink::WebInputEvent& input_event) { |
237 DCHECK(CalledOnValidThread()); | 297 DCHECK(CalledOnValidThread()); |
238 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( | 298 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( |
239 contents_->GetRoutingID(), input_event); | 299 contents_->GetRoutingID(), input_event); |
240 } | 300 } |
241 | 301 |
242 void SynchronousCompositorImpl::DeliverMessages() { | 302 void SynchronousCompositorImpl::DeliverMessages() { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 g_factory.Get(); // Ensure it's initialized. | 369 g_factory.Get(); // Ensure it's initialized. |
310 SynchronousCompositorImpl::CreateForWebContents(contents); | 370 SynchronousCompositorImpl::CreateForWebContents(contents); |
311 } | 371 } |
312 if (SynchronousCompositorImpl* instance = | 372 if (SynchronousCompositorImpl* instance = |
313 SynchronousCompositorImpl::FromWebContents(contents)) { | 373 SynchronousCompositorImpl::FromWebContents(contents)) { |
314 instance->SetClient(client); | 374 instance->SetClient(client); |
315 } | 375 } |
316 } | 376 } |
317 | 377 |
318 } // namespace content | 378 } // namespace content |
OLD | NEW |