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