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 <vector> | |
| 8 | |
| 7 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "cc/output/compositor_frame.h" | 12 #include "cc/output/compositor_frame.h" |
| 11 #include "cc/output/context_provider.h" | 13 #include "cc/output/context_provider.h" |
| 12 #include "cc/output/output_surface_client.h" | 14 #include "cc/output/output_surface_client.h" |
| 13 #include "cc/output/software_output_device.h" | 15 #include "cc/output/software_output_device.h" |
| 14 #include "content/common/android/sync_compositor_messages.h" | 16 #include "content/common/android/sync_compositor_messages.h" |
| 15 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s ource.h" | 17 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s ource.h" |
| 16 #include "content/renderer/android/synchronous_compositor_filter.h" | 18 #include "content/renderer/android/synchronous_compositor_filter.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 return handled; | 120 return handled; |
| 119 } | 121 } |
| 120 | 122 |
| 121 bool SynchronousCompositorOutputSurface::BindToClient( | 123 bool SynchronousCompositorOutputSurface::BindToClient( |
| 122 cc::OutputSurfaceClient* surface_client) { | 124 cc::OutputSurfaceClient* surface_client) { |
| 123 DCHECK(CalledOnValidThread()); | 125 DCHECK(CalledOnValidThread()); |
| 124 if (!cc::OutputSurface::BindToClient(surface_client)) | 126 if (!cc::OutputSurface::BindToClient(surface_client)) |
| 125 return false; | 127 return false; |
| 126 | 128 |
| 127 client_->SetMemoryPolicy(memory_policy_); | 129 client_->SetMemoryPolicy(memory_policy_); |
| 130 client_->SetTreeActivationCallback( | |
| 131 base::Bind(&SynchronousCompositorOutputSurface::DidActivatePendingTree, | |
| 132 base::Unretained(this))); | |
| 128 registry_->RegisterOutputSurface(routing_id_, this); | 133 registry_->RegisterOutputSurface(routing_id_, this); |
| 129 registered_ = true; | 134 registered_ = true; |
| 130 Send(new SyncCompositorHostMsg_OutputSurfaceCreated(routing_id_)); | 135 Send(new SyncCompositorHostMsg_OutputSurfaceCreated(routing_id_)); |
| 131 return true; | 136 return true; |
| 132 } | 137 } |
| 133 | 138 |
| 134 void SynchronousCompositorOutputSurface::DetachFromClient() { | 139 void SynchronousCompositorOutputSurface::DetachFromClient() { |
| 135 DCHECK(CalledOnValidThread()); | 140 DCHECK(CalledOnValidThread()); |
| 136 if (registered_) { | 141 if (registered_) { |
| 137 registry_->UnregisterOutputSurface(routing_id_, this); | 142 registry_->UnregisterOutputSurface(routing_id_, this); |
| 138 } | 143 } |
| 144 client_->SetTreeActivationCallback(base::Closure()); | |
|
boliu
2016/05/13 22:40:20
added this line
| |
| 139 cc::OutputSurface::DetachFromClient(); | 145 cc::OutputSurface::DetachFromClient(); |
| 140 CancelFallbackTick(); | 146 CancelFallbackTick(); |
| 141 } | 147 } |
| 142 | 148 |
| 143 void SynchronousCompositorOutputSurface::Reshape(const gfx::Size& size, | 149 void SynchronousCompositorOutputSurface::Reshape(const gfx::Size& size, |
| 144 float scale_factor, | 150 float scale_factor, |
| 145 bool has_alpha) { | 151 bool has_alpha) { |
| 146 // Intentional no-op: surface size is controlled by the embedder. | 152 // Intentional no-op: surface size is controlled by the embedder. |
| 147 } | 153 } |
| 148 | 154 |
| 149 void SynchronousCompositorOutputSurface::SwapBuffers( | 155 void SynchronousCompositorOutputSurface::SwapBuffers( |
| 150 cc::CompositorFrame* frame) { | 156 cc::CompositorFrame* frame) { |
| 151 DCHECK(CalledOnValidThread()); | 157 DCHECK(CalledOnValidThread()); |
| 152 DCHECK(sync_client_); | 158 DCHECK(sync_client_); |
| 153 if (!fallback_tick_running_) | 159 if (!fallback_tick_running_) { |
| 154 sync_client_->SwapBuffers(output_surface_id_, frame); | 160 sync_client_->SwapBuffers(output_surface_id_, frame); |
| 161 DeliverMessages(); | |
| 162 } | |
| 155 client_->DidSwapBuffers(); | 163 client_->DidSwapBuffers(); |
| 156 did_swap_ = true; | 164 did_swap_ = true; |
| 157 } | 165 } |
| 158 | 166 |
| 159 void SynchronousCompositorOutputSurface::CancelFallbackTick() { | 167 void SynchronousCompositorOutputSurface::CancelFallbackTick() { |
| 160 fallback_tick_.Cancel(); | 168 fallback_tick_.Cancel(); |
| 161 fallback_tick_pending_ = false; | 169 fallback_tick_pending_ = false; |
| 162 } | 170 } |
| 163 | 171 |
| 164 void SynchronousCompositorOutputSurface::FallbackTickFired() { | 172 void SynchronousCompositorOutputSurface::FallbackTickFired() { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 // This is small hack to drop context resources without destroying it | 277 // This is small hack to drop context resources without destroying it |
| 270 // when this compositor is put into the background. | 278 // when this compositor is put into the background. |
| 271 context_provider()->ContextSupport()->SetAggressivelyFreeResources( | 279 context_provider()->ContextSupport()->SetAggressivelyFreeResources( |
| 272 true /* aggressively_free_resources */); | 280 true /* aggressively_free_resources */); |
| 273 } else if (became_non_zero) { | 281 } else if (became_non_zero) { |
| 274 context_provider()->ContextSupport()->SetAggressivelyFreeResources( | 282 context_provider()->ContextSupport()->SetAggressivelyFreeResources( |
| 275 false /* aggressively_free_resources */); | 283 false /* aggressively_free_resources */); |
| 276 } | 284 } |
| 277 } | 285 } |
| 278 | 286 |
| 279 void SynchronousCompositorOutputSurface::SetTreeActivationCallback( | 287 void SynchronousCompositorOutputSurface::DidActivatePendingTree() { |
| 280 const base::Closure& callback) { | 288 DCHECK(CalledOnValidThread()); |
| 281 DCHECK(client_); | 289 if (sync_client_) |
| 282 client_->SetTreeActivationCallback(callback); | 290 sync_client_->DidActivatePendingTree(); |
| 291 DeliverMessages(); | |
| 283 } | 292 } |
| 284 | 293 |
| 285 void SynchronousCompositorOutputSurface::GetMessagesToDeliver( | 294 void SynchronousCompositorOutputSurface::DeliverMessages() { |
| 286 std::vector<std::unique_ptr<IPC::Message>>* messages) { | 295 std::vector<std::unique_ptr<IPC::Message>> messages; |
| 287 DCHECK(CalledOnValidThread()); | |
| 288 std::unique_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = | 296 std::unique_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = |
| 289 frame_swap_message_queue_->AcquireSendMessageScope(); | 297 frame_swap_message_queue_->AcquireSendMessageScope(); |
| 290 frame_swap_message_queue_->DrainMessages(messages); | 298 frame_swap_message_queue_->DrainMessages(&messages); |
| 299 for (auto& msg : messages) { | |
| 300 Send(msg.release()); | |
| 301 } | |
| 291 } | 302 } |
| 292 | 303 |
| 293 bool SynchronousCompositorOutputSurface::Send(IPC::Message* message) { | 304 bool SynchronousCompositorOutputSurface::Send(IPC::Message* message) { |
| 294 DCHECK(CalledOnValidThread()); | 305 DCHECK(CalledOnValidThread()); |
| 295 return sender_->Send(message); | 306 return sender_->Send(message); |
| 296 } | 307 } |
| 297 | 308 |
| 298 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 309 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 299 return thread_checker_.CalledOnValidThread(); | 310 return thread_checker_.CalledOnValidThread(); |
| 300 } | 311 } |
| 301 | 312 |
| 302 } // namespace content | 313 } // namespace content |
| OLD | NEW |