From 1e62a254e6a9ad8c6f18a8def3d104e0fe98a2e2 Mon Sep 17 00:00:00 2001 From: caryclark Date: Wed, 29 Jun 2016 12:10:50 -0700 Subject: fix skia unit tests Add checks to pass unit tests. R=thestig@chromium.org,dsinclair@chromium.org BUG=pdfium:525, pdfium:526, pdfium:527, pdfium:528, pdfium:529 Review-Url: https://codereview.chromium.org/2111553003 --- core/fxge/skia/fx_skia_device.cpp | 21 ++++++++++++++------- core/fxge/skia/fx_skia_device.h | 1 + core/fxge/skia/fx_skia_device_unittest.cpp | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) (limited to 'core/fxge/skia') diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp index c7f231a8ca..148f623124 100644 --- a/core/fxge/skia/fx_skia_device.cpp +++ b/core/fxge/skia/fx_skia_device.cpp @@ -626,7 +626,7 @@ class SkiaState { SkPaint skPaint; skPaint.setAntiAlias(true); skPaint.setColor(m_fillColor); - if (m_pFont->GetFace()) { // exclude placeholder test fonts + if (m_pFont->GetFace() && m_pCache) { // exclude placeholder test fonts sk_sp typeface(SkSafeRef(m_pCache->GetDeviceCache(m_pFont))); skPaint.setTypeface(typeface); } @@ -1005,7 +1005,8 @@ FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, font_size, color, this)) { return TRUE; } - sk_sp typeface(SkSafeRef(pCache->GetDeviceCache(pFont))); + sk_sp typeface( + SkSafeRef(pCache ? pCache->GetDeviceCache(pFont) : nullptr)); SkPaint paint; paint.setAntiAlias(true); paint.setColor(color); @@ -1443,6 +1444,8 @@ FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, pSource->IsAlphaMask() ? kPremul_SkAlphaType : kOpaque_SkAlphaType; SkColorTable* ct = nullptr; void* buffer = pSource->GetBuffer(); + if (!buffer) + return FALSE; std::unique_ptr dst8Storage; std::unique_ptr dst32Storage; int width = pSource->GetWidth(); @@ -1526,15 +1529,19 @@ FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) { } void CFX_SkiaDeviceDriver::PreMultiply() { - void* buffer = m_pBitmap->GetBuffer(); + PreMultiply(m_pBitmap); +} + +void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) { + void* buffer = pDIBitmap->GetBuffer(); if (!buffer) return; - if (m_pBitmap->GetBPP() != 32) { + if (pDIBitmap->GetBPP() != 32) { return; } - int height = m_pBitmap->GetHeight(); - int width = m_pBitmap->GetWidth(); - int rowBytes = m_pBitmap->GetPitch(); + int height = pDIBitmap->GetHeight(); + int width = pDIBitmap->GetWidth(); + int rowBytes = pDIBitmap->GetPitch(); SkImageInfo unpremultipliedInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kUnpremul_SkAlphaType); SkPixmap unpremultiplied(unpremultipliedInfo, buffer, rowBytes); diff --git a/core/fxge/skia/fx_skia_device.h b/core/fxge/skia/fx_skia_device.h index c21119b9a4..f7e5306ab5 100644 --- a/core/fxge/skia/fx_skia_device.h +++ b/core/fxge/skia/fx_skia_device.h @@ -126,6 +126,7 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver { void Flush(); SkPictureRecorder* GetRecorder() const { return m_pRecorder; } void PreMultiply(); + static void PreMultiply(CFX_DIBitmap* pDIBitmap); SkCanvas* SkiaCanvas() { return m_pCanvas; } void Dump() const; diff --git a/core/fxge/skia/fx_skia_device_unittest.cpp b/core/fxge/skia/fx_skia_device_unittest.cpp index eb7559b5e2..b2f7f6de5f 100644 --- a/core/fxge/skia/fx_skia_device_unittest.cpp +++ b/core/fxge/skia/fx_skia_device_unittest.cpp @@ -32,7 +32,7 @@ void EmptyTest(CFX_SkiaDeviceDriver* driver, const State&) { } void CommonTest(CFX_SkiaDeviceDriver* driver, const State& state) { - FXTEXT_CHARPOS charPos[] = {1, 0, 1, 4, false, {0, 0, 0, 0}, false}; + FXTEXT_CHARPOS charPos[] = {{1, 0, 1, 4, false, {0, 0, 0, 0}, false}}; CFX_Font font; FX_FLOAT fontSize = 1; CFX_FontCache cache; -- cgit v1.2.3