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