Chromium Code Reviews| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "cc/output/begin_frame_args.h" | 10 #include "cc/output/begin_frame_args.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 | 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); | 82 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( | 85 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( |
| 86 int routing_id) | 86 int routing_id) |
| 87 : cc::OutputSurface( | 87 : cc::OutputSurface( |
| 88 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), | 88 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), |
| 89 routing_id_(routing_id), | 89 routing_id_(routing_id), |
| 90 needs_begin_frame_(false), | 90 needs_begin_frame_(false), |
| 91 invoking_composite_(false), | |
| 91 did_swap_buffer_(false), | 92 did_swap_buffer_(false), |
| 92 current_sw_canvas_(NULL) { | 93 current_sw_canvas_(NULL) { |
| 93 capabilities_.deferred_gl_initialization = true; | 94 capabilities_.deferred_gl_initialization = true; |
| 94 capabilities_.adjust_deadline_for_parent = false; | 95 capabilities_.adjust_deadline_for_parent = false; |
| 95 // Cannot call out to GetDelegate() here as the output surface is not | 96 // Cannot call out to GetDelegate() here as the output surface is not |
| 96 // constructed on the correct thread. | 97 // constructed on the correct thread. |
| 97 } | 98 } |
| 98 | 99 |
| 99 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { | 100 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { |
| 100 DCHECK(CalledOnValidThread()); | 101 DCHECK(CalledOnValidThread()); |
| 101 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | 102 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
| 102 if (delegate) | 103 if (delegate) |
| 103 delegate->DidDestroySynchronousOutputSurface(this); | 104 delegate->DidDestroySynchronousOutputSurface(this); |
| 104 } | 105 } |
| 105 | 106 |
| 106 bool SynchronousCompositorOutputSurface::ForcedDrawToSoftwareDevice() const { | 107 bool SynchronousCompositorOutputSurface::ForcedDrawToSoftwareDevice() const { |
| 107 return current_sw_canvas_ != NULL; | 108 // |current_sw_canvas_| indicates we're in a DemandDrawSw call. In addition |
| 109 // |invoking_composite_| == false indicates an attempt to draw outside of | |
| 110 // the synchronous compositor's control: force it into SW path and hence to | |
| 111 // the null canvas (and will log a warning there). | |
| 112 return current_sw_canvas_ != NULL || !invoking_composite_; | |
| 108 } | 113 } |
| 109 | 114 |
| 110 bool SynchronousCompositorOutputSurface::BindToClient( | 115 bool SynchronousCompositorOutputSurface::BindToClient( |
| 111 cc::OutputSurfaceClient* surface_client) { | 116 cc::OutputSurfaceClient* surface_client) { |
| 112 DCHECK(CalledOnValidThread()); | 117 DCHECK(CalledOnValidThread()); |
| 113 if (!cc::OutputSurface::BindToClient(surface_client)) | 118 if (!cc::OutputSurface::BindToClient(surface_client)) |
| 114 return false; | 119 return false; |
| 115 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | 120 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
| 116 if (delegate) | 121 if (delegate) |
| 117 delegate->DidBindOutputSurface(this); | 122 delegate->DidBindOutputSurface(this); |
| 118 return true; | 123 return true; |
| 119 } | 124 } |
| 120 | 125 |
| 121 void SynchronousCompositorOutputSurface::Reshape( | 126 void SynchronousCompositorOutputSurface::Reshape( |
| 122 gfx::Size size, float scale_factor) { | 127 gfx::Size size, float scale_factor) { |
| 123 // Intentional no-op: surface size is controlled by the embedder. | 128 // Intentional no-op: surface size is controlled by the embedder. |
| 124 } | 129 } |
| 125 | 130 |
| 126 void SynchronousCompositorOutputSurface::SetNeedsBeginFrame( | 131 void SynchronousCompositorOutputSurface::SetNeedsBeginFrame( |
| 127 bool enable) { | 132 bool enable) { |
| 128 DCHECK(CalledOnValidThread()); | 133 DCHECK(CalledOnValidThread()); |
| 129 cc::OutputSurface::SetNeedsBeginFrame(enable); | 134 cc::OutputSurface::SetNeedsBeginFrame(enable); |
| 130 needs_begin_frame_ = enable; | 135 needs_begin_frame_ = enable; |
| 131 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | 136 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
| 132 if (delegate) | 137 if (delegate) |
| 133 delegate->SetContinuousInvalidate(needs_begin_frame_); | 138 delegate->SetContinuousInvalidate(needs_begin_frame_); |
| 134 } | 139 } |
| 135 | 140 |
| 136 void SynchronousCompositorOutputSurface::SwapBuffers( | 141 void SynchronousCompositorOutputSurface::SwapBuffers( |
|
boliu
2013/06/21 22:44:23
Hmm...slightly tangent, but we could invalidate th
joth
2013/06/21 23:02:14
yeah...... I'd rather not make it any more complic
| |
| 137 cc::CompositorFrame* frame) { | 142 cc::CompositorFrame* frame) { |
| 138 if (!ForcedDrawToSoftwareDevice()) { | 143 if (!ForcedDrawToSoftwareDevice()) { |
| 139 DCHECK(context3d()); | 144 DCHECK(context3d()); |
| 140 context3d()->shallowFlushCHROMIUM(); | 145 context3d()->shallowFlushCHROMIUM(); |
| 141 } | 146 } |
| 142 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | 147 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
| 143 if (delegate) | 148 if (delegate) |
| 144 delegate->UpdateFrameMetaData(frame->metadata); | 149 delegate->UpdateFrameMetaData(frame->metadata); |
| 145 | 150 |
| 146 did_swap_buffer_ = true; | 151 did_swap_buffer_ = true; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 SetExternalDrawConstraints(transform, clip); | 216 SetExternalDrawConstraints(transform, clip); |
| 212 | 217 |
| 213 InvokeComposite(clip.size()); | 218 InvokeComposite(clip.size()); |
| 214 | 219 |
| 215 current_sw_canvas_ = NULL; | 220 current_sw_canvas_ = NULL; |
| 216 return did_swap_buffer_; | 221 return did_swap_buffer_; |
| 217 } | 222 } |
| 218 | 223 |
| 219 void SynchronousCompositorOutputSurface::InvokeComposite( | 224 void SynchronousCompositorOutputSurface::InvokeComposite( |
| 220 gfx::Size damage_size) { | 225 gfx::Size damage_size) { |
| 226 invoking_composite_ = true; | |
|
boliu
2013/06/21 22:40:14
Use base::AutoReset?
joth
2013/06/21 23:02:14
Done.
Nice! Thought that existed, but I was searc
| |
| 221 did_swap_buffer_ = false; | 227 did_swap_buffer_ = false; |
| 222 SetNeedsRedrawRect(gfx::Rect(damage_size)); | 228 SetNeedsRedrawRect(gfx::Rect(damage_size)); |
| 223 if (needs_begin_frame_) | 229 if (needs_begin_frame_) |
| 224 BeginFrame(cc::BeginFrameArgs::CreateForSynchronousCompositor()); | 230 BeginFrame(cc::BeginFrameArgs::CreateForSynchronousCompositor()); |
| 225 | 231 |
| 226 if (did_swap_buffer_) | 232 if (did_swap_buffer_) |
| 227 OnSwapBuffersComplete(NULL); | 233 OnSwapBuffersComplete(NULL); |
| 234 invoking_composite_ = false; | |
| 228 } | 235 } |
| 229 | 236 |
| 230 void SynchronousCompositorOutputSurface::PostCheckForRetroactiveBeginFrame() { | 237 void SynchronousCompositorOutputSurface::PostCheckForRetroactiveBeginFrame() { |
| 231 // Synchronous compositor cannot perform retroactive begin frames, so | 238 // Synchronous compositor cannot perform retroactive begin frames, so |
| 232 // intentionally no-op here. | 239 // intentionally no-op here. |
| 233 } | 240 } |
| 234 | 241 |
| 235 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 242 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| 236 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI | 243 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI |
| 237 // thread. | 244 // thread. |
| 238 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 245 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 239 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 246 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 240 } | 247 } |
| 241 | 248 |
| 242 SynchronousCompositorOutputSurfaceDelegate* | 249 SynchronousCompositorOutputSurfaceDelegate* |
| 243 SynchronousCompositorOutputSurface::GetDelegate() { | 250 SynchronousCompositorOutputSurface::GetDelegate() { |
| 244 return SynchronousCompositorImpl::FromRoutingID(routing_id_); | 251 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
| 245 } | 252 } |
| 246 | 253 |
| 247 } // namespace content | 254 } // namespace content |
| OLD | NEW |