| 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" |
| 11 #include "cc/output/context_provider.h" | 11 #include "cc/output/context_provider.h" |
| 12 #include "cc/output/output_surface_client.h" | 12 #include "cc/output/output_surface_client.h" |
| 13 #include "cc/output/software_output_device.h" | 13 #include "cc/output/software_output_device.h" |
| 14 #include "content/browser/android/in_process/synchronous_compositor_impl.h" | 14 #include "content/browser/android/in_process/synchronous_compositor_impl.h" |
| 15 #include "content/browser/gpu/compositor_util.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "gpu/command_buffer/client/gles2_interface.h" | 17 #include "gpu/command_buffer/client/gles2_interface.h" |
| 17 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 18 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
| 18 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
| 19 #include "ui/gfx/rect_conversions.h" | 20 #include "ui/gfx/rect_conversions.h" |
| 20 #include "ui/gfx/skia_util.h" | 21 #include "ui/gfx/skia_util.h" |
| 21 #include "ui/gfx/transform.h" | 22 #include "ui/gfx/transform.h" |
| 22 | 23 |
| 23 namespace content { | 24 namespace content { |
| 24 | 25 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( | 68 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( |
| 68 int routing_id) | 69 int routing_id) |
| 69 : cc::OutputSurface( | 70 : cc::OutputSurface( |
| 70 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), | 71 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), |
| 71 routing_id_(routing_id), | 72 routing_id_(routing_id), |
| 72 needs_begin_frame_(false), | 73 needs_begin_frame_(false), |
| 73 invoking_composite_(false), | 74 invoking_composite_(false), |
| 74 did_swap_buffer_(false), | 75 did_swap_buffer_(false), |
| 75 current_sw_canvas_(NULL), | 76 current_sw_canvas_(NULL), |
| 76 memory_policy_(0), | 77 memory_policy_(0), |
| 77 output_surface_client_(NULL), | 78 output_surface_client_(NULL) { |
| 78 weak_ptr_factory_(this) { | |
| 79 capabilities_.deferred_gl_initialization = true; | 79 capabilities_.deferred_gl_initialization = true; |
| 80 capabilities_.draw_and_swap_full_viewport_every_frame = true; | 80 capabilities_.draw_and_swap_full_viewport_every_frame = true; |
| 81 capabilities_.adjust_deadline_for_parent = false; | 81 capabilities_.adjust_deadline_for_parent = false; |
| 82 if (IsDelegatedRendererEnabled()) { |
| 83 capabilities_.delegated_rendering = true; |
| 84 capabilities_.max_frames_pending = 1; |
| 85 } |
| 82 // Cannot call out to GetDelegate() here as the output surface is not | 86 // Cannot call out to GetDelegate() here as the output surface is not |
| 83 // constructed on the correct thread. | 87 // constructed on the correct thread. |
| 84 | 88 |
| 85 memory_policy_.priority_cutoff_when_visible = | 89 memory_policy_.priority_cutoff_when_visible = |
| 86 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; | 90 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
| 87 } | 91 } |
| 88 | 92 |
| 89 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { | 93 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { |
| 90 DCHECK(CalledOnValidThread()); | 94 DCHECK(CalledOnValidThread()); |
| 91 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | 95 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 delegate->SetContinuousInvalidate(needs_begin_frame_); | 136 delegate->SetContinuousInvalidate(needs_begin_frame_); |
| 133 } | 137 } |
| 134 | 138 |
| 135 void SynchronousCompositorOutputSurface::SwapBuffers( | 139 void SynchronousCompositorOutputSurface::SwapBuffers( |
| 136 cc::CompositorFrame* frame) { | 140 cc::CompositorFrame* frame) { |
| 137 DCHECK(CalledOnValidThread()); | 141 DCHECK(CalledOnValidThread()); |
| 138 if (!ForcedDrawToSoftwareDevice()) { | 142 if (!ForcedDrawToSoftwareDevice()) { |
| 139 DCHECK(context_provider_); | 143 DCHECK(context_provider_); |
| 140 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); | 144 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); |
| 141 } | 145 } |
| 142 UpdateFrameMetaData(frame->metadata); | 146 |
| 147 DCHECK(frame_); |
| 148 frame->AssignTo(frame_); |
| 143 | 149 |
| 144 did_swap_buffer_ = true; | 150 did_swap_buffer_ = true; |
| 145 client_->DidSwapBuffers(); | 151 client_->DidSwapBuffers(); |
| 146 } | 152 } |
| 147 | 153 |
| 148 void SynchronousCompositorOutputSurface::UpdateFrameMetaData( | |
| 149 const cc::CompositorFrameMetadata& frame_info) { | |
| 150 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 151 BrowserThread::PostTask( | |
| 152 BrowserThread::UI, | |
| 153 FROM_HERE, | |
| 154 base::Bind(&SynchronousCompositorOutputSurface::UpdateFrameMetaData, | |
| 155 weak_ptr_factory_.GetWeakPtr(), | |
| 156 frame_info)); | |
| 157 return; | |
| 158 } | |
| 159 | |
| 160 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | |
| 161 if (delegate) | |
| 162 delegate->UpdateFrameMetaData(frame_info); | |
| 163 } | |
| 164 | |
| 165 namespace { | 154 namespace { |
| 166 void AdjustTransform(gfx::Transform* transform, gfx::Rect viewport) { | 155 void AdjustTransform(gfx::Transform* transform, gfx::Rect viewport) { |
| 167 // CC's draw origin starts at the viewport. | 156 // CC's draw origin starts at the viewport. |
| 168 transform->matrix().postTranslate(-viewport.x(), -viewport.y(), 0); | 157 transform->matrix().postTranslate(-viewport.x(), -viewport.y(), 0); |
| 169 } | 158 } |
| 170 } // namespace | 159 } // namespace |
| 171 | 160 |
| 172 bool SynchronousCompositorOutputSurface::InitializeHwDraw( | 161 bool SynchronousCompositorOutputSurface::InitializeHwDraw( |
| 173 scoped_refptr<cc::ContextProvider> onscreen_context_provider) { | 162 scoped_refptr<cc::ContextProvider> onscreen_context_provider) { |
| 174 DCHECK(CalledOnValidThread()); | 163 DCHECK(CalledOnValidThread()); |
| 175 DCHECK(HasClient()); | 164 DCHECK(HasClient()); |
| 176 DCHECK(!context_provider_); | 165 DCHECK(!context_provider_); |
| 177 | 166 |
| 178 return InitializeAndSetContext3d(onscreen_context_provider); | 167 return InitializeAndSetContext3d(onscreen_context_provider); |
| 179 } | 168 } |
| 180 | 169 |
| 181 void SynchronousCompositorOutputSurface::ReleaseHwDraw() { | 170 void SynchronousCompositorOutputSurface::ReleaseHwDraw() { |
| 182 DCHECK(CalledOnValidThread()); | 171 DCHECK(CalledOnValidThread()); |
| 183 cc::OutputSurface::ReleaseGL(); | 172 cc::OutputSurface::ReleaseGL(); |
| 184 } | 173 } |
| 185 | 174 |
| 186 bool SynchronousCompositorOutputSurface::DemandDrawHw( | 175 bool SynchronousCompositorOutputSurface::DemandDrawHw( |
| 187 gfx::Size surface_size, | 176 gfx::Size surface_size, |
| 188 const gfx::Transform& transform, | 177 const gfx::Transform& transform, |
| 189 gfx::Rect viewport, | 178 gfx::Rect viewport, |
| 190 gfx::Rect clip, | 179 gfx::Rect clip, |
| 191 bool stencil_enabled) { | 180 bool stencil_enabled, |
| 181 cc::CompositorFrame* frame) { |
| 192 DCHECK(CalledOnValidThread()); | 182 DCHECK(CalledOnValidThread()); |
| 193 DCHECK(HasClient()); | 183 DCHECK(HasClient()); |
| 194 DCHECK(context_provider_); | 184 DCHECK(context_provider_); |
| 195 | 185 |
| 186 base::AutoReset<cc::CompositorFrame*> frame_resetter(&frame_, frame); |
| 196 surface_size_ = surface_size; | 187 surface_size_ = surface_size; |
| 197 SetExternalStencilTest(stencil_enabled); | 188 SetExternalStencilTest(stencil_enabled); |
| 198 InvokeComposite(transform, viewport, clip, true); | 189 InvokeComposite(transform, viewport, clip, true); |
| 199 | 190 |
| 200 return did_swap_buffer_; | 191 return did_swap_buffer_; |
| 201 } | 192 } |
| 202 | 193 |
| 203 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | 194 bool SynchronousCompositorOutputSurface::DemandDrawDelegated( |
| 195 const gfx::Transform& transform, |
| 196 gfx::Rect viewport, |
| 197 gfx::Rect clip, |
| 198 cc::CompositorFrame* frame) { |
| 199 DCHECK(CalledOnValidThread()); |
| 200 DCHECK(HasClient()); |
| 201 DCHECK(context_provider_); |
| 202 |
| 203 base::AutoReset<cc::CompositorFrame*> frame_resetter(&frame_, frame); |
| 204 surface_size_ = gfx::Size(viewport.width(), viewport.height()); |
| 205 SetExternalStencilTest(false); |
| 206 InvokeComposite(transform, viewport, clip, true); |
| 207 |
| 208 return did_swap_buffer_; |
| 209 } |
| 210 |
| 211 bool SynchronousCompositorOutputSurface::DemandDrawSw( |
| 212 SkCanvas* canvas, |
| 213 cc::CompositorFrame* frame) { |
| 204 DCHECK(CalledOnValidThread()); | 214 DCHECK(CalledOnValidThread()); |
| 205 DCHECK(canvas); | 215 DCHECK(canvas); |
| 206 DCHECK(!current_sw_canvas_); | 216 DCHECK(!current_sw_canvas_); |
| 217 base::AutoReset<cc::CompositorFrame*> frame_resetter(&frame_, frame); |
| 207 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); | 218 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); |
| 208 | 219 |
| 209 SkIRect canvas_clip; | 220 SkIRect canvas_clip; |
| 210 canvas->getClipDeviceBounds(&canvas_clip); | 221 canvas->getClipDeviceBounds(&canvas_clip); |
| 211 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); | 222 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); |
| 212 | 223 |
| 213 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 224 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
| 214 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. | 225 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. |
| 215 | 226 |
| 216 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), | 227 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 262 } |
| 252 | 263 |
| 253 if (did_swap_buffer_) | 264 if (did_swap_buffer_) |
| 254 client_->DidSwapBuffersComplete(); | 265 client_->DidSwapBuffersComplete(); |
| 255 | 266 |
| 256 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | 267 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
| 257 if (delegate) | 268 if (delegate) |
| 258 delegate->SetContinuousInvalidate(needs_begin_frame_); | 269 delegate->SetContinuousInvalidate(needs_begin_frame_); |
| 259 } | 270 } |
| 260 | 271 |
| 272 void SynchronousCompositorOutputSurface::ReturnResources( |
| 273 const cc::CompositorFrameAck* frame_ack) { |
| 274 DCHECK(frame_ack); |
| 275 ReclaimResources(frame_ack); |
| 276 } |
| 277 |
| 261 void SynchronousCompositorOutputSurface::SetMemoryPolicy( | 278 void SynchronousCompositorOutputSurface::SetMemoryPolicy( |
| 262 const SynchronousCompositorMemoryPolicy& policy) { | 279 const SynchronousCompositorMemoryPolicy& policy) { |
| 263 DCHECK(CalledOnValidThread()); | 280 DCHECK(CalledOnValidThread()); |
| 264 memory_policy_.bytes_limit_when_visible = policy.bytes_limit; | 281 memory_policy_.bytes_limit_when_visible = policy.bytes_limit; |
| 265 memory_policy_.num_resources_limit = policy.num_resources_limit; | 282 memory_policy_.num_resources_limit = policy.num_resources_limit; |
| 266 | 283 |
| 267 if (output_surface_client_) | 284 if (output_surface_client_) |
| 268 output_surface_client_->SetMemoryPolicy(memory_policy_); | 285 output_surface_client_->SetMemoryPolicy(memory_policy_); |
| 269 } | 286 } |
| 270 | 287 |
| 271 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 288 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| 272 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI | 289 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI |
| 273 // thread. | 290 // thread. |
| 274 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 291 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 275 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 292 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 276 } | 293 } |
| 277 | 294 |
| 278 SynchronousCompositorOutputSurfaceDelegate* | 295 SynchronousCompositorOutputSurfaceDelegate* |
| 279 SynchronousCompositorOutputSurface::GetDelegate() { | 296 SynchronousCompositorOutputSurface::GetDelegate() { |
| 280 return SynchronousCompositorImpl::FromRoutingID(routing_id_); | 297 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
| 281 } | 298 } |
| 282 | 299 |
| 283 } // namespace content | 300 } // namespace content |
| OLD | NEW |