| 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_impl.h" | 5 #include "content/browser/android/in_process/synchronous_compositor_impl.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "cc/input/input_handler.h" | 9 #include "cc/input/input_handler.h" |
| 10 #include "content/browser/android/in_process/synchronous_compositor_factory_impl
.h" | 10 #include "content/browser/android/in_process/synchronous_compositor_factory_impl
.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 DCHECK(CalledOnValidThread()); | 82 DCHECK(CalledOnValidThread()); |
| 83 compositor_client_ = compositor_client; | 83 compositor_client_ = compositor_client; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // static | 86 // static |
| 87 void SynchronousCompositor::SetGpuService( | 87 void SynchronousCompositor::SetGpuService( |
| 88 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { | 88 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { |
| 89 g_factory.Get().SetDeferredGpuService(service); | 89 g_factory.Get().SetDeferredGpuService(service); |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool SynchronousCompositorImpl::InitializeHwDraw( | 92 bool SynchronousCompositorImpl::InitializeHwDraw() { |
| 93 scoped_refptr<gfx::GLSurface> surface) { | |
| 94 DCHECK(CalledOnValidThread()); | 93 DCHECK(CalledOnValidThread()); |
| 95 DCHECK(output_surface_); | 94 DCHECK(output_surface_); |
| 96 | 95 |
| 97 scoped_refptr<cc::ContextProvider> onscreen_context = | 96 scoped_refptr<cc::ContextProvider> onscreen_context = |
| 98 g_factory.Get().CreateOnscreenContextProviderForCompositorThread(surface); | 97 g_factory.Get().CreateOnscreenContextProviderForCompositorThread(); |
| 99 | 98 |
| 100 bool success = output_surface_->InitializeHwDraw(onscreen_context); | 99 bool success = output_surface_->InitializeHwDraw(onscreen_context); |
| 101 | 100 |
| 102 if (success) | 101 if (success) |
| 103 g_factory.Get().CompositorInitializedHardwareDraw(); | 102 g_factory.Get().CompositorInitializedHardwareDraw(); |
| 104 return success; | 103 return success; |
| 105 } | 104 } |
| 106 | 105 |
| 107 void SynchronousCompositorImpl::ReleaseHwDraw() { | 106 void SynchronousCompositorImpl::ReleaseHwDraw() { |
| 108 DCHECK(CalledOnValidThread()); | 107 DCHECK(CalledOnValidThread()); |
| 109 DCHECK(output_surface_); | 108 DCHECK(output_surface_); |
| 110 output_surface_->ReleaseHwDraw(); | 109 output_surface_->ReleaseHwDraw(); |
| 111 g_factory.Get().CompositorReleasedHardwareDraw(); | 110 g_factory.Get().CompositorReleasedHardwareDraw(); |
| 112 } | 111 } |
| 113 | 112 |
| 114 gpu::GLInProcessContext* SynchronousCompositorImpl::GetShareContext() { | 113 gpu::GLInProcessContext* SynchronousCompositorImpl::GetShareContext() { |
| 115 DCHECK(CalledOnValidThread()); | 114 DCHECK(CalledOnValidThread()); |
| 116 return g_factory.Get().GetShareContext(); | 115 return g_factory.Get().GetShareContext(); |
| 117 } | 116 } |
| 118 | 117 |
| 119 scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw( | 118 scoped_ptr<cc::CompositorFrame> SynchronousCompositorImpl::DemandDrawHw( |
| 120 gfx::Size surface_size, | 119 gfx::Size surface_size, |
| 121 const gfx::Transform& transform, | 120 const gfx::Transform& transform, |
| 122 gfx::Rect viewport, | 121 gfx::Rect viewport, |
| 123 gfx::Rect clip, | 122 gfx::Rect clip) { |
| 124 bool stencil_enabled) { | |
| 125 DCHECK(CalledOnValidThread()); | 123 DCHECK(CalledOnValidThread()); |
| 126 DCHECK(output_surface_); | 124 DCHECK(output_surface_); |
| 127 | 125 |
| 128 scoped_ptr<cc::CompositorFrame> frame = output_surface_->DemandDrawHw( | 126 scoped_ptr<cc::CompositorFrame> frame = |
| 129 surface_size, transform, viewport, clip, stencil_enabled); | 127 output_surface_->DemandDrawHw(surface_size, transform, viewport, clip); |
| 130 if (frame.get()) | 128 if (frame.get()) |
| 131 UpdateFrameMetaData(frame->metadata); | 129 UpdateFrameMetaData(frame->metadata); |
| 132 return frame.Pass(); | 130 return frame.Pass(); |
| 133 } | 131 } |
| 134 | 132 |
| 135 void SynchronousCompositorImpl::ReturnResources( | 133 void SynchronousCompositorImpl::ReturnResources( |
| 136 const cc::CompositorFrameAck& frame_ack) { | 134 const cc::CompositorFrameAck& frame_ack) { |
| 137 DCHECK(CalledOnValidThread()); | 135 DCHECK(CalledOnValidThread()); |
| 138 output_surface_->ReturnResources(frame_ack); | 136 output_surface_->ReturnResources(frame_ack); |
| 139 } | 137 } |
| 140 | 138 |
| 141 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { | 139 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { |
| 142 DCHECK(CalledOnValidThread()); | 140 DCHECK(CalledOnValidThread()); |
| 143 DCHECK(output_surface_); | 141 DCHECK(output_surface_); |
| 144 | 142 |
| 145 scoped_ptr<cc::CompositorFrame> frame = output_surface_->DemandDrawSw(canvas); | 143 scoped_ptr<cc::CompositorFrame> frame = output_surface_->DemandDrawSw(canvas); |
| 146 if (frame.get()) | 144 if (frame.get()) |
| 147 UpdateFrameMetaData(frame->metadata); | 145 UpdateFrameMetaData(frame->metadata); |
| 148 return !!frame.get(); | 146 return !!frame.get(); |
| 149 } | 147 } |
| 150 | 148 |
| 151 void SynchronousCompositorImpl::UpdateFrameMetaData( | 149 void SynchronousCompositorImpl::UpdateFrameMetaData( |
| 152 const cc::CompositorFrameMetadata& frame_metadata) { | 150 const cc::CompositorFrameMetadata& frame_metadata) { |
| 153 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 154 BrowserThread::PostTask( | |
| 155 BrowserThread::UI, | |
| 156 FROM_HERE, | |
| 157 base::Bind(&SynchronousCompositorImpl::UpdateFrameMetaData, | |
| 158 weak_ptr_factory_.GetWeakPtr(), | |
| 159 frame_metadata)); | |
| 160 return; | |
| 161 } | |
| 162 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 151 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
| 163 contents_->GetRenderWidgetHostView()); | 152 contents_->GetRenderWidgetHostView()); |
| 164 if (rwhv) | 153 if (rwhv) |
| 165 rwhv->SynchronousFrameMetadata(frame_metadata); | 154 rwhv->SynchronousFrameMetadata(frame_metadata); |
| 166 } | 155 } |
| 167 | 156 |
| 168 void SynchronousCompositorImpl::SetMemoryPolicy( | 157 void SynchronousCompositorImpl::SetMemoryPolicy( |
| 169 const SynchronousCompositorMemoryPolicy& policy) { | 158 const SynchronousCompositorMemoryPolicy& policy) { |
| 170 DCHECK(CalledOnValidThread()); | 159 DCHECK(CalledOnValidThread()); |
| 171 DCHECK(output_surface_); | 160 DCHECK(output_surface_); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 g_factory.Get(); // Ensure it's initialized. | 284 g_factory.Get(); // Ensure it's initialized. |
| 296 SynchronousCompositorImpl::CreateForWebContents(contents); | 285 SynchronousCompositorImpl::CreateForWebContents(contents); |
| 297 } | 286 } |
| 298 if (SynchronousCompositorImpl* instance = | 287 if (SynchronousCompositorImpl* instance = |
| 299 SynchronousCompositorImpl::FromWebContents(contents)) { | 288 SynchronousCompositorImpl::FromWebContents(contents)) { |
| 300 instance->SetClient(client); | 289 instance->SetClient(client); |
| 301 } | 290 } |
| 302 } | 291 } |
| 303 | 292 |
| 304 } // namespace content | 293 } // namespace content |
| OLD | NEW |