| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 delegate->DidBindOutputSurface(this); | 116 delegate->DidBindOutputSurface(this); |
| 117 | 117 |
| 118 return true; | 118 return true; |
| 119 } | 119 } |
| 120 | 120 |
| 121 void SynchronousCompositorOutputSurface::Reshape( | 121 void SynchronousCompositorOutputSurface::Reshape( |
| 122 const gfx::Size& size, float scale_factor) { | 122 const gfx::Size& size, float scale_factor) { |
| 123 // Intentional no-op: surface size is controlled by the embedder. | 123 // Intentional no-op: surface size is controlled by the embedder. |
| 124 } | 124 } |
| 125 | 125 |
| 126 void SynchronousCompositorOutputSurface::SetNeedsBeginImplFrame( | 126 void SynchronousCompositorOutputSurface::SetNeedsBeginFrame(bool enable) { |
| 127 bool enable) { | |
| 128 DCHECK(CalledOnValidThread()); | 127 DCHECK(CalledOnValidThread()); |
| 129 needs_begin_impl_frame_ = enable; | 128 needs_begin_frame_ = enable; |
| 130 client_ready_for_begin_impl_frame_ = true; | 129 client_ready_for_begin_frame_ = true; |
| 131 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | 130 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
| 132 if (delegate && !invoking_composite_) | 131 if (delegate && !invoking_composite_) |
| 133 delegate->SetContinuousInvalidate(needs_begin_impl_frame_); | 132 delegate->SetContinuousInvalidate(needs_begin_frame_); |
| 134 } | 133 } |
| 135 | 134 |
| 136 void SynchronousCompositorOutputSurface::SwapBuffers( | 135 void SynchronousCompositorOutputSurface::SwapBuffers( |
| 137 cc::CompositorFrame* frame) { | 136 cc::CompositorFrame* frame) { |
| 138 DCHECK(CalledOnValidThread()); | 137 DCHECK(CalledOnValidThread()); |
| 139 if (!ForcedDrawToSoftwareDevice()) { | 138 if (!ForcedDrawToSoftwareDevice()) { |
| 140 DCHECK(context_provider_); | 139 DCHECK(context_provider_); |
| 141 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); | 140 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); |
| 142 } | 141 } |
| 143 UpdateFrameMetaData(frame->metadata); | 142 UpdateFrameMetaData(frame->metadata); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 bool valid_for_tile_management) { | 231 bool valid_for_tile_management) { |
| 233 DCHECK(!invoking_composite_); | 232 DCHECK(!invoking_composite_); |
| 234 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, true); | 233 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, true); |
| 235 did_swap_buffer_ = false; | 234 did_swap_buffer_ = false; |
| 236 | 235 |
| 237 gfx::Transform adjusted_transform = transform; | 236 gfx::Transform adjusted_transform = transform; |
| 238 AdjustTransform(&adjusted_transform, viewport); | 237 AdjustTransform(&adjusted_transform, viewport); |
| 239 SetExternalDrawConstraints( | 238 SetExternalDrawConstraints( |
| 240 adjusted_transform, viewport, clip, valid_for_tile_management); | 239 adjusted_transform, viewport, clip, valid_for_tile_management); |
| 241 SetNeedsRedrawRect(gfx::Rect(viewport.size())); | 240 SetNeedsRedrawRect(gfx::Rect(viewport.size())); |
| 242 BeginImplFrame(cc::BeginFrameArgs::CreateForSynchronousCompositor()); | 241 BeginFrame(cc::BeginFrameArgs::CreateForSynchronousCompositor()); |
| 243 | 242 |
| 244 // After software draws (which might move the viewport arbitrarily), restore | 243 // After software draws (which might move the viewport arbitrarily), restore |
| 245 // 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 |
| 246 // properly. | 245 // properly. |
| 247 if (valid_for_tile_management) { | 246 if (valid_for_tile_management) { |
| 248 cached_hw_transform_ = adjusted_transform; | 247 cached_hw_transform_ = adjusted_transform; |
| 249 cached_hw_viewport_ = viewport; | 248 cached_hw_viewport_ = viewport; |
| 250 cached_hw_clip_ = clip; | 249 cached_hw_clip_ = clip; |
| 251 } else { | 250 } else { |
| 252 SetExternalDrawConstraints( | 251 SetExternalDrawConstraints( |
| 253 cached_hw_transform_, cached_hw_viewport_, cached_hw_clip_, true); | 252 cached_hw_transform_, cached_hw_viewport_, cached_hw_clip_, true); |
| 254 } | 253 } |
| 255 | 254 |
| 256 if (did_swap_buffer_) | 255 if (did_swap_buffer_) |
| 257 OnSwapBuffersComplete(); | 256 OnSwapBuffersComplete(); |
| 258 | 257 |
| 259 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | 258 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
| 260 if (delegate) | 259 if (delegate) |
| 261 delegate->SetContinuousInvalidate(needs_begin_impl_frame_); | 260 delegate->SetContinuousInvalidate(needs_begin_frame_); |
| 262 } | 261 } |
| 263 | 262 |
| 264 void | 263 void SynchronousCompositorOutputSurface::PostCheckForRetroactiveBeginFrame() { |
| 265 SynchronousCompositorOutputSurface::PostCheckForRetroactiveBeginImplFrame() { | 264 // Synchronous compositor cannot perform retroactive BeginFrames, so |
| 266 // Synchronous compositor cannot perform retroactive BeginImplFrames, so | |
| 267 // intentionally no-op here. | 265 // intentionally no-op here. |
| 268 } | 266 } |
| 269 | 267 |
| 270 void SynchronousCompositorOutputSurface::SetMemoryPolicy( | 268 void SynchronousCompositorOutputSurface::SetMemoryPolicy( |
| 271 const SynchronousCompositorMemoryPolicy& policy) { | 269 const SynchronousCompositorMemoryPolicy& policy) { |
| 272 DCHECK(CalledOnValidThread()); | 270 DCHECK(CalledOnValidThread()); |
| 273 memory_policy_.bytes_limit_when_visible = policy.bytes_limit; | 271 memory_policy_.bytes_limit_when_visible = policy.bytes_limit; |
| 274 memory_policy_.num_resources_limit = policy.num_resources_limit; | 272 memory_policy_.num_resources_limit = policy.num_resources_limit; |
| 275 | 273 |
| 276 if (output_surface_client_) | 274 if (output_surface_client_) |
| 277 output_surface_client_->SetMemoryPolicy(memory_policy_); | 275 output_surface_client_->SetMemoryPolicy(memory_policy_); |
| 278 } | 276 } |
| 279 | 277 |
| 280 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 278 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| 281 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI | 279 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI |
| 282 // thread. | 280 // thread. |
| 283 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 281 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 284 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 282 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 285 } | 283 } |
| 286 | 284 |
| 287 SynchronousCompositorOutputSurfaceDelegate* | 285 SynchronousCompositorOutputSurfaceDelegate* |
| 288 SynchronousCompositorOutputSurface::GetDelegate() { | 286 SynchronousCompositorOutputSurface::GetDelegate() { |
| 289 return SynchronousCompositorImpl::FromRoutingID(routing_id_); | 287 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
| 290 } | 288 } |
| 291 | 289 |
| 292 } // namespace content | 290 } // namespace content |
| OLD | NEW |