Ejemplo n.º 1
0
bool
DataSourceSurfaceCG::InitFromData(unsigned char *aData,
                               const IntSize &aSize,
                               int32_t aStride,
                               SurfaceFormat aFormat)
{
  if (aSize.width <= 0 || aSize.height <= 0) {
    return false;
  }

  size_t bufLen = BufferSizeFromStrideAndHeight(aStride, aSize.height);
  if (bufLen == 0) {
    mImage = nullptr;
    return false;
  }

  void *data = malloc(bufLen);
  memcpy(data, aData, bufLen - aStride + (aSize.width * BytesPerPixel(aFormat)));

  mFormat = aFormat;
  mImage = CreateCGImage(data, data, aSize, aStride, aFormat);

  if (!mImage) {
    free(data);
    return false;
  }

  return true;
}
Ejemplo n.º 2
0
void SourceSurfaceCGBitmapContext::EnsureImage() const
{
  // Instead of using CGBitmapContextCreateImage we create
  // a CGImage around the data associated with the CGBitmapContext
  // we do this to avoid the vm_copy that CGBitmapContextCreateImage.
  // vm_copy tends to cause all sorts of unexpected performance problems
  // because of the mm tricks that vm_copy does. Using a regular
  // memcpy when the bitmap context is modified gives us more predictable
  // performance characteristics.
  if (!mImage) {
    void *info;
    if (mCg) {
      // if we have an mCg than it owns the data
      // and we don't want to tranfer ownership
      // to the CGDataProviderCreateWithData
      info = nullptr;
    } else {
      // otherwise we transfer ownership to
      // the dataProvider
      info = mData;
    }

    if (!mData) abort();

    mImage = CreateCGImage(info, mData, mSize, mStride, mFormat);
  }
}
Ejemplo n.º 3
0
CGImageRef
CreateCGImage(void *aInfo,
              const void *aData,
              const IntSize &aSize,
              int32_t aStride,
              SurfaceFormat aFormat)
{
  return CreateCGImage(releaseCallback,
                       aInfo,
                       aData,
                       aSize,
                       aStride,
                       aFormat);
}
Ejemplo n.º 4
0
void SourceSurfaceCGBitmapContext::EnsureImage() const
{
  // Instead of using CGBitmapContextCreateImage we create
  // a CGImage around the data associated with the CGBitmapContext
  // we do this to avoid the vm_copy that CGBitmapContextCreateImage.
  // vm_copy tends to cause all sorts of unexpected performance problems
  // because of the mm tricks that vm_copy does. Using a regular
  // memcpy when the bitmap context is modified gives us more predictable
  // performance characteristics.
  if (!mImage) {
    if (!mData) abort();
    mImage = CreateCGImage(nullptr, mData, mSize, mStride, mFormat);
  }
}
Ejemplo n.º 5
0
bool
SourceSurfaceCG::InitFromData(unsigned char *aData,
                               const IntSize &aSize,
                               int32_t aStride,
                               SurfaceFormat aFormat)
{
  assert(aSize.width >= 0 && aSize.height >= 0);

  void *data = malloc(aStride * aSize.height);
  // Copy all the data except the stride padding on the very last
  // row since we can't guarantee that is readable.
  memcpy(data, aData, aStride * (aSize.height - 1) + (aSize.width * BytesPerPixel(aFormat)));

  mFormat = aFormat;
  mImage = CreateCGImage(data, data, aSize, aStride, aFormat);

  return mImage != nullptr;
}
Ejemplo n.º 6
0
bool
DataSourceSurfaceCG::InitFromData(unsigned char *aData,
                               const IntSize &aSize,
                               int32_t aStride,
                               SurfaceFormat aFormat)
{
  if (aSize.width <= 0 || aSize.height <= 0) {
    return false;
  }

  void *data = malloc(aStride * aSize.height);
  memcpy(data, aData, aStride * (aSize.height - 1) + (aSize.width * BytesPerPixel(aFormat)));

  mFormat = aFormat;
  mImage = CreateCGImage(data, data, aSize, aStride, aFormat);

  if (!mImage) {
    free(data);
    return false;
  }

  return true;
}