Chromium Code Reviews| 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 if (!found->second.ExpireEntries()) { | 300 if (!found->second.ExpireEntries()) { |
| 301 // There are no more entries for this instance, remove it from the cache. | 301 // There are no more entries for this instance, remove it from the cache. |
| 302 cache_.erase(found); | 302 cache_.erase(found); |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 | 305 |
| 306 } // namespace | 306 } // namespace |
| 307 | 307 |
| 308 // ImageData ------------------------------------------------------------------- | 308 // ImageData ------------------------------------------------------------------- |
| 309 | 309 |
| 310 #if !defined(OS_NACL) | |
| 311 ImageData::ImageData(const HostResource& resource, | 310 ImageData::ImageData(const HostResource& resource, |
| 312 const PP_ImageDataDesc& desc, | 311 const PP_ImageDataDesc& desc) |
| 313 ImageHandle handle) | |
| 314 : Resource(OBJECT_IS_PROXY, resource), | 312 : Resource(OBJECT_IS_PROXY, resource), |
| 315 desc_(desc), | 313 desc_(desc), |
| 316 is_candidate_for_reuse_(false) { | 314 is_candidate_for_reuse_(false) { |
| 317 #if defined(OS_WIN) | |
| 318 transport_dib_.reset(TransportDIB::CreateWithHandle(handle)); | |
| 319 #else | |
| 320 transport_dib_.reset(TransportDIB::Map(handle)); | |
| 321 #endif // defined(OS_WIN) | |
| 322 } | 315 } |
| 323 #else // !defined(OS_NACL) | |
| 324 | |
| 325 ImageData::ImageData(const HostResource& resource, | |
| 326 const PP_ImageDataDesc& desc, | |
| 327 const base::SharedMemoryHandle& handle) | |
| 328 : Resource(OBJECT_IS_PROXY, resource), | |
| 329 desc_(desc), | |
| 330 shm_(handle, false /* read_only */), | |
| 331 size_(desc.size.width * desc.size.height * 4), | |
| 332 map_count_(0), | |
| 333 is_candidate_for_reuse_(false) { | |
| 334 } | |
| 335 #endif // else, !defined(OS_NACL) | |
| 336 | 316 |
| 337 ImageData::~ImageData() { | 317 ImageData::~ImageData() { |
| 338 } | 318 } |
| 339 | 319 |
| 340 PPB_ImageData_API* ImageData::AsPPB_ImageData_API() { | 320 PPB_ImageData_API* ImageData::AsPPB_ImageData_API() { |
| 341 return this; | 321 return this; |
| 342 } | 322 } |
| 343 | 323 |
| 344 void ImageData::LastPluginRefWasDeleted() { | 324 void ImageData::LastPluginRefWasDeleted() { |
| 345 // The plugin no longer needs this ImageData, add it to our cache if it's | 325 // The plugin no longer needs this ImageData, add it to our cache if it's |
| 346 // been used in a ReplaceContents. These are the ImageDatas that the renderer | 326 // been used in a ReplaceContents. These are the ImageDatas that the renderer |
| 347 // will send back ImageDataUsable messages for. | 327 // will send back ImageDataUsable messages for. |
| 348 if (is_candidate_for_reuse_) | 328 if (is_candidate_for_reuse_) |
| 349 ImageDataCache::GetInstance()->Add(this); | 329 ImageDataCache::GetInstance()->Add(this); |
| 350 } | 330 } |
| 351 | 331 |
| 352 void ImageData::InstanceWasDeleted() { | 332 void ImageData::InstanceWasDeleted() { |
| 353 ImageDataCache::GetInstance()->DidDeleteInstance(pp_instance()); | 333 ImageDataCache::GetInstance()->DidDeleteInstance(pp_instance()); |
| 354 } | 334 } |
| 355 | 335 |
| 356 PP_Bool ImageData::Describe(PP_ImageDataDesc* desc) { | 336 PP_Bool ImageData::Describe(PP_ImageDataDesc* desc) { |
| 357 memcpy(desc, &desc_, sizeof(PP_ImageDataDesc)); | 337 memcpy(desc, &desc_, sizeof(PP_ImageDataDesc)); |
| 358 return PP_TRUE; | 338 return PP_TRUE; |
| 359 } | 339 } |
| 360 | 340 |
| 361 void* ImageData::Map() { | 341 int32_t ImageData::GetSharedMemory(int* /* handle */, |
| 362 #if defined(OS_NACL) | 342 uint32_t* /* byte_count */) { |
| 363 if (map_count_++ == 0) | 343 // Not supported in the proxy (this method is for actually implementing the |
| 364 shm_.Map(size_); | 344 // proxy in the host). |
| 365 return shm_.memory(); | 345 return PP_ERROR_NOACCESS; |
| 346 } | |
| 347 | |
| 348 void ImageData::SetIsCandidateForReuse() { | |
| 349 is_candidate_for_reuse_ = true; | |
| 350 } | |
| 351 | |
| 352 void ImageData::RecycleToPlugin(bool zero_contents) { | |
| 353 is_candidate_for_reuse_ = false; | |
| 354 if (zero_contents) { | |
| 355 void* data = Map(); | |
| 356 memset(data, 0, desc_.stride * desc_.size.height); | |
| 357 Unmap(); | |
| 358 } | |
| 359 } | |
| 360 | |
| 361 // PlatformImageData ----------------------------------------------------------- | |
| 362 | |
| 363 #if !defined(OS_NACL) | |
| 364 PlatformImageData::PlatformImageData(const HostResource& resource, | |
| 365 const PP_ImageDataDesc& desc, | |
| 366 ImageHandle handle) | |
| 367 : ImageData(resource, desc) { | |
| 368 #if defined(OS_WIN) | |
| 369 transport_dib_.reset(TransportDIB::CreateWithHandle(handle)); | |
| 366 #else | 370 #else |
| 371 transport_dib_.reset(TransportDIB::Map(handle)); | |
| 372 #endif // defined(OS_WIN) | |
| 373 } | |
| 374 | |
| 375 PlatformImageData::~PlatformImageData() { | |
| 376 } | |
| 377 | |
| 378 void* PlatformImageData::Map() { | |
| 367 if (!mapped_canvas_.get()) { | 379 if (!mapped_canvas_.get()) { |
| 368 mapped_canvas_.reset(transport_dib_->GetPlatformCanvas(desc_.size.width, | 380 mapped_canvas_.reset(transport_dib_->GetPlatformCanvas(desc_.size.width, |
| 369 desc_.size.height)); | 381 desc_.size.height)); |
| 370 if (!mapped_canvas_.get()) | 382 if (!mapped_canvas_.get()) |
| 371 return NULL; | 383 return NULL; |
| 372 } | 384 } |
| 373 const SkBitmap& bitmap = | 385 const SkBitmap& bitmap = |
| 374 skia::GetTopDevice(*mapped_canvas_)->accessBitmap(true); | 386 skia::GetTopDevice(*mapped_canvas_)->accessBitmap(true); |
| 375 | 387 |
| 376 bitmap.lockPixels(); | 388 bitmap.lockPixels(); |
| 377 return bitmap.getAddr(0, 0); | 389 return bitmap.getAddr(0, 0); |
| 378 #endif | |
| 379 } | 390 } |
| 380 | 391 |
| 381 void ImageData::Unmap() { | 392 void PlatformImageData::Unmap() { |
| 382 #if defined(OS_NACL) | |
| 383 if (--map_count_ == 0) | |
| 384 shm_.Unmap(); | |
| 385 #else | |
| 386 // TODO(brettw) have a way to unmap a TransportDIB. Currently this isn't | 393 // TODO(brettw) have a way to unmap a TransportDIB. Currently this isn't |
| 387 // possible since deleting the TransportDIB also frees all the handles. | 394 // possible since deleting the TransportDIB also frees all the handles. |
| 388 // We need to add a method to TransportDIB to release the handles. | 395 // We need to add a method to TransportDIB to release the handles. |
| 389 #endif | |
| 390 } | 396 } |
| 391 | 397 |
| 392 int32_t ImageData::GetSharedMemory(int* /* handle */, | 398 SkCanvas* PlatformImageData::GetPlatformCanvas() { |
| 393 uint32_t* /* byte_count */) { | 399 return mapped_canvas_.get(); |
| 394 // Not supported in the proxy (this method is for actually implementing the | |
| 395 // proxy in the host). | |
| 396 return PP_ERROR_NOACCESS; | |
| 397 } | 400 } |
| 398 | 401 |
| 399 SkCanvas* ImageData::GetPlatformCanvas() { | 402 SkCanvas* PlatformImageData::GetCanvas() { |
| 400 #if defined(OS_NACL) | |
| 401 return NULL; // No canvas in NaCl. | |
| 402 #else | |
| 403 return mapped_canvas_.get(); | 403 return mapped_canvas_.get(); |
| 404 #endif | |
| 405 } | 404 } |
| 406 | 405 |
| 407 SkCanvas* ImageData::GetCanvas() { | |
| 408 #if defined(OS_NACL) | |
| 409 return NULL; // No canvas in NaCl. | |
| 410 #else | |
| 411 return mapped_canvas_.get(); | |
| 412 #endif | |
| 413 } | |
| 414 | |
| 415 void ImageData::SetIsCandidateForReuse() { | |
| 416 is_candidate_for_reuse_ = true; | |
| 417 } | |
| 418 | |
| 419 void ImageData::RecycleToPlugin(bool zero_contents) { | |
| 420 is_candidate_for_reuse_ = false; | |
| 421 if (zero_contents) { | |
| 422 void* data = Map(); | |
| 423 memset(data, 0, desc_.stride * desc_.size.height); | |
| 424 Unmap(); | |
| 425 } | |
| 426 } | |
| 427 | |
| 428 #if !defined(OS_NACL) | |
| 429 // static | 406 // static |
| 430 ImageHandle ImageData::NullHandle() { | 407 ImageHandle PlatformImageData::NullHandle() { |
| 431 #if defined(OS_WIN) | 408 #if defined(OS_WIN) |
| 432 return NULL; | 409 return NULL; |
| 433 #elif defined(TOOLKIT_GTK) | 410 #elif defined(TOOLKIT_GTK) |
| 434 return 0; | 411 return 0; |
| 435 #else | 412 #else |
| 436 return ImageHandle(); | 413 return ImageHandle(); |
| 437 #endif | 414 #endif |
| 438 } | 415 } |
| 439 | 416 |
| 440 ImageHandle ImageData::HandleFromInt(int32_t i) { | 417 ImageHandle PlatformImageData::HandleFromInt(int32_t i) { |
| 441 #if defined(OS_WIN) | 418 #if defined(OS_WIN) |
| 442 return reinterpret_cast<ImageHandle>(i); | 419 return reinterpret_cast<ImageHandle>(i); |
| 443 #elif defined(TOOLKIT_GTK) | 420 #elif defined(TOOLKIT_GTK) |
| 444 return static_cast<ImageHandle>(i); | 421 return static_cast<ImageHandle>(i); |
| 445 #else | 422 #else |
| 446 return ImageHandle(i, false); | 423 return ImageHandle(i, false); |
| 447 #endif | 424 #endif |
| 448 } | 425 } |
| 449 #endif // !defined(OS_NACL) | 426 #endif // !defined(OS_NACL) |
| 450 | 427 |
| 428 // SimpleImageData ------------------------------------------------------------- | |
| 429 | |
| 430 SimpleImageData::SimpleImageData(const HostResource& resource, | |
| 431 const PP_ImageDataDesc& desc, | |
| 432 const base::SharedMemoryHandle& handle) | |
| 433 : ImageData(resource, desc), | |
| 434 shm_(handle, false /* read_only */), | |
| 435 size_(desc.size.width * desc.size.height * 4), | |
| 436 map_count_(0) { | |
| 437 } | |
| 438 | |
| 439 SimpleImageData::~SimpleImageData() { | |
| 440 } | |
| 441 | |
| 442 void* SimpleImageData::Map() { | |
| 443 if (map_count_++ == 0) | |
| 444 shm_.Map(size_); | |
| 445 return shm_.memory(); | |
| 446 } | |
| 447 | |
| 448 void SimpleImageData::Unmap() { | |
| 449 if (--map_count_ == 0) | |
| 450 shm_.Unmap(); | |
| 451 } | |
| 452 | |
| 453 SkCanvas* SimpleImageData::GetPlatformCanvas() { | |
| 454 return NULL; // No canvas available. | |
| 455 } | |
| 456 | |
| 457 SkCanvas* SimpleImageData::GetCanvas() { | |
| 458 return NULL; // No canvas available. | |
| 459 } | |
| 460 | |
| 451 // PPB_ImageData_Proxy --------------------------------------------------------- | 461 // PPB_ImageData_Proxy --------------------------------------------------------- |
| 452 | 462 |
| 453 PPB_ImageData_Proxy::PPB_ImageData_Proxy(Dispatcher* dispatcher) | 463 PPB_ImageData_Proxy::PPB_ImageData_Proxy(Dispatcher* dispatcher) |
| 454 : InterfaceProxy(dispatcher) { | 464 : InterfaceProxy(dispatcher) { |
| 455 } | 465 } |
| 456 | 466 |
| 457 PPB_ImageData_Proxy::~PPB_ImageData_Proxy() { | 467 PPB_ImageData_Proxy::~PPB_ImageData_Proxy() { |
| 458 } | 468 } |
| 459 | 469 |
| 460 // static | 470 // static |
| 461 PP_Resource PPB_ImageData_Proxy::CreateProxyResource(PP_Instance instance, | 471 PP_Resource PPB_ImageData_Proxy::CreateProxyResource(PP_Instance instance, |
| 462 PP_ImageDataFormat format, | 472 PP_ImageDataFormat format, |
| 463 const PP_Size& size, | 473 const PP_Size& size, |
| 464 PP_Bool init_to_zero) { | 474 PP_Bool init_to_zero, |
| 475 PP_Bool platform) { | |
| 465 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 476 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 466 if (!dispatcher) | 477 if (!dispatcher) |
| 467 return 0; | 478 return 0; |
| 468 | 479 |
| 469 // Check the cache. | 480 // Check the cache. |
| 470 scoped_refptr<ImageData> cached_image_data = | 481 scoped_refptr<ImageData> cached_image_data = |
| 471 ImageDataCache::GetInstance()->Get(instance, size.width, size.height, | 482 ImageDataCache::GetInstance()->Get(instance, size.width, size.height, |
| 472 format); | 483 format); |
| 473 if (cached_image_data.get()) { | 484 if (cached_image_data.get()) { |
| 474 // We have one we can re-use rather than allocating a new one. | 485 // We have one we can re-use rather than allocating a new one. |
| 475 cached_image_data->RecycleToPlugin(PP_ToBool(init_to_zero)); | 486 cached_image_data->RecycleToPlugin(PP_ToBool(init_to_zero)); |
| 476 return cached_image_data->GetReference(); | 487 return cached_image_data->GetReference(); |
| 477 } | 488 } |
| 478 | 489 |
| 479 HostResource result; | 490 HostResource result; |
| 480 std::string image_data_desc; | 491 PP_ImageDataDesc desc; |
| 481 #if defined(OS_NACL) | 492 #if defined(OS_NACL) |
|
dmichael (off chromium)
2013/06/10 18:07:29
I think you want to change to checking platform at
bbudge
2013/06/10 23:28:37
Good catch.
| |
| 482 ppapi::proxy::SerializedHandle image_handle_wrapper; | 493 ppapi::proxy::SerializedHandle image_handle_wrapper; |
| 483 dispatcher->Send(new PpapiHostMsg_PPBImageData_CreateNaCl( | 494 dispatcher->Send(new PpapiHostMsg_PPBImageData_CreateSimple( |
| 484 kApiID, instance, format, size, init_to_zero, | 495 kApiID, instance, format, size, init_to_zero, |
| 485 &result, &image_data_desc, &image_handle_wrapper)); | 496 &result, &desc, &image_handle_wrapper)); |
| 486 if (!image_handle_wrapper.is_shmem()) | 497 if (!image_handle_wrapper.is_shmem()) |
| 487 return 0; | 498 return 0; |
| 488 base::SharedMemoryHandle image_handle = image_handle_wrapper.shmem(); | 499 base::SharedMemoryHandle image_handle = image_handle_wrapper.shmem(); |
| 500 if (!result.is_null()) | |
| 501 return (new SimpleImageData(result, desc, image_handle))->GetReference(); | |
| 489 #else | 502 #else |
| 490 ImageHandle image_handle = ImageData::NullHandle(); | 503 ImageHandle image_handle = PlatformImageData::NullHandle(); |
| 491 dispatcher->Send(new PpapiHostMsg_PPBImageData_Create( | 504 dispatcher->Send(new PpapiHostMsg_PPBImageData_CreatePlatform( |
| 492 kApiID, instance, format, size, init_to_zero, | 505 kApiID, instance, format, size, init_to_zero, |
| 493 &result, &image_data_desc, &image_handle)); | 506 &result, &desc, &image_handle)); |
| 507 if (!result.is_null()) | |
| 508 return (new PlatformImageData(result, desc, image_handle))->GetReference(); | |
| 494 #endif | 509 #endif |
| 495 | 510 |
| 496 if (result.is_null() || image_data_desc.size() != sizeof(PP_ImageDataDesc)) | 511 return 0; |
| 497 return 0; | |
| 498 | |
| 499 // We serialize the PP_ImageDataDesc just by copying to a string. | |
| 500 PP_ImageDataDesc desc; | |
| 501 memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc)); | |
| 502 | |
| 503 return (new ImageData(result, desc, image_handle))->GetReference(); | |
| 504 } | 512 } |
| 505 | 513 |
| 506 bool PPB_ImageData_Proxy::OnMessageReceived(const IPC::Message& msg) { | 514 bool PPB_ImageData_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 507 bool handled = true; | 515 bool handled = true; |
| 508 IPC_BEGIN_MESSAGE_MAP(PPB_ImageData_Proxy, msg) | 516 IPC_BEGIN_MESSAGE_MAP(PPB_ImageData_Proxy, msg) |
| 509 #if !defined(OS_NACL) | 517 #if !defined(OS_NACL) |
| 510 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_Create, OnHostMsgCreate) | 518 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_CreatePlatform, |
| 511 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_CreateNaCl, | 519 OnHostMsgCreatePlatform) |
| 512 OnHostMsgCreateNaCl) | 520 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_CreateSimple, |
| 521 OnHostMsgCreateSimple) | |
| 513 #endif | 522 #endif |
| 514 IPC_MESSAGE_HANDLER(PpapiMsg_PPBImageData_NotifyUnusedImageData, | 523 IPC_MESSAGE_HANDLER(PpapiMsg_PPBImageData_NotifyUnusedImageData, |
| 515 OnPluginMsgNotifyUnusedImageData) | 524 OnPluginMsgNotifyUnusedImageData) |
| 516 | 525 |
| 517 IPC_MESSAGE_UNHANDLED(handled = false) | 526 IPC_MESSAGE_UNHANDLED(handled = false) |
| 518 IPC_END_MESSAGE_MAP() | 527 IPC_END_MESSAGE_MAP() |
| 519 return handled; | 528 return handled; |
| 520 } | 529 } |
| 521 | 530 |
| 522 #if !defined(OS_NACL) | 531 #if !defined(OS_NACL) |
| 523 // static | 532 // static |
| 524 PP_Resource PPB_ImageData_Proxy::CreateImageData( | 533 PP_Resource PPB_ImageData_Proxy::CreateImageData( |
| 525 PP_Instance instance, | 534 PP_Instance instance, |
| 526 PP_ImageDataFormat format, | 535 PP_ImageDataFormat format, |
| 527 const PP_Size& size, | 536 const PP_Size& size, |
| 528 bool init_to_zero, | 537 bool init_to_zero, |
| 529 bool is_nacl_plugin, | 538 bool platform, |
| 530 PP_ImageDataDesc* desc, | 539 PP_ImageDataDesc* desc, |
| 531 IPC::PlatformFileForTransit* image_handle, | 540 IPC::PlatformFileForTransit* image_handle, |
| 532 uint32_t* byte_count) { | 541 uint32_t* byte_count) { |
| 533 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 542 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 534 if (!dispatcher) | 543 if (!dispatcher) |
| 535 return 0; | 544 return 0; |
| 536 | 545 |
| 537 thunk::EnterResourceCreation enter(instance); | 546 thunk::EnterResourceCreation enter(instance); |
| 538 if (enter.failed()) | 547 if (enter.failed()) |
| 539 return 0; | 548 return 0; |
| 540 | 549 |
| 541 PP_Bool pp_init_to_zero = init_to_zero ? PP_TRUE : PP_FALSE; | 550 PP_Bool pp_init_to_zero = init_to_zero ? PP_TRUE : PP_FALSE; |
| 542 ppapi::ScopedPPResource resource( | 551 ppapi::ScopedPPResource resource( |
| 543 ppapi::ScopedPPResource::PassRef(), | 552 ppapi::ScopedPPResource::PassRef(), |
| 544 is_nacl_plugin ? | 553 platform ? |
| 545 enter.functions()->CreateImageDataNaCl(instance, format, &size, | 554 enter.functions()->CreateImageDataPlatform(instance, format, &size, |
| 546 pp_init_to_zero) : | 555 pp_init_to_zero) : |
| 547 enter.functions()->CreateImageData(instance, format, &size, | 556 enter.functions()->CreateImageDataSimple(instance, format, &size, |
| 548 pp_init_to_zero)); | 557 pp_init_to_zero)); |
| 549 if (!resource.get()) | 558 if (!resource.get()) |
| 550 return 0; | 559 return 0; |
| 551 | 560 |
| 552 thunk::EnterResourceNoLock<PPB_ImageData_API> enter_resource(resource.get(), | 561 thunk::EnterResourceNoLock<PPB_ImageData_API> enter_resource(resource.get(), |
| 553 false); | 562 false); |
| 554 if (enter_resource.object()->Describe(desc) != PP_TRUE) { | 563 if (enter_resource.object()->Describe(desc) != PP_TRUE) { |
| 555 DVLOG(1) << "CreateImageData failed: could not Describe"; | 564 DVLOG(1) << "CreateImageData failed: could not Describe"; |
| 556 return 0; | 565 return 0; |
| 557 } | 566 } |
| 558 | 567 |
| 559 int local_fd = 0; | 568 int local_fd = 0; |
| 560 if (enter_resource.object()->GetSharedMemory(&local_fd, | 569 if (enter_resource.object()->GetSharedMemory(&local_fd, |
| 561 byte_count) != PP_OK) { | 570 byte_count) != PP_OK) { |
| 562 DVLOG(1) << "CreateImageData failed: could not GetSharedMemory"; | 571 DVLOG(1) << "CreateImageData failed: could not GetSharedMemory"; |
| 563 return 0; | 572 return 0; |
| 564 } | 573 } |
| 565 | 574 |
| 566 #if defined(OS_WIN) | 575 #if defined(OS_WIN) |
| 567 *image_handle = dispatcher->ShareHandleWithRemote( | 576 *image_handle = dispatcher->ShareHandleWithRemote( |
| 568 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)), false); | 577 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)), false); |
| 569 #elif defined(TOOLKIT_GTK) | 578 #elif defined(TOOLKIT_GTK) |
| 570 // On X Windows, a non-nacl handle is a SysV shared memory key. | 579 // On X Windows, a PlatformImageData is backed by a SysV shared memory key, |
| 571 if (is_nacl_plugin) | 580 // so embed that in a fake PlatformFileForTransit and don't share it across |
| 581 // processes. | |
| 582 if (platform) | |
| 583 *image_handle = IPC::PlatformFileForTransit(local_fd, false); | |
| 584 else | |
| 572 *image_handle = dispatcher->ShareHandleWithRemote(local_fd, false); | 585 *image_handle = dispatcher->ShareHandleWithRemote(local_fd, false); |
| 573 else | |
| 574 *image_handle = IPC::PlatformFileForTransit(local_fd, false); | |
| 575 #elif defined(OS_POSIX) | 586 #elif defined(OS_POSIX) |
| 576 *image_handle = dispatcher->ShareHandleWithRemote(local_fd, false); | 587 *image_handle = dispatcher->ShareHandleWithRemote(local_fd, false); |
| 577 #else | 588 #else |
| 578 #error Not implemented. | 589 #error Not implemented. |
| 579 #endif | 590 #endif |
| 580 | 591 |
| 581 return resource.Release(); | 592 return resource.Release(); |
| 582 } | 593 } |
| 583 | 594 |
| 584 void PPB_ImageData_Proxy::OnHostMsgCreate(PP_Instance instance, | 595 void PPB_ImageData_Proxy::OnHostMsgCreatePlatform( |
| 585 int32_t format, | 596 PP_Instance instance, |
| 586 const PP_Size& size, | 597 int32_t format, |
| 587 PP_Bool init_to_zero, | 598 const PP_Size& size, |
| 588 HostResource* result, | 599 PP_Bool init_to_zero, |
| 589 std::string* image_data_desc, | 600 HostResource* result, |
| 590 ImageHandle* result_image_handle) { | 601 PP_ImageDataDesc* desc, |
| 591 PP_ImageDataDesc desc; | 602 ImageHandle* result_image_handle) { |
| 592 IPC::PlatformFileForTransit image_handle; | 603 IPC::PlatformFileForTransit image_handle; |
| 593 uint32_t byte_count; | 604 uint32_t byte_count; |
| 594 PP_Resource resource = | 605 PP_Resource resource = |
| 595 CreateImageData(instance, | 606 CreateImageData(instance, |
| 596 static_cast<PP_ImageDataFormat>(format), | 607 static_cast<PP_ImageDataFormat>(format), |
| 597 size, | 608 size, |
| 598 true /* init_to_zero */, | 609 true /* init_to_zero */, |
| 599 false /* is_nacl_plugin */, | 610 true /* platform */, |
| 600 &desc, &image_handle, &byte_count); | 611 desc, &image_handle, &byte_count); |
| 601 result->SetHostResource(instance, resource); | 612 result->SetHostResource(instance, resource); |
| 602 if (resource) { | 613 if (resource) { |
| 603 image_data_desc->resize(sizeof(PP_ImageDataDesc)); | |
| 604 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); | |
| 605 #if defined(TOOLKIT_GTK) | 614 #if defined(TOOLKIT_GTK) |
| 606 // On X Windows ImageHandle is a SysV shared memory key. | 615 // On X Windows ImageHandle is a SysV shared memory key. |
| 607 *result_image_handle = image_handle.fd; | 616 *result_image_handle = image_handle.fd; |
| 608 #else | 617 #else |
| 609 *result_image_handle = image_handle; | 618 *result_image_handle = image_handle; |
| 610 #endif | 619 #endif |
| 611 } else { | 620 } else { |
| 612 image_data_desc->clear(); | 621 *result_image_handle = PlatformImageData::NullHandle(); |
| 613 *result_image_handle = ImageData::NullHandle(); | |
| 614 } | 622 } |
| 615 } | 623 } |
| 616 | 624 |
| 617 void PPB_ImageData_Proxy::OnHostMsgCreateNaCl( | 625 void PPB_ImageData_Proxy::OnHostMsgCreateSimple( |
| 618 PP_Instance instance, | 626 PP_Instance instance, |
| 619 int32_t format, | 627 int32_t format, |
| 620 const PP_Size& size, | 628 const PP_Size& size, |
| 621 PP_Bool init_to_zero, | 629 PP_Bool init_to_zero, |
| 622 HostResource* result, | 630 HostResource* result, |
| 623 std::string* image_data_desc, | 631 PP_ImageDataDesc* desc, |
| 624 ppapi::proxy::SerializedHandle* result_image_handle) { | 632 ppapi::proxy::SerializedHandle* result_image_handle) { |
| 625 PP_ImageDataDesc desc; | |
| 626 IPC::PlatformFileForTransit image_handle; | 633 IPC::PlatformFileForTransit image_handle; |
| 627 uint32_t byte_count; | 634 uint32_t byte_count; |
| 628 PP_Resource resource = | 635 PP_Resource resource = |
| 629 CreateImageData(instance, | 636 CreateImageData(instance, |
| 630 static_cast<PP_ImageDataFormat>(format), | 637 static_cast<PP_ImageDataFormat>(format), |
| 631 size, | 638 size, |
| 632 true /* init_to_zero */, | 639 true /* init_to_zero */, |
| 633 true /* is_nacl_plugin */, | 640 false /* platform */, |
| 634 &desc, &image_handle, &byte_count); | 641 desc, &image_handle, &byte_count); |
| 635 | 642 |
| 636 result->SetHostResource(instance, resource); | 643 result->SetHostResource(instance, resource); |
| 637 if (resource) { | 644 if (resource) { |
| 638 image_data_desc->resize(sizeof(PP_ImageDataDesc)); | |
| 639 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); | |
| 640 result_image_handle->set_shmem(image_handle, byte_count); | 645 result_image_handle->set_shmem(image_handle, byte_count); |
| 641 } else { | 646 } else { |
| 642 image_data_desc->clear(); | |
| 643 result_image_handle->set_null_shmem(); | 647 result_image_handle->set_null_shmem(); |
| 644 } | 648 } |
| 645 } | 649 } |
| 646 #endif // !defined(OS_NACL) | 650 #endif // !defined(OS_NACL) |
| 647 | 651 |
| 648 void PPB_ImageData_Proxy::OnPluginMsgNotifyUnusedImageData( | 652 void PPB_ImageData_Proxy::OnPluginMsgNotifyUnusedImageData( |
| 649 const HostResource& old_image_data) { | 653 const HostResource& old_image_data) { |
| 650 PluginGlobals* plugin_globals = PluginGlobals::Get(); | 654 PluginGlobals* plugin_globals = PluginGlobals::Get(); |
| 651 if (!plugin_globals) | 655 if (!plugin_globals) |
| 652 return; // This may happen if the plugin is maliciously sending this | 656 return; // This may happen if the plugin is maliciously sending this |
| 653 // message to the renderer. | 657 // message to the renderer. |
| 654 | 658 |
| 655 EnterPluginFromHostResource<PPB_ImageData_API> enter(old_image_data); | 659 EnterPluginFromHostResource<PPB_ImageData_API> enter(old_image_data); |
| 656 if (enter.succeeded()) { | 660 if (enter.succeeded()) { |
| 657 ImageData* image_data = static_cast<ImageData*>(enter.object()); | 661 ImageData* image_data = static_cast<ImageData*>(enter.object()); |
| 658 ImageDataCache::GetInstance()->ImageDataUsable(image_data); | 662 ImageDataCache::GetInstance()->ImageDataUsable(image_data); |
| 659 } | 663 } |
| 660 | 664 |
| 661 // The renderer sent us a reference with the message. If the image data was | 665 // The renderer sent us a reference with the message. If the image data was |
| 662 // still cached in our process, the proxy still holds a reference so we can | 666 // 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 | 667 // 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 | 668 // reference, we released everything and we should also release the one the |
| 665 // renderer just sent us. | 669 // renderer just sent us. |
| 666 dispatcher()->Send(new PpapiHostMsg_PPBCore_ReleaseResource( | 670 dispatcher()->Send(new PpapiHostMsg_PPBCore_ReleaseResource( |
| 667 API_ID_PPB_CORE, old_image_data)); | 671 API_ID_PPB_CORE, old_image_data)); |
| 668 } | 672 } |
| 669 | 673 |
| 670 } // namespace proxy | 674 } // namespace proxy |
| 671 } // namespace ppapi | 675 } // namespace ppapi |
| OLD | NEW |