| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 true); | 172 true); |
| 171 | 173 |
| 172 return frame_holder_.Pass(); | 174 return frame_holder_.Pass(); |
| 173 } | 175 } |
| 174 | 176 |
| 175 scoped_ptr<cc::CompositorFrame> | 177 scoped_ptr<cc::CompositorFrame> |
| 176 SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | 178 SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
| 177 DCHECK(CalledOnValidThread()); | 179 DCHECK(CalledOnValidThread()); |
| 178 DCHECK(canvas); | 180 DCHECK(canvas); |
| 179 DCHECK(!current_sw_canvas_); | 181 DCHECK(!current_sw_canvas_); |
| 182 |
| 180 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); | 183 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); |
| 181 | 184 |
| 182 SkIRect canvas_clip; | 185 SkIRect canvas_clip; |
| 183 canvas->getClipDeviceBounds(&canvas_clip); | 186 canvas->getClipDeviceBounds(&canvas_clip); |
| 184 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); | 187 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); |
| 185 | 188 |
| 186 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 189 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
| 187 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. | 190 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. |
| 188 | 191 |
| 189 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), | 192 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 203 } | 206 } |
| 204 | 207 |
| 205 void SynchronousCompositorOutputSurface::InvokeComposite( | 208 void SynchronousCompositorOutputSurface::InvokeComposite( |
| 206 const gfx::Transform& transform, | 209 const gfx::Transform& transform, |
| 207 gfx::Rect viewport, | 210 gfx::Rect viewport, |
| 208 gfx::Rect clip, | 211 gfx::Rect clip, |
| 209 gfx::Rect viewport_rect_for_tile_priority, | 212 gfx::Rect viewport_rect_for_tile_priority, |
| 210 gfx::Transform transform_for_tile_priority, | 213 gfx::Transform transform_for_tile_priority, |
| 211 bool hardware_draw) { | 214 bool hardware_draw) { |
| 212 DCHECK(!frame_holder_.get()); | 215 DCHECK(!frame_holder_.get()); |
| 213 DCHECK(begin_frame_source_); | 216 DCHECK(compositor_); |
| 214 | 217 |
| 215 gfx::Transform adjusted_transform = transform; | 218 gfx::Transform adjusted_transform = transform; |
| 216 AdjustTransform(&adjusted_transform, viewport); | 219 AdjustTransform(&adjusted_transform, viewport); |
| 217 SetExternalDrawConstraints(adjusted_transform, | 220 SetExternalDrawConstraints(adjusted_transform, |
| 218 viewport, | 221 viewport, |
| 219 clip, | 222 clip, |
| 220 viewport_rect_for_tile_priority, | 223 viewport_rect_for_tile_priority, |
| 221 transform_for_tile_priority, | 224 transform_for_tile_priority, |
| 222 !hardware_draw); | 225 !hardware_draw); |
| 223 SetNeedsRedrawRect(gfx::Rect(viewport.size())); | 226 SetNeedsRedrawRect(gfx::Rect(viewport.size())); |
| 224 | 227 |
| 225 begin_frame_source_->BeginFrame(); | 228 compositor_->SendBeginFrameOnDraw(); |
| 226 | 229 |
| 227 // After software draws (which might move the viewport arbitrarily), restore | 230 // After software draws (which might move the viewport arbitrarily), restore |
| 228 // the previous hardware viewport to allow CC's tile manager to prioritize | 231 // the previous hardware viewport to allow CC's tile manager to prioritize |
| 229 // properly. | 232 // properly. |
| 230 if (hardware_draw) { | 233 if (hardware_draw) { |
| 231 cached_hw_transform_ = adjusted_transform; | 234 cached_hw_transform_ = adjusted_transform; |
| 232 cached_hw_viewport_ = viewport; | 235 cached_hw_viewport_ = viewport; |
| 233 cached_hw_clip_ = clip; | 236 cached_hw_clip_ = clip; |
| 234 cached_hw_viewport_rect_for_tile_priority_ = | 237 cached_hw_viewport_rect_for_tile_priority_ = |
| 235 viewport_rect_for_tile_priority; | 238 viewport_rect_for_tile_priority; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 251 void SynchronousCompositorOutputSurface::ReturnResources( | 254 void SynchronousCompositorOutputSurface::ReturnResources( |
| 252 const cc::CompositorFrameAck& frame_ack) { | 255 const cc::CompositorFrameAck& frame_ack) { |
| 253 ReclaimResources(&frame_ack); | 256 ReclaimResources(&frame_ack); |
| 254 } | 257 } |
| 255 | 258 |
| 256 void SynchronousCompositorOutputSurface::SetMemoryPolicy(size_t bytes_limit) { | 259 void SynchronousCompositorOutputSurface::SetMemoryPolicy(size_t bytes_limit) { |
| 257 DCHECK(CalledOnValidThread()); | 260 DCHECK(CalledOnValidThread()); |
| 258 memory_policy_.bytes_limit_when_visible = bytes_limit; | 261 memory_policy_.bytes_limit_when_visible = bytes_limit; |
| 259 memory_policy_.num_resources_limit = kNumResourcesLimit; | 262 memory_policy_.num_resources_limit = kNumResourcesLimit; |
| 260 | 263 |
| 261 if (output_surface_client_) | 264 if (client_) |
| 262 output_surface_client_->SetMemoryPolicy(memory_policy_); | 265 client_->SetMemoryPolicy(memory_policy_); |
| 263 } | 266 } |
| 264 | 267 |
| 265 void SynchronousCompositorOutputSurface::SetTreeActivationCallback( | 268 void SynchronousCompositorOutputSurface::SetTreeActivationCallback( |
| 266 const base::Closure& callback) { | 269 const base::Closure& callback) { |
| 267 DCHECK(client_); | 270 DCHECK(client_); |
| 268 client_->SetTreeActivationCallback(callback); | 271 client_->SetTreeActivationCallback(callback); |
| 269 } | 272 } |
| 270 | 273 |
| 271 void SynchronousCompositorOutputSurface::GetMessagesToDeliver( | 274 void SynchronousCompositorOutputSurface::GetMessagesToDeliver( |
| 272 ScopedVector<IPC::Message>* messages) { | 275 ScopedVector<IPC::Message>* messages) { |
| 273 DCHECK(CalledOnValidThread()); | 276 DCHECK(CalledOnValidThread()); |
| 274 scoped_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = | 277 scoped_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = |
| 275 frame_swap_message_queue_->AcquireSendMessageScope(); | 278 frame_swap_message_queue_->AcquireSendMessageScope(); |
| 276 frame_swap_message_queue_->DrainMessages(messages); | 279 frame_swap_message_queue_->DrainMessages(messages); |
| 277 } | 280 } |
| 278 | 281 |
| 279 // 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 |
| 280 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI | 283 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI |
| 281 // thread. | 284 // thread. |
| 282 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 285 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 283 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 286 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 284 } | 287 } |
| 285 | 288 |
| 286 } // namespace content | 289 } // namespace content |
| OLD | NEW |