OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ppapi/proxy/ppb_graphics_3d_proxy.h" | 5 #include "ppapi/proxy/ppb_graphics_3d_proxy.h" |
6 | 6 |
7 #include "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
9 #include "ppapi/proxy/enter_proxy.h" | 9 #include "ppapi/proxy/enter_proxy.h" |
10 #include "ppapi/proxy/plugin_dispatcher.h" | 10 #include "ppapi/proxy/plugin_dispatcher.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } // namespace | 62 } // namespace |
63 | 63 |
64 Graphics3D::Graphics3D(const HostResource& resource) | 64 Graphics3D::Graphics3D(const HostResource& resource) |
65 : PPB_Graphics3D_Shared(resource) { | 65 : PPB_Graphics3D_Shared(resource) { |
66 } | 66 } |
67 | 67 |
68 Graphics3D::~Graphics3D() { | 68 Graphics3D::~Graphics3D() { |
69 DestroyGLES2Impl(); | 69 DestroyGLES2Impl(); |
70 } | 70 } |
71 | 71 |
72 bool Graphics3D::Init() { | 72 bool Graphics3D::Init(gpu::gles2::GLES2Implementation* share_gles2) { |
73 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); | 73 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); |
74 if (!dispatcher) | 74 if (!dispatcher) |
75 return false; | 75 return false; |
76 | 76 |
77 command_buffer_.reset( | 77 command_buffer_.reset( |
78 new PpapiCommandBufferProxy(host_resource(), dispatcher)); | 78 new PpapiCommandBufferProxy(host_resource(), dispatcher)); |
79 if (!command_buffer_->Initialize()) | 79 if (!command_buffer_->Initialize()) |
80 return false; | 80 return false; |
81 | 81 |
82 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize); | 82 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize, |
| 83 share_gles2); |
83 } | 84 } |
84 | 85 |
85 PP_Bool Graphics3D::InitCommandBuffer() { | 86 PP_Bool Graphics3D::InitCommandBuffer() { |
86 return PP_FALSE; | 87 return PP_FALSE; |
87 } | 88 } |
88 | 89 |
89 PP_Bool Graphics3D::SetGetBuffer(int32_t /* transfer_buffer_id */) { | 90 PP_Bool Graphics3D::SetGetBuffer(int32_t /* transfer_buffer_id */) { |
90 return PP_FALSE; | 91 return PP_FALSE; |
91 } | 92 } |
92 | 93 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 146 |
146 // static | 147 // static |
147 PP_Resource PPB_Graphics3D_Proxy::CreateProxyResource( | 148 PP_Resource PPB_Graphics3D_Proxy::CreateProxyResource( |
148 PP_Instance instance, | 149 PP_Instance instance, |
149 PP_Resource share_context, | 150 PP_Resource share_context, |
150 const int32_t* attrib_list) { | 151 const int32_t* attrib_list) { |
151 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 152 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
152 if (!dispatcher) | 153 if (!dispatcher) |
153 return PP_ERROR_BADARGUMENT; | 154 return PP_ERROR_BADARGUMENT; |
154 | 155 |
155 // TODO(alokp): Support shared context. | 156 HostResource share_host; |
156 DCHECK_EQ(0, share_context); | 157 gpu::gles2::GLES2Implementation* share_gles2 = NULL; |
157 if (share_context != 0) | 158 if (share_context != 0) { |
158 return 0; | 159 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); |
| 160 if (enter.failed()) |
| 161 return PP_ERROR_BADARGUMENT; |
| 162 |
| 163 PPB_Graphics3D_Shared* share_graphics = |
| 164 static_cast<PPB_Graphics3D_Shared*>(enter.object()); |
| 165 share_host = share_graphics->host_resource(); |
| 166 share_gles2 = share_graphics->gles2_impl(); |
| 167 } |
159 | 168 |
160 std::vector<int32_t> attribs; | 169 std::vector<int32_t> attribs; |
161 if (attrib_list) { | 170 if (attrib_list) { |
162 for (const int32_t* attr = attrib_list; | 171 for (const int32_t* attr = attrib_list; |
163 attr[0] != PP_GRAPHICS3DATTRIB_NONE; | 172 attr[0] != PP_GRAPHICS3DATTRIB_NONE; |
164 attr += 2) { | 173 attr += 2) { |
165 attribs.push_back(attr[0]); | 174 attribs.push_back(attr[0]); |
166 attribs.push_back(attr[1]); | 175 attribs.push_back(attr[1]); |
167 } | 176 } |
168 } | 177 } |
169 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); | 178 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); |
170 | 179 |
171 HostResource result; | 180 HostResource result; |
172 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create( | 181 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create( |
173 API_ID_PPB_GRAPHICS_3D, instance, attribs, &result)); | 182 API_ID_PPB_GRAPHICS_3D, instance, share_host, attribs, &result)); |
174 if (result.is_null()) | 183 if (result.is_null()) |
175 return 0; | 184 return 0; |
176 | 185 |
177 scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result)); | 186 scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result)); |
178 if (!graphics_3d->Init()) | 187 if (!graphics_3d->Init(share_gles2)) |
179 return 0; | 188 return 0; |
180 return graphics_3d->GetReference(); | 189 return graphics_3d->GetReference(); |
181 } | 190 } |
182 | 191 |
183 bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { | 192 bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { |
184 bool handled = true; | 193 bool handled = true; |
185 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg) | 194 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg) |
186 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create, | 195 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create, |
187 OnMsgCreate) | 196 OnMsgCreate) |
188 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_InitCommandBuffer, | 197 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_InitCommandBuffer, |
(...skipping 18 matching lines...) Expand all Loading... |
207 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics3D_SwapBuffersACK, | 216 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics3D_SwapBuffersACK, |
208 OnMsgSwapBuffersACK) | 217 OnMsgSwapBuffersACK) |
209 IPC_MESSAGE_UNHANDLED(handled = false) | 218 IPC_MESSAGE_UNHANDLED(handled = false) |
210 | 219 |
211 IPC_END_MESSAGE_MAP() | 220 IPC_END_MESSAGE_MAP() |
212 // FIXME(brettw) handle bad messages! | 221 // FIXME(brettw) handle bad messages! |
213 return handled; | 222 return handled; |
214 } | 223 } |
215 | 224 |
216 void PPB_Graphics3D_Proxy::OnMsgCreate(PP_Instance instance, | 225 void PPB_Graphics3D_Proxy::OnMsgCreate(PP_Instance instance, |
| 226 HostResource share_context, |
217 const std::vector<int32_t>& attribs, | 227 const std::vector<int32_t>& attribs, |
218 HostResource* result) { | 228 HostResource* result) { |
219 if (attribs.empty() || attribs.back() != PP_GRAPHICS3DATTRIB_NONE) | 229 if (attribs.empty() || attribs.back() != PP_GRAPHICS3DATTRIB_NONE) |
220 return; // Bad message. | 230 return; // Bad message. |
221 | 231 |
222 thunk::EnterResourceCreation enter(instance); | 232 thunk::EnterResourceCreation enter(instance); |
| 233 |
223 if (enter.succeeded()) { | 234 if (enter.succeeded()) { |
224 result->SetHostResource( | 235 result->SetHostResource( |
225 instance, | 236 instance, |
226 enter.functions()->CreateGraphics3DRaw(instance, 0, &attribs.front())); | 237 enter.functions()->CreateGraphics3DRaw(instance, |
| 238 share_context.host_resource(), |
| 239 &attribs.front())); |
227 } | 240 } |
228 } | 241 } |
229 | 242 |
230 void PPB_Graphics3D_Proxy::OnMsgInitCommandBuffer( | 243 void PPB_Graphics3D_Proxy::OnMsgInitCommandBuffer( |
231 const HostResource& context) { | 244 const HostResource& context) { |
232 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 245 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
233 if (enter.failed()) | 246 if (enter.failed()) |
234 return; | 247 return; |
235 | 248 |
236 if (!enter.object()->InitCommandBuffer()) | 249 if (!enter.object()->InitCommandBuffer()) |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( | 349 void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( |
337 int32_t result, | 350 int32_t result, |
338 const HostResource& context) { | 351 const HostResource& context) { |
339 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( | 352 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( |
340 API_ID_PPB_GRAPHICS_3D, context, result)); | 353 API_ID_PPB_GRAPHICS_3D, context, result)); |
341 } | 354 } |
342 | 355 |
343 } // namespace proxy | 356 } // namespace proxy |
344 } // namespace ppapi | 357 } // namespace ppapi |
345 | 358 |
OLD | NEW |