Enable RenderManyRectanglesWithExternalMemory for SkiaPaths/Skia.
Enables test RenderManyRectanglesWithExternalMemory for Skia and
SkiaPaths modes by fixing the following issues:
1. Skia and SkiaPaths only support color types that BPP (bit per pixel)
is 8 or 32. Skip the test for FPDFBitmap_BGR format, which has
BBP = 24.
2. Skia/SkiaPaths supports 2 SkColorTypes for bitmap with BPP = 8,
kAlpha_8_SkColorType and kGray_8_SkColorType. However, the rendering
process only uses kAlpha_8_SkColorType as the color type for all
BBP = 8 cases without checking whether the bitmap format is an alpha
type, which leads to the blank rendering result for format
FPDFBitmap_Gray. This CL adds the check for alpha type when choosing
SkColorTypes during rendering.
3. Skia/SkiaPaths uses a different algorithm to render gradient effect
compared to AGG. This CL adds the expected results for Skia and
SkiaPaths modes.
Bug: pdfium:1488
Change-Id: I88dbf139e2c6fe33bde83efa51f2665f8525f6d1
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/67050
Commit-Queue: Hui Yingst <nigi@chromium.org>
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index d5817a2..b209ba4 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -1613,11 +1613,20 @@
#endif // _SKIA_SUPPORT_PATHS_
m_bGroupKnockout(bGroupKnockout) {
SkBitmap skBitmap;
- ASSERT(pBitmap->GetBPP() == 8 || pBitmap->GetBPP() == 32);
- SkImageInfo imageInfo = SkImageInfo::Make(
- pBitmap->GetWidth(), pBitmap->GetHeight(),
- pBitmap->GetBPP() == 8 ? kAlpha_8_SkColorType : kN32_SkColorType,
- kOpaque_SkAlphaType);
+ SkColorType color_type;
+ const int bpp = pBitmap->GetBPP();
+ if (bpp == 8) {
+ color_type = GetIsAlphaFromFormat(pBitmap->GetFormat())
+ ? kAlpha_8_SkColorType
+ : kGray_8_SkColorType;
+ } else {
+ ASSERT(bpp == 32);
+ color_type = kN32_SkColorType;
+ }
+
+ SkImageInfo imageInfo =
+ SkImageInfo::Make(pBitmap->GetWidth(), pBitmap->GetHeight(), color_type,
+ kOpaque_SkAlphaType);
skBitmap.installPixels(imageInfo, pBitmap->GetBuffer(), pBitmap->GetPitch());
m_pCanvas = new SkCanvas(skBitmap);
}
diff --git a/fpdfsdk/fpdf_view_embeddertest.cpp b/fpdfsdk/fpdf_view_embeddertest.cpp
index 022b991..cbeeaf6 100644
--- a/fpdfsdk/fpdf_view_embeddertest.cpp
+++ b/fpdfsdk/fpdf_view_embeddertest.cpp
@@ -1095,27 +1095,28 @@
UnloadPage(page);
}
-// TODO(crbug.com/pdfium/1488): Fix this test and enable.
-#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
-#define MAYBE_RenderManyRectanglesWithExternalMemory \
- DISABLED_RenderManyRectanglesWithExternalMemory
-#else
-#define MAYBE_RenderManyRectanglesWithExternalMemory \
- RenderManyRectanglesWithExternalMemory
-#endif
-TEST_F(FPDFViewEmbedderTest, MAYBE_RenderManyRectanglesWithExternalMemory) {
- static const char kNormalMD5[] = "b0170c575b65ecb93ebafada0ff0f038";
- static const char kGrayMD5[] = "b561c11edc44dc3972125a9b8744fa2f";
- static const char kBgrMD5[] = "ab6312e04c0d3f4e46fb302a45173d05";
-
+TEST_F(FPDFViewEmbedderTest, RenderManyRectanglesWithExternalMemory) {
ASSERT_TRUE(OpenDocument("many_rectangles.pdf"));
FPDF_PAGE page = LoadPage(0);
ASSERT_TRUE(page);
- TestRenderPageBitmapWithExternalMemory(page, FPDFBitmap_Gray, kGrayMD5);
+#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
+ static const char kGrayMD5[] = "3dfe1fc3889123d68e1748fefac65e72";
+ static const char kNormalMD5[] = "4e7e280c1597222afcb0ee3bb90ec119";
+
+ // TODO(crbug.com/pdfium/1489): Add a test for FPDFBitmap_BGR in
+ // Skia/SkiaPaths modes once Skia provides support for BGR24 format.
+#else
+ static const char kGrayMD5[] = "b561c11edc44dc3972125a9b8744fa2f";
+ static const char kBgrMD5[] = "ab6312e04c0d3f4e46fb302a45173d05";
+ static const char kNormalMD5[] = "b0170c575b65ecb93ebafada0ff0f038";
+
TestRenderPageBitmapWithExternalMemory(page, FPDFBitmap_BGR, kBgrMD5);
+#endif
+ TestRenderPageBitmapWithExternalMemory(page, FPDFBitmap_Gray, kGrayMD5);
TestRenderPageBitmapWithExternalMemory(page, FPDFBitmap_BGRx, kNormalMD5);
TestRenderPageBitmapWithExternalMemory(page, FPDFBitmap_BGRA, kNormalMD5);
+
UnloadPage(page);
}