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/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 share_resources, |
59 const gfx::Size& size, | 58 gfx::AcceleratedWidget window, |
60 const GLInProcessContextAttribs& attribs, | 59 const gfx::Size& size, |
61 gfx::GpuPreference gpu_preference); | 60 const GLInProcessContextAttribs& attribs, |
61 gfx::GpuPreference gpu_preference, | |
62 const scoped_refptr<InProcessCommandBuffer::Service>& service); | |
62 | 63 |
63 // GLInProcessContext implementation: | 64 // GLInProcessContext implementation: |
64 virtual void SetContextLostCallback(const base::Closure& callback) OVERRIDE; | 65 virtual void SetContextLostCallback(const base::Closure& callback) OVERRIDE; |
65 virtual gles2::GLES2Implementation* GetImplementation() OVERRIDE; | 66 virtual gles2::GLES2Implementation* GetImplementation() OVERRIDE; |
66 | 67 |
67 #if defined(OS_ANDROID) | 68 #if defined(OS_ANDROID) |
68 virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( | 69 virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( |
69 uint32 stream_id) OVERRIDE; | 70 uint32 stream_id) OVERRIDE; |
70 #endif | 71 #endif |
71 | 72 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 } | 119 } |
119 } | 120 } |
120 | 121 |
121 bool GLInProcessContextImpl::Initialize( | 122 bool GLInProcessContextImpl::Initialize( |
122 scoped_refptr<gfx::GLSurface> surface, | 123 scoped_refptr<gfx::GLSurface> surface, |
123 bool is_offscreen, | 124 bool is_offscreen, |
124 bool share_resources, | 125 bool share_resources, |
125 gfx::AcceleratedWidget window, | 126 gfx::AcceleratedWidget window, |
126 const gfx::Size& size, | 127 const gfx::Size& size, |
127 const GLInProcessContextAttribs& attribs, | 128 const GLInProcessContextAttribs& attribs, |
128 gfx::GpuPreference gpu_preference) { | 129 gfx::GpuPreference gpu_preference, |
130 const scoped_refptr<InProcessCommandBuffer::Service>& service) { | |
129 DCHECK(size.width() >= 0 && size.height() >= 0); | 131 DCHECK(size.width() >= 0 && size.height() >= 0); |
130 | 132 |
131 // Changes to these values should also be copied to | 133 // Changes to these values should also be copied to |
132 // gpu/command_buffer/client/gl_in_process_context.cc and to | 134 // gpu/command_buffer/client/gl_in_process_context.cc and to |
133 // content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h | 135 // content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h |
134 const int32 ALPHA_SIZE = 0x3021; | 136 const int32 ALPHA_SIZE = 0x3021; |
135 const int32 BLUE_SIZE = 0x3022; | 137 const int32 BLUE_SIZE = 0x3022; |
136 const int32 GREEN_SIZE = 0x3023; | 138 const int32 GREEN_SIZE = 0x3023; |
137 const int32 RED_SIZE = 0x3024; | 139 const int32 RED_SIZE = 0x3024; |
138 const int32 DEPTH_SIZE = 0x3025; | 140 const int32 DEPTH_SIZE = 0x3025; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 attrib_vector.push_back(attribs.sample_buffers); | 180 attrib_vector.push_back(attribs.sample_buffers); |
179 } | 181 } |
180 if (attribs.fail_if_major_perf_caveat > 0) { | 182 if (attribs.fail_if_major_perf_caveat > 0) { |
181 attrib_vector.push_back(FAIL_IF_MAJOR_PERF_CAVEAT); | 183 attrib_vector.push_back(FAIL_IF_MAJOR_PERF_CAVEAT); |
182 attrib_vector.push_back(attribs.fail_if_major_perf_caveat); | 184 attrib_vector.push_back(attribs.fail_if_major_perf_caveat); |
183 } | 185 } |
184 attrib_vector.push_back(NONE); | 186 attrib_vector.push_back(NONE); |
185 | 187 |
186 base::Closure wrapped_callback = | 188 base::Closure wrapped_callback = |
187 base::Bind(&GLInProcessContextImpl::OnContextLost, AsWeakPtr()); | 189 base::Bind(&GLInProcessContextImpl::OnContextLost, AsWeakPtr()); |
188 command_buffer_.reset(new InProcessCommandBuffer()); | 190 command_buffer_.reset(new InProcessCommandBuffer(service)); |
189 | 191 |
190 scoped_ptr<base::AutoLock> scoped_shared_context_lock; | 192 scoped_ptr<base::AutoLock> scoped_shared_context_lock; |
191 scoped_refptr<gles2::ShareGroup> share_group; | 193 scoped_refptr<gles2::ShareGroup> share_group; |
192 if (share_resources) { | 194 if (share_resources) { |
193 scoped_shared_context_lock.reset( | 195 scoped_shared_context_lock.reset( |
194 new base::AutoLock(g_all_shared_contexts_lock.Get())); | 196 new base::AutoLock(g_all_shared_contexts_lock.Get())); |
195 for (std::set<GLInProcessContextImpl*>::const_iterator it = | 197 for (std::set<GLInProcessContextImpl*>::const_iterator it = |
196 g_all_shared_contexts.Get().begin(); | 198 g_all_shared_contexts.Get().begin(); |
197 it != g_all_shared_contexts.Get().end(); | 199 it != g_all_shared_contexts.Get().end(); |
198 it++) { | 200 it++) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 gfx::GpuPreference gpu_preference) { | 308 gfx::GpuPreference gpu_preference) { |
307 scoped_ptr<GLInProcessContextImpl> context( | 309 scoped_ptr<GLInProcessContextImpl> context( |
308 new GLInProcessContextImpl()); | 310 new GLInProcessContextImpl()); |
309 if (!context->Initialize( | 311 if (!context->Initialize( |
310 NULL /* surface */, | 312 NULL /* surface */, |
311 is_offscreen, | 313 is_offscreen, |
312 share_resources, | 314 share_resources, |
313 window, | 315 window, |
314 size, | 316 size, |
315 attribs, | 317 attribs, |
316 gpu_preference)) | 318 gpu_preference, |
319 scoped_refptr<InProcessCommandBuffer::Service>())) | |
317 return NULL; | 320 return NULL; |
318 | 321 |
319 return context.release(); | 322 return context.release(); |
320 } | 323 } |
321 | 324 |
322 // static | 325 // static |
323 GLInProcessContext* GLInProcessContext::CreateWithSurface( | 326 GLInProcessContext* GLInProcessContext::CreateWithSurface( |
324 scoped_refptr<gfx::GLSurface> surface, | 327 scoped_refptr<gfx::GLSurface> surface, |
328 scoped_refptr<gpu::InProcessCommandBuffer::Service> service, | |
325 bool share_resources, | 329 bool share_resources, |
326 const GLInProcessContextAttribs& attribs, | 330 const GLInProcessContextAttribs& attribs, |
327 gfx::GpuPreference gpu_preference) { | 331 gfx::GpuPreference gpu_preference) { |
328 scoped_ptr<GLInProcessContextImpl> context( | 332 scoped_ptr<GLInProcessContextImpl> context( |
329 new GLInProcessContextImpl()); | 333 new GLInProcessContextImpl()); |
330 if (!context->Initialize( | 334 if (!context->Initialize( |
331 surface, | 335 surface, |
332 surface->IsOffscreen(), | 336 surface->IsOffscreen(), |
333 share_resources, | 337 share_resources, |
334 gfx::kNullAcceleratedWidget, | 338 gfx::kNullAcceleratedWidget, |
335 surface->GetSize(), | 339 surface->GetSize(), |
336 attribs, | 340 attribs, |
337 gpu_preference)) | 341 gpu_preference, |
342 scoped_refptr<InProcessCommandBuffer::Service>())) | |
boliu
2014/02/10 18:42:08
oh, need to pass service param here, updated https
no sievers
2014/02/12 03:09:15
Doh, thanks.
| |
338 return NULL; | 343 return NULL; |
339 | 344 |
340 return context.release(); | 345 return context.release(); |
341 } | 346 } |
342 | 347 |
343 } // namespace gpu | 348 } // namespace gpu |
OLD | NEW |