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 "webkit/glue/plugins/pepper_graphics_3d.h" | 5 #include "webkit/glue/plugins/pepper_graphics_3d.h" |
6 | 6 |
7 #include "gpu/command_buffer/common/command_buffer.h" | 7 #include "gpu/command_buffer/common/command_buffer.h" |
8 #include "base/singleton.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/thread_local.h" | 9 #include "base/thread_local.h" |
10 #include "ppapi/c/dev/ppb_graphics_3d_dev.h" | 10 #include "ppapi/c/dev/ppb_graphics_3d_dev.h" |
11 #include "webkit/glue/plugins/pepper_common.h" | 11 #include "webkit/glue/plugins/pepper_common.h" |
12 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 12 #include "webkit/glue/plugins/pepper_plugin_instance.h" |
13 | 13 |
14 namespace pepper { | 14 namespace pepper { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 struct CurrentContextTag {}; | 18 static base::LazyInstance<base::ThreadLocalPointer<Graphics3D> > |
19 typedef Singleton<base::ThreadLocalPointer<Graphics3D>, | 19 g_current_context_key(base::LINKER_INITIALIZED); |
20 DefaultSingletonTraits<base::ThreadLocalPointer<Graphics3D> >, | |
21 CurrentContextTag> CurrentContextKey; | |
22 | 20 |
23 // Size of the transfer buffer. | 21 // Size of the transfer buffer. |
24 enum { kTransferBufferSize = 512 * 1024 }; | 22 enum { kTransferBufferSize = 512 * 1024 }; |
25 | 23 |
26 PP_Bool IsGraphics3D(PP_Resource resource) { | 24 PP_Bool IsGraphics3D(PP_Resource resource) { |
27 return BoolToPPBool(!!Resource::GetAs<Graphics3D>(resource)); | 25 return BoolToPPBool(!!Resource::GetAs<Graphics3D>(resource)); |
28 } | 26 } |
29 | 27 |
30 PP_Bool GetConfigs(int32_t* configs, int32_t config_size, int32_t* num_config) { | 28 PP_Bool GetConfigs(int32_t* configs, int32_t config_size, int32_t* num_config) { |
31 // TODO(neb): Implement me! | 29 // TODO(neb): Implement me! |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 Graphics3D::Graphics3D(PluginModule* module) | 129 Graphics3D::Graphics3D(PluginModule* module) |
132 : Resource(module), | 130 : Resource(module), |
133 bound_instance_(NULL) { | 131 bound_instance_(NULL) { |
134 } | 132 } |
135 | 133 |
136 const PPB_Graphics3D_Dev* Graphics3D::GetInterface() { | 134 const PPB_Graphics3D_Dev* Graphics3D::GetInterface() { |
137 return &ppb_graphics3d; | 135 return &ppb_graphics3d; |
138 } | 136 } |
139 | 137 |
140 Graphics3D* Graphics3D::GetCurrent() { | 138 Graphics3D* Graphics3D::GetCurrent() { |
141 return CurrentContextKey::get()->Get(); | 139 return g_current_context_key.Get().Get(); |
142 } | 140 } |
143 | 141 |
144 void Graphics3D::ResetCurrent() { | 142 void Graphics3D::ResetCurrent() { |
145 CurrentContextKey::get()->Set(NULL); | 143 g_current_context_key.Get().Set(NULL); |
146 } | 144 } |
147 | 145 |
148 Graphics3D::~Graphics3D() { | 146 Graphics3D::~Graphics3D() { |
149 Destroy(); | 147 Destroy(); |
150 } | 148 } |
151 | 149 |
152 bool Graphics3D::Init(PP_Instance instance_id, int32_t config, | 150 bool Graphics3D::Init(PP_Instance instance_id, int32_t config, |
153 const int32_t* attrib_list) { | 151 const int32_t* attrib_list) { |
154 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 152 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
155 if (!instance) { | 153 if (!instance) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 } | 192 } |
195 | 193 |
196 bound_instance_ = new_instance; | 194 bound_instance_ = new_instance; |
197 return true; | 195 return true; |
198 } | 196 } |
199 | 197 |
200 bool Graphics3D::MakeCurrent() { | 198 bool Graphics3D::MakeCurrent() { |
201 if (!platform_context_.get()) | 199 if (!platform_context_.get()) |
202 return false; | 200 return false; |
203 | 201 |
204 CurrentContextKey::get()->Set(this); | 202 g_current_context_key.Get().Set(this); |
205 | 203 |
206 // TODO(apatrick): Return false on context lost. | 204 // TODO(apatrick): Return false on context lost. |
207 return true; | 205 return true; |
208 } | 206 } |
209 | 207 |
210 bool Graphics3D::SwapBuffers() { | 208 bool Graphics3D::SwapBuffers() { |
211 if (!platform_context_.get()) | 209 if (!platform_context_.get()) |
212 return false; | 210 return false; |
213 | 211 |
214 return platform_context_->SwapBuffers(); | 212 return platform_context_->SwapBuffers(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 ResetCurrent(); | 245 ResetCurrent(); |
248 } | 246 } |
249 | 247 |
250 gles2_implementation_ = NULL; | 248 gles2_implementation_ = NULL; |
251 | 249 |
252 platform_context_.reset(); | 250 platform_context_.reset(); |
253 } | 251 } |
254 | 252 |
255 } // namespace pepper | 253 } // namespace pepper |
256 | 254 |
OLD | NEW |