[Skia] Partially fix FPDFAnnotEmbedderTest.AddAndModifyImage
Make sure to finish painting the background bitmap before applying
the mask layer. This fixes an issue in
FPDFAnnotEmbedderTest.AddAndModifyImage that the dot annotation was
not supposed to be rendered on top of the newly added masked image.
This change appears to fix the issue that only half of the masked
image was rendered by Skia when cache painting is enabled (the
default behavior), which allows us to enable this test. However, the
non-cache painting result still remains unfixed. Therefore, update the
TODO comment to address this remaining issue.
Bug: pdfium:1500,pdfium:1541
Change-Id: Id965812acd31224f7fc650194aa2a33d249294f3
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/95430
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Nigi <nigi@chromium.org>
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index 4bb1fef..3d5cfbc 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -2824,9 +2824,12 @@
BlendMode blend_type) {
CFX_SkiaDeviceDriver* skDriver =
static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver());
- if (skDriver)
+ if (skDriver) {
+ // Finish painting before drawing masks.
+ Flush(false);
return skDriver->SetBitsWithMask(pBitmap, pMask, left, top, bitmap_alpha,
blend_type);
+ }
return false;
}
#endif // defined(_SKIA_SUPPORT_)
diff --git a/fpdfsdk/fpdf_annot_embeddertest.cpp b/fpdfsdk/fpdf_annot_embeddertest.cpp
index 6e8c157..5646d42 100644
--- a/fpdfsdk/fpdf_annot_embeddertest.cpp
+++ b/fpdfsdk/fpdf_annot_embeddertest.cpp
@@ -1305,14 +1305,15 @@
UnloadPage(page);
}
-// TODO(crbug.com/pdfium/1541): Fix this test and enable.
+// TODO(crbug.com/pdfium/1541): When Skia is enabled and its cache rendering is
+// disabled (To turn off cache, set `m_debugDisable` to true in
+// core/fxge/skia/fx_skia_device.cpp.), `kMd5NewImage`'s rendering result is
+// incorrect compared to the expectation.
+TEST_F(FPDFAnnotEmbedderTest, AddAndModifyImage) {
#if defined(_SKIA_SUPPORT_)
-#define MAYBE_AddAndModifyImage DISABLED_AddAndModifyImage
-#else
-#define MAYBE_AddAndModifyImage AddAndModifyImage
-#endif
-TEST_F(FPDFAnnotEmbedderTest, MAYBE_AddAndModifyImage) {
-#if defined(_SKIA_SUPPORT_PATHS_)
+ static const char kMd5NewImage[] = "4ba31e174d873b3fda1d7a160d4a0e85";
+ static const char kMd5ModifiedImage[] = "5806fadc1a192bc4bb07511a0711c957";
+#elif defined(_SKIA_SUPPORT_PATHS_)
static const char kMd5NewImage[] = "bf158b64c0373f3f36e347ae83e55cde";
static const char kMd5ModifiedImage[] = "5806fadc1a192bc4bb07511a0711c957";
#else
@@ -1322,8 +1323,8 @@
#else
static const char kMd5NewImage[] = "62c2706511cb50e32e7caeb82b1d3d49";
static const char kMd5ModifiedImage[] = "83093ce9fac746db69fbd2fb394434ac";
-#endif
-#endif // defined(_SKIA_SUPPORT_PATHS_)
+#endif // BUILDFLAG(IS_APPLE)
+#endif // defined(_SKIA_SUPPORT_)
// Open a file with two annotations and load its first page.
ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));