| 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), |
| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 bool valid_for_tile_management) { | 229 bool valid_for_tile_management) { |
| 230 DCHECK(!invoking_composite_); | 230 DCHECK(!invoking_composite_); |
| 231 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, true); | 231 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, true); |
| 232 did_swap_buffer_ = false; | 232 did_swap_buffer_ = false; |
| 233 | 233 |
| 234 gfx::Transform adjusted_transform = transform; | 234 gfx::Transform adjusted_transform = transform; |
| 235 AdjustTransform(&adjusted_transform, viewport); | 235 AdjustTransform(&adjusted_transform, viewport); |
| 236 SetExternalDrawConstraints( | 236 SetExternalDrawConstraints( |
| 237 adjusted_transform, viewport, clip, valid_for_tile_management); | 237 adjusted_transform, viewport, clip, valid_for_tile_management); |
| 238 SetNeedsRedrawRect(gfx::Rect(viewport.size())); | 238 SetNeedsRedrawRect(gfx::Rect(viewport.size())); |
| 239 BeginFrame(cc::BeginFrameArgs::CreateForSynchronousCompositor()); | 239 client_->BeginFrame(cc::BeginFrameArgs::CreateForSynchronousCompositor()); |
| 240 | 240 |
| 241 // After software draws (which might move the viewport arbitrarily), restore | 241 // After software draws (which might move the viewport arbitrarily), restore |
| 242 // the previous hardware viewport to allow CC's tile manager to prioritize | 242 // the previous hardware viewport to allow CC's tile manager to prioritize |
| 243 // properly. | 243 // properly. |
| 244 if (valid_for_tile_management) { | 244 if (valid_for_tile_management) { |
| 245 cached_hw_transform_ = adjusted_transform; | 245 cached_hw_transform_ = adjusted_transform; |
| 246 cached_hw_viewport_ = viewport; | 246 cached_hw_viewport_ = viewport; |
| 247 cached_hw_clip_ = clip; | 247 cached_hw_clip_ = clip; |
| 248 } else { | 248 } else { |
| 249 SetExternalDrawConstraints( | 249 SetExternalDrawConstraints( |
| 250 cached_hw_transform_, cached_hw_viewport_, cached_hw_clip_, true); | 250 cached_hw_transform_, cached_hw_viewport_, cached_hw_clip_, true); |
| 251 } | 251 } |
| 252 | 252 |
| 253 if (did_swap_buffer_) | 253 if (did_swap_buffer_) |
| 254 OnSwapBuffersComplete(); | 254 client_->DidSwapBuffersComplete(); |
| 255 | 255 |
| 256 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | 256 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
| 257 if (delegate) | 257 if (delegate) |
| 258 delegate->SetContinuousInvalidate(needs_begin_frame_); | 258 delegate->SetContinuousInvalidate(needs_begin_frame_); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void SynchronousCompositorOutputSurface::PostCheckForRetroactiveBeginFrame() { | |
| 262 // Synchronous compositor cannot perform retroactive BeginFrames, so | |
| 263 // intentionally no-op here. | |
| 264 } | |
| 265 | |
| 266 void SynchronousCompositorOutputSurface::SetMemoryPolicy( | 261 void SynchronousCompositorOutputSurface::SetMemoryPolicy( |
| 267 const SynchronousCompositorMemoryPolicy& policy) { | 262 const SynchronousCompositorMemoryPolicy& policy) { |
| 268 DCHECK(CalledOnValidThread()); | 263 DCHECK(CalledOnValidThread()); |
| 269 memory_policy_.bytes_limit_when_visible = policy.bytes_limit; | 264 memory_policy_.bytes_limit_when_visible = policy.bytes_limit; |
| 270 memory_policy_.num_resources_limit = policy.num_resources_limit; | 265 memory_policy_.num_resources_limit = policy.num_resources_limit; |
| 271 | 266 |
| 272 if (output_surface_client_) | 267 if (output_surface_client_) |
| 273 output_surface_client_->SetMemoryPolicy(memory_policy_); | 268 output_surface_client_->SetMemoryPolicy(memory_policy_); |
| 274 } | 269 } |
| 275 | 270 |
| 276 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 271 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| 277 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI | 272 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI |
| 278 // thread. | 273 // thread. |
| 279 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 274 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 280 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 275 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 281 } | 276 } |
| 282 | 277 |
| 283 SynchronousCompositorOutputSurfaceDelegate* | 278 SynchronousCompositorOutputSurfaceDelegate* |
| 284 SynchronousCompositorOutputSurface::GetDelegate() { | 279 SynchronousCompositorOutputSurface::GetDelegate() { |
| 285 return SynchronousCompositorImpl::FromRoutingID(routing_id_); | 280 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
| 286 } | 281 } |
| 287 | 282 |
| 288 } // namespace content | 283 } // namespace content |
| OLD | NEW |