Remove last reference to SkBitmap
Removes the last remaining reference to SkBitmap in the PDFium code,
which was in CFX_SkiaDeviceDriver::GetDIBits(). This has no functional
effect, but the Skia team discourages new uses of the SkBitmap API.
Also fixes a bug in which GetDIBits() was using the destination buffer's
dimensions to draw the source image. This didn't matter as long as the
source and destination dimensions were the same.
Bug: pdfium:2007
Change-Id: If2dbf45a6668d02db25a387ac6ac391c1ffc2882
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/108730
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Auto-Submit: K. Moon <kmoon@chromium.org>
Commit-Queue: K. Moon <kmoon@chromium.org>
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index 2bd14e1..ff2c8eb 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -51,7 +51,6 @@
#include "third_party/base/numerics/safe_conversions.h"
#include "third_party/base/ptr_util.h"
#include "third_party/base/span.h"
-#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkBlendMode.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkClipOp.h"
@@ -1352,32 +1351,28 @@
if (!m_pBitmap)
return true;
- const uint8_t* srcBuffer = m_pBitmap->GetBuffer().data();
- if (!srcBuffer)
+ const uint8_t* input_buffer = m_pBitmap->GetBuffer().data();
+ if (!input_buffer) {
return true;
+ }
- SkImageInfo srcImageInfo =
+ uint8_t* output_buffer = pBitmap->GetWritableBuffer().data();
+ DCHECK(output_buffer);
+
+ SkImageInfo input_info =
SkImageInfo::Make(m_pBitmap->GetWidth(), m_pBitmap->GetHeight(),
SkColorType::kN32_SkColorType, kPremul_SkAlphaType);
- sk_sp<SkImage> source = SkImages::RasterFromPixmap(
- SkPixmap(srcImageInfo, srcBuffer, m_pBitmap->GetPitch()),
+ sk_sp<SkImage> input = SkImages::RasterFromPixmap(
+ SkPixmap(input_info, input_buffer, m_pBitmap->GetPitch()),
/*rasterReleaseProc=*/nullptr, /*releaseContext=*/nullptr);
- uint8_t* dstBuffer = pBitmap->GetWritableBuffer().data();
- DCHECK(dstBuffer);
+ SkImageInfo output_info = SkImageInfo::Make(
+ pBitmap->GetWidth(), pBitmap->GetHeight(),
+ Get32BitSkColorType(m_bRgbByteOrder), kPremul_SkAlphaType);
+ sk_sp<SkSurface> output =
+ SkSurfaces::WrapPixels(output_info, output_buffer, pBitmap->GetPitch());
- int dstWidth = pBitmap->GetWidth();
- int dstHeight = pBitmap->GetHeight();
- size_t dstRowBytes = pBitmap->GetPitch();
- SkImageInfo dstImageInfo = SkImageInfo::Make(
- dstWidth, dstHeight, Get32BitSkColorType(m_bRgbByteOrder),
- kPremul_SkAlphaType);
- SkBitmap skDstBitmap;
- skDstBitmap.installPixels(dstImageInfo, dstBuffer, dstRowBytes);
-
- SkCanvas canvas(skDstBitmap);
- canvas.drawImageRect(source, SkRect::MakeXYWH(left, top, dstWidth, dstHeight),
- SkSamplingOptions(), /*paint=*/nullptr);
+ output->getCanvas()->drawImage(input, left, top, SkSamplingOptions());
return true;
}