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