OLD | NEW |
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/gpu_memory_buffer_factory.h" | |
27 #include "gpu/command_buffer/client/image_factory.h" | |
28 #include "gpu/command_buffer/client/transfer_buffer.h" | 26 #include "gpu/command_buffer/client/transfer_buffer.h" |
29 #include "gpu/command_buffer/common/command_buffer.h" | 27 #include "gpu/command_buffer/common/command_buffer.h" |
30 #include "gpu/command_buffer/common/constants.h" | 28 #include "gpu/command_buffer/common/constants.h" |
31 #include "gpu/command_buffer/service/in_process_command_buffer.h" | 29 #include "gpu/command_buffer/service/in_process_command_buffer.h" |
32 #include "ui/gfx/size.h" | 30 #include "ui/gfx/size.h" |
33 #include "ui/gl/gl_image.h" | 31 #include "ui/gl/gl_image.h" |
34 | 32 |
35 namespace gpu { | 33 namespace gpu { |
36 | 34 |
37 namespace { | 35 namespace { |
38 | 36 |
39 const int32 kCommandBufferSize = 1024 * 1024; | 37 const int32 kCommandBufferSize = 1024 * 1024; |
40 // TODO(kbr): make the transfer buffer size configurable via context | 38 // TODO(kbr): make the transfer buffer size configurable via context |
41 // creation attributes. | 39 // creation attributes. |
42 const size_t kStartTransferBufferSize = 4 * 1024 * 1024; | 40 const size_t kStartTransferBufferSize = 4 * 1024 * 1024; |
43 const size_t kMinTransferBufferSize = 1 * 256 * 1024; | 41 const size_t kMinTransferBufferSize = 1 * 256 * 1024; |
44 const size_t kMaxTransferBufferSize = 16 * 1024 * 1024; | 42 const size_t kMaxTransferBufferSize = 16 * 1024 * 1024; |
45 | 43 |
46 static GpuMemoryBufferFactory* g_gpu_memory_buffer_factory = NULL; | |
47 | |
48 class GLInProcessContextImpl | 44 class GLInProcessContextImpl |
49 : public GLInProcessContext, | 45 : public GLInProcessContext, |
50 public gles2::ImageFactory, | |
51 public base::SupportsWeakPtr<GLInProcessContextImpl> { | 46 public base::SupportsWeakPtr<GLInProcessContextImpl> { |
52 public: | 47 public: |
53 explicit GLInProcessContextImpl(); | 48 explicit GLInProcessContextImpl(); |
54 virtual ~GLInProcessContextImpl(); | 49 virtual ~GLInProcessContextImpl(); |
55 | 50 |
56 bool Initialize(scoped_refptr<gfx::GLSurface> surface, | 51 bool Initialize(scoped_refptr<gfx::GLSurface> surface, |
57 bool is_offscreen, | 52 bool is_offscreen, |
58 bool share_resources, | 53 bool share_resources, |
59 gfx::AcceleratedWidget window, | 54 gfx::AcceleratedWidget window, |
60 const gfx::Size& size, | 55 const gfx::Size& size, |
61 const char* allowed_extensions, | 56 const char* allowed_extensions, |
62 const GLInProcessContextAttribs& attribs, | 57 const GLInProcessContextAttribs& attribs, |
63 gfx::GpuPreference gpu_preference); | 58 gfx::GpuPreference gpu_preference); |
64 | 59 |
65 // GLInProcessContext implementation: | 60 // GLInProcessContext implementation: |
66 virtual void SetContextLostCallback(const base::Closure& callback) OVERRIDE; | 61 virtual void SetContextLostCallback(const base::Closure& callback) OVERRIDE; |
67 virtual void SignalSyncPoint(unsigned sync_point, | 62 virtual void SignalSyncPoint(unsigned sync_point, |
68 const base::Closure& callback) OVERRIDE; | 63 const base::Closure& callback) OVERRIDE; |
69 virtual void SignalQuery(unsigned query, const base::Closure& callback) | 64 virtual void SignalQuery(unsigned query, const base::Closure& callback) |
70 OVERRIDE; | 65 OVERRIDE; |
71 virtual gles2::GLES2Implementation* GetImplementation() OVERRIDE; | 66 virtual gles2::GLES2Implementation* GetImplementation() OVERRIDE; |
72 | 67 |
73 // ImageFactory implementation: | |
74 virtual scoped_ptr<gfx::GpuMemoryBuffer> CreateGpuMemoryBuffer( | |
75 int width, int height, GLenum internalformat, | |
76 unsigned* image_id) OVERRIDE; | |
77 virtual void DeleteGpuMemoryBuffer(unsigned image_id) OVERRIDE; | |
78 | |
79 private: | 68 private: |
80 void Destroy(); | 69 void Destroy(); |
81 void PollQueryCallbacks(); | 70 void PollQueryCallbacks(); |
82 void CallQueryCallback(size_t index); | 71 void CallQueryCallback(size_t index); |
83 void OnContextLost(); | 72 void OnContextLost(); |
84 void OnSignalSyncPoint(const base::Closure& callback); | 73 void OnSignalSyncPoint(const base::Closure& callback); |
85 | 74 |
86 scoped_ptr<gles2::GLES2CmdHelper> gles2_helper_; | 75 scoped_ptr<gles2::GLES2CmdHelper> gles2_helper_; |
87 scoped_ptr<TransferBuffer> transfer_buffer_; | 76 scoped_ptr<TransferBuffer> transfer_buffer_; |
88 scoped_ptr<gles2::GLES2Implementation> gles2_implementation_; | 77 scoped_ptr<gles2::GLES2Implementation> gles2_implementation_; |
(...skipping 12 matching lines...) Expand all Loading... |
101 base::LazyInstance<base::Lock> g_all_shared_contexts_lock = | 90 base::LazyInstance<base::Lock> g_all_shared_contexts_lock = |
102 LAZY_INSTANCE_INITIALIZER; | 91 LAZY_INSTANCE_INITIALIZER; |
103 base::LazyInstance<std::set<GLInProcessContextImpl*> > g_all_shared_contexts = | 92 base::LazyInstance<std::set<GLInProcessContextImpl*> > g_all_shared_contexts = |
104 LAZY_INSTANCE_INITIALIZER; | 93 LAZY_INSTANCE_INITIALIZER; |
105 | 94 |
106 size_t SharedContextCount() { | 95 size_t SharedContextCount() { |
107 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | 96 base::AutoLock lock(g_all_shared_contexts_lock.Get()); |
108 return g_all_shared_contexts.Get().size(); | 97 return g_all_shared_contexts.Get().size(); |
109 } | 98 } |
110 | 99 |
111 scoped_ptr<gfx::GpuMemoryBuffer> GLInProcessContextImpl::CreateGpuMemoryBuffer( | |
112 int width, int height, GLenum internalformat, unsigned int* image_id) { | |
113 scoped_ptr<gfx::GpuMemoryBuffer> buffer( | |
114 g_gpu_memory_buffer_factory->CreateGpuMemoryBuffer(width, | |
115 height, | |
116 internalformat)); | |
117 if (!buffer) | |
118 return scoped_ptr<gfx::GpuMemoryBuffer>(); | |
119 | |
120 *image_id = command_buffer_->CreateImageForGpuMemoryBuffer( | |
121 buffer->GetHandle(), gfx::Size(width, height)); | |
122 return buffer.Pass(); | |
123 } | |
124 | |
125 void GLInProcessContextImpl::DeleteGpuMemoryBuffer(unsigned int image_id) { | |
126 command_buffer_->RemoveImage(image_id); | |
127 } | |
128 | |
129 GLInProcessContextImpl::GLInProcessContextImpl() | 100 GLInProcessContextImpl::GLInProcessContextImpl() |
130 : share_group_id_(0), context_lost_(false) {} | 101 : share_group_id_(0), context_lost_(false) {} |
131 | 102 |
132 GLInProcessContextImpl::~GLInProcessContextImpl() { | 103 GLInProcessContextImpl::~GLInProcessContextImpl() { |
133 { | 104 { |
134 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | 105 base::AutoLock lock(g_all_shared_contexts_lock.Get()); |
135 g_all_shared_contexts.Get().erase(this); | 106 g_all_shared_contexts.Get().erase(this); |
136 } | 107 } |
137 Destroy(); | 108 Destroy(); |
138 } | 109 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 243 |
273 // Create a transfer buffer. | 244 // Create a transfer buffer. |
274 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); | 245 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); |
275 | 246 |
276 // Create the object exposing the OpenGL API. | 247 // Create the object exposing the OpenGL API. |
277 gles2_implementation_.reset(new gles2::GLES2Implementation( | 248 gles2_implementation_.reset(new gles2::GLES2Implementation( |
278 gles2_helper_.get(), | 249 gles2_helper_.get(), |
279 share_group, | 250 share_group, |
280 transfer_buffer_.get(), | 251 transfer_buffer_.get(), |
281 false, | 252 false, |
282 this)); | 253 command_buffer_.get())); |
283 | 254 |
284 if (share_resources) { | 255 if (share_resources) { |
285 g_all_shared_contexts.Get().insert(this); | 256 g_all_shared_contexts.Get().insert(this); |
286 scoped_shared_context_lock.reset(); | 257 scoped_shared_context_lock.reset(); |
287 } | 258 } |
288 | 259 |
289 if (!gles2_implementation_->Initialize( | 260 if (!gles2_implementation_->Initialize( |
290 kStartTransferBufferSize, | 261 kStartTransferBufferSize, |
291 kMinTransferBufferSize, | 262 kMinTransferBufferSize, |
292 kMaxTransferBufferSize)) { | 263 kMaxTransferBufferSize)) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 gfx::kNullAcceleratedWidget, | 385 gfx::kNullAcceleratedWidget, |
415 surface->GetSize(), | 386 surface->GetSize(), |
416 allowed_extensions, | 387 allowed_extensions, |
417 attribs, | 388 attribs, |
418 gpu_preference)) | 389 gpu_preference)) |
419 return NULL; | 390 return NULL; |
420 | 391 |
421 return context.release(); | 392 return context.release(); |
422 } | 393 } |
423 | 394 |
424 // static | |
425 void GLInProcessContext::SetGpuMemoryBufferFactory( | |
426 GpuMemoryBufferFactory* factory) { | |
427 DCHECK_EQ(0u, SharedContextCount()); | |
428 g_gpu_memory_buffer_factory = factory; | |
429 } | |
430 | |
431 } // namespace gpu | 395 } // namespace gpu |
OLD | NEW |