Пример #1
0
bool
TestShmemParent::RecvTake(Shmem& mem, Shmem& unsafe,
                          const size_t& expectedSize)
{
    if (mem.Size<char>() != expectedSize)
        fail("expected shmem size %lu, but it has size %lu",
             expectedSize, mem.Size<char>());
    if (unsafe.Size<char>() != expectedSize)
        fail("expected shmem size %lu, but it has size %lu",
             expectedSize, unsafe.Size<char>());

    if (strcmp(mem.get<char>(), "And yourself!"))
        fail("expected message was not written");
    if (strcmp(unsafe.get<char>(), "And yourself!"))
        fail("expected message was not written");

    if (!DeallocShmem(mem))
        fail("DeallocShmem");
    if (!DeallocShmem(unsafe))
        fail("DeallocShmem");

    Close();

    return true;
}
void
ISurfaceAllocator::DestroySharedSurface(SurfaceDescriptor* aSurface)
{
  MOZ_ASSERT(aSurface);
  if (!aSurface) {
    return;
  }
  if (!IsOnCompositorSide() && ReleaseOwnedSurfaceDescriptor(*aSurface)) {
    *aSurface = SurfaceDescriptor();
    return;
  }
  if (PlatformDestroySharedSurface(aSurface)) {
    return;
  }
  switch (aSurface->type()) {
    case SurfaceDescriptor::TShmem:
      DeallocShmem(aSurface->get_Shmem());
      break;
    case SurfaceDescriptor::TYCbCrImage:
      DeallocShmem(aSurface->get_YCbCrImage().data());
      break;
    case SurfaceDescriptor::TRGBImage:
      DeallocShmem(aSurface->get_RGBImage().data());
      break;
    case SurfaceDescriptor::TSurfaceDescriptorD3D10:
      break;
    case SurfaceDescriptor::Tnull_t:
    case SurfaceDescriptor::T__None:
      break;
    default:
      NS_RUNTIMEABORT("surface type not implemented!");
  }
  *aSurface = SurfaceDescriptor();
}
void
ISurfaceAllocator::DestroySharedSurface(SurfaceDescriptor* aSurface)
{
  MOZ_ASSERT(aSurface);
  if (!aSurface) {
    return;
  }
  if (PlatformDestroySharedSurface(aSurface)) {
    return;
  }
  switch (aSurface->type()) {
    case SurfaceDescriptor::TShmem:
      DeallocShmem(aSurface->get_Shmem());
      break;
    case SurfaceDescriptor::TYCbCrImage:
      DeallocShmem(aSurface->get_YCbCrImage().data());
      break;
    case SurfaceDescriptor::TRGBImage:
      DeallocShmem(aSurface->get_RGBImage().data());
      break;
    case SurfaceDescriptor::TSurfaceDescriptorD3D9:
    case SurfaceDescriptor::TSurfaceDescriptorD3D10:
      break;
    case SurfaceDescriptor::TMemoryImage:
      delete [] (unsigned char *)aSurface->get_MemoryImage().data();
      break;
    case SurfaceDescriptor::Tnull_t:
    case SurfaceDescriptor::T__None:
      break;
    default:
      NS_RUNTIMEABORT("surface type not implemented!");
  }
  *aSurface = SurfaceDescriptor();
}
Пример #4
0
void
GMPVideoDecoderChild::Dealloc(Shmem& aMem)
{
#ifndef SHMEM_ALLOC_IN_CHILD
  SendParentShmemForPool(aMem);
#else
  DeallocShmem(aMem);
#endif
}
Пример #5
0
mozilla::ipc::IPCResult
GMPVideoEncoderParent::RecvParentShmemForPool(Shmem&& aFrameBuffer)
{
  if (aFrameBuffer.IsWritable()) {
    // This test may be paranoia now that we don't shut down the VideoHost
    // in ::Shutdown, but doesn't hurt
    if (mVideoHost.SharedMemMgr()) {
      mVideoHost.SharedMemMgr()->MgrDeallocShmem(GMPSharedMem::kGMPFrameData,
                                                 aFrameBuffer);
    } else {
      LOGD(("%s::%s: %p Called in shutdown, ignoring and freeing directly", __CLASS__, __FUNCTION__, this));
      DeallocShmem(aFrameBuffer);
    }
  }
  return IPC_OK();
}
Пример #6
0
mozilla::ipc::IPCResult
VideoDecoderParent::RecvInput(const MediaRawDataIPDL& aData)
{
  MOZ_ASSERT(OnManagerThread());
  // XXX: This copies the data into a buffer owned by the MediaRawData. Ideally we'd just take ownership
  // of the shmem.
  RefPtr<MediaRawData> data = new MediaRawData(aData.buffer().get<uint8_t>(), aData.buffer().Size<uint8_t>());
  data->mOffset = aData.base().offset();
  data->mTime = aData.base().time();
  data->mTimecode = aData.base().timecode();
  data->mDuration = aData.base().duration();
  data->mKeyframe = aData.base().keyframe();

  DeallocShmem(aData.buffer());

  mDecoder->Input(data);
  return IPC_OK();
}
Пример #7
0
bool
RemotePrintJobParent::RecvProcessPage(Shmem&& aStoredPage)
{
  nsresult rv = PrintPage(aStoredPage);

  // Always deallocate the shared memory no matter what the result.
  if (!DeallocShmem(aStoredPage)) {
    NS_WARNING("Failed to deallocated shared memory, remote print will abort.");
    rv = NS_ERROR_FAILURE;
  }

  if (NS_FAILED(rv)) {
    Unused << SendAbortPrint(rv);
  } else {
    Unused << SendPageProcessed();
  }

  return true;
}
SharedImage* ImageContainerChild::AllocateSharedImageFor(Image* image)
{
  NS_ABORT_IF_FALSE(InImageBridgeChildThread(),
                  "Should be in ImageBridgeChild thread.");
  if (!image) {
    return nullptr;
  }

  if (image->GetFormat() == PLANAR_YCBCR ) {
    PlanarYCbCrImage *planarYCbCrImage = static_cast<PlanarYCbCrImage*>(image);
    const PlanarYCbCrImage::Data *data = planarYCbCrImage->GetData();
    NS_ASSERTION(data, "Must be able to retrieve yuv data from image!");
    if (!data) {
      return nullptr;
    }

    SharedMemory::SharedMemoryType shmType = OptimalShmemType();
    size_t size = ShmemYCbCrImage::ComputeMinBufferSize(data->mYSize,
                                                        data->mCbCrSize);
    Shmem shmem;
    if (!AllocUnsafeShmem(size, shmType, &shmem)) {
      return nullptr;
    }

    ShmemYCbCrImage::InitializeBufferInfo(shmem.get<uint8_t>(),
                                          data->mYSize,
                                          data->mCbCrSize);
    ShmemYCbCrImage shmemImage(shmem);

    if (!shmemImage.IsValid()) {
      NS_WARNING("Failed to properly allocate image data!");
      DeallocShmem(shmem);
      return nullptr;
    }

    ++mActiveImageCount;
    return new SharedImage(YCbCrImage(shmem, 0, data->GetPictureRect()));
  } else {
    NS_RUNTIMEABORT("TODO: Only YCbCrImage is supported here right now.");
  }
  return nullptr;
}
Пример #9
0
SharedImage* ImageContainerChild::CreateSharedImageFromData(Image* image)
{
    NS_ABORT_IF_FALSE(InImageBridgeChildThread(),
                      "Should be in ImageBridgeChild thread.");

    if (!image) {
        return nullptr;
    }
    if (image->GetFormat() == PLANAR_YCBCR ) {
        PlanarYCbCrImage *planarYCbCrImage = static_cast<PlanarYCbCrImage*>(image);
        const PlanarYCbCrImage::Data *data = planarYCbCrImage->GetData();
        NS_ASSERTION(data, "Must be able to retrieve yuv data from image!");
        if (!data) {
            return nullptr;
        }

        SharedMemory::SharedMemoryType shmType = OptimalShmemType();
        size_t size = ShmemYCbCrImage::ComputeMinBufferSize(data->mYSize,
                      data->mCbCrSize);
        Shmem shmem;
        if (!AllocUnsafeShmem(size, shmType, &shmem)) {
            return nullptr;
        }

        ShmemYCbCrImage::InitializeBufferInfo(shmem.get<uint8_t>(),
                                              data->mYSize,
                                              data->mCbCrSize);
        ShmemYCbCrImage shmemImage(shmem);

        if (!shmemImage.IsValid() || shmem.Size<uint8_t>() < size) {
            DeallocShmem(shmem);
            return nullptr;
        }

        for (int i = 0; i < data->mYSize.height; i++) {
            memcpy(shmemImage.GetYData() + i * shmemImage.GetYStride(),
                   data->mYChannel + i * data->mYStride,
                   data->mYSize.width);
        }
        for (int i = 0; i < data->mCbCrSize.height; i++) {
            memcpy(shmemImage.GetCbData() + i * shmemImage.GetCbCrStride(),
                   data->mCbChannel + i * data->mCbCrStride,
                   data->mCbCrSize.width);
            memcpy(shmemImage.GetCrData() + i * shmemImage.GetCbCrStride(),
                   data->mCrChannel + i * data->mCbCrStride,
                   data->mCbCrSize.width);
        }

        ++mActiveImageCount;
        SharedImage* result = new SharedImage(YCbCrImage(shmem, 0, data->GetPictureRect()));
        return result;
#ifdef MOZ_WIDGET_GONK
    } else if (image->GetFormat() == GONK_IO_SURFACE) {
        GonkIOSurfaceImage* gonkImage = static_cast<GonkIOSurfaceImage*>(image);
        SharedImage* result = new SharedImage(gonkImage->GetSurfaceDescriptor());
        return result;
    } else if (image->GetFormat() == GRALLOC_PLANAR_YCBCR) {
        GrallocPlanarYCbCrImage* GrallocImage = static_cast<GrallocPlanarYCbCrImage*>(image);
        SharedImage* result = new SharedImage(GrallocImage->GetSurfaceDescriptor());
        return result;
#endif
    } else {
        NS_RUNTIMEABORT("TODO: Only YCbCrImage is supported here right now.");
    }
    return nullptr;
}