Skia: Call UnPreMultiply() in FPDF_RenderPage() Under certain conditions, FPDF_RenderPage() will render into a CPDF_WindowsRenderDevice directly. Otherwise, it renders into a bitmap first, and then render the bitmap into the CPDF_WindowsRenderDevice. In the latter case, when Skia is the default renderer, the bitmap needs to be un-premultiply before being passed to CPDF_WindowsRenderDevice. The bitmap also does not need to be cleared, like with AGG. Skia renders just fine into the newly created bitmap. Unsuppress several pixel and corpus tests that are rendering better as a result of this change. The new expectation files are using the updated file name scheme from https://pdfium-review.googlesource.com/112092, so update the presubmit to allow these new names. Using test expectation update by rolling DEPS for testing/corpus: https://pdfium.googlesource.com/pdfium_tests/+log/dc2cd9afdd1b..dcc9273d7f2a Bug: pdfium:2080 Change-Id: Icb04c4c7e06b5d44a9007305e73c9ab2f9096573 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/112091 Reviewed-by: Nigi <nigi@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/DEPS b/DEPS index 915a907..dd86fef 100644 --- a/DEPS +++ b/DEPS
@@ -156,7 +156,7 @@ # Three lines of non-changing comments so that # the commit queue can handle CLs rolling pdfium_tests # and whatever else without interference from each other. - 'pdfium_tests_revision': 'dc2cd9afdd1bad8666072416c340ad1c6a01e388', + 'pdfium_tests_revision': 'dcc9273d7f2a39e91472f942344c41897cdaff8a', # Three lines of non-changing comments so that # the commit queue can handle CLs rolling resultdb # and whatever else without interference from each other.
diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 14c0506..3d5a231 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py
@@ -428,12 +428,12 @@ """Checks that .png files have the right file name format, which must be in the form: - NAME_expected(_(agg|gdi|skia))?(_(linux|mac|win))?.pdf.\d+.png + NAME_expected(_gdi)?(_(agg|skia))?(_(linux|mac|win))?.pdf.\d+.png This must be the same format as the one in testing/corpus's PRESUBMIT.py. """ expected_pattern = input_api.re.compile( - r'.+_expected(_(agg|gdi|skia))?(_(linux|mac|win))?\.pdf\.\d+.png') + r'.+_expected(_gdi)?(_(agg|skia))?(_(linux|mac|win))?\.pdf\.\d+.png') results = [] for f in input_api.AffectedFiles(include_deletes=False): if not f.LocalPath().endswith('.png'):
diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py index c5f9650..ee2c355 100755 --- a/PRESUBMIT_test.py +++ b/PRESUBMIT_test.py
@@ -59,6 +59,12 @@ 'test_expected_agg_linux.pdf.3.png', 'test_expected_skia.pdf.2.png', 'test_expected_skia_mac.pdf.4.png', + 'test_expected_gdi_agg.pdf.3.png', + 'test_expected_gdi_agg_win.pdf.4.png', + 'test_expected_gdi_skia.pdf.10.png', + 'test_expected_gdi_skia_linux.pdf.5.png', + 'test_expected_gdi.pdf.99.png', + 'test_expected_gdi_mac.pdf.0.png', 'notpng.cc', # Check will be skipped for non-PNG files ] wrong_paths = [ @@ -66,9 +72,13 @@ 'test1_expected.0.png', # Missing '.pdf' 'test2_expected.pdf.png', # Missing page number 'test3_expected.pdf.x.png', # Wrong character for page number + 'test4_expected_agg_gdi.pdf.0.png', # Wrong order of keywords 'test4_expected_linux_agg.pdf.0.png', # Wrong order of keywords 'test4_expected_mac_skia.pdf.0.png', # Wrong order of keywords + 'test4_expected_skia_gdi.pdf.0.png', # Wrong order of keywords 'test5_expected_useskia.pdf.0.png', # Wrong keyword + 'test6_expected_win_mac.pdf.0.png', # Too many platforms + 'test7_expected_agg_skia.pdf.0.png', # Too many renderers ] mock_input_api = MockInputApi() mock_output_api = MockOutputApi()
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp index 9e7228f..958d361 100644 --- a/fpdfsdk/fpdf_view.cpp +++ b/fpdfsdk/fpdf_view.cpp
@@ -583,7 +583,11 @@ // Create will probably work fine even if it fails here: we will just attach // a zero-sized bitmap to `device`. pBitmap->Create(size_x, size_y, FXDIB_Format::kArgb); - pBitmap->Clear(0x00ffffff); + if (!CFX_DefaultRenderDevice::SkiaIsDefaultRenderer()) { + // Not needed by Skia. Call it for AGG to preserve pre-existing behavior. + pBitmap->Clear(0x00ffffff); + } + auto device = std::make_unique<CFX_DefaultRenderDevice>(); device->Attach(pBitmap); context->m_pDevice = std::move(device); @@ -597,6 +601,12 @@ /*need_to_restore=*/true, /*pause=*/nullptr); +#if defined(_SKIA_SUPPORT_) + if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer()) { + pBitmap->UnPreMultiply(); + } +#endif + if (!bHasMask) { CPDF_WindowsRenderDevice win_dc(dc, render_data->GetPSFontTracker()); bool bitsStretched = false;
diff --git a/testing/SUPPRESSIONS b/testing/SUPPRESSIONS index 90dd254..fee3524 100644 --- a/testing/SUPPRESSIONS +++ b/testing/SUPPRESSIONS
@@ -536,14 +536,12 @@ widget_javascript.pdf * * * gdi # TODO(pdfium:2056): Remove after associated bug is fixed -11.pdf * * * gdi 1_10_watermark.pdf * * * gdi 1_matrix.pdf * * * gdi 2_color_tiling.pdf * * * gdi 2_shading_type_6_00.pdf * * * gdi 2_shading_type_6_001.pdf * * * gdi 2_uncolor_tiling.pdf * * * gdi -3_image_imagemask.pdf * * * gdi FRC_11_8.2.4_View_edit.pdf * * * gdi FRC_12_8.2.4_View_remove_all.pdf * * * gdi FRC_13_8.2.4_View_remove_value.pdf * * * gdi @@ -595,7 +593,6 @@ path_7.pdf * * * gdi path_9.pdf * * * gdi transformation.pdf * * * gdi -transparent.pdf * * * gdi transparent1.pdf * * * gdi xfermodes.pdf * * * gdi xfermodes2.pdf * * * gdi @@ -756,7 +753,6 @@ bug_1822.in * * * gdi bug_1847.in * * * gdi bug_1949.in * * * gdi -bug_1966.in * * * gdi bug_1972_1.in * * * gdi bug_1972_3.in * * * gdi bug_1995.in * * * gdi
diff --git a/testing/resources/pixel/bug_1966_expected_gdi_skia.pdf.0.png b/testing/resources/pixel/bug_1966_expected_gdi_skia.pdf.0.png new file mode 100644 index 0000000..134ca64 --- /dev/null +++ b/testing/resources/pixel/bug_1966_expected_gdi_skia.pdf.0.png Binary files differ