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

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: this time for real 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
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 scoped_refptr<cc::ContextProvider> context_provider_;
68 gpu::GLInProcessContext* gl_in_process_context_;
69
70 DISALLOW_COPY_AND_ASSIGN(VideoContextProvider);
71 };
72
41 class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory { 73 class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory {
42 public: 74 public:
43 SynchronousCompositorFactoryImpl() { 75 SynchronousCompositorFactoryImpl()
76 : wrapped_gl_context_for_main_thread_(NULL) {
44 SynchronousCompositorFactory::SetInstance(this); 77 SynchronousCompositorFactory::SetInstance(this);
45 } 78 }
46 79
47 // SynchronousCompositorFactory 80 // SynchronousCompositorFactory
48 virtual scoped_refptr<base::MessageLoopProxy> 81 virtual scoped_refptr<base::MessageLoopProxy>
49 GetCompositorMessageLoop() OVERRIDE { 82 GetCompositorMessageLoop() OVERRIDE {
50 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); 83 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI);
51 } 84 }
52 85
53 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface( 86 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(
54 int routing_id) OVERRIDE { 87 int routing_id) OVERRIDE {
55 scoped_ptr<SynchronousCompositorOutputSurface> output_surface( 88 scoped_ptr<SynchronousCompositorOutputSurface> output_surface(
56 new SynchronousCompositorOutputSurface(routing_id)); 89 new SynchronousCompositorOutputSurface(routing_id));
57 return output_surface.PassAs<cc::OutputSurface>(); 90 return output_surface.PassAs<cc::OutputSurface>();
58 } 91 }
59 92
60 virtual InputHandlerManagerClient* GetInputHandlerManagerClient() OVERRIDE { 93 virtual InputHandlerManagerClient* GetInputHandlerManagerClient() OVERRIDE {
61 return synchronous_input_event_filter(); 94 return synchronous_input_event_filter();
62 } 95 }
63 96
64 SynchronousInputEventFilter* synchronous_input_event_filter() { 97 SynchronousInputEventFilter* synchronous_input_event_filter() {
65 return &synchronous_input_event_filter_; 98 return &synchronous_input_event_filter_;
66 } 99 }
67 100
101 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
102 CreateOffscreenContext() {
103 if (!gfx::GLSurface::InitializeOneOff())
104 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>();
105
106 const char* allowed_extensions = "*";
107 const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
108
109 WebKit::WebGraphicsContext3D::Attributes attributes;
110 attributes.antialias = false;
111 attributes.shareResources = true;
112 attributes.noAutomaticFlushes = true;
113
114 gpu::GLInProcessContextAttribs in_process_attribs;
115 WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes(
116 attributes, &in_process_attribs);
117 scoped_ptr<gpu::GLInProcessContext> context(
118 gpu::GLInProcessContext::CreateContext(true,
119 NULL,
120 gfx::Size(1, 1),
121 attributes.shareResources,
122 allowed_extensions,
123 in_process_attribs,
124 gpu_preference));
125
126 wrapped_gl_context_for_main_thread_ = context.get();
127 if (!context.get())
128 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>();
129
130 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>(
131 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext(
132 context.Pass(), attributes));
133 }
134
68 virtual scoped_refptr<cc::ContextProvider> 135 virtual scoped_refptr<cc::ContextProvider>
69 GetOffscreenContextProviderForMainThread() OVERRIDE { 136 GetOffscreenContextProviderForMainThread() OVERRIDE {
70 if (!offscreen_context_for_main_thread_.get() || 137 if (!offscreen_context_for_main_thread_.get() ||
71 offscreen_context_for_main_thread_->DestroyedOnMainThread()) { 138 offscreen_context_for_main_thread_->DestroyedOnMainThread()) {
72 offscreen_context_for_main_thread_ = 139 offscreen_context_for_main_thread_ =
73 webkit::gpu::ContextProviderInProcess::CreateOffscreen(); 140 webkit::gpu::ContextProviderInProcess::Create(base::Bind(
141 &SynchronousCompositorFactoryImpl::CreateOffscreenContext,
142 base::Unretained(this)));
74 if (offscreen_context_for_main_thread_.get() && 143 if (offscreen_context_for_main_thread_.get() &&
75 !offscreen_context_for_main_thread_->BindToCurrentThread()) 144 !offscreen_context_for_main_thread_->BindToCurrentThread()) {
76 offscreen_context_for_main_thread_ = NULL; 145 offscreen_context_for_main_thread_ = NULL;
146 wrapped_gl_context_for_main_thread_ = NULL;
147 }
77 } 148 }
78 return offscreen_context_for_main_thread_; 149 return offscreen_context_for_main_thread_;
79 } 150 }
80 151
81 // This is called on both renderer main thread (offscreen context creation 152 // This is called on both renderer main thread (offscreen context creation
82 // path shared between cross-process and in-process platforms) and renderer 153 // path shared between cross-process and in-process platforms) and renderer
83 // compositor impl thread (InitializeHwDraw) in order to support Android 154 // compositor impl thread (InitializeHwDraw) in order to support Android
84 // WebView synchronously enable and disable hardware mode multiple times in 155 // 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 156 // the same task. This is ok because in-process WGC3D creation may happen on
86 // any thread and is lightweight. 157 // any thread and is lightweight.
87 virtual scoped_refptr<cc::ContextProvider> 158 virtual scoped_refptr<cc::ContextProvider>
88 GetOffscreenContextProviderForCompositorThread() OVERRIDE { 159 GetOffscreenContextProviderForCompositorThread() OVERRIDE {
89 base::AutoLock lock(offscreen_context_for_compositor_thread_creation_lock_); 160 base::AutoLock lock(offscreen_context_for_compositor_thread_creation_lock_);
90 if (!offscreen_context_for_compositor_thread_.get() || 161 if (!offscreen_context_for_compositor_thread_.get() ||
91 offscreen_context_for_compositor_thread_->DestroyedOnMainThread()) { 162 offscreen_context_for_compositor_thread_->DestroyedOnMainThread()) {
92 offscreen_context_for_compositor_thread_ = 163 offscreen_context_for_compositor_thread_ =
93 webkit::gpu::ContextProviderInProcess::CreateOffscreen(); 164 webkit::gpu::ContextProviderInProcess::CreateOffscreen();
94 } 165 }
95 return offscreen_context_for_compositor_thread_; 166 return offscreen_context_for_compositor_thread_;
96 } 167 }
97 168
169 virtual scoped_ptr<StreamTextureFactory> CreateStreamTextureFactory(
170 int view_id) OVERRIDE {
171 scoped_refptr<VideoContextProvider> context_provider =
172 new VideoContextProvider(offscreen_context_for_main_thread_,
173 wrapped_gl_context_for_main_thread_);
174 return make_scoped_ptr(new StreamTextureFactorySynchronousImpl(
175 context_provider.get(), view_id))
176 .PassAs<StreamTextureFactory>();
177 }
178
98 private: 179 private:
99 SynchronousInputEventFilter synchronous_input_event_filter_; 180 SynchronousInputEventFilter synchronous_input_event_filter_;
100 181
101 // Only guards construction of |offscreen_context_for_compositor_thread_|, 182 // Only guards construction of |offscreen_context_for_compositor_thread_|,
102 // not usage. 183 // not usage.
103 base::Lock offscreen_context_for_compositor_thread_creation_lock_; 184 base::Lock offscreen_context_for_compositor_thread_creation_lock_;
104 scoped_refptr<cc::ContextProvider> offscreen_context_for_main_thread_; 185 scoped_refptr<cc::ContextProvider> offscreen_context_for_main_thread_;
186 // This is a pointer to the context owned by
187 // |offscreen_context_for_main_thread_|.
188 gpu::GLInProcessContext* wrapped_gl_context_for_main_thread_;
105 scoped_refptr<cc::ContextProvider> offscreen_context_for_compositor_thread_; 189 scoped_refptr<cc::ContextProvider> offscreen_context_for_compositor_thread_;
106 }; 190 };
107 191
108 base::LazyInstance<SynchronousCompositorFactoryImpl>::Leaky g_factory = 192 base::LazyInstance<SynchronousCompositorFactoryImpl>::Leaky g_factory =
109 LAZY_INSTANCE_INITIALIZER; 193 LAZY_INSTANCE_INITIALIZER;
110 194
111 } // namespace 195 } // namespace
112 196
113 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SynchronousCompositorImpl); 197 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SynchronousCompositorImpl);
114 198
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 g_factory.Get(); // Ensure it's initialized. 371 g_factory.Get(); // Ensure it's initialized.
288 SynchronousCompositorImpl::CreateForWebContents(contents); 372 SynchronousCompositorImpl::CreateForWebContents(contents);
289 } 373 }
290 if (SynchronousCompositorImpl* instance = 374 if (SynchronousCompositorImpl* instance =
291 SynchronousCompositorImpl::FromWebContents(contents)) { 375 SynchronousCompositorImpl::FromWebContents(contents)) {
292 instance->SetClient(client); 376 instance->SetClient(client);
293 } 377 }
294 } 378 }
295 379
296 } // namespace content 380 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/common/gpu/stream_texture_manager_android.h » ('j') | content/renderer/render_view_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698