Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: content/browser/android/in_process/synchronous_compositor_impl.cc

Issue 23234003: Support stream textures with the synchronous compositor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: android clang Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/common/gpu/stream_texture_manager_android.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/synchronization/lock.h" 9 #include "base/synchronization/lock.h"
10 #include "cc/input/input_handler.h" 10 #include "cc/input/input_handler.h"
11 #include "cc/input/layer_scroll_offset_delegate.h" 11 #include "cc/input/layer_scroll_offset_delegate.h"
12 #include "content/browser/android/in_process/synchronous_input_event_filter.h" 12 #include "content/browser/android/in_process/synchronous_input_event_filter.h"
13 #include "content/browser/renderer_host/render_widget_host_view_android.h" 13 #include "content/browser/renderer_host/render_widget_host_view_android.h"
14 #include "content/public/browser/android/synchronous_compositor_client.h" 14 #include "content/public/browser/android/synchronous_compositor_client.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/render_process_host.h" 16 #include "content/public/browser/render_process_host.h"
17 #include "content/public/browser/render_view_host.h" 17 #include "content/public/browser/render_view_host.h"
18 #include "content/renderer/android/synchronous_compositor_factory.h" 18 #include "content/renderer/android/synchronous_compositor_factory.h"
19 #include "content/renderer/media/android/stream_texture_factory_android_synchron ous_impl.h"
20 #include "gpu/command_buffer/client/gl_in_process_context.h"
21 #include "gpu/command_buffer/service/stream_texture_manager_in_process_android.h "
22 #include "ui/gl/android/surface_texture_bridge.h"
19 #include "ui/gl/gl_surface.h" 23 #include "ui/gl/gl_surface.h"
20 #include "webkit/common/gpu/context_provider_in_process.h" 24 #include "webkit/common/gpu/context_provider_in_process.h"
25 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h"
21 26
22 namespace content { 27 namespace content {
23 28
24 namespace { 29 namespace {
25 30
31 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
32
26 int GetInProcessRendererId() { 33 int GetInProcessRendererId() {
27 content::RenderProcessHost::iterator it = 34 content::RenderProcessHost::iterator it =
28 content::RenderProcessHost::AllHostsIterator(); 35 content::RenderProcessHost::AllHostsIterator();
29 if (it.IsAtEnd()) { 36 if (it.IsAtEnd()) {
30 // There should always be one RPH in single process mode. 37 // There should always be one RPH in single process mode.
31 NOTREACHED(); 38 NOTREACHED();
32 return 0; 39 return 0;
33 } 40 }
34 41
35 int id = it.GetCurrentValue()->GetID(); 42 int id = it.GetCurrentValue()->GetID();
36 it.Advance(); 43 it.Advance();
37 DCHECK(it.IsAtEnd()); // Not multiprocess compatible. 44 DCHECK(it.IsAtEnd()); // Not multiprocess compatible.
38 return id; 45 return id;
39 } 46 }
40 47
48 class VideoContextProvider
49 : public StreamTextureFactorySynchronousImpl::ContextProvider {
50 public:
51 VideoContextProvider(
52 const scoped_refptr<cc::ContextProvider>& context_provider,
53 gpu::GLInProcessContext* gl_in_process_context)
54 : context_provider_(context_provider),
55 gl_in_process_context_(gl_in_process_context) {}
56
57 virtual scoped_refptr<gfx::SurfaceTextureBridge> GetSurfaceTexture(
58 uint32 stream_id) OVERRIDE {
59 return gl_in_process_context_->GetSurfaceTexture(stream_id);
60 }
61
62 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE {
63 return context_provider_->Context3d();
64 }
65
66 private:
67 friend class base::RefCountedThreadSafe<VideoContextProvider>;
68 virtual ~VideoContextProvider() {}
69
70 scoped_refptr<cc::ContextProvider> context_provider_;
71 gpu::GLInProcessContext* gl_in_process_context_;
72
73 DISALLOW_COPY_AND_ASSIGN(VideoContextProvider);
74 };
75
41 class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory { 76 class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory {
42 public: 77 public:
43 SynchronousCompositorFactoryImpl() { 78 SynchronousCompositorFactoryImpl()
79 : wrapped_gl_context_for_main_thread_(NULL) {
44 SynchronousCompositorFactory::SetInstance(this); 80 SynchronousCompositorFactory::SetInstance(this);
45 } 81 }
46 82
47 // SynchronousCompositorFactory 83 // SynchronousCompositorFactory
48 virtual scoped_refptr<base::MessageLoopProxy> 84 virtual scoped_refptr<base::MessageLoopProxy>
49 GetCompositorMessageLoop() OVERRIDE { 85 GetCompositorMessageLoop() OVERRIDE {
50 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); 86 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI);
51 } 87 }
52 88
53 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface( 89 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(
54 int routing_id) OVERRIDE { 90 int routing_id) OVERRIDE {
55 scoped_ptr<SynchronousCompositorOutputSurface> output_surface( 91 scoped_ptr<SynchronousCompositorOutputSurface> output_surface(
56 new SynchronousCompositorOutputSurface(routing_id)); 92 new SynchronousCompositorOutputSurface(routing_id));
57 return output_surface.PassAs<cc::OutputSurface>(); 93 return output_surface.PassAs<cc::OutputSurface>();
58 } 94 }
59 95
60 virtual InputHandlerManagerClient* GetInputHandlerManagerClient() OVERRIDE { 96 virtual InputHandlerManagerClient* GetInputHandlerManagerClient() OVERRIDE {
61 return synchronous_input_event_filter(); 97 return synchronous_input_event_filter();
62 } 98 }
63 99
64 SynchronousInputEventFilter* synchronous_input_event_filter() { 100 SynchronousInputEventFilter* synchronous_input_event_filter() {
65 return &synchronous_input_event_filter_; 101 return &synchronous_input_event_filter_;
66 } 102 }
67 103
104 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
105 CreateOffscreenContext() {
106 if (!gfx::GLSurface::InitializeOneOff())
107 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>();
108
109 const char* allowed_extensions = "*";
110 const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
111
112 WebKit::WebGraphicsContext3D::Attributes attributes;
113 attributes.antialias = false;
114 attributes.shareResources = true;
115 attributes.noAutomaticFlushes = true;
116
117 gpu::GLInProcessContextAttribs in_process_attribs;
118 WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes(
119 attributes, &in_process_attribs);
120 scoped_ptr<gpu::GLInProcessContext> context(
121 gpu::GLInProcessContext::CreateContext(true,
122 NULL,
123 gfx::Size(1, 1),
124 attributes.shareResources,
125 allowed_extensions,
126 in_process_attribs,
127 gpu_preference));
128
129 wrapped_gl_context_for_main_thread_ = context.get();
130 if (!context.get())
131 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>();
132
133 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>(
134 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext(
135 context.Pass(), attributes));
136 }
137
68 virtual scoped_refptr<cc::ContextProvider> 138 virtual scoped_refptr<cc::ContextProvider>
69 GetOffscreenContextProviderForMainThread() OVERRIDE { 139 GetOffscreenContextProviderForMainThread() OVERRIDE {
70 if (!offscreen_context_for_main_thread_.get() || 140 if (!offscreen_context_for_main_thread_.get() ||
71 offscreen_context_for_main_thread_->DestroyedOnMainThread()) { 141 offscreen_context_for_main_thread_->DestroyedOnMainThread()) {
72 offscreen_context_for_main_thread_ = 142 offscreen_context_for_main_thread_ =
73 webkit::gpu::ContextProviderInProcess::CreateOffscreen(); 143 webkit::gpu::ContextProviderInProcess::Create(
144 CreateOffscreenContext());
74 if (offscreen_context_for_main_thread_.get() && 145 if (offscreen_context_for_main_thread_.get() &&
75 !offscreen_context_for_main_thread_->BindToCurrentThread()) 146 !offscreen_context_for_main_thread_->BindToCurrentThread()) {
76 offscreen_context_for_main_thread_ = NULL; 147 offscreen_context_for_main_thread_ = NULL;
148 wrapped_gl_context_for_main_thread_ = NULL;
149 }
77 } 150 }
78 return offscreen_context_for_main_thread_; 151 return offscreen_context_for_main_thread_;
79 } 152 }
80 153
81 // This is called on both renderer main thread (offscreen context creation 154 // This is called on both renderer main thread (offscreen context creation
82 // path shared between cross-process and in-process platforms) and renderer 155 // path shared between cross-process and in-process platforms) and renderer
83 // compositor impl thread (InitializeHwDraw) in order to support Android 156 // compositor impl thread (InitializeHwDraw) in order to support Android
84 // WebView synchronously enable and disable hardware mode multiple times in 157 // WebView synchronously enable and disable hardware mode multiple times in
85 // the same task. This is ok because in-process WGC3D creation may happen on 158 // the same task. This is ok because in-process WGC3D creation may happen on
86 // any thread and is lightweight. 159 // any thread and is lightweight.
87 virtual scoped_refptr<cc::ContextProvider> 160 virtual scoped_refptr<cc::ContextProvider>
88 GetOffscreenContextProviderForCompositorThread() OVERRIDE { 161 GetOffscreenContextProviderForCompositorThread() OVERRIDE {
89 base::AutoLock lock(offscreen_context_for_compositor_thread_creation_lock_); 162 base::AutoLock lock(offscreen_context_for_compositor_thread_creation_lock_);
90 if (!offscreen_context_for_compositor_thread_.get() || 163 if (!offscreen_context_for_compositor_thread_.get() ||
91 offscreen_context_for_compositor_thread_->DestroyedOnMainThread()) { 164 offscreen_context_for_compositor_thread_->DestroyedOnMainThread()) {
92 offscreen_context_for_compositor_thread_ = 165 offscreen_context_for_compositor_thread_ =
93 webkit::gpu::ContextProviderInProcess::CreateOffscreen(); 166 webkit::gpu::ContextProviderInProcess::CreateOffscreen();
94 } 167 }
95 return offscreen_context_for_compositor_thread_; 168 return offscreen_context_for_compositor_thread_;
96 } 169 }
97 170
171 virtual scoped_ptr<StreamTextureFactory> CreateStreamTextureFactory(
172 int view_id) OVERRIDE {
173 scoped_refptr<VideoContextProvider> context_provider =
174 new VideoContextProvider(offscreen_context_for_main_thread_,
175 wrapped_gl_context_for_main_thread_);
176 return make_scoped_ptr(new StreamTextureFactorySynchronousImpl(
177 context_provider.get(), view_id))
178 .PassAs<StreamTextureFactory>();
179 }
180
98 private: 181 private:
99 SynchronousInputEventFilter synchronous_input_event_filter_; 182 SynchronousInputEventFilter synchronous_input_event_filter_;
100 183
101 // Only guards construction of |offscreen_context_for_compositor_thread_|, 184 // Only guards construction of |offscreen_context_for_compositor_thread_|,
102 // not usage. 185 // not usage.
103 base::Lock offscreen_context_for_compositor_thread_creation_lock_; 186 base::Lock offscreen_context_for_compositor_thread_creation_lock_;
104 scoped_refptr<cc::ContextProvider> offscreen_context_for_main_thread_; 187 scoped_refptr<cc::ContextProvider> offscreen_context_for_main_thread_;
188 // This is a pointer to the context owned by
189 // |offscreen_context_for_main_thread_|.
190 gpu::GLInProcessContext* wrapped_gl_context_for_main_thread_;
105 scoped_refptr<cc::ContextProvider> offscreen_context_for_compositor_thread_; 191 scoped_refptr<cc::ContextProvider> offscreen_context_for_compositor_thread_;
106 }; 192 };
107 193
108 base::LazyInstance<SynchronousCompositorFactoryImpl>::Leaky g_factory = 194 base::LazyInstance<SynchronousCompositorFactoryImpl>::Leaky g_factory =
109 LAZY_INSTANCE_INITIALIZER; 195 LAZY_INSTANCE_INITIALIZER;
110 196
111 } // namespace 197 } // namespace
112 198
113 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SynchronousCompositorImpl); 199 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SynchronousCompositorImpl);
114 200
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 g_factory.Get(); // Ensure it's initialized. 373 g_factory.Get(); // Ensure it's initialized.
288 SynchronousCompositorImpl::CreateForWebContents(contents); 374 SynchronousCompositorImpl::CreateForWebContents(contents);
289 } 375 }
290 if (SynchronousCompositorImpl* instance = 376 if (SynchronousCompositorImpl* instance =
291 SynchronousCompositorImpl::FromWebContents(contents)) { 377 SynchronousCompositorImpl::FromWebContents(contents)) {
292 instance->SetClient(client); 378 instance->SetClient(client);
293 } 379 }
294 } 380 }
295 381
296 } // namespace content 382 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/common/gpu/stream_texture_manager_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698