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_output_surfa ce.h" | 5 #include "content/browser/android/in_process/synchronous_compositor_output_surfa ce.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "cc/output/begin_frame_args.h" | 9 #include "cc/output/begin_frame_args.h" |
10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 SkCanvas null_canvas_; | 62 SkCanvas null_canvas_; |
63 | 63 |
64 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); | 64 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); |
65 }; | 65 }; |
66 | 66 |
67 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( | 67 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( |
68 int routing_id) | 68 int routing_id) |
69 : cc::OutputSurface( | 69 : cc::OutputSurface( |
70 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), | 70 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), |
71 routing_id_(routing_id), | 71 routing_id_(routing_id), |
72 needs_begin_frame_(false), | |
piman
2014/04/24 20:27:56
nit: nothing sets/reads this AFAICT. Remove?
brianderson
2014/04/24 21:33:43
I removed needs_begin_frame_ from the base OutputS
| |
72 invoking_composite_(false), | 73 invoking_composite_(false), |
73 did_swap_buffer_(false), | 74 did_swap_buffer_(false), |
74 current_sw_canvas_(NULL), | 75 current_sw_canvas_(NULL), |
75 memory_policy_(0), | 76 memory_policy_(0), |
76 output_surface_client_(NULL), | 77 output_surface_client_(NULL), |
77 weak_ptr_factory_(this) { | 78 weak_ptr_factory_(this) { |
78 capabilities_.deferred_gl_initialization = true; | 79 capabilities_.deferred_gl_initialization = true; |
79 capabilities_.draw_and_swap_full_viewport_every_frame = true; | 80 capabilities_.draw_and_swap_full_viewport_every_frame = true; |
80 capabilities_.adjust_deadline_for_parent = false; | 81 capabilities_.adjust_deadline_for_parent = false; |
81 // Cannot call out to GetDelegate() here as the output surface is not | 82 // Cannot call out to GetDelegate() here as the output surface is not |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 } | 120 } |
120 | 121 |
121 void SynchronousCompositorOutputSurface::Reshape( | 122 void SynchronousCompositorOutputSurface::Reshape( |
122 const gfx::Size& size, float scale_factor) { | 123 const gfx::Size& size, float scale_factor) { |
123 // Intentional no-op: surface size is controlled by the embedder. | 124 // Intentional no-op: surface size is controlled by the embedder. |
124 } | 125 } |
125 | 126 |
126 void SynchronousCompositorOutputSurface::SetNeedsBeginFrame(bool enable) { | 127 void SynchronousCompositorOutputSurface::SetNeedsBeginFrame(bool enable) { |
127 DCHECK(CalledOnValidThread()); | 128 DCHECK(CalledOnValidThread()); |
128 needs_begin_frame_ = enable; | 129 needs_begin_frame_ = enable; |
129 client_ready_for_begin_frame_ = true; | |
130 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | 130 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
131 if (delegate && !invoking_composite_) | 131 if (delegate && !invoking_composite_) |
132 delegate->SetContinuousInvalidate(needs_begin_frame_); | 132 delegate->SetContinuousInvalidate(needs_begin_frame_); |
133 } | 133 } |
134 | 134 |
135 void SynchronousCompositorOutputSurface::SwapBuffers( | 135 void SynchronousCompositorOutputSurface::SwapBuffers( |
136 cc::CompositorFrame* frame) { | 136 cc::CompositorFrame* frame) { |
137 DCHECK(CalledOnValidThread()); | 137 DCHECK(CalledOnValidThread()); |
138 if (!ForcedDrawToSoftwareDevice()) { | 138 if (!ForcedDrawToSoftwareDevice()) { |
139 DCHECK(context_provider_); | 139 DCHECK(context_provider_); |
140 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); | 140 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); |
141 } | 141 } |
142 UpdateFrameMetaData(frame->metadata); | 142 UpdateFrameMetaData(frame->metadata); |
143 | 143 |
144 did_swap_buffer_ = true; | 144 did_swap_buffer_ = true; |
145 DidSwapBuffers(); | 145 client_->DidSwapBuffers(); |
146 } | 146 } |
147 | 147 |
148 void SynchronousCompositorOutputSurface::UpdateFrameMetaData( | 148 void SynchronousCompositorOutputSurface::UpdateFrameMetaData( |
149 const cc::CompositorFrameMetadata& frame_info) { | 149 const cc::CompositorFrameMetadata& frame_info) { |
150 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 150 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
151 BrowserThread::PostTask( | 151 BrowserThread::PostTask( |
152 BrowserThread::UI, | 152 BrowserThread::UI, |
153 FROM_HERE, | 153 FROM_HERE, |
154 base::Bind(&SynchronousCompositorOutputSurface::UpdateFrameMetaData, | 154 base::Bind(&SynchronousCompositorOutputSurface::UpdateFrameMetaData, |
155 weak_ptr_factory_.GetWeakPtr(), | 155 weak_ptr_factory_.GetWeakPtr(), |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 bool valid_for_tile_management) { | 231 bool valid_for_tile_management) { |
232 DCHECK(!invoking_composite_); | 232 DCHECK(!invoking_composite_); |
233 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, true); | 233 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, true); |
234 did_swap_buffer_ = false; | 234 did_swap_buffer_ = false; |
235 | 235 |
236 gfx::Transform adjusted_transform = transform; | 236 gfx::Transform adjusted_transform = transform; |
237 AdjustTransform(&adjusted_transform, viewport); | 237 AdjustTransform(&adjusted_transform, viewport); |
238 SetExternalDrawConstraints( | 238 SetExternalDrawConstraints( |
239 adjusted_transform, viewport, clip, valid_for_tile_management); | 239 adjusted_transform, viewport, clip, valid_for_tile_management); |
240 SetNeedsRedrawRect(gfx::Rect(viewport.size())); | 240 SetNeedsRedrawRect(gfx::Rect(viewport.size())); |
241 BeginFrame(cc::BeginFrameArgs::CreateForSynchronousCompositor()); | 241 client_->BeginFrame(cc::BeginFrameArgs::CreateForSynchronousCompositor()); |
242 | 242 |
243 // After software draws (which might move the viewport arbitrarily), restore | 243 // After software draws (which might move the viewport arbitrarily), restore |
244 // the previous hardware viewport to allow CC's tile manager to prioritize | 244 // the previous hardware viewport to allow CC's tile manager to prioritize |
245 // properly. | 245 // properly. |
246 if (valid_for_tile_management) { | 246 if (valid_for_tile_management) { |
247 cached_hw_transform_ = adjusted_transform; | 247 cached_hw_transform_ = adjusted_transform; |
248 cached_hw_viewport_ = viewport; | 248 cached_hw_viewport_ = viewport; |
249 cached_hw_clip_ = clip; | 249 cached_hw_clip_ = clip; |
250 } else { | 250 } else { |
251 SetExternalDrawConstraints( | 251 SetExternalDrawConstraints( |
252 cached_hw_transform_, cached_hw_viewport_, cached_hw_clip_, true); | 252 cached_hw_transform_, cached_hw_viewport_, cached_hw_clip_, true); |
253 } | 253 } |
254 | 254 |
255 if (did_swap_buffer_) | 255 if (did_swap_buffer_) |
256 OnSwapBuffersComplete(); | 256 client_->DidSwapBuffersComplete(); |
257 | 257 |
258 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | 258 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
259 if (delegate) | 259 if (delegate) |
260 delegate->SetContinuousInvalidate(needs_begin_frame_); | 260 delegate->SetContinuousInvalidate(needs_begin_frame_); |
261 } | 261 } |
262 | 262 |
263 void SynchronousCompositorOutputSurface::PostCheckForRetroactiveBeginFrame() { | |
264 // Synchronous compositor cannot perform retroactive BeginFrames, so | |
265 // intentionally no-op here. | |
266 } | |
267 | |
268 void SynchronousCompositorOutputSurface::SetMemoryPolicy( | 263 void SynchronousCompositorOutputSurface::SetMemoryPolicy( |
269 const SynchronousCompositorMemoryPolicy& policy) { | 264 const SynchronousCompositorMemoryPolicy& policy) { |
270 DCHECK(CalledOnValidThread()); | 265 DCHECK(CalledOnValidThread()); |
271 memory_policy_.bytes_limit_when_visible = policy.bytes_limit; | 266 memory_policy_.bytes_limit_when_visible = policy.bytes_limit; |
272 memory_policy_.num_resources_limit = policy.num_resources_limit; | 267 memory_policy_.num_resources_limit = policy.num_resources_limit; |
273 | 268 |
274 if (output_surface_client_) | 269 if (output_surface_client_) |
275 output_surface_client_->SetMemoryPolicy(memory_policy_); | 270 output_surface_client_->SetMemoryPolicy(memory_policy_); |
276 } | 271 } |
277 | 272 |
278 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 273 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
279 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI | 274 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI |
280 // thread. | 275 // thread. |
281 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 276 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
282 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 277 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
283 } | 278 } |
284 | 279 |
285 SynchronousCompositorOutputSurfaceDelegate* | 280 SynchronousCompositorOutputSurfaceDelegate* |
286 SynchronousCompositorOutputSurface::GetDelegate() { | 281 SynchronousCompositorOutputSurface::GetDelegate() { |
287 return SynchronousCompositorImpl::FromRoutingID(routing_id_); | 282 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
288 } | 283 } |
289 | 284 |
290 } // namespace content | 285 } // namespace content |
OLD | NEW |