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

Side by Side Diff: webkit/plugins/ppapi/ppb_graphics_3d_impl.cc

Issue 5927002: Moved the logic of maintaining the current context to gles2 helper library. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years 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) 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/plugins/ppapi/ppb_graphics_3d_impl.h" 5 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h"
6 6
7 #include "gpu/command_buffer/common/command_buffer.h" 7 #include "gpu/command_buffer/common/command_buffer.h"
8 #include "base/lazy_instance.h"
9 #include "base/thread_local.h"
10 #include "ppapi/c/dev/ppb_graphics_3d_dev.h" 8 #include "ppapi/c/dev/ppb_graphics_3d_dev.h"
11 #include "webkit/plugins/ppapi/common.h" 9 #include "webkit/plugins/ppapi/common.h"
12 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 10 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
13 11
14 namespace webkit { 12 namespace webkit {
15 namespace ppapi { 13 namespace ppapi {
16 14
17 namespace { 15 namespace {
18 16
19 static base::LazyInstance<base::ThreadLocalPointer<PPB_Graphics3D_Impl> >
20 g_current_context_key(base::LINKER_INITIALIZED);
21
22 // Size of the transfer buffer. 17 // Size of the transfer buffer.
23 enum { kTransferBufferSize = 512 * 1024 }; 18 enum { kTransferBufferSize = 512 * 1024 };
24 19
25 PP_Bool IsGraphics3D(PP_Resource resource) { 20 PP_Bool IsGraphics3D(PP_Resource resource) {
26 return BoolToPPBool(!!Resource::GetAs<PPB_Graphics3D_Impl>(resource)); 21 return BoolToPPBool(!!Resource::GetAs<PPB_Graphics3D_Impl>(resource));
27 } 22 }
28 23
29 PP_Bool GetConfigs(int32_t* configs, int32_t config_size, int32_t* num_config) { 24 PP_Bool GetConfigs(int32_t* configs, int32_t config_size, int32_t* num_config) {
30 // TODO(neb): Implement me! 25 // TODO(neb): Implement me!
31 return PP_FALSE; 26 return PP_FALSE;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 69 }
75 70
76 return context->GetReference(); 71 return context->GetReference();
77 } 72 }
78 73
79 void* GetProcAddress(const char* name) { 74 void* GetProcAddress(const char* name) {
80 // TODO(neb): Implement me! 75 // TODO(neb): Implement me!
81 return NULL; 76 return NULL;
82 } 77 }
83 78
84 PP_Bool MakeCurrent(PP_Resource graphics3d) {
85 if (!graphics3d) {
86 PPB_Graphics3D_Impl::ResetCurrent();
87 return PP_TRUE;
88 } else {
89 scoped_refptr<PPB_Graphics3D_Impl> context(
90 Resource::GetAs<PPB_Graphics3D_Impl>(graphics3d));
91 return BoolToPPBool(context.get() && context->MakeCurrent());
92 }
93 }
94
95 PP_Resource GetCurrentContext() {
96 PPB_Graphics3D_Impl* current_context = PPB_Graphics3D_Impl::GetCurrent();
97 return current_context ? current_context->GetReference() : 0;
98 }
99
100 PP_Bool SwapBuffers(PP_Resource graphics3d) { 79 PP_Bool SwapBuffers(PP_Resource graphics3d) {
101 scoped_refptr<PPB_Graphics3D_Impl> context( 80 scoped_refptr<PPB_Graphics3D_Impl> context(
102 Resource::GetAs<PPB_Graphics3D_Impl>(graphics3d)); 81 Resource::GetAs<PPB_Graphics3D_Impl>(graphics3d));
103 return BoolToPPBool(context && context->SwapBuffers()); 82 return BoolToPPBool(context && context->SwapBuffers());
104 } 83 }
105 84
106 uint32_t GetError() { 85 uint32_t GetError() {
107 // Technically, this should return the last error that occurred on the current 86 // TODO(alokp): Fix this.
108 // thread, rather than an error associated with a particular context. 87 return 0;
109 // TODO(apatrick): Fix this.
110 PPB_Graphics3D_Impl* current_context = PPB_Graphics3D_Impl::GetCurrent();
111 if (!current_context)
112 return 0;
113
114 return current_context->GetError();
115 } 88 }
116 89
117 const PPB_Graphics3D_Dev ppb_graphics3d = { 90 const PPB_Graphics3D_Dev ppb_graphics3d = {
118 &IsGraphics3D, 91 &IsGraphics3D,
119 &GetConfigs, 92 &GetConfigs,
120 &ChooseConfig, 93 &ChooseConfig,
121 &GetConfigAttrib, 94 &GetConfigAttrib,
122 &QueryString, 95 &QueryString,
123 &CreateContext, 96 &CreateContext,
124 &GetProcAddress, 97 &GetProcAddress,
125 &MakeCurrent,
126 &GetCurrentContext,
127 &SwapBuffers, 98 &SwapBuffers,
128 &GetError 99 &GetError
129 }; 100 };
130 101
131 } // namespace 102 } // namespace
132 103
133 PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PluginModule* module) 104 PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PluginModule* module)
134 : Resource(module), 105 : Resource(module),
135 bound_instance_(NULL) { 106 bound_instance_(NULL) {
136 } 107 }
137 108
138 const PPB_Graphics3D_Dev* PPB_Graphics3D_Impl::GetInterface() { 109 const PPB_Graphics3D_Dev* PPB_Graphics3D_Impl::GetInterface() {
139 return &ppb_graphics3d; 110 return &ppb_graphics3d;
140 } 111 }
141 112
142 PPB_Graphics3D_Impl* PPB_Graphics3D_Impl::GetCurrent() {
143 return g_current_context_key.Get().Get();
144 }
145
146 void PPB_Graphics3D_Impl::ResetCurrent() {
147 g_current_context_key.Get().Set(NULL);
148 }
149
150 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() { 113 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() {
151 Destroy(); 114 Destroy();
152 } 115 }
153 116
154 PPB_Graphics3D_Impl* PPB_Graphics3D_Impl::AsPPB_Graphics3D_Impl() { 117 PPB_Graphics3D_Impl* PPB_Graphics3D_Impl::AsPPB_Graphics3D_Impl() {
155 return this; 118 return this;
156 } 119 }
157 120
158 bool PPB_Graphics3D_Impl::Init(PP_Instance instance_id, int32_t config, 121 bool PPB_Graphics3D_Impl::Init(PP_Instance instance_id, int32_t config,
159 const int32_t* attrib_list) { 122 const int32_t* attrib_list) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 // since the SwapBuffers is written to the command buffer and that command 159 // since the SwapBuffers is written to the command buffer and that command
197 // buffer might be written to by another thread. 160 // buffer might be written to by another thread.
198 // TODO(apatrick): Figure out the semantics of binding and resizing. 161 // TODO(apatrick): Figure out the semantics of binding and resizing.
199 platform_context_->SwapBuffers(); 162 platform_context_->SwapBuffers();
200 } 163 }
201 164
202 bound_instance_ = new_instance; 165 bound_instance_ = new_instance;
203 return true; 166 return true;
204 } 167 }
205 168
206 bool PPB_Graphics3D_Impl::MakeCurrent() {
207 if (!platform_context_.get())
208 return false;
209
210 g_current_context_key.Get().Set(this);
211
212 // TODO(apatrick): Return false on context lost.
213 return true;
214 }
215
216 bool PPB_Graphics3D_Impl::SwapBuffers() { 169 bool PPB_Graphics3D_Impl::SwapBuffers() {
217 if (!platform_context_.get()) 170 if (!platform_context_.get())
218 return false; 171 return false;
219 172
220 return platform_context_->SwapBuffers(); 173 return platform_context_->SwapBuffers();
221 } 174 }
222 175
223 unsigned PPB_Graphics3D_Impl::GetError() { 176 unsigned PPB_Graphics3D_Impl::GetError() {
224 if (!platform_context_.get()) 177 if (!platform_context_.get())
225 return 0; 178 return 0;
(...skipping 16 matching lines...) Expand all
242 } 195 }
243 196
244 unsigned PPB_Graphics3D_Impl::GetBackingTextureId() { 197 unsigned PPB_Graphics3D_Impl::GetBackingTextureId() {
245 if (!platform_context_.get()) 198 if (!platform_context_.get())
246 return 0; 199 return 0;
247 200
248 return platform_context_->GetBackingTextureId(); 201 return platform_context_->GetBackingTextureId();
249 } 202 }
250 203
251 void PPB_Graphics3D_Impl::Destroy() { 204 void PPB_Graphics3D_Impl::Destroy() {
252 if (GetCurrent() == this) {
253 ResetCurrent();
254 }
255
256 gles2_implementation_ = NULL; 205 gles2_implementation_ = NULL;
257
258 platform_context_.reset(); 206 platform_context_.reset();
259 } 207 }
260 208
261 } // namespace ppapi 209 } // namespace ppapi
262 } // namespace webkit 210 } // namespace webkit
263 211
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_graphics_3d_impl.h ('k') | webkit/plugins/ppapi/ppb_open_gl_es_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698