| 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/begin_frame_args.h" | 9 #include "cc/output/begin_frame_args.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/browser/android/in_process/synchronous_compositor_impl.h" | 14 #include "content/browser/android/in_process/synchronous_compositor_impl.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/renderer/gpu/frame_swap_message_queue.h" |
| 16 #include "gpu/command_buffer/client/gles2_interface.h" | 17 #include "gpu/command_buffer/client/gles2_interface.h" |
| 17 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 18 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
| 18 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
| 19 #include "ui/gfx/rect_conversions.h" | 20 #include "ui/gfx/rect_conversions.h" |
| 20 #include "ui/gfx/skia_util.h" | 21 #include "ui/gfx/skia_util.h" |
| 21 #include "ui/gfx/transform.h" | 22 #include "ui/gfx/transform.h" |
| 22 | 23 |
| 23 namespace content { | 24 namespace content { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } | 60 } |
| 60 | 61 |
| 61 private: | 62 private: |
| 62 SynchronousCompositorOutputSurface* surface_; | 63 SynchronousCompositorOutputSurface* surface_; |
| 63 SkCanvas null_canvas_; | 64 SkCanvas null_canvas_; |
| 64 | 65 |
| 65 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); | 66 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); |
| 66 }; | 67 }; |
| 67 | 68 |
| 68 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( | 69 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( |
| 69 int routing_id) | 70 int routing_id, |
| 71 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) |
| 70 : cc::OutputSurface( | 72 : cc::OutputSurface( |
| 71 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), | 73 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), |
| 72 routing_id_(routing_id), | 74 routing_id_(routing_id), |
| 73 needs_begin_frame_(false), | 75 needs_begin_frame_(false), |
| 74 invoking_composite_(false), | 76 invoking_composite_(false), |
| 75 did_swap_buffer_(false), | 77 did_swap_buffer_(false), |
| 76 current_sw_canvas_(NULL), | 78 current_sw_canvas_(NULL), |
| 77 memory_policy_(0), | 79 memory_policy_(0), |
| 78 output_surface_client_(NULL), | 80 output_surface_client_(NULL), |
| 81 frame_swap_message_queue_(frame_swap_message_queue), |
| 79 weak_ptr_factory_(this) { | 82 weak_ptr_factory_(this) { |
| 80 capabilities_.deferred_gl_initialization = true; | 83 capabilities_.deferred_gl_initialization = true; |
| 81 capabilities_.draw_and_swap_full_viewport_every_frame = true; | 84 capabilities_.draw_and_swap_full_viewport_every_frame = true; |
| 82 capabilities_.adjust_deadline_for_parent = false; | 85 capabilities_.adjust_deadline_for_parent = false; |
| 83 // Cannot call out to GetDelegate() here as the output surface is not | 86 // Cannot call out to GetDelegate() here as the output surface is not |
| 84 // constructed on the correct thread. | 87 // constructed on the correct thread. |
| 85 | 88 |
| 86 memory_policy_.priority_cutoff_when_visible = | 89 memory_policy_.priority_cutoff_when_visible = |
| 87 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; | 90 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
| 88 } | 91 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 cc::CompositorFrame* frame) { | 140 cc::CompositorFrame* frame) { |
| 138 DCHECK(CalledOnValidThread()); | 141 DCHECK(CalledOnValidThread()); |
| 139 if (!ForcedDrawToSoftwareDevice()) { | 142 if (!ForcedDrawToSoftwareDevice()) { |
| 140 DCHECK(context_provider_); | 143 DCHECK(context_provider_); |
| 141 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); | 144 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); |
| 142 } | 145 } |
| 143 UpdateFrameMetaData(frame->metadata); | 146 UpdateFrameMetaData(frame->metadata); |
| 144 | 147 |
| 145 did_swap_buffer_ = true; | 148 did_swap_buffer_ = true; |
| 146 client_->DidSwapBuffers(); | 149 client_->DidSwapBuffers(); |
| 150 |
| 151 std::vector<IPC::Message> messages_to_deliver_with_frame; |
| 152 { |
| 153 scoped_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = |
| 154 frame_swap_message_queue_->AcquireSendMessageScope(); |
| 155 frame_swap_message_queue_->DrainMessages(&messages_to_deliver_with_frame); |
| 156 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 157 BrowserThread::PostTask( |
| 158 BrowserThread::UI, |
| 159 FROM_HERE, |
| 160 base::Bind(&SynchronousCompositorOutputSurface::DeliverMessages, |
| 161 weak_ptr_factory_.GetWeakPtr(), |
| 162 messages_to_deliver_with_frame)); |
| 163 return; |
| 164 } |
| 165 } |
| 166 DeliverMessages(messages_to_deliver_with_frame); |
| 147 } | 167 } |
| 148 | 168 |
| 149 void SynchronousCompositorOutputSurface::UpdateFrameMetaData( | 169 void SynchronousCompositorOutputSurface::UpdateFrameMetaData( |
| 150 const cc::CompositorFrameMetadata& frame_info) { | 170 const cc::CompositorFrameMetadata& frame_info) { |
| 151 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 171 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 152 BrowserThread::PostTask( | 172 BrowserThread::PostTask( |
| 153 BrowserThread::UI, | 173 BrowserThread::UI, |
| 154 FROM_HERE, | 174 FROM_HERE, |
| 155 base::Bind(&SynchronousCompositorOutputSurface::UpdateFrameMetaData, | 175 base::Bind(&SynchronousCompositorOutputSurface::UpdateFrameMetaData, |
| 156 weak_ptr_factory_.GetWeakPtr(), | 176 weak_ptr_factory_.GetWeakPtr(), |
| 157 frame_info)); | 177 frame_info)); |
| 158 return; | 178 return; |
| 159 } | 179 } |
| 160 | 180 |
| 161 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | 181 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
| 162 if (delegate) | 182 if (delegate) |
| 163 delegate->UpdateFrameMetaData(frame_info); | 183 delegate->UpdateFrameMetaData(frame_info); |
| 164 } | 184 } |
| 165 | 185 |
| 186 void SynchronousCompositorOutputSurface::DeliverMessages( |
| 187 const std::vector<IPC::Message>& messages) { |
| 188 DCHECK(CalledOnValidThread()); |
| 189 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
| 190 if (delegate) |
| 191 delegate->DeliverMessages(messages); |
| 192 } |
| 193 |
| 166 namespace { | 194 namespace { |
| 167 void AdjustTransform(gfx::Transform* transform, gfx::Rect viewport) { | 195 void AdjustTransform(gfx::Transform* transform, gfx::Rect viewport) { |
| 168 // CC's draw origin starts at the viewport. | 196 // CC's draw origin starts at the viewport. |
| 169 transform->matrix().postTranslate(-viewport.x(), -viewport.y(), 0); | 197 transform->matrix().postTranslate(-viewport.x(), -viewport.y(), 0); |
| 170 } | 198 } |
| 171 } // namespace | 199 } // namespace |
| 172 | 200 |
| 173 bool SynchronousCompositorOutputSurface::InitializeHwDraw( | 201 bool SynchronousCompositorOutputSurface::InitializeHwDraw( |
| 174 scoped_refptr<cc::ContextProvider> onscreen_context_provider) { | 202 scoped_refptr<cc::ContextProvider> onscreen_context_provider) { |
| 175 DCHECK(CalledOnValidThread()); | 203 DCHECK(CalledOnValidThread()); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 303 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 276 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 304 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 277 } | 305 } |
| 278 | 306 |
| 279 SynchronousCompositorOutputSurfaceDelegate* | 307 SynchronousCompositorOutputSurfaceDelegate* |
| 280 SynchronousCompositorOutputSurface::GetDelegate() { | 308 SynchronousCompositorOutputSurface::GetDelegate() { |
| 281 return SynchronousCompositorImpl::FromRoutingID(routing_id_); | 309 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
| 282 } | 310 } |
| 283 | 311 |
| 284 } // namespace content | 312 } // namespace content |
| OLD | NEW |