| 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" | |
| 10 #include "cc/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
| 11 #include "cc/output/context_provider.h" | 10 #include "cc/output/context_provider.h" |
| 12 #include "cc/output/output_surface_client.h" | 11 #include "cc/output/output_surface_client.h" |
| 13 #include "cc/output/software_output_device.h" | 12 #include "cc/output/software_output_device.h" |
| 13 #include "content/browser/android/in_process/synchronous_compositor_external_beg
in_frame_source.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/browser/gpu/compositor_util.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/renderer/gpu/frame_swap_message_queue.h" | 17 #include "content/renderer/gpu/frame_swap_message_queue.h" |
| 18 #include "gpu/command_buffer/client/gles2_interface.h" | 18 #include "gpu/command_buffer/client/gles2_interface.h" |
| 19 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 19 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
| 20 #include "third_party/skia/include/core/SkCanvas.h" | 20 #include "third_party/skia/include/core/SkCanvas.h" |
| 21 #include "ui/gfx/rect_conversions.h" | 21 #include "ui/gfx/rect_conversions.h" |
| 22 #include "ui/gfx/skia_util.h" | 22 #include "ui/gfx/skia_util.h" |
| 23 #include "ui/gfx/transform.h" | 23 #include "ui/gfx/transform.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); | 70 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( | 73 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( |
| 74 int routing_id, | 74 int routing_id, |
| 75 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) | 75 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) |
| 76 : cc::OutputSurface( | 76 : cc::OutputSurface( |
| 77 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), | 77 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), |
| 78 routing_id_(routing_id), | 78 routing_id_(routing_id), |
| 79 needs_begin_frame_(false), | |
| 80 invoking_composite_(false), | |
| 81 current_sw_canvas_(NULL), | 79 current_sw_canvas_(NULL), |
| 82 memory_policy_(0), | 80 memory_policy_(0), |
| 83 output_surface_client_(NULL), | 81 output_surface_client_(NULL), |
| 84 frame_swap_message_queue_(frame_swap_message_queue) { | 82 frame_swap_message_queue_(frame_swap_message_queue) { |
| 85 capabilities_.deferred_gl_initialization = true; | 83 capabilities_.deferred_gl_initialization = true; |
| 86 capabilities_.draw_and_swap_full_viewport_every_frame = true; | 84 capabilities_.draw_and_swap_full_viewport_every_frame = true; |
| 87 capabilities_.adjust_deadline_for_parent = false; | 85 capabilities_.adjust_deadline_for_parent = false; |
| 88 capabilities_.delegated_rendering = true; | 86 capabilities_.delegated_rendering = true; |
| 89 capabilities_.max_frames_pending = 1; | 87 capabilities_.max_frames_pending = 1; |
| 90 // Cannot call out to GetDelegate() here as the output surface is not | 88 // Cannot call out to GetDelegate() here as the output surface is not |
| (...skipping 26 matching lines...) Expand all Loading... |
| 117 delegate->DidBindOutputSurface(this); | 115 delegate->DidBindOutputSurface(this); |
| 118 | 116 |
| 119 return true; | 117 return true; |
| 120 } | 118 } |
| 121 | 119 |
| 122 void SynchronousCompositorOutputSurface::Reshape( | 120 void SynchronousCompositorOutputSurface::Reshape( |
| 123 const gfx::Size& size, float scale_factor) { | 121 const gfx::Size& size, float scale_factor) { |
| 124 // Intentional no-op: surface size is controlled by the embedder. | 122 // Intentional no-op: surface size is controlled by the embedder. |
| 125 } | 123 } |
| 126 | 124 |
| 127 void SynchronousCompositorOutputSurface::SetNeedsBeginFrame(bool enable) { | |
| 128 DCHECK(CalledOnValidThread()); | |
| 129 needs_begin_frame_ = enable; | |
| 130 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | |
| 131 if (delegate && !invoking_composite_) | |
| 132 delegate->SetContinuousInvalidate(needs_begin_frame_); | |
| 133 } | |
| 134 | |
| 135 void SynchronousCompositorOutputSurface::SwapBuffers( | 125 void SynchronousCompositorOutputSurface::SwapBuffers( |
| 136 cc::CompositorFrame* frame) { | 126 cc::CompositorFrame* frame) { |
| 137 DCHECK(CalledOnValidThread()); | 127 DCHECK(CalledOnValidThread()); |
| 138 | 128 |
| 139 frame_holder_.reset(new cc::CompositorFrame); | 129 frame_holder_.reset(new cc::CompositorFrame); |
| 140 frame->AssignTo(frame_holder_.get()); | 130 frame->AssignTo(frame_holder_.get()); |
| 141 | 131 |
| 142 client_->DidSwapBuffers(); | 132 client_->DidSwapBuffers(); |
| 143 } | 133 } |
| 144 | 134 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 return frame_holder_.Pass(); | 206 return frame_holder_.Pass(); |
| 217 } | 207 } |
| 218 | 208 |
| 219 void SynchronousCompositorOutputSurface::InvokeComposite( | 209 void SynchronousCompositorOutputSurface::InvokeComposite( |
| 220 const gfx::Transform& transform, | 210 const gfx::Transform& transform, |
| 221 gfx::Rect viewport, | 211 gfx::Rect viewport, |
| 222 gfx::Rect clip, | 212 gfx::Rect clip, |
| 223 gfx::Rect viewport_rect_for_tile_priority, | 213 gfx::Rect viewport_rect_for_tile_priority, |
| 224 gfx::Transform transform_for_tile_priority, | 214 gfx::Transform transform_for_tile_priority, |
| 225 bool hardware_draw) { | 215 bool hardware_draw) { |
| 226 DCHECK(!invoking_composite_); | |
| 227 DCHECK(!frame_holder_.get()); | 216 DCHECK(!frame_holder_.get()); |
| 228 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, true); | 217 DCHECK(begin_frame_source_); |
| 229 | 218 |
| 230 gfx::Transform adjusted_transform = transform; | 219 gfx::Transform adjusted_transform = transform; |
| 231 AdjustTransform(&adjusted_transform, viewport); | 220 AdjustTransform(&adjusted_transform, viewport); |
| 232 SetExternalDrawConstraints(adjusted_transform, | 221 SetExternalDrawConstraints(adjusted_transform, |
| 233 viewport, | 222 viewport, |
| 234 clip, | 223 clip, |
| 235 viewport_rect_for_tile_priority, | 224 viewport_rect_for_tile_priority, |
| 236 transform_for_tile_priority, | 225 transform_for_tile_priority, |
| 237 !hardware_draw); | 226 !hardware_draw); |
| 238 SetNeedsRedrawRect(gfx::Rect(viewport.size())); | 227 SetNeedsRedrawRect(gfx::Rect(viewport.size())); |
| 239 client_->BeginFrame(cc::BeginFrameArgs::CreateForSynchronousCompositor()); | 228 |
| 229 begin_frame_source_->BeginFrame(); |
| 240 | 230 |
| 241 // After software draws (which might move the viewport arbitrarily), restore | 231 // After software draws (which might move the viewport arbitrarily), restore |
| 242 // the previous hardware viewport to allow CC's tile manager to prioritize | 232 // the previous hardware viewport to allow CC's tile manager to prioritize |
| 243 // properly. | 233 // properly. |
| 244 if (hardware_draw) { | 234 if (hardware_draw) { |
| 245 cached_hw_transform_ = adjusted_transform; | 235 cached_hw_transform_ = adjusted_transform; |
| 246 cached_hw_viewport_ = viewport; | 236 cached_hw_viewport_ = viewport; |
| 247 cached_hw_clip_ = clip; | 237 cached_hw_clip_ = clip; |
| 248 cached_hw_viewport_rect_for_tile_priority_ = | 238 cached_hw_viewport_rect_for_tile_priority_ = |
| 249 viewport_rect_for_tile_priority; | 239 viewport_rect_for_tile_priority; |
| 250 cached_hw_transform_for_tile_priority_ = transform_for_tile_priority; | 240 cached_hw_transform_for_tile_priority_ = transform_for_tile_priority; |
| 251 } else { | 241 } else { |
| 252 bool resourceless_software_draw = false; | 242 bool resourceless_software_draw = false; |
| 253 SetExternalDrawConstraints(cached_hw_transform_, | 243 SetExternalDrawConstraints(cached_hw_transform_, |
| 254 cached_hw_viewport_, | 244 cached_hw_viewport_, |
| 255 cached_hw_clip_, | 245 cached_hw_clip_, |
| 256 cached_hw_viewport_rect_for_tile_priority_, | 246 cached_hw_viewport_rect_for_tile_priority_, |
| 257 cached_hw_transform_for_tile_priority_, | 247 cached_hw_transform_for_tile_priority_, |
| 258 resourceless_software_draw); | 248 resourceless_software_draw); |
| 259 } | 249 } |
| 260 | 250 |
| 261 if (frame_holder_.get()) | 251 if (frame_holder_.get()) |
| 262 client_->DidSwapBuffersComplete(); | 252 client_->DidSwapBuffersComplete(); |
| 263 | |
| 264 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | |
| 265 if (delegate) | |
| 266 delegate->SetContinuousInvalidate(needs_begin_frame_); | |
| 267 } | 253 } |
| 268 | 254 |
| 269 void SynchronousCompositorOutputSurface::ReturnResources( | 255 void SynchronousCompositorOutputSurface::ReturnResources( |
| 270 const cc::CompositorFrameAck& frame_ack) { | 256 const cc::CompositorFrameAck& frame_ack) { |
| 271 ReclaimResources(&frame_ack); | 257 ReclaimResources(&frame_ack); |
| 272 } | 258 } |
| 273 | 259 |
| 274 void SynchronousCompositorOutputSurface::SetMemoryPolicy(size_t bytes_limit) { | 260 void SynchronousCompositorOutputSurface::SetMemoryPolicy(size_t bytes_limit) { |
| 275 DCHECK(CalledOnValidThread()); | 261 DCHECK(CalledOnValidThread()); |
| 276 memory_policy_.bytes_limit_when_visible = bytes_limit; | 262 memory_policy_.bytes_limit_when_visible = bytes_limit; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 294 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 280 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 295 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 281 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 296 } | 282 } |
| 297 | 283 |
| 298 SynchronousCompositorOutputSurfaceDelegate* | 284 SynchronousCompositorOutputSurfaceDelegate* |
| 299 SynchronousCompositorOutputSurface::GetDelegate() { | 285 SynchronousCompositorOutputSurface::GetDelegate() { |
| 300 return SynchronousCompositorImpl::FromRoutingID(routing_id_); | 286 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
| 301 } | 287 } |
| 302 | 288 |
| 303 } // namespace content | 289 } // namespace content |
| OLD | NEW |