Chromium Code Reviews| 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 "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
| 11 #include "cc/output/context_provider.h" | 11 #include "cc/output/context_provider.h" |
| 12 #include "cc/output/output_surface_client.h" | 12 #include "cc/output/output_surface_client.h" |
| 13 #include "cc/output/software_output_device.h" | 13 #include "cc/output/software_output_device.h" |
| 14 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s ource.h" | 14 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s ource.h" |
| 15 #include "content/renderer/android/synchronous_compositor_registry.h" | 15 #include "content/renderer/android/synchronous_compositor_registry.h" |
| 16 #include "content/renderer/gpu/frame_swap_message_queue.h" | 16 #include "content/renderer/gpu/frame_swap_message_queue.h" |
| 17 #include "gpu/command_buffer/client/context_support.h" | 17 #include "gpu/command_buffer/client/context_support.h" |
| 18 #include "gpu/command_buffer/client/gles2_interface.h" | 18 #include "gpu/command_buffer/client/gles2_interface.h" |
| 19 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 19 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
| 20 #include "third_party/skia/include/core/SkCanvas.h" | 20 #include "third_party/skia/include/core/SkCanvas.h" |
| 21 #include "ui/gfx/geometry/rect_conversions.h" | 21 #include "ui/gfx/geometry/rect_conversions.h" |
| 22 #include "ui/gfx/skia_util.h" | 22 #include "ui/gfx/skia_util.h" |
| 23 #include "ui/gfx/transform.h" | 23 #include "ui/gfx/transform.h" |
| 24 | 24 |
| 25 namespace content { | 25 namespace content { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 const int64_t kFallbackTickTimeoutInMilliseconds = 100; | |
| 30 | |
| 29 // Do not limit number of resources, so use an unrealistically high value. | 31 // Do not limit number of resources, so use an unrealistically high value. |
| 30 const size_t kNumResourcesLimit = 10 * 1000 * 1000; | 32 const size_t kNumResourcesLimit = 10 * 1000 * 1000; |
| 31 | 33 |
| 32 } // namespace | 34 } // namespace |
| 33 | 35 |
| 34 class SynchronousCompositorOutputSurface::SoftwareDevice | 36 class SynchronousCompositorOutputSurface::SoftwareDevice |
| 35 : public cc::SoftwareOutputDevice { | 37 : public cc::SoftwareOutputDevice { |
| 36 public: | 38 public: |
| 37 SoftwareDevice(SynchronousCompositorOutputSurface* surface) | 39 SoftwareDevice(SynchronousCompositorOutputSurface* surface) |
| 38 : surface_(surface) { | 40 : surface_(surface) { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 68 context_provider, | 70 context_provider, |
| 69 worker_context_provider, | 71 worker_context_provider, |
| 70 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), | 72 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), |
| 71 routing_id_(routing_id), | 73 routing_id_(routing_id), |
| 72 registry_(registry), | 74 registry_(registry), |
| 73 registered_(false), | 75 registered_(false), |
| 74 sync_client_(nullptr), | 76 sync_client_(nullptr), |
| 75 current_sw_canvas_(nullptr), | 77 current_sw_canvas_(nullptr), |
| 76 memory_policy_(0u), | 78 memory_policy_(0u), |
| 77 did_swap_(false), | 79 did_swap_(false), |
| 78 frame_swap_message_queue_(frame_swap_message_queue) { | 80 frame_swap_message_queue_(frame_swap_message_queue), |
| 81 fallback_tick_pending_(false), | |
| 82 fallback_tick_running_(false) { | |
| 79 thread_checker_.DetachFromThread(); | 83 thread_checker_.DetachFromThread(); |
| 80 DCHECK(registry_); | 84 DCHECK(registry_); |
| 81 capabilities_.adjust_deadline_for_parent = false; | 85 capabilities_.adjust_deadline_for_parent = false; |
| 82 capabilities_.delegated_rendering = true; | 86 capabilities_.delegated_rendering = true; |
| 83 memory_policy_.priority_cutoff_when_visible = | 87 memory_policy_.priority_cutoff_when_visible = |
| 84 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; | 88 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
| 85 } | 89 } |
| 86 | 90 |
| 87 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() {} | 91 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() {} |
| 88 | 92 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 108 registered_ = true; | 112 registered_ = true; |
| 109 return true; | 113 return true; |
| 110 } | 114 } |
| 111 | 115 |
| 112 void SynchronousCompositorOutputSurface::DetachFromClient() { | 116 void SynchronousCompositorOutputSurface::DetachFromClient() { |
| 113 DCHECK(CalledOnValidThread()); | 117 DCHECK(CalledOnValidThread()); |
| 114 if (registered_) { | 118 if (registered_) { |
| 115 registry_->UnregisterOutputSurface(routing_id_, this); | 119 registry_->UnregisterOutputSurface(routing_id_, this); |
| 116 } | 120 } |
| 117 cc::OutputSurface::DetachFromClient(); | 121 cc::OutputSurface::DetachFromClient(); |
| 122 fallback_tick_.Cancel(); | |
| 123 fallback_tick_pending_ = false; | |
|
boliu
2016/03/16 19:05:57
This Cancel + pending_ = false pattern is repeated
| |
| 118 } | 124 } |
| 119 | 125 |
| 120 void SynchronousCompositorOutputSurface::Reshape(const gfx::Size& size, | 126 void SynchronousCompositorOutputSurface::Reshape(const gfx::Size& size, |
| 121 float scale_factor, | 127 float scale_factor, |
| 122 bool has_alpha) { | 128 bool has_alpha) { |
| 123 // Intentional no-op: surface size is controlled by the embedder. | 129 // Intentional no-op: surface size is controlled by the embedder. |
| 124 } | 130 } |
| 125 | 131 |
| 126 void SynchronousCompositorOutputSurface::SwapBuffers( | 132 void SynchronousCompositorOutputSurface::SwapBuffers( |
| 127 cc::CompositorFrame* frame) { | 133 cc::CompositorFrame* frame) { |
| 128 DCHECK(CalledOnValidThread()); | 134 DCHECK(CalledOnValidThread()); |
| 129 DCHECK(sync_client_); | 135 DCHECK(sync_client_); |
| 130 sync_client_->SwapBuffers(frame); | 136 if (!fallback_tick_running_) |
| 137 sync_client_->SwapBuffers(frame); | |
| 131 client_->DidSwapBuffers(); | 138 client_->DidSwapBuffers(); |
| 132 did_swap_ = true; | 139 did_swap_ = true; |
| 133 } | 140 } |
| 134 | 141 |
| 142 void SynchronousCompositorOutputSurface::FallbackTickFired() { | |
| 143 DCHECK(CalledOnValidThread()); | |
| 144 TRACE_EVENT0("renderer", | |
| 145 "SynchronousCompositorOutputSurface::FallbackTickFired"); | |
| 146 base::AutoReset<bool> in_fallback_tick(&fallback_tick_running_, true); | |
| 147 SkBitmap bitmap; | |
| 148 bitmap.allocN32Pixels(1, 1); | |
| 149 bitmap.eraseColor(0); | |
| 150 SkCanvas canvas(bitmap); | |
| 151 fallback_tick_pending_ = false; | |
| 152 DemandDrawSw(&canvas); | |
| 153 } | |
| 154 | |
| 135 void SynchronousCompositorOutputSurface::Invalidate() { | 155 void SynchronousCompositorOutputSurface::Invalidate() { |
| 136 DCHECK(CalledOnValidThread()); | 156 DCHECK(CalledOnValidThread()); |
| 137 if (sync_client_) | 157 if (sync_client_) |
| 138 sync_client_->Invalidate(); | 158 sync_client_->Invalidate(); |
| 159 | |
| 160 if (!fallback_tick_pending_) { | |
| 161 fallback_tick_.Reset( | |
| 162 base::Bind(&SynchronousCompositorOutputSurface::FallbackTickFired, | |
| 163 base::Unretained(this))); | |
| 164 base::MessageLoop::current()->PostDelayedTask( | |
| 165 FROM_HERE, fallback_tick_.callback(), | |
| 166 base::TimeDelta::FromMilliseconds(kFallbackTickTimeoutInMilliseconds)); | |
| 167 fallback_tick_pending_ = true; | |
| 168 } | |
| 139 } | 169 } |
| 140 | 170 |
| 141 void SynchronousCompositorOutputSurface::DemandDrawHw( | 171 void SynchronousCompositorOutputSurface::DemandDrawHw( |
| 142 const gfx::Size& surface_size, | 172 const gfx::Size& surface_size, |
| 143 const gfx::Transform& transform, | 173 const gfx::Transform& transform, |
| 144 const gfx::Rect& viewport, | 174 const gfx::Rect& viewport, |
| 145 const gfx::Rect& clip, | 175 const gfx::Rect& clip, |
| 146 const gfx::Rect& viewport_rect_for_tile_priority, | 176 const gfx::Rect& viewport_rect_for_tile_priority, |
| 147 const gfx::Transform& transform_for_tile_priority) { | 177 const gfx::Transform& transform_for_tile_priority) { |
| 148 DCHECK(CalledOnValidThread()); | 178 DCHECK(CalledOnValidThread()); |
| 149 DCHECK(HasClient()); | 179 DCHECK(HasClient()); |
| 150 DCHECK(context_provider_.get()); | 180 DCHECK(context_provider_.get()); |
| 181 fallback_tick_.Cancel(); | |
| 182 fallback_tick_pending_ = false; | |
| 151 | 183 |
| 152 surface_size_ = surface_size; | 184 surface_size_ = surface_size; |
| 153 client_->SetExternalTilePriorityConstraints(viewport_rect_for_tile_priority, | 185 client_->SetExternalTilePriorityConstraints(viewport_rect_for_tile_priority, |
| 154 transform_for_tile_priority); | 186 transform_for_tile_priority); |
| 155 const bool software_draw = false; | 187 const bool software_draw = false; |
| 156 InvokeComposite(transform, viewport, clip, software_draw); | 188 InvokeComposite(transform, viewport, clip, software_draw); |
| 157 } | 189 } |
| 158 | 190 |
| 159 void SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | 191 void SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
| 160 DCHECK(CalledOnValidThread()); | 192 DCHECK(CalledOnValidThread()); |
| 161 DCHECK(canvas); | 193 DCHECK(canvas); |
| 162 DCHECK(!current_sw_canvas_); | 194 DCHECK(!current_sw_canvas_); |
| 195 fallback_tick_.Cancel(); | |
| 196 fallback_tick_pending_ = false; | |
| 163 | 197 |
| 164 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); | 198 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); |
| 165 | 199 |
| 166 SkIRect canvas_clip; | 200 SkIRect canvas_clip; |
| 167 canvas->getClipDeviceBounds(&canvas_clip); | 201 canvas->getClipDeviceBounds(&canvas_clip); |
| 168 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); | 202 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); |
| 169 | 203 |
| 170 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 204 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
| 171 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. | 205 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. |
| 172 | 206 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 scoped_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = | 263 scoped_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = |
| 230 frame_swap_message_queue_->AcquireSendMessageScope(); | 264 frame_swap_message_queue_->AcquireSendMessageScope(); |
| 231 frame_swap_message_queue_->DrainMessages(messages); | 265 frame_swap_message_queue_->DrainMessages(messages); |
| 232 } | 266 } |
| 233 | 267 |
| 234 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 268 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 235 return thread_checker_.CalledOnValidThread(); | 269 return thread_checker_.CalledOnValidThread(); |
| 236 } | 270 } |
| 237 | 271 |
| 238 } // namespace content | 272 } // namespace content |
| OLD | NEW |