OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_context_3d_proxy.h" | 5 #include "ppapi/proxy/ppb_context_3d_proxy.h" |
6 | 6 |
7 #include "base/hash_tables.h" | 7 #include "base/hash_tables.h" |
8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
9 #include "gpu/command_buffer/client/gles2_implementation.h" | 9 #include "gpu/command_buffer/client/gles2_implementation.h" |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/c/pp_resource.h" | 11 #include "ppapi/c/pp_resource.h" |
12 #include "ppapi/c/dev/ppb_context_3d_dev.h" | 12 #include "ppapi/c/dev/ppb_context_3d_dev.h" |
13 #include "ppapi/c/dev/ppb_context_3d_trusted_dev.h" | 13 #include "ppapi/c/dev/ppb_context_3d_trusted_dev.h" |
| 14 #include "ppapi/proxy/enter_proxy.h" |
14 #include "ppapi/proxy/plugin_dispatcher.h" | 15 #include "ppapi/proxy/plugin_dispatcher.h" |
15 #include "ppapi/proxy/plugin_resource.h" | 16 #include "ppapi/proxy/plugin_resource.h" |
16 #include "ppapi/proxy/ppapi_messages.h" | 17 #include "ppapi/proxy/ppapi_messages.h" |
17 #include "ppapi/proxy/ppb_surface_3d_proxy.h" | 18 #include "ppapi/proxy/ppb_surface_3d_proxy.h" |
| 19 #include "ppapi/thunk/enter.h" |
| 20 #include "ppapi/thunk/resource_creation_api.h" |
| 21 #include "ppapi/thunk/thunk.h" |
| 22 |
| 23 using ppapi::thunk::EnterFunctionNoLock; |
| 24 using ppapi::thunk::EnterResourceNoLock; |
| 25 using ppapi::thunk::PPB_Context3D_API; |
| 26 using ppapi::thunk::PPB_Surface3D_API; |
| 27 using ppapi::thunk::ResourceCreationAPI; |
18 | 28 |
19 namespace pp { | 29 namespace pp { |
20 namespace proxy { | 30 namespace proxy { |
21 | 31 |
22 namespace { | 32 namespace { |
23 | 33 |
24 PP_Resource Create(PP_Instance instance, | |
25 PP_Config3D_Dev config, | |
26 PP_Resource share_context, | |
27 const int32_t* attrib_list) { | |
28 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | |
29 if (!dispatcher) | |
30 return PP_ERROR_BADARGUMENT; | |
31 | |
32 // TODO(alokp): Support shared context. | |
33 DCHECK_EQ(0, share_context); | |
34 if (share_context != 0) | |
35 return 0; | |
36 | |
37 std::vector<int32_t> attribs; | |
38 if (attrib_list) { | |
39 for (const int32_t* attr = attrib_list; attr; ++attr) | |
40 attribs.push_back(*attr); | |
41 } else { | |
42 attribs.push_back(0); | |
43 } | |
44 | |
45 HostResource result; | |
46 dispatcher->Send(new PpapiHostMsg_PPBContext3D_Create( | |
47 INTERFACE_ID_PPB_CONTEXT_3D, instance, config, attribs, &result)); | |
48 | |
49 if (result.is_null()) | |
50 return 0; | |
51 linked_ptr<Context3D> context_3d(new Context3D(result)); | |
52 if (!context_3d->CreateImplementation()) | |
53 return 0; | |
54 return PluginResourceTracker::GetInstance()->AddResource(context_3d); | |
55 } | |
56 | |
57 PP_Bool IsContext3D(PP_Resource resource) { | |
58 Context3D* object = PluginResource::GetAs<Context3D>(resource); | |
59 return BoolToPPBool(!!object); | |
60 } | |
61 | |
62 int32_t GetAttrib(PP_Resource context, | |
63 int32_t attribute, | |
64 int32_t* value) { | |
65 // TODO(alokp): Implement me. | |
66 return 0; | |
67 } | |
68 | |
69 int32_t BindSurfaces(PP_Resource context_id, | |
70 PP_Resource draw, | |
71 PP_Resource read) { | |
72 Context3D* object = PluginResource::GetAs<Context3D>(context_id); | |
73 if (!object) | |
74 return PP_ERROR_BADRESOURCE; | |
75 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( | |
76 object->instance()); | |
77 if (!dispatcher) | |
78 return PP_ERROR_FAILED; | |
79 | |
80 // TODO(alokp): Support separate draw-read surfaces. | |
81 DCHECK_EQ(draw, read); | |
82 if (draw != read) | |
83 return PP_GRAPHICS3DERROR_BAD_MATCH; | |
84 | |
85 Surface3D* draw_surface = PluginResource::GetAs<Surface3D>(draw); | |
86 Surface3D* read_surface = PluginResource::GetAs<Surface3D>(read); | |
87 if (draw && !draw_surface) | |
88 return PP_ERROR_BADRESOURCE; | |
89 if (read && !read_surface) | |
90 return PP_ERROR_BADRESOURCE; | |
91 HostResource host_draw = | |
92 draw_surface ? draw_surface->host_resource() : HostResource(); | |
93 HostResource host_read = | |
94 read_surface ? read_surface->host_resource() : HostResource(); | |
95 | |
96 int32_t result; | |
97 dispatcher->Send(new PpapiHostMsg_PPBContext3D_BindSurfaces( | |
98 INTERFACE_ID_PPB_CONTEXT_3D, | |
99 object->host_resource(), | |
100 host_draw, | |
101 host_read, | |
102 &result)); | |
103 | |
104 if (result == PP_OK) | |
105 object->BindSurfaces(draw_surface, read_surface); | |
106 | |
107 return result; | |
108 } | |
109 | |
110 int32_t GetBoundSurfaces(PP_Resource context, | |
111 PP_Resource* draw, | |
112 PP_Resource* read) { | |
113 Context3D* object = PluginResource::GetAs<Context3D>(context); | |
114 if (!object) | |
115 return PP_ERROR_BADRESOURCE; | |
116 | |
117 Surface3D* draw_surface = object->get_draw_surface(); | |
118 Surface3D* read_surface = object->get_read_surface(); | |
119 | |
120 *draw = draw_surface ? draw_surface->resource() : 0; | |
121 *read = read_surface ? read_surface->resource() : 0; | |
122 return PP_OK; | |
123 } | |
124 | |
125 | |
126 const PPB_Context3D_Dev context_3d_interface = { | |
127 &Create, | |
128 &IsContext3D, | |
129 &GetAttrib, | |
130 &BindSurfaces, | |
131 &GetBoundSurfaces, | |
132 }; | |
133 | |
134 base::SharedMemoryHandle TransportSHMHandleFromInt(Dispatcher* dispatcher, | 34 base::SharedMemoryHandle TransportSHMHandleFromInt(Dispatcher* dispatcher, |
135 int shm_handle) { | 35 int shm_handle) { |
136 // TODO(piman): Change trusted interface to return a PP_FileHandle, those | 36 // TODO(piman): Change trusted interface to return a PP_FileHandle, those |
137 // casts are ugly. | 37 // casts are ugly. |
138 base::PlatformFile source = | 38 base::PlatformFile source = |
139 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
140 reinterpret_cast<HANDLE>(static_cast<intptr_t>(shm_handle)); | 40 reinterpret_cast<HANDLE>(static_cast<intptr_t>(shm_handle)); |
141 #elif defined(OS_POSIX) | 41 #elif defined(OS_POSIX) |
142 shm_handle; | 42 shm_handle; |
143 #else | 43 #else |
144 #error Not implemented. | 44 #error Not implemented. |
145 #endif | 45 #endif |
146 // Don't close the handle, it doesn't belong to us. | 46 // Don't close the handle, it doesn't belong to us. |
147 return dispatcher->ShareHandleWithRemote(source, false); | 47 return dispatcher->ShareHandleWithRemote(source, false); |
148 } | 48 } |
149 | 49 |
| 50 PP_Context3DTrustedState GetErrorState() { |
| 51 PP_Context3DTrustedState error_state = { 0 }; |
| 52 error_state.error = kGenericError; |
| 53 return error_state; |
| 54 } |
| 55 |
150 gpu::CommandBuffer::State GPUStateFromPPState( | 56 gpu::CommandBuffer::State GPUStateFromPPState( |
151 const PP_Context3DTrustedState& s) { | 57 const PP_Context3DTrustedState& s) { |
152 gpu::CommandBuffer::State state; | 58 gpu::CommandBuffer::State state; |
153 state.num_entries = s.num_entries; | 59 state.num_entries = s.num_entries; |
154 state.get_offset = s.get_offset; | 60 state.get_offset = s.get_offset; |
155 state.put_offset = s.put_offset; | 61 state.put_offset = s.put_offset; |
156 state.token = s.token; | 62 state.token = s.token; |
157 state.error = static_cast<gpu::error::Error>(s.error); | 63 state.error = static_cast<gpu::error::Error>(s.error); |
158 state.generation = s.generation; | 64 state.generation = s.generation; |
159 return state; | 65 return state; |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 return false; | 318 return false; |
413 } | 319 } |
414 | 320 |
415 void PepperCommandBuffer::UpdateState(const gpu::CommandBuffer::State& state) { | 321 void PepperCommandBuffer::UpdateState(const gpu::CommandBuffer::State& state) { |
416 // Handle wraparound. It works as long as we don't have more than 2B state | 322 // Handle wraparound. It works as long as we don't have more than 2B state |
417 // updates in flight across which reordering occurs. | 323 // updates in flight across which reordering occurs. |
418 if (state.generation - last_state_.generation < 0x80000000U) | 324 if (state.generation - last_state_.generation < 0x80000000U) |
419 last_state_ = state; | 325 last_state_ = state; |
420 } | 326 } |
421 | 327 |
| 328 // Context3D ------------------------------------------------------------------- |
| 329 |
422 Context3D::Context3D(const HostResource& resource) | 330 Context3D::Context3D(const HostResource& resource) |
423 : PluginResource(resource), | 331 : PluginResource(resource), |
424 draw_(NULL), | 332 draw_(NULL), |
425 read_(NULL), | 333 read_(NULL), |
426 transfer_buffer_id_(0) { | 334 transfer_buffer_id_(0) { |
427 } | 335 } |
428 | 336 |
429 Context3D::~Context3D() { | 337 Context3D::~Context3D() { |
430 if (draw_) | 338 if (draw_) |
431 draw_->set_context(NULL); | 339 draw_->set_context(NULL); |
432 } | 340 } |
433 | 341 |
| 342 PPB_Context3D_API* Context3D::AsPPB_Context3D_API() { |
| 343 return this; |
| 344 } |
| 345 |
434 bool Context3D::CreateImplementation() { | 346 bool Context3D::CreateImplementation() { |
435 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance()); | 347 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance()); |
436 if (!dispatcher) | 348 if (!dispatcher) |
437 return false; | 349 return false; |
438 | 350 |
439 command_buffer_.reset(new PepperCommandBuffer(host_resource(), dispatcher)); | 351 command_buffer_.reset(new PepperCommandBuffer(host_resource(), dispatcher)); |
440 | 352 |
441 if (!command_buffer_->Initialize(kCommandBufferSize)) | 353 if (!command_buffer_->Initialize(kCommandBufferSize)) |
442 return false; | 354 return false; |
443 | 355 |
(...skipping 14 matching lines...) Expand all Loading... |
458 gles2_impl_.reset(new gpu::gles2::GLES2Implementation( | 370 gles2_impl_.reset(new gpu::gles2::GLES2Implementation( |
459 helper_.get(), | 371 helper_.get(), |
460 transfer_buffer.size, | 372 transfer_buffer.size, |
461 transfer_buffer.ptr, | 373 transfer_buffer.ptr, |
462 transfer_buffer_id_, | 374 transfer_buffer_id_, |
463 false)); | 375 false)); |
464 | 376 |
465 return true; | 377 return true; |
466 } | 378 } |
467 | 379 |
468 void Context3D::BindSurfaces(Surface3D* draw, Surface3D* read) { | 380 int32_t Context3D::GetAttrib(int32_t attribute, int32_t* value) { |
469 if (draw != draw_) { | 381 // TODO(alokp): Implement me. |
| 382 return 0; |
| 383 } |
| 384 |
| 385 int32_t Context3D::BindSurfaces(PP_Resource pp_draw, PP_Resource pp_read) { |
| 386 // TODO(alokp): Support separate draw-read surfaces. |
| 387 DCHECK_EQ(pp_draw, pp_read); |
| 388 if (pp_draw != pp_read) |
| 389 return PP_GRAPHICS3DERROR_BAD_MATCH; |
| 390 |
| 391 EnterResourceNoLock<PPB_Surface3D_API> enter_draw(pp_draw, false); |
| 392 EnterResourceNoLock<PPB_Surface3D_API> enter_read(pp_read, false); |
| 393 Surface3D* draw_surface = enter_draw.succeeded() ? |
| 394 static_cast<Surface3D*>(enter_draw.object()) : NULL; |
| 395 Surface3D* read_surface = enter_read.succeeded() ? |
| 396 static_cast<Surface3D*>(enter_read.object()) : NULL; |
| 397 |
| 398 if (pp_draw && !draw_surface) |
| 399 return PP_ERROR_BADRESOURCE; |
| 400 if (pp_read && !read_surface) |
| 401 return PP_ERROR_BADRESOURCE; |
| 402 HostResource host_draw = |
| 403 draw_surface ? draw_surface->host_resource() : HostResource(); |
| 404 HostResource host_read = |
| 405 read_surface ? read_surface->host_resource() : HostResource(); |
| 406 |
| 407 int32_t result; |
| 408 GetDispatcher()->Send(new PpapiHostMsg_PPBContext3D_BindSurfaces( |
| 409 INTERFACE_ID_PPB_CONTEXT_3D, |
| 410 host_resource(), host_draw, host_read, &result)); |
| 411 if (result != PP_OK) |
| 412 return result; |
| 413 |
| 414 if (draw_surface != draw_) { |
470 if (draw_) | 415 if (draw_) |
471 draw_->set_context(NULL); | 416 draw_->set_context(NULL); |
472 if (draw) { | 417 if (draw_surface) { |
473 draw->set_context(this); | 418 draw_surface->set_context(this); |
474 // Resize the backing texture to the size of the instance when it is | 419 // Resize the backing texture to the size of the instance when it is |
475 // bound. | 420 // bound. |
476 // TODO(alokp): This should be the responsibility of plugins. | 421 // TODO(alokp): This should be the responsibility of plugins. |
477 PluginDispatcher* dispatcher = | 422 InstanceData* data = GetDispatcher()->GetInstanceData(instance()); |
478 PluginDispatcher::GetForInstance(instance()); | |
479 DCHECK(dispatcher); | |
480 InstanceData* data = dispatcher->GetInstanceData(instance()); | |
481 DCHECK(data); | |
482 gles2_impl()->ResizeCHROMIUM(data->position.size.width, | 423 gles2_impl()->ResizeCHROMIUM(data->position.size.width, |
483 data->position.size.height); | 424 data->position.size.height); |
484 } | 425 } |
485 draw_ = draw; | 426 draw_ = draw_surface; |
486 } | 427 } |
487 read_ = read; | 428 read_ = read_surface; |
| 429 return PP_OK; |
488 } | 430 } |
489 | 431 |
| 432 int32_t Context3D::GetBoundSurfaces(PP_Resource* draw, PP_Resource* read) { |
| 433 *draw = draw_ ? draw_->resource() : 0; |
| 434 *read = read_ ? read_->resource() : 0; |
| 435 return PP_OK; |
| 436 } |
| 437 |
| 438 PP_Bool Context3D::InitializeTrusted(int32_t size) { |
| 439 // Trusted interface not implemented in the proxy. |
| 440 return PP_FALSE; |
| 441 } |
| 442 |
| 443 PP_Bool Context3D::GetRingBuffer(int* shm_handle, |
| 444 uint32_t* shm_size) { |
| 445 // Trusted interface not implemented in the proxy. |
| 446 return PP_FALSE; |
| 447 } |
| 448 |
| 449 PP_Context3DTrustedState Context3D::GetState() { |
| 450 // Trusted interface not implemented in the proxy. |
| 451 return GetErrorState(); |
| 452 } |
| 453 |
| 454 PP_Bool Context3D::Flush(int32_t put_offset) { |
| 455 // Trusted interface not implemented in the proxy. |
| 456 return PP_FALSE; |
| 457 } |
| 458 |
| 459 PP_Context3DTrustedState Context3D::FlushSync(int32_t put_offset) { |
| 460 // Trusted interface not implemented in the proxy. |
| 461 return GetErrorState(); |
| 462 } |
| 463 |
| 464 int32_t Context3D::CreateTransferBuffer(uint32_t size) { |
| 465 // Trusted interface not implemented in the proxy. |
| 466 return 0; |
| 467 } |
| 468 |
| 469 PP_Bool Context3D::DestroyTransferBuffer(int32_t id) { |
| 470 // Trusted interface not implemented in the proxy. |
| 471 return PP_FALSE; |
| 472 } |
| 473 |
| 474 PP_Bool Context3D::GetTransferBuffer(int32_t id, |
| 475 int* shm_handle, |
| 476 uint32_t* shm_size) { |
| 477 // Trusted interface not implemented in the proxy. |
| 478 return PP_FALSE; |
| 479 } |
| 480 |
| 481 PP_Context3DTrustedState Context3D::FlushSyncFast(int32_t put_offset, |
| 482 int32_t last_known_get) { |
| 483 // Trusted interface not implemented in the proxy. |
| 484 return GetErrorState(); |
| 485 } |
| 486 |
| 487 void* Context3D::MapTexSubImage2DCHROMIUM(GLenum target, |
| 488 GLint level, |
| 489 GLint xoffset, |
| 490 GLint yoffset, |
| 491 GLsizei width, |
| 492 GLsizei height, |
| 493 GLenum format, |
| 494 GLenum type, |
| 495 GLenum access) { |
| 496 return gles2_impl_->MapTexSubImage2DCHROMIUM( |
| 497 target, level, xoffset, yoffset, width, height, format, type, access); |
| 498 } |
| 499 |
| 500 void Context3D::UnmapTexSubImage2DCHROMIUM(const void* mem) { |
| 501 gles2_impl_->UnmapTexSubImage2DCHROMIUM(mem); |
| 502 } |
| 503 |
| 504 // PPB_Context3D_Proxy --------------------------------------------------------- |
| 505 |
490 PPB_Context3D_Proxy::PPB_Context3D_Proxy(Dispatcher* dispatcher, | 506 PPB_Context3D_Proxy::PPB_Context3D_Proxy(Dispatcher* dispatcher, |
491 const void* target_interface) | 507 const void* target_interface) |
492 : InterfaceProxy(dispatcher, target_interface) { | 508 : InterfaceProxy(dispatcher, target_interface) { |
493 } | 509 } |
494 | 510 |
495 PPB_Context3D_Proxy::~PPB_Context3D_Proxy() { | 511 PPB_Context3D_Proxy::~PPB_Context3D_Proxy() { |
496 } | 512 } |
497 | 513 |
498 // static | 514 // static |
499 const InterfaceProxy::Info* PPB_Context3D_Proxy::GetInfo() { | 515 const InterfaceProxy::Info* PPB_Context3D_Proxy::GetInfo() { |
500 static const Info info = { | 516 static const Info info = { |
501 &context_3d_interface, | 517 ::ppapi::thunk::GetPPB_Context3D_Thunk(), |
502 PPB_CONTEXT_3D_DEV_INTERFACE, | 518 PPB_CONTEXT_3D_DEV_INTERFACE, |
503 INTERFACE_ID_PPB_CONTEXT_3D, | 519 INTERFACE_ID_PPB_CONTEXT_3D, |
504 false, | 520 false, |
505 &CreateContext3DProxy, | 521 &CreateContext3DProxy, |
506 }; | 522 }; |
507 return &info; | 523 return &info; |
508 } | 524 } |
509 | 525 |
510 const PPB_Context3DTrusted_Dev* | 526 // static |
511 PPB_Context3D_Proxy::ppb_context_3d_trusted() const { | 527 const InterfaceProxy::Info* PPB_Context3D_Proxy::GetTextureMappingInfo() { |
512 return static_cast<const PPB_Context3DTrusted_Dev*>( | 528 static const Info info = { |
513 dispatcher()->GetLocalInterface( | 529 ::ppapi::thunk::GetPPB_GLESChromiumTextureMapping_Thunk(), |
514 PPB_CONTEXT_3D_TRUSTED_DEV_INTERFACE)); | 530 PPB_GLES_CHROMIUM_TEXTURE_MAPPING_DEV_INTERFACE, |
| 531 INTERFACE_ID_NONE, // CONTEXT_3D is the canonical one. |
| 532 false, |
| 533 &CreateContext3DProxy, |
| 534 }; |
| 535 return &info; |
| 536 } |
| 537 |
| 538 // static |
| 539 PP_Resource PPB_Context3D_Proxy::Create(PP_Instance instance, |
| 540 PP_Config3D_Dev config, |
| 541 PP_Resource share_context, |
| 542 const int32_t* attrib_list) { |
| 543 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 544 if (!dispatcher) |
| 545 return PP_ERROR_BADARGUMENT; |
| 546 |
| 547 // TODO(alokp): Support shared context. |
| 548 DCHECK_EQ(0, share_context); |
| 549 if (share_context != 0) |
| 550 return 0; |
| 551 |
| 552 std::vector<int32_t> attribs; |
| 553 if (attrib_list) { |
| 554 for (const int32_t* attr = attrib_list; attr; ++attr) |
| 555 attribs.push_back(*attr); |
| 556 } else { |
| 557 attribs.push_back(0); |
| 558 } |
| 559 |
| 560 HostResource result; |
| 561 dispatcher->Send(new PpapiHostMsg_PPBContext3D_Create( |
| 562 INTERFACE_ID_PPB_CONTEXT_3D, instance, config, attribs, &result)); |
| 563 |
| 564 if (result.is_null()) |
| 565 return 0; |
| 566 linked_ptr<Context3D> context_3d(new Context3D(result)); |
| 567 if (!context_3d->CreateImplementation()) |
| 568 return 0; |
| 569 return PluginResourceTracker::GetInstance()->AddResource(context_3d); |
515 } | 570 } |
516 | 571 |
517 bool PPB_Context3D_Proxy::OnMessageReceived(const IPC::Message& msg) { | 572 bool PPB_Context3D_Proxy::OnMessageReceived(const IPC::Message& msg) { |
518 bool handled = true; | 573 bool handled = true; |
519 IPC_BEGIN_MESSAGE_MAP(PPB_Context3D_Proxy, msg) | 574 IPC_BEGIN_MESSAGE_MAP(PPB_Context3D_Proxy, msg) |
520 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_Create, | 575 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_Create, |
521 OnMsgCreate) | 576 OnMsgCreate) |
522 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_BindSurfaces, | 577 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_BindSurfaces, |
523 OnMsgBindSurfaces) | 578 OnMsgBindSurfaces) |
524 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_Initialize, | 579 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_Initialize, |
(...skipping 13 matching lines...) Expand all Loading... |
538 IPC_MESSAGE_UNHANDLED(handled = false) | 593 IPC_MESSAGE_UNHANDLED(handled = false) |
539 | 594 |
540 IPC_END_MESSAGE_MAP() | 595 IPC_END_MESSAGE_MAP() |
541 // FIXME(brettw) handle bad messages! | 596 // FIXME(brettw) handle bad messages! |
542 return handled; | 597 return handled; |
543 } | 598 } |
544 | 599 |
545 void PPB_Context3D_Proxy::OnMsgCreate(PP_Instance instance, | 600 void PPB_Context3D_Proxy::OnMsgCreate(PP_Instance instance, |
546 PP_Config3D_Dev config, | 601 PP_Config3D_Dev config, |
547 std::vector<int32_t> attribs, | 602 std::vector<int32_t> attribs, |
548 HostResource* result) { | 603 HostResource* result) { |
549 DCHECK(attribs.back() == 0); | 604 if (attribs.empty() || attribs.back() != 0) |
550 PP_Resource resource = ppb_context_3d_trusted()->CreateRaw( | 605 return; // Bad message. |
551 instance, config, 0, &attribs.front()); | 606 EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); |
552 result->SetHostResource(instance, resource); | 607 if (enter.succeeded()) { |
| 608 result->SetHostResource( |
| 609 instance, |
| 610 enter.functions()->CreateContext3DRaw(instance, config, 0, |
| 611 &attribs.front())); |
| 612 } |
553 } | 613 } |
554 | 614 |
555 void PPB_Context3D_Proxy::OnMsgBindSurfaces(const HostResource& context, | 615 void PPB_Context3D_Proxy::OnMsgBindSurfaces(const HostResource& context, |
556 const HostResource& draw, | 616 const HostResource& draw, |
557 const HostResource& read, | 617 const HostResource& read, |
558 int32_t* result) { | 618 int32_t* result) { |
559 *result = ppb_context_3d_target()->BindSurfaces(context.host_resource(), | 619 EnterHostFromHostResource<PPB_Context3D_API> enter(context); |
560 draw.host_resource(), | 620 if (enter.succeeded()) { |
561 read.host_resource()); | 621 *result = enter.object()->BindSurfaces(draw.host_resource(), |
| 622 read.host_resource()); |
| 623 } else { |
| 624 *result = PP_ERROR_BADRESOURCE; |
| 625 } |
562 } | 626 } |
563 | 627 |
564 void PPB_Context3D_Proxy::OnMsgInitialize( | 628 void PPB_Context3D_Proxy::OnMsgInitialize( |
565 const HostResource& context, | 629 const HostResource& context, |
566 int32 size, | 630 int32 size, |
567 base::SharedMemoryHandle* ring_buffer) { | 631 base::SharedMemoryHandle* ring_buffer) { |
568 const PPB_Context3DTrusted_Dev* context_3d_trusted = ppb_context_3d_trusted(); | |
569 *ring_buffer = base::SharedMemory::NULLHandle(); | 632 *ring_buffer = base::SharedMemory::NULLHandle(); |
570 if (!context_3d_trusted->Initialize(context.host_resource(), size)) | 633 EnterHostFromHostResource<PPB_Context3D_API> enter(context); |
| 634 if (enter.failed()) |
| 635 return; |
| 636 |
| 637 if (!enter.object()->InitializeTrusted(size)) |
571 return; | 638 return; |
572 | 639 |
573 int shm_handle; | 640 int shm_handle; |
574 uint32_t shm_size; | 641 uint32_t shm_size; |
575 if (!context_3d_trusted->GetRingBuffer(context.host_resource(), | 642 if (!enter.object()->GetRingBuffer(&shm_handle, &shm_size)) |
576 &shm_handle, | |
577 &shm_size)) { | |
578 return; | 643 return; |
579 } | |
580 | |
581 *ring_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); | 644 *ring_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); |
582 } | 645 } |
583 | 646 |
584 void PPB_Context3D_Proxy::OnMsgGetState(const HostResource& context, | 647 void PPB_Context3D_Proxy::OnMsgGetState(const HostResource& context, |
585 gpu::CommandBuffer::State* state) { | 648 gpu::CommandBuffer::State* state) { |
586 PP_Context3DTrustedState pp_state = | 649 EnterHostFromHostResource<PPB_Context3D_API> enter(context); |
587 ppb_context_3d_trusted()->GetState(context.host_resource()); | 650 if (enter.failed()) |
| 651 return; |
| 652 PP_Context3DTrustedState pp_state = enter.object()->GetState(); |
588 *state = GPUStateFromPPState(pp_state); | 653 *state = GPUStateFromPPState(pp_state); |
589 } | 654 } |
590 | 655 |
591 void PPB_Context3D_Proxy::OnMsgFlush(const HostResource& context, | 656 void PPB_Context3D_Proxy::OnMsgFlush(const HostResource& context, |
592 int32 put_offset, | 657 int32 put_offset, |
593 int32 last_known_get, | 658 int32 last_known_get, |
594 gpu::CommandBuffer::State* state) { | 659 gpu::CommandBuffer::State* state) { |
595 PP_Context3DTrustedState pp_state = ppb_context_3d_trusted()->FlushSyncFast( | 660 EnterHostFromHostResource<PPB_Context3D_API> enter(context); |
596 context.host_resource(), put_offset, last_known_get); | 661 if (enter.failed()) |
| 662 return; |
| 663 PP_Context3DTrustedState pp_state = enter.object()->FlushSyncFast( |
| 664 put_offset, last_known_get); |
597 *state = GPUStateFromPPState(pp_state); | 665 *state = GPUStateFromPPState(pp_state); |
598 } | 666 } |
599 | 667 |
600 void PPB_Context3D_Proxy::OnMsgAsyncFlush(const HostResource& context, | 668 void PPB_Context3D_Proxy::OnMsgAsyncFlush(const HostResource& context, |
601 int32 put_offset) { | 669 int32 put_offset) { |
602 ppb_context_3d_trusted()->Flush(context.host_resource(), put_offset); | 670 EnterHostFromHostResource<PPB_Context3D_API> enter(context); |
| 671 if (enter.succeeded()) |
| 672 enter.object()->Flush(put_offset); |
603 } | 673 } |
604 | 674 |
605 void PPB_Context3D_Proxy::OnMsgCreateTransferBuffer( | 675 void PPB_Context3D_Proxy::OnMsgCreateTransferBuffer( |
606 const HostResource& context, | 676 const HostResource& context, |
607 int32 size, | 677 int32 size, |
608 int32* id) { | 678 int32* id) { |
609 *id = ppb_context_3d_trusted()->CreateTransferBuffer( | 679 EnterHostFromHostResource<PPB_Context3D_API> enter(context); |
610 context.host_resource(), size); | 680 if (enter.succeeded()) |
| 681 *id = enter.object()->CreateTransferBuffer(size); |
| 682 else |
| 683 *id = 0; |
611 } | 684 } |
612 | 685 |
613 void PPB_Context3D_Proxy::OnMsgDestroyTransferBuffer( | 686 void PPB_Context3D_Proxy::OnMsgDestroyTransferBuffer( |
614 const HostResource& context, | 687 const HostResource& context, |
615 int32 id) { | 688 int32 id) { |
616 ppb_context_3d_trusted()->DestroyTransferBuffer(context.host_resource(), id); | 689 EnterHostFromHostResource<PPB_Context3D_API> enter(context); |
| 690 if (enter.succeeded()) |
| 691 enter.object()->DestroyTransferBuffer(id); |
617 } | 692 } |
618 | 693 |
619 void PPB_Context3D_Proxy::OnMsgGetTransferBuffer( | 694 void PPB_Context3D_Proxy::OnMsgGetTransferBuffer( |
620 const HostResource& context, | 695 const HostResource& context, |
621 int32 id, | 696 int32 id, |
622 base::SharedMemoryHandle* transfer_buffer, | 697 base::SharedMemoryHandle* transfer_buffer, |
623 uint32* size) { | 698 uint32* size) { |
624 *transfer_buffer = base::SharedMemory::NULLHandle(); | 699 *transfer_buffer = base::SharedMemory::NULLHandle(); |
625 int shm_handle; | 700 *size = 0; |
626 uint32_t shm_size; | 701 |
627 if (!ppb_context_3d_trusted()->GetTransferBuffer(context.host_resource(), | 702 EnterHostFromHostResource<PPB_Context3D_API> enter(context); |
628 id, | 703 int shm_handle = 0; |
629 &shm_handle, | 704 uint32_t shm_size = 0; |
630 &shm_size)) { | 705 if (enter.succeeded() && |
631 return; | 706 enter.object()->GetTransferBuffer(id, &shm_handle, &shm_size)) { |
| 707 *transfer_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); |
| 708 *size = shm_size; |
632 } | 709 } |
633 *transfer_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); | |
634 *size = shm_size; | |
635 } | 710 } |
636 | 711 |
637 } // namespace proxy | 712 } // namespace proxy |
638 } // namespace pp | 713 } // namespace pp |
OLD | NEW |