OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <build/build_config.h> | |
6 | |
5 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 7 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
6 #include "gpu/command_buffer/client/gles2_implementation.h" | 8 #include "gpu/command_buffer/client/gles2_implementation.h" |
7 #include "gpu/command_buffer/client/gles2_lib.h" | 9 #include "gpu/command_buffer/client/gles2_lib.h" |
10 #include "gpu/command_buffer/common/thread_local.h" | |
8 #include "gpu/pgl/command_buffer_pepper.h" | 11 #include "gpu/pgl/command_buffer_pepper.h" |
9 #include "gpu/pgl/pgl.h" | 12 #include "gpu/pgl/pgl.h" |
10 | 13 |
11 namespace { | 14 namespace { |
12 const int32 kTransferBufferSize = 512 * 1024; | 15 const int32 kTransferBufferSize = 512 * 1024; |
13 | 16 |
14 class PGLContextImpl { | 17 class PGLContextImpl { |
15 public: | 18 public: |
16 PGLContextImpl(NPP npp, | 19 PGLContextImpl(NPP npp, |
17 NPDevice* device, | 20 NPDevice* device, |
(...skipping 18 matching lines...) Expand all Loading... | |
36 | 39 |
37 NPP npp_; | 40 NPP npp_; |
38 NPDevice* device_; | 41 NPDevice* device_; |
39 NPDeviceContext3D* device_context_; | 42 NPDeviceContext3D* device_context_; |
40 CommandBufferPepper* command_buffer_; | 43 CommandBufferPepper* command_buffer_; |
41 gpu::gles2::GLES2CmdHelper* gles2_helper_; | 44 gpu::gles2::GLES2CmdHelper* gles2_helper_; |
42 int32 transfer_buffer_id_; | 45 int32 transfer_buffer_id_; |
43 gpu::gles2::GLES2Implementation* gles2_implementation_; | 46 gpu::gles2::GLES2Implementation* gles2_implementation_; |
44 }; | 47 }; |
45 | 48 |
46 THREAD_LOCAL PGLContextImpl* g_current_pgl_context; | 49 gpu::ThreadLocalKey g_pgl_context_key; |
47 | 50 |
48 PGLContextImpl::PGLContextImpl(NPP npp, | 51 PGLContextImpl::PGLContextImpl(NPP npp, |
49 NPDevice* device, | 52 NPDevice* device, |
50 NPDeviceContext3D* device_context) | 53 NPDeviceContext3D* device_context) |
51 : npp_(npp), | 54 : npp_(npp), |
52 device_(device), | 55 device_(device), |
53 device_context_(device_context), | 56 device_context_(device_context), |
54 command_buffer_(NULL), | 57 command_buffer_(NULL), |
55 gles2_helper_(NULL), | 58 gles2_helper_(NULL), |
56 transfer_buffer_id_(0), | 59 transfer_buffer_id_(0), |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 } | 99 } |
97 | 100 |
98 delete gles2_helper_; | 101 delete gles2_helper_; |
99 gles2_helper_ = NULL; | 102 gles2_helper_ = NULL; |
100 | 103 |
101 delete command_buffer_; | 104 delete command_buffer_; |
102 command_buffer_ = NULL; | 105 command_buffer_ = NULL; |
103 } | 106 } |
104 | 107 |
105 bool PGLContextImpl::MakeCurrent(PGLContextImpl* pgl_context) { | 108 bool PGLContextImpl::MakeCurrent(PGLContextImpl* pgl_context) { |
106 g_current_pgl_context = pgl_context; | 109 if (!g_pgl_context_key) |
110 return false; | |
111 | |
112 gpu::ThreadLocalSetValue(g_pgl_context_key, pgl_context); | |
107 if (pgl_context) | 113 if (pgl_context) |
108 gles2::SetGLContext(pgl_context->gles2_implementation_); | 114 gles2::SetGLContext(pgl_context->gles2_implementation_); |
109 else | 115 else |
110 gles2::SetGLContext(NULL); | 116 gles2::SetGLContext(NULL); |
111 | 117 |
112 return true; | 118 return true; |
113 } | 119 } |
114 | 120 |
115 bool PGLContextImpl::SwapBuffers() { | 121 bool PGLContextImpl::SwapBuffers() { |
116 gles2_implementation_->SwapBuffers(); | 122 gles2_implementation_->SwapBuffers(); |
117 return true; | 123 return true; |
118 } | 124 } |
119 } // namespace anonymous | 125 } // namespace anonymous |
120 | 126 |
121 extern "C" { | 127 extern "C" { |
122 | 128 |
129 PGLBoolean pglInitialize() { | |
130 if (g_pgl_context_key) | |
131 return true; | |
132 | |
133 gles2::Initialize(); | |
134 g_pgl_context_key = gpu::ThreadLocalAlloc(); | |
135 return true; | |
136 } | |
137 | |
138 PGLBoolean pglTerminate() { | |
139 if (!g_pgl_context_key) | |
140 return true; | |
141 | |
142 gpu::ThreadLocalFree(g_pgl_context_key); | |
143 gles2::Terminate(); | |
144 return true; | |
145 } | |
146 | |
123 PGLContext pglCreateContext(NPP npp, | 147 PGLContext pglCreateContext(NPP npp, |
rvargas (doing something else)
2010/01/27 19:45:18
Out of curiosity, what's the reason for having thi
apatrick_chromium
2010/01/27 19:55:10
It's using this style:
http://www.khronos.org/regi
| |
124 NPDevice* device, | 148 NPDevice* device, |
125 NPDeviceContext3D* device_context) { | 149 NPDeviceContext3D* device_context) { |
150 if (!g_pgl_context_key) | |
151 return NULL; | |
152 | |
126 PGLContextImpl* pgl_context = new PGLContextImpl( | 153 PGLContextImpl* pgl_context = new PGLContextImpl( |
127 npp, device, device_context); | 154 npp, device, device_context); |
128 if (pgl_context->Initialize(kTransferBufferSize)) { | 155 if (pgl_context->Initialize(kTransferBufferSize)) { |
129 return pgl_context; | 156 return pgl_context; |
130 } | 157 } |
131 | 158 |
132 delete pgl_context; | 159 delete pgl_context; |
133 return NULL; | 160 return NULL; |
134 } | 161 } |
135 | 162 |
136 PGLBoolean pglMakeCurrent(PGLContext pgl_context) { | 163 PGLBoolean pglMakeCurrent(PGLContext pgl_context) { |
137 return PGLContextImpl::MakeCurrent(static_cast<PGLContextImpl*>(pgl_context)); | 164 return PGLContextImpl::MakeCurrent(static_cast<PGLContextImpl*>(pgl_context)); |
138 } | 165 } |
139 | 166 |
140 PGLContext pglGetCurrentContext(void) { | 167 PGLContext pglGetCurrentContext(void) { |
141 return g_current_pgl_context; | 168 if (!g_pgl_context_key) |
169 return NULL; | |
170 | |
171 return static_cast<PGLContext>(gpu::ThreadLocalGetValue(g_pgl_context_key)); | |
142 } | 172 } |
143 | 173 |
144 PGLBoolean pglSwapBuffers(void) { | 174 PGLBoolean pglSwapBuffers(void) { |
145 if (!g_current_pgl_context) | 175 PGLContextImpl* context = static_cast<PGLContextImpl*>( |
176 pglGetCurrentContext()); | |
177 if (!context) | |
146 return false; | 178 return false; |
147 | 179 |
148 return g_current_pgl_context->SwapBuffers(); | 180 return context->SwapBuffers(); |
149 } | 181 } |
150 | 182 |
151 PGLBoolean pglDestroyContext(PGLContext pgl_context) { | 183 PGLBoolean pglDestroyContext(PGLContext pgl_context) { |
184 if (!g_pgl_context_key) | |
185 return NULL; | |
186 | |
152 if (!pgl_context) | 187 if (!pgl_context) |
153 return false; | 188 return false; |
154 | 189 |
190 if (pgl_context == pglGetCurrentContext()) | |
191 pglMakeCurrent(NULL); | |
192 | |
155 delete static_cast<PGLContextImpl*>(pgl_context); | 193 delete static_cast<PGLContextImpl*>(pgl_context); |
156 return true; | 194 return true; |
157 } | 195 } |
158 | 196 |
159 } // extern "C" | 197 } // extern "C" |
OLD | NEW |