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

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

Issue 143023005: Support multiple service instances with GLInProcessContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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
11 #include <GLES2/gl2.h> 11 #include <GLES2/gl2.h>
12 #ifndef GL_GLEXT_PROTOTYPES 12 #ifndef GL_GLEXT_PROTOTYPES
13 #define GL_GLEXT_PROTOTYPES 1 13 #define GL_GLEXT_PROTOTYPES 1
14 #endif 14 #endif
15 #include <GLES2/gl2ext.h> 15 #include <GLES2/gl2ext.h>
16 #include <GLES2/gl2extchromium.h> 16 #include <GLES2/gl2extchromium.h>
17 17
18 #include "base/bind.h" 18 #include "base/bind.h"
19 #include "base/bind_helpers.h" 19 #include "base/bind_helpers.h"
20 #include "base/lazy_instance.h" 20 #include "base/lazy_instance.h"
21 #include "base/logging.h" 21 #include "base/logging.h"
22 #include "base/memory/scoped_ptr.h" 22 #include "base/memory/scoped_ptr.h"
23 #include "base/memory/weak_ptr.h" 23 #include "base/memory/weak_ptr.h"
24 #include "base/message_loop/message_loop.h" 24 #include "base/message_loop/message_loop.h"
25 #include "gpu/command_buffer/client/gles2_implementation.h" 25 #include "gpu/command_buffer/client/gles2_implementation.h"
26 #include "gpu/command_buffer/client/transfer_buffer.h" 26 #include "gpu/command_buffer/client/transfer_buffer.h"
27 #include "gpu/command_buffer/common/command_buffer.h" 27 #include "gpu/command_buffer/common/command_buffer.h"
28 #include "gpu/command_buffer/common/constants.h" 28 #include "gpu/command_buffer/common/constants.h"
29 #include "gpu/command_buffer/service/in_process_command_buffer.h"
30 #include "ui/gfx/size.h" 29 #include "ui/gfx/size.h"
31 #include "ui/gl/gl_image.h" 30 #include "ui/gl/gl_image.h"
32 31
33 #if defined(OS_ANDROID) 32 #if defined(OS_ANDROID)
34 #include "ui/gl/android/surface_texture.h" 33 #include "ui/gl/android/surface_texture.h"
35 #endif 34 #endif
36 35
37 namespace gpu { 36 namespace gpu {
38 37
39 namespace { 38 namespace {
40 39
41 const int32 kCommandBufferSize = 1024 * 1024; 40 const int32 kCommandBufferSize = 1024 * 1024;
42 // TODO(kbr): make the transfer buffer size configurable via context 41 // TODO(kbr): make the transfer buffer size configurable via context
43 // creation attributes. 42 // creation attributes.
44 const size_t kStartTransferBufferSize = 4 * 1024 * 1024; 43 const size_t kStartTransferBufferSize = 4 * 1024 * 1024;
45 const size_t kMinTransferBufferSize = 1 * 256 * 1024; 44 const size_t kMinTransferBufferSize = 1 * 256 * 1024;
46 const size_t kMaxTransferBufferSize = 16 * 1024 * 1024; 45 const size_t kMaxTransferBufferSize = 16 * 1024 * 1024;
47 46
48 class GLInProcessContextImpl 47 class GLInProcessContextImpl
49 : public GLInProcessContext, 48 : public GLInProcessContext,
50 public base::SupportsWeakPtr<GLInProcessContextImpl> { 49 public base::SupportsWeakPtr<GLInProcessContextImpl> {
51 public: 50 public:
52 explicit GLInProcessContextImpl(); 51 explicit GLInProcessContextImpl();
53 virtual ~GLInProcessContextImpl(); 52 virtual ~GLInProcessContextImpl();
54 53
55 bool Initialize(scoped_refptr<gfx::GLSurface> surface, 54 bool Initialize(
56 bool is_offscreen, 55 scoped_refptr<gfx::GLSurface> surface,
57 bool share_resources, 56 bool is_offscreen,
58 gfx::AcceleratedWidget window, 57 bool use_global_share_group,
59 const gfx::Size& size, 58 GLInProcessContext* share_context,
60 const GLInProcessContextAttribs& attribs, 59 gfx::AcceleratedWidget window,
61 gfx::GpuPreference gpu_preference); 60 const gfx::Size& size,
61 const GLInProcessContextAttribs& attribs,
62 gfx::GpuPreference gpu_preference,
63 const scoped_refptr<InProcessCommandBuffer::Service>& service);
62 64
63 // GLInProcessContext implementation: 65 // GLInProcessContext implementation:
64 virtual void SetContextLostCallback(const base::Closure& callback) OVERRIDE; 66 virtual void SetContextLostCallback(const base::Closure& callback) OVERRIDE;
65 virtual gles2::GLES2Implementation* GetImplementation() OVERRIDE; 67 virtual gles2::GLES2Implementation* GetImplementation() OVERRIDE;
66 68
67 #if defined(OS_ANDROID) 69 #if defined(OS_ANDROID)
68 virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( 70 virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture(
69 uint32 stream_id) OVERRIDE; 71 uint32 stream_id) OVERRIDE;
70 #endif 72 #endif
71 73
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 void GLInProcessContextImpl::OnContextLost() { 115 void GLInProcessContextImpl::OnContextLost() {
114 context_lost_ = true; 116 context_lost_ = true;
115 if (!context_lost_callback_.is_null()) { 117 if (!context_lost_callback_.is_null()) {
116 context_lost_callback_.Run(); 118 context_lost_callback_.Run();
117 } 119 }
118 } 120 }
119 121
120 bool GLInProcessContextImpl::Initialize( 122 bool GLInProcessContextImpl::Initialize(
121 scoped_refptr<gfx::GLSurface> surface, 123 scoped_refptr<gfx::GLSurface> surface,
122 bool is_offscreen, 124 bool is_offscreen,
123 bool share_resources, 125 bool use_global_share_group,
126 GLInProcessContext* share_context,
124 gfx::AcceleratedWidget window, 127 gfx::AcceleratedWidget window,
125 const gfx::Size& size, 128 const gfx::Size& size,
126 const GLInProcessContextAttribs& attribs, 129 const GLInProcessContextAttribs& attribs,
127 gfx::GpuPreference gpu_preference) { 130 gfx::GpuPreference gpu_preference,
131 const scoped_refptr<InProcessCommandBuffer::Service>& service) {
132 DCHECK(!use_global_share_group || !share_context);
128 DCHECK(size.width() >= 0 && size.height() >= 0); 133 DCHECK(size.width() >= 0 && size.height() >= 0);
129 134
130 // Changes to these values should also be copied to 135 // Changes to these values should also be copied to
131 // gpu/command_buffer/client/gl_in_process_context.cc and to 136 // gpu/command_buffer/client/gl_in_process_context.cc and to
132 // content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h 137 // content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h
133 const int32 ALPHA_SIZE = 0x3021; 138 const int32 ALPHA_SIZE = 0x3021;
134 const int32 BLUE_SIZE = 0x3022; 139 const int32 BLUE_SIZE = 0x3022;
135 const int32 GREEN_SIZE = 0x3023; 140 const int32 GREEN_SIZE = 0x3023;
136 const int32 RED_SIZE = 0x3024; 141 const int32 RED_SIZE = 0x3024;
137 const int32 DEPTH_SIZE = 0x3025; 142 const int32 DEPTH_SIZE = 0x3025;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 attrib_vector.push_back(attribs.sample_buffers); 182 attrib_vector.push_back(attribs.sample_buffers);
178 } 183 }
179 if (attribs.fail_if_major_perf_caveat > 0) { 184 if (attribs.fail_if_major_perf_caveat > 0) {
180 attrib_vector.push_back(FAIL_IF_MAJOR_PERF_CAVEAT); 185 attrib_vector.push_back(FAIL_IF_MAJOR_PERF_CAVEAT);
181 attrib_vector.push_back(attribs.fail_if_major_perf_caveat); 186 attrib_vector.push_back(attribs.fail_if_major_perf_caveat);
182 } 187 }
183 attrib_vector.push_back(NONE); 188 attrib_vector.push_back(NONE);
184 189
185 base::Closure wrapped_callback = 190 base::Closure wrapped_callback =
186 base::Bind(&GLInProcessContextImpl::OnContextLost, AsWeakPtr()); 191 base::Bind(&GLInProcessContextImpl::OnContextLost, AsWeakPtr());
187 command_buffer_.reset(new InProcessCommandBuffer()); 192 command_buffer_.reset(new InProcessCommandBuffer(service));
188 193
189 scoped_ptr<base::AutoLock> scoped_shared_context_lock; 194 scoped_ptr<base::AutoLock> scoped_shared_context_lock;
190 scoped_refptr<gles2::ShareGroup> share_group; 195 scoped_refptr<gles2::ShareGroup> share_group;
191 InProcessCommandBuffer* share_command_buffer = NULL; 196 InProcessCommandBuffer* share_command_buffer = NULL;
192 if (share_resources) { 197 if (use_global_share_group) {
193 scoped_shared_context_lock.reset( 198 scoped_shared_context_lock.reset(
194 new base::AutoLock(g_all_shared_contexts_lock.Get())); 199 new base::AutoLock(g_all_shared_contexts_lock.Get()));
195 for (std::set<GLInProcessContextImpl*>::const_iterator it = 200 for (std::set<GLInProcessContextImpl*>::const_iterator it =
196 g_all_shared_contexts.Get().begin(); 201 g_all_shared_contexts.Get().begin();
197 it != g_all_shared_contexts.Get().end(); 202 it != g_all_shared_contexts.Get().end();
198 it++) { 203 it++) {
199 const GLInProcessContextImpl* context = *it; 204 const GLInProcessContextImpl* context = *it;
200 if (!context->context_lost_) { 205 if (!context->context_lost_) {
201 share_group = context->gles2_implementation_->share_group(); 206 share_group = context->gles2_implementation_->share_group();
202 share_command_buffer = context->command_buffer_.get(); 207 share_command_buffer = context->command_buffer_.get();
203 DCHECK(share_group); 208 DCHECK(share_group);
204 DCHECK(share_command_buffer); 209 DCHECK(share_command_buffer);
205 break; 210 break;
206 } 211 }
207 } 212 }
213 } else if (share_context) {
214 GLInProcessContextImpl* impl =
215 static_cast<GLInProcessContextImpl*>(share_context);
216 share_group = impl->gles2_implementation_->share_group();
217 share_command_buffer = impl->command_buffer_.get();
218 DCHECK(share_group);
219 DCHECK(share_command_buffer);
208 } 220 }
221
209 if (!command_buffer_->Initialize(surface, 222 if (!command_buffer_->Initialize(surface,
210 is_offscreen, 223 is_offscreen,
211 window, 224 window,
212 size, 225 size,
213 attrib_vector, 226 attrib_vector,
214 gpu_preference, 227 gpu_preference,
215 wrapped_callback, 228 wrapped_callback,
216 share_command_buffer)) { 229 share_command_buffer)) {
217 LOG(ERROR) << "Failed to initialize InProcessCommmandBuffer"; 230 LOG(ERROR) << "Failed to initialize InProcessCommmandBuffer";
218 return false; 231 return false;
(...skipping 15 matching lines...) Expand all
234 247
235 // Create the object exposing the OpenGL API. 248 // Create the object exposing the OpenGL API.
236 gles2_implementation_.reset(new gles2::GLES2Implementation( 249 gles2_implementation_.reset(new gles2::GLES2Implementation(
237 gles2_helper_.get(), 250 gles2_helper_.get(),
238 share_group, 251 share_group,
239 transfer_buffer_.get(), 252 transfer_buffer_.get(),
240 bind_generates_resources, 253 bind_generates_resources,
241 free_everything_when_invisible, 254 free_everything_when_invisible,
242 command_buffer_.get())); 255 command_buffer_.get()));
243 256
244 if (share_resources) { 257 if (use_global_share_group) {
245 g_all_shared_contexts.Get().insert(this); 258 g_all_shared_contexts.Get().insert(this);
246 scoped_shared_context_lock.reset(); 259 scoped_shared_context_lock.reset();
247 } 260 }
248 261
249 if (!gles2_implementation_->Initialize( 262 if (!gles2_implementation_->Initialize(
250 kStartTransferBufferSize, 263 kStartTransferBufferSize,
251 kMinTransferBufferSize, 264 kMinTransferBufferSize,
252 kMaxTransferBufferSize, 265 kMaxTransferBufferSize,
253 gles2::GLES2Implementation::kNoLimit)) { 266 gles2::GLES2Implementation::kNoLimit)) {
254 return false; 267 return false;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 const gfx::Size& size, 313 const gfx::Size& size,
301 bool share_resources, 314 bool share_resources,
302 const GLInProcessContextAttribs& attribs, 315 const GLInProcessContextAttribs& attribs,
303 gfx::GpuPreference gpu_preference) { 316 gfx::GpuPreference gpu_preference) {
304 scoped_ptr<GLInProcessContextImpl> context( 317 scoped_ptr<GLInProcessContextImpl> context(
305 new GLInProcessContextImpl()); 318 new GLInProcessContextImpl());
306 if (!context->Initialize( 319 if (!context->Initialize(
307 NULL /* surface */, 320 NULL /* surface */,
308 is_offscreen, 321 is_offscreen,
309 share_resources, 322 share_resources,
323 NULL,
310 window, 324 window,
311 size, 325 size,
312 attribs, 326 attribs,
313 gpu_preference)) 327 gpu_preference,
328 scoped_refptr<InProcessCommandBuffer::Service>()))
314 return NULL; 329 return NULL;
315 330
316 return context.release(); 331 return context.release();
317 } 332 }
318 333
319 // static 334 // static
320 GLInProcessContext* GLInProcessContext::CreateWithSurface( 335 GLInProcessContext* GLInProcessContext::CreateWithSurface(
321 scoped_refptr<gfx::GLSurface> surface, 336 scoped_refptr<gfx::GLSurface> surface,
322 bool share_resources, 337 scoped_refptr<gpu::InProcessCommandBuffer::Service> service,
338 GLInProcessContext* share_context,
323 const GLInProcessContextAttribs& attribs, 339 const GLInProcessContextAttribs& attribs,
324 gfx::GpuPreference gpu_preference) { 340 gfx::GpuPreference gpu_preference) {
325 scoped_ptr<GLInProcessContextImpl> context( 341 scoped_ptr<GLInProcessContextImpl> context(
326 new GLInProcessContextImpl()); 342 new GLInProcessContextImpl());
327 if (!context->Initialize( 343 if (!context->Initialize(
328 surface, 344 surface,
329 surface->IsOffscreen(), 345 surface->IsOffscreen(),
330 share_resources, 346 false,
347 share_context,
331 gfx::kNullAcceleratedWidget, 348 gfx::kNullAcceleratedWidget,
332 surface->GetSize(), 349 surface->GetSize(),
333 attribs, 350 attribs,
334 gpu_preference)) 351 gpu_preference,
352 service))
335 return NULL; 353 return NULL;
336 354
337 return context.release(); 355 return context.release();
338 } 356 }
339 357
340 } // namespace gpu 358 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gl_in_process_context.h ('k') | gpu/command_buffer/service/in_process_command_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698