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