Commit eaf3360d authored by Kelsey Gilbert's avatar Kelsey Gilbert
Browse files

Bug 1812932 - Add size outvar to GetImageBuffer. r=gfx-reviewers,bradwerth

parent 44baa0f6
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -1845,10 +1845,11 @@ CanvasRenderingContext2D::SetContextOptions(JSContext* aCx,
}

UniquePtr<uint8_t[]> CanvasRenderingContext2D::GetImageBuffer(
    int32_t* aFormat) {
    int32_t* out_format, gfx::IntSize* out_imageSize) {
  UniquePtr<uint8_t[]> ret;

  *aFormat = 0;
  *out_format = 0;
  *out_imageSize = {};

  if (!GetBufferProvider() && !EnsureTarget()) {
    return nullptr;
@@ -1858,7 +1859,8 @@ UniquePtr<uint8_t[]> CanvasRenderingContext2D::GetImageBuffer(
  if (snapshot) {
    RefPtr<DataSourceSurface> data = snapshot->GetDataSurface();
    if (data && data->GetSize() == GetSize()) {
      *aFormat = imgIEncoder::INPUT_FORMAT_HOSTARGB;
      *out_format = imgIEncoder::INPUT_FORMAT_HOSTARGB;
      *out_imageSize = data->GetSize();
      ret = SurfaceToPackedBGRA(data);
    }
  }
@@ -1880,14 +1882,15 @@ CanvasRenderingContext2D::GetInputStream(const char* aMimeType,
  }

  int32_t format = 0;
  UniquePtr<uint8_t[]> imageBuffer = GetImageBuffer(&format);
  gfx::IntSize imageSize = {};
  UniquePtr<uint8_t[]> imageBuffer = GetImageBuffer(&format, &imageSize);
  if (!imageBuffer) {
    return NS_ERROR_FAILURE;
  }

  return ImageEncoder::GetInputStream(mWidth, mHeight, imageBuffer.get(),
                                      format, encoder, aEncoderOptions,
                                      aStream);
  return ImageEncoder::GetInputStream(imageSize.width, imageSize.height,
                                      imageBuffer.get(), format, encoder,
                                      aEncoderOptions, aStream);
}

already_AddRefed<mozilla::gfx::SourceSurface>
+2 −1
Original line number Diff line number Diff line
@@ -516,7 +516,8 @@ class CanvasRenderingContext2D : public nsICanvasRenderingContextInternal,
    }
  }

  virtual UniquePtr<uint8_t[]> GetImageBuffer(int32_t* aFormat) override;
  virtual UniquePtr<uint8_t[]> GetImageBuffer(
      int32_t* out_format, gfx::IntSize* out_imageSize) override;

  virtual void OnShutdown();

+4 −3
Original line number Diff line number Diff line
@@ -98,11 +98,11 @@ void CanvasRenderingContextHelper::ToBlob(EncodeCompleteCallback* aCallback,
                                          bool aUsingCustomOptions,
                                          bool aUsePlaceholder,
                                          ErrorResult& aRv) {
  const nsIntSize elementSize = GetWidthHeight();
  if (mCurrentContext) {
    // We disallow canvases of width or height zero, and set them to 1, so
    // we will have a discrepancy with the sizes of the canvas and the context.
    // That discrepancy is OK, the rest are not.
    nsIntSize elementSize = GetWidthHeight();
    if ((elementSize.width != mCurrentContext->GetWidth() &&
         (elementSize.width != 0 || mCurrentContext->GetWidth() != 1)) ||
        (elementSize.height != mCurrentContext->GetHeight() &&
@@ -114,15 +114,16 @@ void CanvasRenderingContextHelper::ToBlob(EncodeCompleteCallback* aCallback,

  UniquePtr<uint8_t[]> imageBuffer;
  int32_t format = 0;
  auto imageSize = gfx::IntSize{elementSize.width, elementSize.height};
  if (mCurrentContext) {
    imageBuffer = mCurrentContext->GetImageBuffer(&format);
    imageBuffer = mCurrentContext->GetImageBuffer(&format, &imageSize);
  }

  RefPtr<EncodeCompleteCallback> callback = aCallback;

  aRv = ImageEncoder::ExtractDataAsync(
      aType, aEncodeOptions, aUsingCustomOptions, std::move(imageBuffer),
      format, GetWidthHeight(), aUsePlaceholder, callback);
      format, {imageSize.width, imageSize.height}, aUsePlaceholder, callback);
}

already_AddRefed<nsICanvasRenderingContextInternal>
+4 −1
Original line number Diff line number Diff line
@@ -1170,8 +1170,10 @@ RefPtr<gfx::DataSourceSurface> ClientWebGLContext::BackBufferSnapshot() {
  return surf;
}

UniquePtr<uint8_t[]> ClientWebGLContext::GetImageBuffer(int32_t* out_format) {
UniquePtr<uint8_t[]> ClientWebGLContext::GetImageBuffer(
    int32_t* out_format, gfx::IntSize* out_imageSize) {
  *out_format = 0;
  *out_imageSize = {};

  // Use GetSurfaceSnapshot() to make sure that appropriate y-flip gets applied
  gfxAlphaType any;
@@ -1181,6 +1183,7 @@ UniquePtr<uint8_t[]> ClientWebGLContext::GetImageBuffer(int32_t* out_format) {
  RefPtr<gfx::DataSourceSurface> dataSurface = snapshot->GetDataSurface();

  const auto& premultAlpha = mNotLost->info.options.premultipliedAlpha;
  *out_imageSize = dataSurface->GetSize();
  return gfxUtils::GetImageBuffer(dataSurface, premultAlpha, out_format);
}

+2 −1
Original line number Diff line number Diff line
@@ -970,7 +970,8 @@ class ClientWebGLContext final : public nsICanvasRenderingContextInternal,

  void ResetBitmap() override;

  UniquePtr<uint8_t[]> GetImageBuffer(int32_t* out_format) override;
  UniquePtr<uint8_t[]> GetImageBuffer(int32_t* out_format,
                                      gfx::IntSize* out_imageSize) override;
  NS_IMETHOD GetInputStream(const char* mimeType,
                            const nsAString& encoderOptions,
                            nsIInputStream** out_stream) override;
Loading