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

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

Issue 5828003: Move the Pepper implementation from webkit/glue/plugins/pepper_* to... (Closed) Base URL: svn://chrome-svn/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/glue/plugins/pepper_graphics_3d.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/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/plugins/ppapi/common.h"
12 #include "webkit/glue/plugins/pepper_plugin_instance.h" 12 #include "webkit/plugins/ppapi/plugin_instance.h"
13 13
14 namespace pepper { 14 namespace webkit {
15 namespace plugins {
16 namespace ppapi {
15 17
16 namespace { 18 namespace {
17 19
18 struct CurrentContextTag {}; 20 static base::LazyInstance<base::ThreadLocalPointer<PPB_Graphics3D_Impl> >
19 typedef Singleton<base::ThreadLocalPointer<Graphics3D>, 21 g_current_context_key(base::LINKER_INITIALIZED);
20 DefaultSingletonTraits<base::ThreadLocalPointer<Graphics3D> >,
21 CurrentContextTag> CurrentContextKey;
22 22
23 // Size of the transfer buffer. 23 // Size of the transfer buffer.
24 enum { kTransferBufferSize = 512 * 1024 }; 24 enum { kTransferBufferSize = 512 * 1024 };
25 25
26 PP_Bool IsGraphics3D(PP_Resource resource) { 26 PP_Bool IsGraphics3D(PP_Resource resource) {
27 return BoolToPPBool(!!Resource::GetAs<Graphics3D>(resource)); 27 return BoolToPPBool(!!Resource::GetAs<PPB_Graphics3D_Impl>(resource));
28 } 28 }
29 29
30 PP_Bool GetConfigs(int32_t* configs, int32_t config_size, int32_t* num_config) { 30 PP_Bool GetConfigs(int32_t* configs, int32_t config_size, int32_t* num_config) {
31 // TODO(neb): Implement me! 31 // TODO(neb): Implement me!
32 return PP_FALSE; 32 return PP_FALSE;
33 } 33 }
34 34
35 PP_Bool ChooseConfig(const int32_t* attrib_list, int32_t* configs, 35 PP_Bool ChooseConfig(const int32_t* attrib_list, int32_t* configs,
36 int32_t config_size, int32_t* num_config) { 36 int32_t config_size, int32_t* num_config) {
37 // TODO(neb): Implement me! 37 // TODO(neb): Implement me!
(...skipping 23 matching lines...) Expand all
61 PP_Resource CreateContext(PP_Instance instance_id, int32_t config, 61 PP_Resource CreateContext(PP_Instance instance_id, int32_t config,
62 int32_t share_context, 62 int32_t share_context,
63 const int32_t* attrib_list) { 63 const int32_t* attrib_list) {
64 DCHECK_EQ(0, share_context); 64 DCHECK_EQ(0, share_context);
65 65
66 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); 66 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
67 if (!instance) { 67 if (!instance) {
68 return 0; 68 return 0;
69 } 69 }
70 70
71 scoped_refptr<Graphics3D> context(new Graphics3D(instance->module())); 71 scoped_refptr<PPB_Graphics3D_Impl> context(
72 new PPB_Graphics3D_Impl(instance->module()));
72 if (!context->Init(instance_id, config, attrib_list)) { 73 if (!context->Init(instance_id, config, attrib_list)) {
73 return 0; 74 return 0;
74 } 75 }
75 76
76 return context->GetReference(); 77 return context->GetReference();
77 } 78 }
78 79
79 void* GetProcAddress(const char* name) { 80 void* GetProcAddress(const char* name) {
80 // TODO(neb): Implement me! 81 // TODO(neb): Implement me!
81 return NULL; 82 return NULL;
82 } 83 }
83 84
84 PP_Bool MakeCurrent(PP_Resource graphics3d) { 85 PP_Bool MakeCurrent(PP_Resource graphics3d) {
85 if (!graphics3d) { 86 if (!graphics3d) {
86 Graphics3D::ResetCurrent(); 87 PPB_Graphics3D_Impl::ResetCurrent();
87 return PP_TRUE; 88 return PP_TRUE;
88 } else { 89 } else {
89 scoped_refptr<Graphics3D> context(Resource::GetAs<Graphics3D>(graphics3d)); 90 scoped_refptr<PPB_Graphics3D_Impl> context(
91 Resource::GetAs<PPB_Graphics3D_Impl>(graphics3d));
90 return BoolToPPBool(context.get() && context->MakeCurrent()); 92 return BoolToPPBool(context.get() && context->MakeCurrent());
91 } 93 }
92 } 94 }
93 95
94 PP_Resource GetCurrentContext() { 96 PP_Resource GetCurrentContext() {
95 Graphics3D* current_context = Graphics3D::GetCurrent(); 97 PPB_Graphics3D_Impl* current_context = PPB_Graphics3D_Impl::GetCurrent();
96 return current_context ? current_context->GetReference() : 0; 98 return current_context ? current_context->GetReference() : 0;
97 } 99 }
98 100
99 PP_Bool SwapBuffers(PP_Resource graphics3d) { 101 PP_Bool SwapBuffers(PP_Resource graphics3d) {
100 scoped_refptr<Graphics3D> context(Resource::GetAs<Graphics3D>(graphics3d)); 102 scoped_refptr<PPB_Graphics3D_Impl> context(
103 Resource::GetAs<PPB_Graphics3D_Impl>(graphics3d));
101 return BoolToPPBool(context && context->SwapBuffers()); 104 return BoolToPPBool(context && context->SwapBuffers());
102 } 105 }
103 106
104 uint32_t GetError() { 107 uint32_t GetError() {
105 // Technically, this should return the last error that occurred on the current 108 // Technically, this should return the last error that occurred on the current
106 // thread, rather than an error associated with a particular context. 109 // thread, rather than an error associated with a particular context.
107 // TODO(apatrick): Fix this. 110 // TODO(apatrick): Fix this.
108 Graphics3D* current_context = Graphics3D::GetCurrent(); 111 PPB_Graphics3D_Impl* current_context = PPB_Graphics3D_Impl::GetCurrent();
109 if (!current_context) 112 if (!current_context)
110 return 0; 113 return 0;
111 114
112 return current_context->GetError(); 115 return current_context->GetError();
113 } 116 }
114 117
115 const PPB_Graphics3D_Dev ppb_graphics3d = { 118 const PPB_Graphics3D_Dev ppb_graphics3d = {
116 &IsGraphics3D, 119 &IsGraphics3D,
117 &GetConfigs, 120 &GetConfigs,
118 &ChooseConfig, 121 &ChooseConfig,
119 &GetConfigAttrib, 122 &GetConfigAttrib,
120 &QueryString, 123 &QueryString,
121 &CreateContext, 124 &CreateContext,
122 &GetProcAddress, 125 &GetProcAddress,
123 &MakeCurrent, 126 &MakeCurrent,
124 &GetCurrentContext, 127 &GetCurrentContext,
125 &SwapBuffers, 128 &SwapBuffers,
126 &GetError 129 &GetError
127 }; 130 };
128 131
129 } // namespace 132 } // namespace
130 133
131 Graphics3D::Graphics3D(PluginModule* module) 134 PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PluginModule* module)
132 : Resource(module), 135 : Resource(module),
133 bound_instance_(NULL) { 136 bound_instance_(NULL) {
134 } 137 }
135 138
136 const PPB_Graphics3D_Dev* Graphics3D::GetInterface() { 139 const PPB_Graphics3D_Dev* PPB_Graphics3D_Impl::GetInterface() {
137 return &ppb_graphics3d; 140 return &ppb_graphics3d;
138 } 141 }
139 142
140 Graphics3D* Graphics3D::GetCurrent() { 143 PPB_Graphics3D_Impl* PPB_Graphics3D_Impl::GetCurrent() {
141 return CurrentContextKey::get()->Get(); 144 return g_current_context_key.Get().Get();
142 } 145 }
143 146
144 void Graphics3D::ResetCurrent() { 147 void PPB_Graphics3D_Impl::ResetCurrent() {
145 CurrentContextKey::get()->Set(NULL); 148 g_current_context_key.Get().Set(NULL);
146 } 149 }
147 150
148 Graphics3D::~Graphics3D() { 151 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() {
149 Destroy(); 152 Destroy();
150 } 153 }
151 154
152 bool Graphics3D::Init(PP_Instance instance_id, int32_t config, 155 PPB_Graphics3D_Impl* PPB_Graphics3D_Impl::AsGraphics3D() {
153 const int32_t* attrib_list) { 156 return this;
157 }
158
159 bool PPB_Graphics3D_Impl::Init(PP_Instance instance_id, int32_t config,
160 const int32_t* attrib_list) {
154 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); 161 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
155 if (!instance) { 162 if (!instance) {
156 return false; 163 return false;
157 } 164 }
158 165
159 // Create and initialize the objects required to issue GLES2 calls. 166 // Create and initialize the objects required to issue GLES2 calls.
160 platform_context_.reset(instance->delegate()->CreateContext3D()); 167 platform_context_.reset(instance->delegate()->CreateContext3D());
161 if (!platform_context_.get()) { 168 if (!platform_context_.get()) {
162 Destroy(); 169 Destroy();
163 return false; 170 return false;
164 } 171 }
165 172
166 if (!platform_context_->Init()) { 173 if (!platform_context_->Init()) {
167 Destroy(); 174 Destroy();
168 return false; 175 return false;
169 } 176 }
170 177
171 gles2_implementation_ = platform_context_->GetGLES2Implementation(); 178 gles2_implementation_ = platform_context_->GetGLES2Implementation();
172 DCHECK(gles2_implementation_); 179 DCHECK(gles2_implementation_);
173 180
174 return true; 181 return true;
175 } 182 }
176 183
177 bool Graphics3D::BindToInstance(PluginInstance* new_instance) { 184 bool PPB_Graphics3D_Impl::BindToInstance(PluginInstance* new_instance) {
178 if (bound_instance_ == new_instance) 185 if (bound_instance_ == new_instance)
179 return true; // Rebinding the same device, nothing to do. 186 return true; // Rebinding the same device, nothing to do.
180 if (bound_instance_ && new_instance) 187 if (bound_instance_ && new_instance)
181 return false; // Can't change a bound device. 188 return false; // Can't change a bound device.
182 189
183 if (new_instance) { 190 if (new_instance) {
184 // Resize the backing texture to the size of the instance when it is bound. 191 // Resize the backing texture to the size of the instance when it is bound.
185 platform_context_->ResizeBackingTexture(new_instance->position().size()); 192 platform_context_->ResizeBackingTexture(new_instance->position().size());
186 193
187 // This is a temporary hack. The SwapBuffers is issued to force the resize 194 // This is a temporary hack. The SwapBuffers is issued to force the resize
188 // to take place before any subsequent rendering. This might lead to a 195 // to take place before any subsequent rendering. This might lead to a
189 // partially rendered frame being displayed. It is also not thread safe 196 // partially rendered frame being displayed. It is also not thread safe
190 // since the SwapBuffers is written to the command buffer and that command 197 // since the SwapBuffers is written to the command buffer and that command
191 // buffer might be written to by another thread. 198 // buffer might be written to by another thread.
192 // TODO(apatrick): Figure out the semantics of binding and resizing. 199 // TODO(apatrick): Figure out the semantics of binding and resizing.
193 platform_context_->SwapBuffers(); 200 platform_context_->SwapBuffers();
194 } 201 }
195 202
196 bound_instance_ = new_instance; 203 bound_instance_ = new_instance;
197 return true; 204 return true;
198 } 205 }
199 206
200 bool Graphics3D::MakeCurrent() { 207 bool PPB_Graphics3D_Impl::MakeCurrent() {
201 if (!platform_context_.get()) 208 if (!platform_context_.get())
202 return false; 209 return false;
203 210
204 CurrentContextKey::get()->Set(this); 211 g_current_context_key.Get().Set(this);
205 212
206 // TODO(apatrick): Return false on context lost. 213 // TODO(apatrick): Return false on context lost.
207 return true; 214 return true;
208 } 215 }
209 216
210 bool Graphics3D::SwapBuffers() { 217 bool PPB_Graphics3D_Impl::SwapBuffers() {
211 if (!platform_context_.get()) 218 if (!platform_context_.get())
212 return false; 219 return false;
213 220
214 return platform_context_->SwapBuffers(); 221 return platform_context_->SwapBuffers();
215 } 222 }
216 223
217 unsigned Graphics3D::GetError() { 224 unsigned PPB_Graphics3D_Impl::GetError() {
218 if (!platform_context_.get()) 225 if (!platform_context_.get())
219 return 0; 226 return 0;
220 227
221 return platform_context_->GetError(); 228 return platform_context_->GetError();
222 } 229 }
223 230
224 void Graphics3D::ResizeBackingTexture(const gfx::Size& size) { 231 void PPB_Graphics3D_Impl::ResizeBackingTexture(const gfx::Size& size) {
225 if (!platform_context_.get()) 232 if (!platform_context_.get())
226 return; 233 return;
227 234
228 platform_context_->ResizeBackingTexture(size); 235 platform_context_->ResizeBackingTexture(size);
229 } 236 }
230 237
231 void Graphics3D::SetSwapBuffersCallback(Callback0::Type* callback) { 238 void PPB_Graphics3D_Impl::SetSwapBuffersCallback(Callback0::Type* callback) {
232 if (!platform_context_.get()) 239 if (!platform_context_.get())
233 return; 240 return;
234 241
235 platform_context_->SetSwapBuffersCallback(callback); 242 platform_context_->SetSwapBuffersCallback(callback);
236 } 243 }
237 244
238 unsigned Graphics3D::GetBackingTextureId() { 245 unsigned PPB_Graphics3D_Impl::GetBackingTextureId() {
239 if (!platform_context_.get()) 246 if (!platform_context_.get())
240 return 0; 247 return 0;
241 248
242 return platform_context_->GetBackingTextureId(); 249 return platform_context_->GetBackingTextureId();
243 } 250 }
244 251
245 void Graphics3D::Destroy() { 252 void PPB_Graphics3D_Impl::Destroy() {
246 if (GetCurrent() == this) { 253 if (GetCurrent() == this) {
247 ResetCurrent(); 254 ResetCurrent();
248 } 255 }
249 256
250 gles2_implementation_ = NULL; 257 gles2_implementation_ = NULL;
251 258
252 platform_context_.reset(); 259 platform_context_.reset();
253 } 260 }
254 261
255 } // namespace pepper 262 } // namespace ppapi
263 } // namespace plugins
264 } // namespace webkit
256 265
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698