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

Side by Side Diff: gpu/command_buffer/client/gl_in_process_context.cc

Issue 22066002: Add FBO support in Android WebView (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove blank line 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "gpu/command_buffer/client/gl_in_process_context.h" 5 #include "gpu/command_buffer/client/gl_in_process_context.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 static GpuMemoryBufferFactory* g_gpu_memory_buffer_factory = NULL; 46 static GpuMemoryBufferFactory* g_gpu_memory_buffer_factory = NULL;
47 47
48 class GLInProcessContextImpl 48 class GLInProcessContextImpl
49 : public GLInProcessContext, 49 : public GLInProcessContext,
50 public gles2::ImageFactory, 50 public gles2::ImageFactory,
51 public base::SupportsWeakPtr<GLInProcessContextImpl> { 51 public base::SupportsWeakPtr<GLInProcessContextImpl> {
52 public: 52 public:
53 explicit GLInProcessContextImpl(); 53 explicit GLInProcessContextImpl();
54 virtual ~GLInProcessContextImpl(); 54 virtual ~GLInProcessContextImpl();
55 55
56 bool Initialize(bool is_offscreen, 56 bool Initialize(scoped_refptr<gfx::GLSurface> surface,
57 bool is_offscreen,
57 bool share_resources, 58 bool share_resources,
58 gfx::AcceleratedWidget window, 59 gfx::AcceleratedWidget window,
59 const gfx::Size& size, 60 const gfx::Size& size,
60 const char* allowed_extensions, 61 const char* allowed_extensions,
61 const int32* attrib_list, 62 const int32* attrib_list,
62 gfx::GpuPreference gpu_preference, 63 gfx::GpuPreference gpu_preference);
63 const base::Closure& context_lost_callback);
64 64
65 // GLInProcessContext implementation: 65 // GLInProcessContext implementation:
66 virtual void SetContextLostCallback(const base::Closure& callback) OVERRIDE;
66 virtual void SignalSyncPoint(unsigned sync_point, 67 virtual void SignalSyncPoint(unsigned sync_point,
67 const base::Closure& callback) OVERRIDE; 68 const base::Closure& callback) OVERRIDE;
68 virtual void SignalQuery(unsigned query, const base::Closure& callback) 69 virtual void SignalQuery(unsigned query, const base::Closure& callback)
69 OVERRIDE; 70 OVERRIDE;
70 virtual gles2::GLES2Implementation* GetImplementation() OVERRIDE; 71 virtual gles2::GLES2Implementation* GetImplementation() OVERRIDE;
71 72
72 // ImageFactory implementation: 73 // ImageFactory implementation:
73 virtual scoped_ptr<gfx::GpuMemoryBuffer> CreateGpuMemoryBuffer( 74 virtual scoped_ptr<gfx::GpuMemoryBuffer> CreateGpuMemoryBuffer(
74 int width, int height, GLenum internalformat, 75 int width, int height, GLenum internalformat,
75 unsigned* image_id) OVERRIDE; 76 unsigned* image_id) OVERRIDE;
76 virtual void DeleteGpuMemoryBuffer(unsigned image_id) OVERRIDE; 77 virtual void DeleteGpuMemoryBuffer(unsigned image_id) OVERRIDE;
77 78
78 private: 79 private:
79 void Destroy(); 80 void Destroy();
80 void PollQueryCallbacks(); 81 void PollQueryCallbacks();
81 void CallQueryCallback(size_t index); 82 void CallQueryCallback(size_t index);
82 void OnContextLost(const base::Closure& callback); 83 void OnContextLost();
83 void OnSignalSyncPoint(const base::Closure& callback); 84 void OnSignalSyncPoint(const base::Closure& callback);
84 85
85 scoped_ptr<gles2::GLES2CmdHelper> gles2_helper_; 86 scoped_ptr<gles2::GLES2CmdHelper> gles2_helper_;
86 scoped_ptr<TransferBuffer> transfer_buffer_; 87 scoped_ptr<TransferBuffer> transfer_buffer_;
87 scoped_ptr<gles2::GLES2Implementation> gles2_implementation_; 88 scoped_ptr<gles2::GLES2Implementation> gles2_implementation_;
88 scoped_ptr<InProcessCommandBuffer> command_buffer_; 89 scoped_ptr<InProcessCommandBuffer> command_buffer_;
89 90
90 typedef std::pair<unsigned, base::Closure> QueryCallback; 91 typedef std::pair<unsigned, base::Closure> QueryCallback;
91 std::vector<QueryCallback> query_callbacks_; 92 std::vector<QueryCallback> query_callbacks_;
92 93
93 unsigned int share_group_id_; 94 unsigned int share_group_id_;
94 bool context_lost_; 95 bool context_lost_;
96 base::Closure context_lost_callback_;
95 97
96 DISALLOW_COPY_AND_ASSIGN(GLInProcessContextImpl); 98 DISALLOW_COPY_AND_ASSIGN(GLInProcessContextImpl);
97 }; 99 };
98 100
99 base::LazyInstance<base::Lock> g_all_shared_contexts_lock = 101 base::LazyInstance<base::Lock> g_all_shared_contexts_lock =
100 LAZY_INSTANCE_INITIALIZER; 102 LAZY_INSTANCE_INITIALIZER;
101 base::LazyInstance<std::set<GLInProcessContextImpl*> > g_all_shared_contexts = 103 base::LazyInstance<std::set<GLInProcessContextImpl*> > g_all_shared_contexts =
102 LAZY_INSTANCE_INITIALIZER; 104 LAZY_INSTANCE_INITIALIZER;
103 105
104 size_t SharedContextCount() { 106 size_t SharedContextCount() {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 DCHECK(!callback.is_null()); 142 DCHECK(!callback.is_null());
141 base::Closure wrapped_callback = base::Bind( 143 base::Closure wrapped_callback = base::Bind(
142 &GLInProcessContextImpl::OnSignalSyncPoint, AsWeakPtr(), callback); 144 &GLInProcessContextImpl::OnSignalSyncPoint, AsWeakPtr(), callback);
143 command_buffer_->SignalSyncPoint(sync_point, wrapped_callback); 145 command_buffer_->SignalSyncPoint(sync_point, wrapped_callback);
144 } 146 }
145 147
146 gles2::GLES2Implementation* GLInProcessContextImpl::GetImplementation() { 148 gles2::GLES2Implementation* GLInProcessContextImpl::GetImplementation() {
147 return gles2_implementation_.get(); 149 return gles2_implementation_.get();
148 } 150 }
149 151
150 void GLInProcessContextImpl::OnContextLost(const base::Closure& callback) { 152 void GLInProcessContextImpl::SetContextLostCallback(
153 const base::Closure& callback) {
154 context_lost_callback_ = callback;
155 }
156
157 void GLInProcessContextImpl::OnContextLost() {
151 context_lost_ = true; 158 context_lost_ = true;
152 callback.Run(); 159 if (!context_lost_callback_.is_null()) {
160 context_lost_callback_.Run();
161 }
153 } 162 }
154 163
155 void GLInProcessContextImpl::OnSignalSyncPoint(const base::Closure& callback) { 164 void GLInProcessContextImpl::OnSignalSyncPoint(const base::Closure& callback) {
156 // TODO: Should it always trigger callbacks? 165 // TODO: Should it always trigger callbacks?
157 if (!context_lost_) 166 if (!context_lost_)
158 callback.Run(); 167 callback.Run();
159 } 168 }
160 169
161 bool GLInProcessContextImpl::Initialize( 170 bool GLInProcessContextImpl::Initialize(
171 scoped_refptr<gfx::GLSurface> surface,
162 bool is_offscreen, 172 bool is_offscreen,
163 bool share_resources, 173 bool share_resources,
164 gfx::AcceleratedWidget window, 174 gfx::AcceleratedWidget window,
165 const gfx::Size& size, 175 const gfx::Size& size,
166 const char* allowed_extensions, 176 const char* allowed_extensions,
167 const int32* attrib_list, 177 const int32* attrib_list,
168 gfx::GpuPreference gpu_preference, 178 gfx::GpuPreference gpu_preference) {
169 const base::Closure& context_lost_callback) {
170 DCHECK(size.width() >= 0 && size.height() >= 0); 179 DCHECK(size.width() >= 0 && size.height() >= 0);
171 180
172 std::vector<int32> attribs; 181 std::vector<int32> attribs;
173 while (attrib_list) { 182 while (attrib_list) {
174 int32 attrib = *attrib_list++; 183 int32 attrib = *attrib_list++;
175 switch (attrib) { 184 switch (attrib) {
176 // Known attributes 185 // Known attributes
177 case ALPHA_SIZE: 186 case ALPHA_SIZE:
178 case BLUE_SIZE: 187 case BLUE_SIZE:
179 case GREEN_SIZE: 188 case GREEN_SIZE:
(...skipping 10 matching lines...) Expand all
190 attrib_list = NULL; 199 attrib_list = NULL;
191 break; 200 break;
192 default: 201 default:
193 attribs.push_back(NONE); 202 attribs.push_back(NONE);
194 attrib_list = NULL; 203 attrib_list = NULL;
195 break; 204 break;
196 } 205 }
197 } 206 }
198 207
199 base::Closure wrapped_callback = 208 base::Closure wrapped_callback =
200 base::Bind(&GLInProcessContextImpl::OnContextLost, 209 base::Bind(&GLInProcessContextImpl::OnContextLost, AsWeakPtr());
201 AsWeakPtr(),
202 context_lost_callback);
203 command_buffer_.reset(new InProcessCommandBuffer()); 210 command_buffer_.reset(new InProcessCommandBuffer());
204 211
205 scoped_ptr<base::AutoLock> scoped_shared_context_lock; 212 scoped_ptr<base::AutoLock> scoped_shared_context_lock;
206 scoped_refptr<gles2::ShareGroup> share_group; 213 scoped_refptr<gles2::ShareGroup> share_group;
207 if (share_resources) { 214 if (share_resources) {
208 scoped_shared_context_lock.reset( 215 scoped_shared_context_lock.reset(
209 new base::AutoLock(g_all_shared_contexts_lock.Get())); 216 new base::AutoLock(g_all_shared_contexts_lock.Get()));
210 for (std::set<GLInProcessContextImpl*>::const_iterator it = 217 for (std::set<GLInProcessContextImpl*>::const_iterator it =
211 g_all_shared_contexts.Get().begin(); 218 g_all_shared_contexts.Get().begin();
212 it != g_all_shared_contexts.Get().end(); 219 it != g_all_shared_contexts.Get().end();
213 it++) { 220 it++) {
214 const GLInProcessContextImpl* context = *it; 221 const GLInProcessContextImpl* context = *it;
215 if (!context->context_lost_) { 222 if (!context->context_lost_) {
216 share_group = context->gles2_implementation_->share_group(); 223 share_group = context->gles2_implementation_->share_group();
217 DCHECK(share_group); 224 DCHECK(share_group);
218 share_group_id_ = context->share_group_id_; 225 share_group_id_ = context->share_group_id_;
219 break; 226 break;
220 } 227 }
221 share_group_id_ = std::max(share_group_id_, context->share_group_id_); 228 share_group_id_ = std::max(share_group_id_, context->share_group_id_);
222 } 229 }
223 if (!share_group && !++share_group_id_) 230 if (!share_group && !++share_group_id_)
224 ++share_group_id_; 231 ++share_group_id_;
225 } 232 }
226 if (!command_buffer_->Initialize(is_offscreen, 233 if (!command_buffer_->Initialize(surface,
227 share_resources, 234 is_offscreen,
228 window, 235 share_resources,
229 size, 236 window,
230 allowed_extensions, 237 size,
231 attribs, 238 allowed_extensions,
232 gpu_preference, 239 attribs,
233 wrapped_callback, 240 gpu_preference,
234 share_group_id_)) { 241 wrapped_callback,
242 share_group_id_)) {
235 LOG(INFO) << "Failed to initialize InProcessCommmandBuffer"; 243 LOG(INFO) << "Failed to initialize InProcessCommmandBuffer";
236 return false; 244 return false;
237 } 245 }
238 246
239 // Create the GLES2 helper, which writes the command buffer protocol. 247 // Create the GLES2 helper, which writes the command buffer protocol.
240 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); 248 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get()));
241 if (!gles2_helper_->Initialize(kCommandBufferSize)) { 249 if (!gles2_helper_->Initialize(kCommandBufferSize)) {
242 LOG(INFO) << "Failed to initialize GLES2CmdHelper"; 250 LOG(INFO) << "Failed to initialize GLES2CmdHelper";
243 Destroy(); 251 Destroy();
244 return false; 252 return false;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 } // anonymous namespace 346 } // anonymous namespace
339 347
340 // static 348 // static
341 GLInProcessContext* GLInProcessContext::CreateContext( 349 GLInProcessContext* GLInProcessContext::CreateContext(
342 bool is_offscreen, 350 bool is_offscreen,
343 gfx::AcceleratedWidget window, 351 gfx::AcceleratedWidget window,
344 const gfx::Size& size, 352 const gfx::Size& size,
345 bool share_resources, 353 bool share_resources,
346 const char* allowed_extensions, 354 const char* allowed_extensions,
347 const int32* attrib_list, 355 const int32* attrib_list,
348 gfx::GpuPreference gpu_preference, 356 gfx::GpuPreference gpu_preference) {
349 const base::Closure& callback) {
350 scoped_ptr<GLInProcessContextImpl> context( 357 scoped_ptr<GLInProcessContextImpl> context(
351 new GLInProcessContextImpl()); 358 new GLInProcessContextImpl());
352 if (!context->Initialize( 359 if (!context->Initialize(
360 NULL /* surface */,
353 is_offscreen, 361 is_offscreen,
354 share_resources, 362 share_resources,
355 window, 363 window,
356 size, 364 size,
357 allowed_extensions, 365 allowed_extensions,
358 attrib_list, 366 attrib_list,
359 gpu_preference, 367 gpu_preference))
360 callback))
361 return NULL; 368 return NULL;
362 369
363 return context.release(); 370 return context.release();
371 }
372
373 // static
374 GLInProcessContext* GLInProcessContext::CreateWithSurface(
375 scoped_refptr<gfx::GLSurface> surface,
376 bool is_offscreen,
377 const gfx::Size& size,
378 bool share_resources,
379 const char* allowed_extensions,
380 const int32* attrib_list,
381 gfx::GpuPreference gpu_preference) {
382 scoped_ptr<GLInProcessContextImpl> context(
383 new GLInProcessContextImpl());
384 if (!context->Initialize(
385 surface,
386 is_offscreen,
387 share_resources,
388 NULL /* window */,
389 size,
390 allowed_extensions,
391 attrib_list,
392 gpu_preference))
393 return NULL;
394
395 return context.release();
364 } 396 }
365 397
366 // static 398 // static
367 void GLInProcessContext::SetGpuMemoryBufferFactory( 399 void GLInProcessContext::SetGpuMemoryBufferFactory(
368 GpuMemoryBufferFactory* factory) { 400 GpuMemoryBufferFactory* factory) {
369 DCHECK_EQ(0u, SharedContextCount()); 401 DCHECK_EQ(0u, SharedContextCount());
370 g_gpu_memory_buffer_factory = factory; 402 g_gpu_memory_buffer_factory = factory;
371 } 403 }
372 404
373 } // namespace gpu 405 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698