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_image_data_proxy.h" | 5 #include "ppapi/proxy/ppb_image_data_proxy.h" |
6 | 6 |
7 #include <string.h> // For memcpy | 7 #include <string.h> // For memcpy |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 memset(data, 0, desc_.stride * desc_.size.height); | 423 memset(data, 0, desc_.stride * desc_.size.height); |
424 Unmap(); | 424 Unmap(); |
425 } | 425 } |
426 } | 426 } |
427 | 427 |
428 #if !defined(OS_NACL) | 428 #if !defined(OS_NACL) |
429 // static | 429 // static |
430 ImageHandle ImageData::NullHandle() { | 430 ImageHandle ImageData::NullHandle() { |
431 #if defined(OS_WIN) | 431 #if defined(OS_WIN) |
432 return NULL; | 432 return NULL; |
433 #elif defined(OS_MACOSX) || defined(OS_ANDROID) | 433 #elif defined(TOOLKIT_GTK) |
| 434 return 0; |
| 435 #else |
434 return ImageHandle(); | 436 return ImageHandle(); |
435 #else | |
436 return 0; | |
437 #endif | 437 #endif |
438 } | 438 } |
439 | 439 |
440 ImageHandle ImageData::HandleFromInt(int32_t i) { | 440 ImageHandle ImageData::HandleFromInt(int32_t i) { |
441 #if defined(OS_WIN) | 441 #if defined(OS_WIN) |
442 return reinterpret_cast<ImageHandle>(i); | 442 return reinterpret_cast<ImageHandle>(i); |
443 #elif defined(OS_MACOSX) || defined(OS_ANDROID) | 443 #elif defined(TOOLKIT_GTK) |
| 444 return static_cast<ImageHandle>(i); |
| 445 #else |
444 return ImageHandle(i, false); | 446 return ImageHandle(i, false); |
445 #else | |
446 return static_cast<ImageHandle>(i); | |
447 #endif | 447 #endif |
448 } | 448 } |
449 #endif // !defined(OS_NACL) | 449 #endif // !defined(OS_NACL) |
450 | 450 |
451 // PPB_ImageData_Proxy --------------------------------------------------------- | 451 // PPB_ImageData_Proxy --------------------------------------------------------- |
452 | 452 |
453 PPB_ImageData_Proxy::PPB_ImageData_Proxy(Dispatcher* dispatcher) | 453 PPB_ImageData_Proxy::PPB_ImageData_Proxy(Dispatcher* dispatcher) |
454 : InterfaceProxy(dispatcher) { | 454 : InterfaceProxy(dispatcher) { |
455 } | 455 } |
456 | 456 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 int local_fd = 0; | 559 int local_fd = 0; |
560 if (enter_resource.object()->GetSharedMemory(&local_fd, | 560 if (enter_resource.object()->GetSharedMemory(&local_fd, |
561 byte_count) != PP_OK) { | 561 byte_count) != PP_OK) { |
562 DVLOG(1) << "CreateImageData failed: could not GetSharedMemory"; | 562 DVLOG(1) << "CreateImageData failed: could not GetSharedMemory"; |
563 return 0; | 563 return 0; |
564 } | 564 } |
565 | 565 |
566 #if defined(OS_WIN) | 566 #if defined(OS_WIN) |
567 *image_handle = dispatcher->ShareHandleWithRemote( | 567 *image_handle = dispatcher->ShareHandleWithRemote( |
568 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)), false); | 568 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)), false); |
569 #elif defined(OS_MACOSX) || defined(OS_ANDROID) | 569 #elif defined(TOOLKIT_GTK) |
570 *image_handle = dispatcher->ShareHandleWithRemote(local_fd, false); | |
571 #elif defined(OS_POSIX) | |
572 // On X Windows, a non-nacl handle is a SysV shared memory key. | 570 // On X Windows, a non-nacl handle is a SysV shared memory key. |
573 if (is_nacl_plugin) | 571 if (is_nacl_plugin) |
574 *image_handle = dispatcher->ShareHandleWithRemote(local_fd, false); | 572 *image_handle = dispatcher->ShareHandleWithRemote(local_fd, false); |
575 else | 573 else |
576 *image_handle = IPC::PlatformFileForTransit(local_fd, false); | 574 *image_handle = IPC::PlatformFileForTransit(local_fd, false); |
| 575 #elif defined(OS_POSIX) |
| 576 *image_handle = dispatcher->ShareHandleWithRemote(local_fd, false); |
577 #else | 577 #else |
578 #error Not implemented. | 578 #error Not implemented. |
579 #endif | 579 #endif |
580 | 580 |
581 return resource.Release(); | 581 return resource.Release(); |
582 } | 582 } |
583 | 583 |
584 void PPB_ImageData_Proxy::OnHostMsgCreate(PP_Instance instance, | 584 void PPB_ImageData_Proxy::OnHostMsgCreate(PP_Instance instance, |
585 int32_t format, | 585 int32_t format, |
586 const PP_Size& size, | 586 const PP_Size& size, |
587 PP_Bool init_to_zero, | 587 PP_Bool init_to_zero, |
588 HostResource* result, | 588 HostResource* result, |
589 std::string* image_data_desc, | 589 std::string* image_data_desc, |
590 ImageHandle* result_image_handle) { | 590 ImageHandle* result_image_handle) { |
591 PP_ImageDataDesc desc; | 591 PP_ImageDataDesc desc; |
592 IPC::PlatformFileForTransit image_handle; | 592 IPC::PlatformFileForTransit image_handle; |
593 uint32_t byte_count; | 593 uint32_t byte_count; |
594 PP_Resource resource = | 594 PP_Resource resource = |
595 CreateImageData(instance, | 595 CreateImageData(instance, |
596 static_cast<PP_ImageDataFormat>(format), | 596 static_cast<PP_ImageDataFormat>(format), |
597 size, | 597 size, |
598 true /* init_to_zero */, | 598 true /* init_to_zero */, |
599 false /* is_nacl_plugin */, | 599 false /* is_nacl_plugin */, |
600 &desc, &image_handle, &byte_count); | 600 &desc, &image_handle, &byte_count); |
601 result->SetHostResource(instance, resource); | 601 result->SetHostResource(instance, resource); |
602 if (resource) { | 602 if (resource) { |
603 image_data_desc->resize(sizeof(PP_ImageDataDesc)); | 603 image_data_desc->resize(sizeof(PP_ImageDataDesc)); |
604 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); | 604 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); |
605 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_ANDROID) | 605 #if defined(TOOLKIT_GTK) |
606 *result_image_handle = image_handle; | |
607 #else | |
608 // On X Windows ImageHandle is a SysV shared memory key. | 606 // On X Windows ImageHandle is a SysV shared memory key. |
609 *result_image_handle = image_handle.fd; | 607 *result_image_handle = image_handle.fd; |
| 608 #else |
| 609 *result_image_handle = image_handle; |
610 #endif | 610 #endif |
611 } else { | 611 } else { |
612 image_data_desc->clear(); | 612 image_data_desc->clear(); |
613 *result_image_handle = ImageData::NullHandle(); | 613 *result_image_handle = ImageData::NullHandle(); |
614 } | 614 } |
615 } | 615 } |
616 | 616 |
617 void PPB_ImageData_Proxy::OnHostMsgCreateNaCl( | 617 void PPB_ImageData_Proxy::OnHostMsgCreateNaCl( |
618 PP_Instance instance, | 618 PP_Instance instance, |
619 int32_t format, | 619 int32_t format, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 // still cached in our process, the proxy still holds a reference so we can | 662 // still cached in our process, the proxy still holds a reference so we can |
663 // remove the one the renderer just sent is. If the proxy no longer holds a | 663 // remove the one the renderer just sent is. If the proxy no longer holds a |
664 // reference, we released everything and we should also release the one the | 664 // reference, we released everything and we should also release the one the |
665 // renderer just sent us. | 665 // renderer just sent us. |
666 dispatcher()->Send(new PpapiHostMsg_PPBCore_ReleaseResource( | 666 dispatcher()->Send(new PpapiHostMsg_PPBCore_ReleaseResource( |
667 API_ID_PPB_CORE, old_image_data)); | 667 API_ID_PPB_CORE, old_image_data)); |
668 } | 668 } |
669 | 669 |
670 } // namespace proxy | 670 } // namespace proxy |
671 } // namespace ppapi | 671 } // namespace ppapi |
OLD | NEW |