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
diff --git a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp
index 272c779..10fd5f3 100644
--- a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp
+++ b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp
@@ -27,6 +27,10 @@
 #include "core/fxcrt/include/fx_safe_types.h"
 #include "core/fxge/include/fx_ge.h"
 
+#ifdef _SKIA_SUPPORT_
+#include "core/fxge/skia/fx_skia_device.h"
+#endif
+
 FX_BOOL CPDF_RenderStatus::ProcessImage(const CPDF_ImageObject* pImageObj,
                                         const CFX_Matrix* pObj2Device) {
   CPDF_ImageRenderer render;
@@ -58,6 +62,10 @@
         pDIBitmap->MultiplyAlpha(bitmap_alpha);
 #endif
       }
+#ifdef _SKIA_SUPPORT_
+      static_cast<CFX_SkiaDeviceDriver*>(m_pDevice->GetDeviceDriver())
+          ->PreMultiply(pDIBitmap);
+#endif
       if (m_pDevice->SetDIBits(pDIBitmap, left, top)) {
         return;
       }
@@ -920,7 +928,7 @@
   int width = pClipRect->right - pClipRect->left;
   int height = pClipRect->bottom - pClipRect->top;
   FXDIB_Format format;
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || defined _SKIA_SUPPORT_
   format = bLuminosity ? FXDIB_Rgb32 : FXDIB_8bppMask;
 #else
   format = bLuminosity ? FXDIB_Rgb : FXDIB_8bppMask;
diff --git a/core/fpdfapi/fpdf_render/fpdf_render_loadimage_embeddertest.cpp b/core/fpdfapi/fpdf_render/fpdf_render_loadimage_embeddertest.cpp
index bbaf7b3..5c6a8c5 100644
--- a/core/fpdfapi/fpdf_render/fpdf_render_loadimage_embeddertest.cpp
+++ b/core/fpdfapi/fpdf_render/fpdf_render_loadimage_embeddertest.cpp
@@ -7,12 +7,7 @@
 
 class FPDFRenderLoadImageEmbeddertest : public EmbedderTest {};
 
-#if defined(_SKIA_SUPPORT_)
-#define MAYBE_Bug_554151 DISABLED_Bug_554151
-#else
-#define MAYBE_Bug_554151 Bug_554151
-#endif
-TEST_F(FPDFRenderLoadImageEmbeddertest, MAYBE_Bug_554151) {
+TEST_F(FPDFRenderLoadImageEmbeddertest, Bug_554151) {
   // Test scanline downsampling with a BitsPerComponent of 4.
   // Should not crash.
   EXPECT_TRUE(OpenDocument("bug_554151.pdf"));
diff --git a/core/fpdfapi/fpdf_render/fpdf_render_pattern_embeddertest.cpp b/core/fpdfapi/fpdf_render/fpdf_render_pattern_embeddertest.cpp
index 48fe352..176c923 100644
--- a/core/fpdfapi/fpdf_render/fpdf_render_pattern_embeddertest.cpp
+++ b/core/fpdfapi/fpdf_render/fpdf_render_pattern_embeddertest.cpp
@@ -7,12 +7,7 @@
 
 class FPDFRenderPatternEmbeddertest : public EmbedderTest {};
 
-#if defined(_SKIA_SUPPORT_)
-#define MAYBE_LoadError_547706 DISABLED_LoadError_547706
-#else
-#define MAYBE_LoadError_547706 LoadError_547706
-#endif
-TEST_F(FPDFRenderPatternEmbeddertest, MAYBE_LoadError_547706) {
+TEST_F(FPDFRenderPatternEmbeddertest, LoadError_547706) {
   // Test shading where object is a dictionary instead of a stream.
   EXPECT_TRUE(OpenDocument("bug_547706.pdf"));
   FPDF_PAGE page = LoadPage(0);
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index c7f231a..148f623 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -626,7 +626,7 @@
     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<SkTypeface> typeface(SkSafeRef(m_pCache->GetDeviceCache(m_pFont)));
       skPaint.setTypeface(typeface);
     }
@@ -1005,7 +1005,8 @@
                          font_size, color, this)) {
     return TRUE;
   }
-  sk_sp<SkTypeface> typeface(SkSafeRef(pCache->GetDeviceCache(pFont)));
+  sk_sp<SkTypeface> typeface(
+      SkSafeRef(pCache ? pCache->GetDeviceCache(pFont) : nullptr));
   SkPaint paint;
   paint.setAntiAlias(true);
   paint.setColor(color);
@@ -1443,6 +1444,8 @@
       pSource->IsAlphaMask() ? kPremul_SkAlphaType : kOpaque_SkAlphaType;
   SkColorTable* ct = nullptr;
   void* buffer = pSource->GetBuffer();
+  if (!buffer)
+    return FALSE;
   std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage;
   std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage;
   int width = pSource->GetWidth();
@@ -1526,15 +1529,19 @@
 }
 
 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 c21119b..f7e5306 100644
--- a/core/fxge/skia/fx_skia_device.h
+++ b/core/fxge/skia/fx_skia_device.h
@@ -126,6 +126,7 @@
   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 eb7559b..b2f7f6d 100644
--- a/core/fxge/skia/fx_skia_device_unittest.cpp
+++ b/core/fxge/skia/fx_skia_device_unittest.cpp
@@ -32,7 +32,7 @@
 }
 
 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;