| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_factory_impl
.h" | 5 #include "content/browser/android/in_process/synchronous_compositor_factory_impl
.h" |
| 6 | 6 |
| 7 #include "content/browser/android/in_process/synchronous_compositor_output_surfa
ce.h" | 7 #include "content/browser/android/in_process/synchronous_compositor_output_surfa
ce.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "gpu/command_buffer/client/gl_in_process_context.h" | 9 #include "gpu/command_buffer/client/gl_in_process_context.h" |
| 10 #include "ui/gl/android/surface_texture.h" | 10 #include "ui/gl/android/surface_texture.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(VideoContextProvider); | 45 DISALLOW_COPY_AND_ASSIGN(VideoContextProvider); |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; | 50 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; |
| 51 | 51 |
| 52 SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl() | 52 SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl() |
| 53 : wrapped_gl_context_for_main_thread_(NULL), | 53 : wrapped_gl_context_for_main_thread_(NULL), |
| 54 wrapped_gl_context_for_compositor_thread_(NULL), |
| 54 num_hardware_compositors_(0) { | 55 num_hardware_compositors_(0) { |
| 55 SynchronousCompositorFactory::SetInstance(this); | 56 SynchronousCompositorFactory::SetInstance(this); |
| 56 } | 57 } |
| 57 | 58 |
| 58 SynchronousCompositorFactoryImpl::~SynchronousCompositorFactoryImpl() {} | 59 SynchronousCompositorFactoryImpl::~SynchronousCompositorFactoryImpl() {} |
| 59 | 60 |
| 60 scoped_refptr<base::MessageLoopProxy> | 61 scoped_refptr<base::MessageLoopProxy> |
| 61 SynchronousCompositorFactoryImpl::GetCompositorMessageLoop() { | 62 SynchronousCompositorFactoryImpl::GetCompositorMessageLoop() { |
| 62 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); | 63 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); |
| 63 } | 64 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 76 | 77 |
| 77 scoped_refptr<ContextProviderWebContext> | 78 scoped_refptr<ContextProviderWebContext> |
| 78 SynchronousCompositorFactoryImpl::GetOffscreenContextProviderForMainThread() { | 79 SynchronousCompositorFactoryImpl::GetOffscreenContextProviderForMainThread() { |
| 79 // This check only guarantees the main thread context is created after | 80 // This check only guarantees the main thread context is created after |
| 80 // a compositor did successfully initialize hardware draw in the past. | 81 // a compositor did successfully initialize hardware draw in the past. |
| 81 // In particular this does not guarantee that the main thread context | 82 // In particular this does not guarantee that the main thread context |
| 82 // will fail creation when all compositors release hardware draw. | 83 // will fail creation when all compositors release hardware draw. |
| 83 bool failed = false; | 84 bool failed = false; |
| 84 if ((!offscreen_context_for_main_thread_.get() || | 85 if ((!offscreen_context_for_main_thread_.get() || |
| 85 offscreen_context_for_main_thread_->DestroyedOnMainThread())) { | 86 offscreen_context_for_main_thread_->DestroyedOnMainThread())) { |
| 87 scoped_ptr<gpu::GLInProcessContext> context = CreateOffscreenContext(); |
| 88 wrapped_gl_context_for_main_thread_ = context.get(); |
| 86 offscreen_context_for_main_thread_ = | 89 offscreen_context_for_main_thread_ = |
| 87 webkit::gpu::ContextProviderInProcess::Create( | 90 webkit::gpu::ContextProviderInProcess::Create( |
| 88 CreateOffscreenContext(), | 91 WrapContext(context.Pass()), |
| 89 "Compositor-Offscreen"); | 92 "Compositor-Offscreen-main-thread"); |
| 90 failed = !offscreen_context_for_main_thread_.get() || | 93 failed = !offscreen_context_for_main_thread_.get() || |
| 91 !offscreen_context_for_main_thread_->BindToCurrentThread(); | 94 !offscreen_context_for_main_thread_->BindToCurrentThread(); |
| 92 } | 95 } |
| 93 | 96 |
| 94 if (failed) { | 97 if (failed) { |
| 95 offscreen_context_for_main_thread_ = NULL; | 98 offscreen_context_for_main_thread_ = NULL; |
| 96 wrapped_gl_context_for_main_thread_ = NULL; | 99 wrapped_gl_context_for_main_thread_ = NULL; |
| 97 } | 100 } |
| 98 return offscreen_context_for_main_thread_; | 101 return offscreen_context_for_main_thread_; |
| 99 } | 102 } |
| 100 | 103 |
| 101 // This is called on both renderer main thread (offscreen context creation | 104 // This is called on both renderer main thread (offscreen context creation |
| 102 // path shared between cross-process and in-process platforms) and renderer | 105 // path shared between cross-process and in-process platforms) and renderer |
| 103 // compositor impl thread (InitializeHwDraw) in order to support Android | 106 // compositor impl thread (InitializeHwDraw) in order to support Android |
| 104 // WebView synchronously enable and disable hardware mode multiple times in | 107 // WebView synchronously enable and disable hardware mode multiple times in |
| 105 // the same task. This is ok because in-process WGC3D creation may happen on | 108 // the same task. This is ok because in-process WGC3D creation may happen on |
| 106 // any thread and is lightweight. | 109 // any thread and is lightweight. |
| 107 scoped_refptr<cc::ContextProvider> SynchronousCompositorFactoryImpl:: | 110 scoped_refptr<cc::ContextProvider> SynchronousCompositorFactoryImpl:: |
| 108 GetOffscreenContextProviderForCompositorThread() { | 111 GetOffscreenContextProviderForCompositorThread() { |
| 109 base::AutoLock lock(offscreen_context_for_compositor_thread_lock_); | 112 base::AutoLock lock(offscreen_context_for_compositor_thread_lock_); |
| 110 if (!offscreen_context_for_compositor_thread_.get() || | 113 if (!offscreen_context_for_compositor_thread_.get() || |
| 111 offscreen_context_for_compositor_thread_->DestroyedOnMainThread()) { | 114 offscreen_context_for_compositor_thread_->DestroyedOnMainThread()) { |
| 115 scoped_ptr<gpu::GLInProcessContext> context = CreateOffscreenContext(); |
| 116 wrapped_gl_context_for_compositor_thread_ = context.get(); |
| 112 offscreen_context_for_compositor_thread_ = | 117 offscreen_context_for_compositor_thread_ = |
| 113 webkit::gpu::ContextProviderInProcess::CreateOffscreen(); | 118 webkit::gpu::ContextProviderInProcess::Create( |
| 119 WrapContext(context.Pass()), |
| 120 "Compositor-Offscreen-compositor-thread"); |
| 121 failed = !offscreen_context_for_compositor_thread_.get() || |
| 122 !offscreen_context_for_compositor_thread_->BindToCurrentThread(); |
| 123 } |
| 124 if (failed) { |
| 125 offscreen_context_for_compositor_thread_ = NULL; |
| 126 wrapped_gl_context_for_compositor_thread_ = NULL; |
| 114 } | 127 } |
| 115 return offscreen_context_for_compositor_thread_; | 128 return offscreen_context_for_compositor_thread_; |
| 116 } | 129 } |
| 117 | 130 |
| 118 scoped_ptr<StreamTextureFactory> | 131 scoped_ptr<StreamTextureFactory> |
| 119 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int view_id) { | 132 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int view_id) { |
| 120 scoped_ptr<StreamTextureFactorySynchronousImpl> factory( | 133 scoped_ptr<StreamTextureFactorySynchronousImpl> factory( |
| 121 new StreamTextureFactorySynchronousImpl( | 134 new StreamTextureFactorySynchronousImpl( |
| 122 base::Bind(&SynchronousCompositorFactoryImpl:: | 135 base::Bind(&SynchronousCompositorFactoryImpl:: |
| 123 TryCreateStreamTextureFactory, | 136 TryCreateStreamTextureFactory, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 wrapped_gl_context_for_main_thread_); | 184 wrapped_gl_context_for_main_thread_); |
| 172 } | 185 } |
| 173 return context_provider; | 186 return context_provider; |
| 174 } | 187 } |
| 175 | 188 |
| 176 // TODO(boliu): Deduplicate this with synchronous_compositor_output_surface.cc. | 189 // TODO(boliu): Deduplicate this with synchronous_compositor_output_surface.cc. |
| 177 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> | 190 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> |
| 178 SynchronousCompositorFactoryImpl::CreateOffscreenContext() { | 191 SynchronousCompositorFactoryImpl::CreateOffscreenContext() { |
| 179 const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | 192 const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
| 180 | 193 |
| 181 blink::WebGraphicsContext3D::Attributes attributes; | |
| 182 attributes.antialias = false; | |
| 183 attributes.shareResources = true; | |
| 184 attributes.noAutomaticFlushes = true; | |
| 185 | |
| 186 gpu::GLInProcessContextAttribs in_process_attribs; | 194 gpu::GLInProcessContextAttribs in_process_attribs; |
| 187 WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes( | 195 WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes( |
| 188 attributes, &in_process_attribs); | 196 attributes, &in_process_attribs); |
| 189 scoped_ptr<gpu::GLInProcessContext> context( | 197 scoped_ptr<gpu::GLInProcessContext> context( |
| 190 gpu::GLInProcessContext::CreateContext(true, | 198 gpu::GLInProcessContext::CreateContext(true, |
| 191 NULL, | 199 NULL, |
| 192 gfx::Size(1, 1), | 200 gfx::Size(1, 1), |
| 193 attributes.shareResources, | 201 true /* share_resources */, |
| 194 in_process_attribs, | 202 in_process_attribs, |
| 195 gpu_preference)); | 203 gpu_preference)); |
| 204 return context.Pass(); |
| 205 } |
| 196 | 206 |
| 197 wrapped_gl_context_for_main_thread_ = context.get(); | 207 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> |
| 208 SynchronousCompositorFactoryImpl::WrapContext( |
| 209 scoped_ptr<gpu::GLInProcessContext> context) { |
| 198 if (!context.get()) | 210 if (!context.get()) |
| 199 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>(); | 211 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>(); |
| 200 | 212 |
| 213 blink::WebGraphicsContext3D::Attributes attributes; |
| 214 attributes.antialias = false; |
| 215 attributes.shareResources = true; |
| 216 attributes.noAutomaticFlushes = true; |
| 217 |
| 201 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>( | 218 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>( |
| 202 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( | 219 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( |
| 203 context.Pass(), attributes)); | 220 context.Pass(), attributes)); |
| 204 } | 221 } |
| 205 | 222 |
| 206 } // namespace content | 223 } // namespace content |
| OLD | NEW |