| 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/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
| 10 #include "cc/output/context_provider.h" | 10 #include "cc/output/context_provider.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( | 67 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( |
| 68 int routing_id, | 68 int routing_id, |
| 69 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) | 69 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) |
| 70 : cc::OutputSurface( | 70 : cc::OutputSurface( |
| 71 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), | 71 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), |
| 72 routing_id_(routing_id), | 72 routing_id_(routing_id), |
| 73 registered_(false), | 73 registered_(false), |
| 74 current_sw_canvas_(nullptr), | 74 current_sw_canvas_(nullptr), |
| 75 memory_policy_(0), | 75 memory_policy_(0), |
| 76 output_surface_client_(nullptr), | 76 frame_swap_message_queue_(frame_swap_message_queue) { |
| 77 frame_swap_message_queue_(frame_swap_message_queue), | |
| 78 begin_frame_source_(nullptr) { | |
| 79 capabilities_.deferred_gl_initialization = true; | 77 capabilities_.deferred_gl_initialization = true; |
| 80 capabilities_.draw_and_swap_full_viewport_every_frame = true; | 78 capabilities_.draw_and_swap_full_viewport_every_frame = true; |
| 81 capabilities_.adjust_deadline_for_parent = false; | 79 capabilities_.adjust_deadline_for_parent = false; |
| 82 capabilities_.delegated_rendering = true; | 80 capabilities_.delegated_rendering = true; |
| 83 capabilities_.max_frames_pending = 1; | 81 capabilities_.max_frames_pending = 1; |
| 84 memory_policy_.priority_cutoff_when_visible = | 82 memory_policy_.priority_cutoff_when_visible = |
| 85 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; | 83 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
| 86 } | 84 } |
| 87 | 85 |
| 88 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { | 86 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { |
| 89 DCHECK(CalledOnValidThread()); | 87 DCHECK(CalledOnValidThread()); |
| 90 if (registered_) { | 88 if (registered_) { |
| 91 SynchronousCompositorRegistry::GetInstance()->UnregisterOutputSurface( | 89 SynchronousCompositorRegistry::GetInstance()->UnregisterOutputSurface( |
| 92 routing_id_, this); | 90 routing_id_, this); |
| 93 } | 91 } |
| 94 DCHECK(!begin_frame_source_); | |
| 95 } | 92 } |
| 96 | 93 |
| 97 bool SynchronousCompositorOutputSurface::BindToClient( | 94 bool SynchronousCompositorOutputSurface::BindToClient( |
| 98 cc::OutputSurfaceClient* surface_client) { | 95 cc::OutputSurfaceClient* surface_client) { |
| 99 DCHECK(CalledOnValidThread()); | 96 DCHECK(CalledOnValidThread()); |
| 100 if (!cc::OutputSurface::BindToClient(surface_client)) | 97 if (!cc::OutputSurface::BindToClient(surface_client)) |
| 101 return false; | 98 return false; |
| 102 | 99 |
| 103 output_surface_client_ = surface_client; | 100 client_->SetMemoryPolicy(memory_policy_); |
| 104 output_surface_client_->SetMemoryPolicy(memory_policy_); | |
| 105 | 101 |
| 106 SynchronousCompositorRegistry::GetInstance()->RegisterOutputSurface( | 102 SynchronousCompositorRegistry::GetInstance()->RegisterOutputSurface( |
| 107 routing_id_, this); | 103 routing_id_, this); |
| 108 registered_ = true; | 104 registered_ = true; |
| 109 | 105 |
| 110 return true; | 106 return true; |
| 111 } | 107 } |
| 112 | 108 |
| 113 void SynchronousCompositorOutputSurface::Reshape( | 109 void SynchronousCompositorOutputSurface::Reshape( |
| 114 const gfx::Size& size, float scale_factor) { | 110 const gfx::Size& size, float scale_factor) { |
| 115 // Intentional no-op: surface size is controlled by the embedder. | 111 // Intentional no-op: surface size is controlled by the embedder. |
| 116 } | 112 } |
| 117 | 113 |
| 118 void SynchronousCompositorOutputSurface::SwapBuffers( | 114 void SynchronousCompositorOutputSurface::SwapBuffers( |
| 119 cc::CompositorFrame* frame) { | 115 cc::CompositorFrame* frame) { |
| 120 DCHECK(CalledOnValidThread()); | 116 DCHECK(CalledOnValidThread()); |
| 121 | 117 |
| 122 frame_holder_.reset(new cc::CompositorFrame); | 118 frame_holder_.reset(new cc::CompositorFrame); |
| 123 frame->AssignTo(frame_holder_.get()); | 119 frame->AssignTo(frame_holder_.get()); |
| 124 | 120 |
| 125 client_->DidSwapBuffers(); | 121 client_->DidSwapBuffers(); |
| 126 } | 122 } |
| 127 | 123 |
| 128 void SynchronousCompositorOutputSurface::SetBeginFrameSource( | 124 void SynchronousCompositorOutputSurface::Invalidate() { |
| 129 SynchronousCompositorExternalBeginFrameSource* begin_frame_source) { | 125 DCHECK(CalledOnValidThread()); |
| 130 begin_frame_source_ = begin_frame_source; | 126 if (!invalidate_callback_.is_null()) |
| 127 invalidate_callback_.Run(); |
| 131 } | 128 } |
| 132 | 129 |
| 133 namespace { | 130 namespace { |
| 134 void AdjustTransform(gfx::Transform* transform, gfx::Rect viewport) { | 131 void AdjustTransform(gfx::Transform* transform, gfx::Rect viewport) { |
| 135 // CC's draw origin starts at the viewport. | 132 // CC's draw origin starts at the viewport. |
| 136 transform->matrix().postTranslate(-viewport.x(), -viewport.y(), 0); | 133 transform->matrix().postTranslate(-viewport.x(), -viewport.y(), 0); |
| 137 } | 134 } |
| 138 } // namespace | 135 } // namespace |
| 139 | 136 |
| 140 bool SynchronousCompositorOutputSurface::InitializeHwDraw( | 137 bool SynchronousCompositorOutputSurface::InitializeHwDraw( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 } | 202 } |
| 206 | 203 |
| 207 void SynchronousCompositorOutputSurface::InvokeComposite( | 204 void SynchronousCompositorOutputSurface::InvokeComposite( |
| 208 const gfx::Transform& transform, | 205 const gfx::Transform& transform, |
| 209 gfx::Rect viewport, | 206 gfx::Rect viewport, |
| 210 gfx::Rect clip, | 207 gfx::Rect clip, |
| 211 gfx::Rect viewport_rect_for_tile_priority, | 208 gfx::Rect viewport_rect_for_tile_priority, |
| 212 gfx::Transform transform_for_tile_priority, | 209 gfx::Transform transform_for_tile_priority, |
| 213 bool hardware_draw) { | 210 bool hardware_draw) { |
| 214 DCHECK(!frame_holder_.get()); | 211 DCHECK(!frame_holder_.get()); |
| 215 DCHECK(begin_frame_source_); | |
| 216 | 212 |
| 217 gfx::Transform adjusted_transform = transform; | 213 gfx::Transform adjusted_transform = transform; |
| 218 AdjustTransform(&adjusted_transform, viewport); | 214 AdjustTransform(&adjusted_transform, viewport); |
| 219 SetExternalDrawConstraints(adjusted_transform, | 215 SetExternalDrawConstraints(adjusted_transform, |
| 220 viewport, | 216 viewport, |
| 221 clip, | 217 clip, |
| 222 viewport_rect_for_tile_priority, | 218 viewport_rect_for_tile_priority, |
| 223 transform_for_tile_priority, | 219 transform_for_tile_priority, |
| 224 !hardware_draw); | 220 !hardware_draw); |
| 225 SetNeedsRedrawRect(gfx::Rect(viewport.size())); | 221 SetNeedsRedrawRect(gfx::Rect(viewport.size())); |
| 226 | 222 |
| 227 begin_frame_source_->BeginFrame(); | 223 client_->RequestDraw(); |
| 228 | 224 |
| 229 // After software draws (which might move the viewport arbitrarily), restore | 225 // After software draws (which might move the viewport arbitrarily), restore |
| 230 // the previous hardware viewport to allow CC's tile manager to prioritize | 226 // the previous hardware viewport to allow CC's tile manager to prioritize |
| 231 // properly. | 227 // properly. |
| 232 if (hardware_draw) { | 228 if (hardware_draw) { |
| 233 cached_hw_transform_ = adjusted_transform; | 229 cached_hw_transform_ = adjusted_transform; |
| 234 cached_hw_viewport_ = viewport; | 230 cached_hw_viewport_ = viewport; |
| 235 cached_hw_clip_ = clip; | 231 cached_hw_clip_ = clip; |
| 236 cached_hw_viewport_rect_for_tile_priority_ = | 232 cached_hw_viewport_rect_for_tile_priority_ = |
| 237 viewport_rect_for_tile_priority; | 233 viewport_rect_for_tile_priority; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 253 void SynchronousCompositorOutputSurface::ReturnResources( | 249 void SynchronousCompositorOutputSurface::ReturnResources( |
| 254 const cc::CompositorFrameAck& frame_ack) { | 250 const cc::CompositorFrameAck& frame_ack) { |
| 255 ReclaimResources(&frame_ack); | 251 ReclaimResources(&frame_ack); |
| 256 } | 252 } |
| 257 | 253 |
| 258 void SynchronousCompositorOutputSurface::SetMemoryPolicy(size_t bytes_limit) { | 254 void SynchronousCompositorOutputSurface::SetMemoryPolicy(size_t bytes_limit) { |
| 259 DCHECK(CalledOnValidThread()); | 255 DCHECK(CalledOnValidThread()); |
| 260 memory_policy_.bytes_limit_when_visible = bytes_limit; | 256 memory_policy_.bytes_limit_when_visible = bytes_limit; |
| 261 memory_policy_.num_resources_limit = kNumResourcesLimit; | 257 memory_policy_.num_resources_limit = kNumResourcesLimit; |
| 262 | 258 |
| 263 if (output_surface_client_) | 259 if (client_) |
| 264 output_surface_client_->SetMemoryPolicy(memory_policy_); | 260 client_->SetMemoryPolicy(memory_policy_); |
| 261 } |
| 262 |
| 263 void SynchronousCompositorOutputSurface::SetInvalidateCallback( |
| 264 const base::Closure& callback) { |
| 265 invalidate_callback_ = callback; |
| 265 } | 266 } |
| 266 | 267 |
| 267 void SynchronousCompositorOutputSurface::SetTreeActivationCallback( | 268 void SynchronousCompositorOutputSurface::SetTreeActivationCallback( |
| 268 const base::Closure& callback) { | 269 const base::Closure& callback) { |
| 269 DCHECK(client_); | 270 DCHECK(client_); |
| 270 client_->SetTreeActivationCallback(callback); | 271 client_->SetTreeActivationCallback(callback); |
| 271 } | 272 } |
| 272 | 273 |
| 273 void SynchronousCompositorOutputSurface::GetMessagesToDeliver( | 274 void SynchronousCompositorOutputSurface::GetMessagesToDeliver( |
| 274 ScopedVector<IPC::Message>* messages) { | 275 ScopedVector<IPC::Message>* messages) { |
| 275 DCHECK(CalledOnValidThread()); | 276 DCHECK(CalledOnValidThread()); |
| 276 scoped_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = | 277 scoped_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = |
| 277 frame_swap_message_queue_->AcquireSendMessageScope(); | 278 frame_swap_message_queue_->AcquireSendMessageScope(); |
| 278 frame_swap_message_queue_->DrainMessages(messages); | 279 frame_swap_message_queue_->DrainMessages(messages); |
| 279 } | 280 } |
| 280 | 281 |
| 281 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 282 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| 282 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI | 283 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI |
| 283 // thread. | 284 // thread. |
| 284 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 285 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 285 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 286 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 286 } | 287 } |
| 287 | 288 |
| 288 } // namespace content | 289 } // namespace content |
| OLD | NEW |