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 "base/numerics/safe_conversions.h" | 7 #include "base/numerics/safe_conversions.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "gpu/command_buffer/client/gles2_implementation.h" | 9 #include "gpu/command_buffer/client/gles2_implementation.h" |
10 #include "gpu/command_buffer/common/command_buffer.h" | 10 #include "gpu/command_buffer/common/command_buffer.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); | 165 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); |
166 if (enter.failed()) | 166 if (enter.failed()) |
167 return PP_ERROR_BADARGUMENT; | 167 return PP_ERROR_BADARGUMENT; |
168 | 168 |
169 PPB_Graphics3D_Shared* share_graphics = | 169 PPB_Graphics3D_Shared* share_graphics = |
170 static_cast<PPB_Graphics3D_Shared*>(enter.object()); | 170 static_cast<PPB_Graphics3D_Shared*>(enter.object()); |
171 share_host = share_graphics->host_resource(); | 171 share_host = share_graphics->host_resource(); |
172 share_gles2 = share_graphics->gles2_impl(); | 172 share_gles2 = share_graphics->gles2_impl(); |
173 } | 173 } |
174 | 174 |
175 gpu::gles2::ContextCreationAttribHelper attrib_helper; | |
176 std::vector<int32_t> attribs; | 175 std::vector<int32_t> attribs; |
177 if (attrib_list) { | 176 if (attrib_list) { |
178 for (const int32_t* attr = attrib_list; attr[0] != PP_GRAPHICS3DATTRIB_NONE; | 177 for (const int32_t* attr = attrib_list; |
| 178 attr[0] != PP_GRAPHICS3DATTRIB_NONE; |
179 attr += 2) { | 179 attr += 2) { |
180 switch (attr[0]) { | 180 attribs.push_back(attr[0]); |
181 case PP_GRAPHICS3DATTRIB_WIDTH: | 181 attribs.push_back(attr[1]); |
182 attrib_helper.offscreen_framebuffer_size.set_width(attr[1]); | |
183 break; | |
184 case PP_GRAPHICS3DATTRIB_HEIGHT: | |
185 attrib_helper.offscreen_framebuffer_size.set_height(attr[1]); | |
186 break; | |
187 case PP_GRAPHICS3DATTRIB_GPU_PREFERENCE: | |
188 attrib_helper.gpu_preference = | |
189 (attr[1] == PP_GRAPHICS3DATTRIB_GPU_PREFERENCE_LOW_POWER) | |
190 ? gl::PreferIntegratedGpu | |
191 : gl::PreferDiscreteGpu; | |
192 break; | |
193 default: | |
194 attribs.push_back(attr[0]); | |
195 attribs.push_back(attr[1]); | |
196 break; | |
197 } | |
198 } | 182 } |
199 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); | |
200 } | 183 } |
201 if (!attrib_helper.Parse(attribs)) | 184 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); |
202 return 0; | |
203 | 185 |
204 HostResource result; | 186 HostResource result; |
205 gpu::Capabilities capabilities; | 187 gpu::Capabilities capabilities; |
206 ppapi::proxy::SerializedHandle shared_state; | 188 ppapi::proxy::SerializedHandle shared_state; |
207 gpu::CommandBufferId command_buffer_id; | 189 gpu::CommandBufferId command_buffer_id; |
208 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create( | 190 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create(API_ID_PPB_GRAPHICS_3D, |
209 API_ID_PPB_GRAPHICS_3D, instance, share_host, attrib_helper, &result, | 191 instance, share_host, attribs, &result, &capabilities, &shared_state, |
210 &capabilities, &shared_state, &command_buffer_id)); | 192 &command_buffer_id)); |
211 | 193 |
212 if (result.is_null()) | 194 if (result.is_null()) |
213 return 0; | 195 return 0; |
214 | 196 |
215 scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result)); | 197 scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result)); |
216 if (!graphics_3d->Init(share_gles2, capabilities, shared_state, | 198 if (!graphics_3d->Init(share_gles2, capabilities, shared_state, |
217 command_buffer_id)) { | 199 command_buffer_id)) { |
218 return 0; | 200 return 0; |
219 } | 201 } |
220 return graphics_3d->GetReference(); | 202 return graphics_3d->GetReference(); |
(...skipping 30 matching lines...) Expand all Loading... |
251 | 233 |
252 IPC_END_MESSAGE_MAP() | 234 IPC_END_MESSAGE_MAP() |
253 // FIXME(brettw) handle bad messages! | 235 // FIXME(brettw) handle bad messages! |
254 return handled; | 236 return handled; |
255 } | 237 } |
256 | 238 |
257 #if !defined(OS_NACL) | 239 #if !defined(OS_NACL) |
258 void PPB_Graphics3D_Proxy::OnMsgCreate( | 240 void PPB_Graphics3D_Proxy::OnMsgCreate( |
259 PP_Instance instance, | 241 PP_Instance instance, |
260 HostResource share_context, | 242 HostResource share_context, |
261 const gpu::gles2::ContextCreationAttribHelper& attrib_helper, | 243 const std::vector<int32_t>& attribs, |
262 HostResource* result, | 244 HostResource* result, |
263 gpu::Capabilities* capabilities, | 245 gpu::Capabilities* capabilities, |
264 SerializedHandle* shared_state, | 246 SerializedHandle* shared_state, |
265 gpu::CommandBufferId* command_buffer_id) { | 247 gpu::CommandBufferId* command_buffer_id) { |
266 shared_state->set_null_shmem(); | 248 shared_state->set_null_shmem(); |
| 249 if (attribs.empty() || |
| 250 attribs.back() != PP_GRAPHICS3DATTRIB_NONE || |
| 251 !(attribs.size() & 1)) |
| 252 return; // Bad message. |
267 | 253 |
268 thunk::EnterResourceCreation enter(instance); | 254 thunk::EnterResourceCreation enter(instance); |
269 | 255 |
270 if (!enter.succeeded()) | 256 if (!enter.succeeded()) |
271 return; | 257 return; |
272 | 258 |
273 base::SharedMemoryHandle handle = base::SharedMemory::NULLHandle(); | 259 base::SharedMemoryHandle handle = base::SharedMemory::NULLHandle(); |
274 result->SetHostResource( | 260 result->SetHostResource( |
275 instance, enter.functions()->CreateGraphics3DRaw( | 261 instance, |
276 instance, share_context.host_resource(), attrib_helper, | 262 enter.functions()->CreateGraphics3DRaw(instance, |
277 capabilities, &handle, command_buffer_id)); | 263 share_context.host_resource(), |
| 264 &attribs.front(), |
| 265 capabilities, |
| 266 &handle, |
| 267 command_buffer_id)); |
278 if (!result->is_null()) { | 268 if (!result->is_null()) { |
279 shared_state->set_shmem(TransportSHMHandle(dispatcher(), handle), | 269 shared_state->set_shmem(TransportSHMHandle(dispatcher(), handle), |
280 sizeof(gpu::CommandBuffer::State)); | 270 sizeof(gpu::CommandBuffer::State)); |
281 } | 271 } |
282 } | 272 } |
283 | 273 |
284 void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer(const HostResource& context, | 274 void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer(const HostResource& context, |
285 int32_t transfer_buffer_id) { | 275 int32_t transfer_buffer_id) { |
286 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 276 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
287 if (enter.succeeded()) | 277 if (enter.succeeded()) |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( | 380 void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( |
391 int32_t result, | 381 int32_t result, |
392 const HostResource& context) { | 382 const HostResource& context) { |
393 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( | 383 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( |
394 API_ID_PPB_GRAPHICS_3D, context, result)); | 384 API_ID_PPB_GRAPHICS_3D, context, result)); |
395 } | 385 } |
396 #endif // !defined(OS_NACL) | 386 #endif // !defined(OS_NACL) |
397 | 387 |
398 } // namespace proxy | 388 } // namespace proxy |
399 } // namespace ppapi | 389 } // namespace ppapi |
OLD | NEW |