| 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/renderer/android/synchronous_compositor_output_surface.h" | 5 #include "content/renderer/android/synchronous_compositor_output_surface.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 SynchronousCompositorRegistry* registry, | 64 SynchronousCompositorRegistry* registry, |
| 65 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) | 65 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) |
| 66 : cc::OutputSurface( | 66 : cc::OutputSurface( |
| 67 context_provider, | 67 context_provider, |
| 68 worker_context_provider, | 68 worker_context_provider, |
| 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 registry_(registry), | 71 registry_(registry), |
| 72 registered_(false), | 72 registered_(false), |
| 73 sync_client_(nullptr), | 73 sync_client_(nullptr), |
| 74 next_hardware_draw_needs_damage_(false), | |
| 75 current_sw_canvas_(nullptr), | 74 current_sw_canvas_(nullptr), |
| 76 memory_policy_(0u), | 75 memory_policy_(0u), |
| 77 frame_swap_message_queue_(frame_swap_message_queue) { | 76 frame_swap_message_queue_(frame_swap_message_queue) { |
| 78 thread_checker_.DetachFromThread(); | 77 thread_checker_.DetachFromThread(); |
| 79 DCHECK(registry_); | 78 DCHECK(registry_); |
| 80 capabilities_.adjust_deadline_for_parent = false; | 79 capabilities_.adjust_deadline_for_parent = false; |
| 81 capabilities_.delegated_rendering = true; | 80 capabilities_.delegated_rendering = true; |
| 82 memory_policy_.priority_cutoff_when_visible = | 81 memory_policy_.priority_cutoff_when_visible = |
| 83 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; | 82 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
| 84 } | 83 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 const gfx::Transform& transform, | 135 const gfx::Transform& transform, |
| 137 const gfx::Rect& viewport, | 136 const gfx::Rect& viewport, |
| 138 const gfx::Rect& clip, | 137 const gfx::Rect& clip, |
| 139 const gfx::Rect& viewport_rect_for_tile_priority, | 138 const gfx::Rect& viewport_rect_for_tile_priority, |
| 140 const gfx::Transform& transform_for_tile_priority) { | 139 const gfx::Transform& transform_for_tile_priority) { |
| 141 DCHECK(CalledOnValidThread()); | 140 DCHECK(CalledOnValidThread()); |
| 142 DCHECK(HasClient()); | 141 DCHECK(HasClient()); |
| 143 DCHECK(context_provider_.get()); | 142 DCHECK(context_provider_.get()); |
| 144 | 143 |
| 145 surface_size_ = surface_size; | 144 surface_size_ = surface_size; |
| 146 InvokeComposite(transform, viewport, clip, viewport_rect_for_tile_priority, | 145 client_->SetExternalTilePriorityConstraints(viewport_rect_for_tile_priority, |
| 147 transform_for_tile_priority, true); | 146 transform_for_tile_priority); |
| 147 const bool software_draw = false; |
| 148 InvokeComposite(transform, viewport, clip, software_draw); |
| 148 | 149 |
| 149 return frame_holder_.Pass(); | 150 return frame_holder_.Pass(); |
| 150 } | 151 } |
| 151 | 152 |
| 152 scoped_ptr<cc::CompositorFrame> | 153 scoped_ptr<cc::CompositorFrame> |
| 153 SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | 154 SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
| 154 DCHECK(CalledOnValidThread()); | 155 DCHECK(CalledOnValidThread()); |
| 155 DCHECK(canvas); | 156 DCHECK(canvas); |
| 156 DCHECK(!current_sw_canvas_); | 157 DCHECK(!current_sw_canvas_); |
| 157 | 158 |
| 158 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); | 159 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); |
| 159 | 160 |
| 160 SkIRect canvas_clip; | 161 SkIRect canvas_clip; |
| 161 canvas->getClipDeviceBounds(&canvas_clip); | 162 canvas->getClipDeviceBounds(&canvas_clip); |
| 162 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); | 163 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); |
| 163 | 164 |
| 164 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 165 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
| 165 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. | 166 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. |
| 166 | 167 |
| 167 surface_size_ = gfx::Size(canvas->getBaseLayerSize().width(), | 168 surface_size_ = gfx::Size(canvas->getBaseLayerSize().width(), |
| 168 canvas->getBaseLayerSize().height()); | 169 canvas->getBaseLayerSize().height()); |
| 169 | 170 const bool software_draw = true; |
| 170 // Pass in the cached hw viewport and transform for tile priority to avoid | 171 InvokeComposite(transform, clip, clip, software_draw); |
| 171 // tile thrashing when the WebView is alternating between hardware and | |
| 172 // software draws. | |
| 173 InvokeComposite(transform, | |
| 174 clip, | |
| 175 clip, | |
| 176 cached_hw_viewport_rect_for_tile_priority_, | |
| 177 cached_hw_transform_for_tile_priority_, | |
| 178 false); | |
| 179 | 172 |
| 180 return frame_holder_.Pass(); | 173 return frame_holder_.Pass(); |
| 181 } | 174 } |
| 182 | 175 |
| 183 void SynchronousCompositorOutputSurface::InvokeComposite( | 176 void SynchronousCompositorOutputSurface::InvokeComposite( |
| 184 const gfx::Transform& transform, | 177 const gfx::Transform& transform, |
| 185 const gfx::Rect& viewport, | 178 const gfx::Rect& viewport, |
| 186 const gfx::Rect& clip, | 179 const gfx::Rect& clip, |
| 187 const gfx::Rect& viewport_rect_for_tile_priority, | 180 bool software_draw) { |
| 188 const gfx::Transform& transform_for_tile_priority, | |
| 189 bool hardware_draw) { | |
| 190 DCHECK(!frame_holder_.get()); | 181 DCHECK(!frame_holder_.get()); |
| 191 | 182 |
| 192 gfx::Transform adjusted_transform = transform; | 183 gfx::Transform adjusted_transform = transform; |
| 193 adjusted_transform.matrix().postTranslate(-viewport.x(), -viewport.y(), 0); | 184 adjusted_transform.matrix().postTranslate(-viewport.x(), -viewport.y(), 0); |
| 194 SetExternalDrawConstraints(adjusted_transform, viewport, clip, | 185 client_->OnDraw(adjusted_transform, viewport, clip, software_draw); |
| 195 viewport_rect_for_tile_priority, | |
| 196 transform_for_tile_priority, !hardware_draw); | |
| 197 if (!hardware_draw || next_hardware_draw_needs_damage_) { | |
| 198 next_hardware_draw_needs_damage_ = false; | |
| 199 SetNeedsRedrawRect(gfx::Rect(viewport.size())); | |
| 200 } | |
| 201 | |
| 202 client_->OnDraw(); | |
| 203 | |
| 204 // After software draws (which might move the viewport arbitrarily), restore | |
| 205 // the previous hardware viewport to allow CC's tile manager to prioritize | |
| 206 // properly. | |
| 207 if (hardware_draw) { | |
| 208 cached_hw_transform_ = adjusted_transform; | |
| 209 cached_hw_viewport_ = viewport; | |
| 210 cached_hw_clip_ = clip; | |
| 211 cached_hw_viewport_rect_for_tile_priority_ = | |
| 212 viewport_rect_for_tile_priority; | |
| 213 cached_hw_transform_for_tile_priority_ = transform_for_tile_priority; | |
| 214 } else { | |
| 215 bool resourceless_software_draw = false; | |
| 216 SetExternalDrawConstraints(cached_hw_transform_, | |
| 217 cached_hw_viewport_, | |
| 218 cached_hw_clip_, | |
| 219 cached_hw_viewport_rect_for_tile_priority_, | |
| 220 cached_hw_transform_for_tile_priority_, | |
| 221 resourceless_software_draw); | |
| 222 // This draw may have reset all damage, which would lead to subsequent | |
| 223 // incorrect hardware draw, so explicitly set damage for next hardware | |
| 224 // draw as well. | |
| 225 next_hardware_draw_needs_damage_ = true; | |
| 226 } | |
| 227 | 186 |
| 228 if (frame_holder_.get()) | 187 if (frame_holder_.get()) |
| 229 client_->DidSwapBuffersComplete(); | 188 client_->DidSwapBuffersComplete(); |
| 230 } | 189 } |
| 231 | 190 |
| 232 void SynchronousCompositorOutputSurface::ReturnResources( | 191 void SynchronousCompositorOutputSurface::ReturnResources( |
| 233 const cc::CompositorFrameAck& frame_ack) { | 192 const cc::CompositorFrameAck& frame_ack) { |
| 234 ReclaimResources(&frame_ack); | 193 ReclaimResources(&frame_ack); |
| 235 } | 194 } |
| 236 | 195 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 scoped_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = | 227 scoped_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = |
| 269 frame_swap_message_queue_->AcquireSendMessageScope(); | 228 frame_swap_message_queue_->AcquireSendMessageScope(); |
| 270 frame_swap_message_queue_->DrainMessages(messages); | 229 frame_swap_message_queue_->DrainMessages(messages); |
| 271 } | 230 } |
| 272 | 231 |
| 273 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 232 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 274 return thread_checker_.CalledOnValidThread(); | 233 return thread_checker_.CalledOnValidThread(); |
| 275 } | 234 } |
| 276 | 235 |
| 277 } // namespace content | 236 } // namespace content |
| OLD | NEW |