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/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 "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/c/pp_var.h" |
8 #include "ppapi/c/dev/ppb_graphics_3d_dev.h" | 9 #include "ppapi/c/dev/ppb_graphics_3d_dev.h" |
9 #include "webkit/plugins/ppapi/common.h" | |
10 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | |
11 | 10 |
12 namespace webkit { | 11 namespace webkit { |
13 namespace ppapi { | 12 namespace ppapi { |
14 | 13 |
15 namespace { | 14 namespace { |
16 | 15 |
17 // Size of the transfer buffer. | 16 int32_t GetConfigs(PP_Config3D_Dev* configs, |
18 enum { kTransferBufferSize = 512 * 1024 }; | 17 int32_t config_size, |
19 | 18 int32_t* num_config) { |
20 PP_Bool IsGraphics3D(PP_Resource resource) { | 19 // TODO(alokp): Implement me. |
21 return BoolToPPBool(!!Resource::GetAs<PPB_Graphics3D_Impl>(resource)); | 20 return PP_ERROR_FAILED; |
22 } | 21 } |
23 | 22 |
24 PP_Bool GetConfigs(int32_t* configs, int32_t config_size, int32_t* num_config) { | 23 int32_t GetConfigAttribs(PP_Config3D_Dev config, int32_t* attrib_list) { |
25 // TODO(neb): Implement me! | 24 // TODO(alokp): Implement me. |
26 return PP_FALSE; | 25 return PP_ERROR_FAILED; |
27 } | 26 } |
28 | 27 |
29 PP_Bool ChooseConfig(const int32_t* attrib_list, int32_t* configs, | 28 PP_Var GetString(int32_t name) { |
30 int32_t config_size, int32_t* num_config) { | 29 // TODO(alokp): Implement me. |
31 // TODO(neb): Implement me! | 30 return PP_MakeUndefined(); |
32 return PP_FALSE; | |
33 } | |
34 | |
35 PP_Bool GetConfigAttrib(int32_t config, int32_t attribute, int32_t* value) { | |
36 // TODO(neb): Implement me! | |
37 return PP_FALSE; | |
38 } | |
39 | |
40 const char* QueryString(int32_t name) { | |
41 switch (name) { | |
42 case EGL_CLIENT_APIS: | |
43 return "OpenGL_ES"; | |
44 case EGL_EXTENSIONS: | |
45 return ""; | |
46 case EGL_VENDOR: | |
47 return "Google"; | |
48 case EGL_VERSION: | |
49 return "1.0 Google"; | |
50 default: | |
51 return NULL; | |
52 } | |
53 } | |
54 | |
55 PP_Resource CreateContext(PP_Instance instance_id, int32_t config, | |
56 int32_t share_context, | |
57 const int32_t* attrib_list) { | |
58 DCHECK_EQ(0, share_context); | |
59 | |
60 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | |
61 if (!instance) { | |
62 return 0; | |
63 } | |
64 | |
65 scoped_refptr<PPB_Graphics3D_Impl> context( | |
66 new PPB_Graphics3D_Impl(instance->module())); | |
67 if (!context->Init(instance_id, config, attrib_list)) { | |
68 return 0; | |
69 } | |
70 | |
71 return context->GetReference(); | |
72 } | |
73 | |
74 void* GetProcAddress(const char* name) { | |
75 // TODO(neb): Implement me! | |
76 return NULL; | |
77 } | |
78 | |
79 PP_Bool SwapBuffers(PP_Resource graphics3d) { | |
80 scoped_refptr<PPB_Graphics3D_Impl> context( | |
81 Resource::GetAs<PPB_Graphics3D_Impl>(graphics3d)); | |
82 return BoolToPPBool(context && context->SwapBuffers()); | |
83 } | |
84 | |
85 uint32_t GetError() { | |
86 // TODO(alokp): Fix this. | |
87 return 0; | |
88 } | 31 } |
89 | 32 |
90 const PPB_Graphics3D_Dev ppb_graphics3d = { | 33 const PPB_Graphics3D_Dev ppb_graphics3d = { |
91 &IsGraphics3D, | |
92 &GetConfigs, | 34 &GetConfigs, |
93 &ChooseConfig, | 35 &GetConfigAttribs, |
94 &GetConfigAttrib, | 36 &GetString |
95 &QueryString, | |
96 &CreateContext, | |
97 &GetProcAddress, | |
98 &SwapBuffers, | |
99 &GetError | |
100 }; | 37 }; |
101 | 38 |
102 } // namespace | 39 } // namespace |
103 | 40 |
104 PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PluginModule* module) | |
105 : Resource(module), | |
106 bound_instance_(NULL) { | |
107 } | |
108 | |
109 const PPB_Graphics3D_Dev* PPB_Graphics3D_Impl::GetInterface() { | 41 const PPB_Graphics3D_Dev* PPB_Graphics3D_Impl::GetInterface() { |
110 return &ppb_graphics3d; | 42 return &ppb_graphics3d; |
111 } | 43 } |
112 | 44 |
113 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() { | |
114 Destroy(); | |
115 } | |
116 | |
117 PPB_Graphics3D_Impl* PPB_Graphics3D_Impl::AsPPB_Graphics3D_Impl() { | |
118 return this; | |
119 } | |
120 | |
121 bool PPB_Graphics3D_Impl::Init(PP_Instance instance_id, int32_t config, | |
122 const int32_t* attrib_list) { | |
123 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | |
124 if (!instance) { | |
125 return false; | |
126 } | |
127 | |
128 // Create and initialize the objects required to issue GLES2 calls. | |
129 platform_context_.reset(instance->delegate()->CreateContext3D()); | |
130 if (!platform_context_.get()) { | |
131 Destroy(); | |
132 return false; | |
133 } | |
134 | |
135 if (!platform_context_->Init()) { | |
136 Destroy(); | |
137 return false; | |
138 } | |
139 | |
140 gles2_implementation_ = platform_context_->GetGLES2Implementation(); | |
141 DCHECK(gles2_implementation_); | |
142 | |
143 return true; | |
144 } | |
145 | |
146 bool PPB_Graphics3D_Impl::BindToInstance(PluginInstance* new_instance) { | |
147 if (bound_instance_ == new_instance) | |
148 return true; // Rebinding the same device, nothing to do. | |
149 if (bound_instance_ && new_instance) | |
150 return false; // Can't change a bound device. | |
151 | |
152 if (new_instance) { | |
153 // Resize the backing texture to the size of the instance when it is bound. | |
154 platform_context_->ResizeBackingTexture(new_instance->position().size()); | |
155 | |
156 // This is a temporary hack. The SwapBuffers is issued to force the resize | |
157 // to take place before any subsequent rendering. This might lead to a | |
158 // partially rendered frame being displayed. It is also not thread safe | |
159 // since the SwapBuffers is written to the command buffer and that command | |
160 // buffer might be written to by another thread. | |
161 // TODO(apatrick): Figure out the semantics of binding and resizing. | |
162 platform_context_->SwapBuffers(); | |
163 } | |
164 | |
165 bound_instance_ = new_instance; | |
166 return true; | |
167 } | |
168 | |
169 bool PPB_Graphics3D_Impl::SwapBuffers() { | |
170 if (!platform_context_.get()) | |
171 return false; | |
172 | |
173 return platform_context_->SwapBuffers(); | |
174 } | |
175 | |
176 unsigned PPB_Graphics3D_Impl::GetError() { | |
177 if (!platform_context_.get()) | |
178 return 0; | |
179 | |
180 return platform_context_->GetError(); | |
181 } | |
182 | |
183 void PPB_Graphics3D_Impl::ResizeBackingTexture(const gfx::Size& size) { | |
184 if (!platform_context_.get()) | |
185 return; | |
186 | |
187 platform_context_->ResizeBackingTexture(size); | |
188 } | |
189 | |
190 void PPB_Graphics3D_Impl::SetSwapBuffersCallback(Callback0::Type* callback) { | |
191 if (!platform_context_.get()) | |
192 return; | |
193 | |
194 platform_context_->SetSwapBuffersCallback(callback); | |
195 } | |
196 | |
197 unsigned PPB_Graphics3D_Impl::GetBackingTextureId() { | |
198 if (!platform_context_.get()) | |
199 return 0; | |
200 | |
201 return platform_context_->GetBackingTextureId(); | |
202 } | |
203 | |
204 void PPB_Graphics3D_Impl::Destroy() { | |
205 gles2_implementation_ = NULL; | |
206 platform_context_.reset(); | |
207 } | |
208 | |
209 } // namespace ppapi | 45 } // namespace ppapi |
210 } // namespace webkit | 46 } // namespace webkit |
211 | 47 |
OLD | NEW |