Make Skia and SkiaPaths take fill option |aliased_path| into account.
In CFX_FillOptions, flag |aliased_path| indicates whether to disable
anti-aliasing for drawing paths. To enable Skia and SkiaPaths to both
take this flag into account, this CL makes the following changes:
1. In CFX_SkiaDeviceDriver, make |m_FillOptions| available for both Skia
and SkiaPaths, and set SkPaint's anti-aliasing status according to
|m_FillOptions.aliased_path|.
2. With path anti-aliasing disabled, it's easier to tell Skia shows
improvement when rendering many_rectangles.pdf. Therefore, add the
Skia expected results for test
FPDFViewEmbedderTest.RenderManyRectanglesWithFlags and enable it for
Skia and SkiaPaths.
Bug: pdfium:1565
Change-Id: Iad7384a3ae8fa96e10650fc15549fcfec7415104
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/71632
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Hui Yingst <nigi@chromium.org>
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index ef24f78..d780302 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -602,11 +602,12 @@
}
void SetBitmapPaint(bool isAlphaMask,
+ bool anti_alias,
uint32_t argb,
int bitmap_alpha,
BlendMode blend_type,
SkPaint* paint) {
- paint->setAntiAlias(true);
+ paint->setAntiAlias(anti_alias);
if (isAlphaMask)
paint->setColorFilter(SkColorFilters::Blend(argb, SkBlendMode::kSrc));
@@ -750,7 +751,7 @@
}
if (Accumulator::kPath != m_type) {
m_skPath.reset();
- m_fillFullCover = fill_options.full_cover;
+ m_fillOptions = fill_options;
m_fillPath =
fill_options.fill_type != CFX_FillRenderOptions::FillType::kNoFill &&
fill_color;
@@ -778,8 +779,8 @@
Dump(__func__);
SkMatrix skMatrix = ToSkMatrix(m_drawMatrix);
SkPaint skPaint;
- skPaint.setAntiAlias(true);
- if (m_fillFullCover)
+ skPaint.setAntiAlias(!m_fillOptions.aliased_path);
+ if (m_fillOptions.full_cover)
skPaint.setBlendMode(SkBlendMode::kPlus);
int stroke_alpha = FXARGB_A(m_strokeColor);
if (stroke_alpha)
@@ -1508,6 +1509,7 @@
CFX_GraphStateData m_clipState;
CFX_GraphStateData m_drawState;
CFX_Matrix m_clipMatrix;
+ CFX_FillRenderOptions m_fillOptions;
UnownedPtr<CFX_SkiaDeviceDriver> const m_pDriver;
sk_sp<CFX_TypeFace> m_pTypeFace;
float m_fontSize = 0;
@@ -1520,7 +1522,6 @@
int m_clipIndex = 0; // position reflecting depth of canvas clip stacck
int m_italicAngle = 0;
Accumulator m_type = Accumulator::kNone; // type of pending draw
- bool m_fillFullCover = false;
bool m_fillPath = false;
bool m_groupKnockout = false;
bool m_isSubstFontBold = false;
@@ -1593,7 +1594,7 @@
intervals.data(), intervals.size(), pGraphState->m_DashPhase));
}
spaint->setStyle(SkPaint::kStroke_Style);
- spaint->setAntiAlias(true);
+ spaint->setAntiAlias(!m_FillOptions.aliased_path);
spaint->setStrokeWidth(width);
spaint->setStrokeMiter(pGraphState->m_MiterLimit);
spaint->setStrokeCap(cap);
@@ -1952,12 +1953,11 @@
const CFX_PathData* pPathData, // path info
const CFX_Matrix* pObject2Device, // flips object's y-axis
const CFX_FillRenderOptions& fill_options) {
+ m_FillOptions = fill_options;
CFX_Matrix identity;
const CFX_Matrix* deviceMatrix = pObject2Device ? pObject2Device : &identity;
bool cached = m_pCache->SetClipFill(pPathData, deviceMatrix, fill_options);
-
#ifdef _SKIA_SUPPORT_PATHS_
- m_FillOptions = fill_options;
if (!m_pClipRgn) {
m_pClipRgn = std::make_unique<CFX_ClipRgn>(
GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT));
@@ -2047,6 +2047,7 @@
uint32_t stroke_color, // stroke color
const CFX_FillRenderOptions& fill_options,
BlendMode blend_type) {
+ m_FillOptions = fill_options;
if (m_pCache->DrawPath(pPathData, pObject2Device, pGraphState, fill_color,
stroke_color, fill_options, blend_type)) {
return true;
@@ -2057,7 +2058,7 @@
else
skMatrix.setIdentity();
SkPaint skPaint;
- skPaint.setAntiAlias(true);
+ skPaint.setAntiAlias(!fill_options.aliased_path);
if (fill_options.full_cover)
skPaint.setBlendMode(SkBlendMode::kPlus);
int stroke_alpha = FXARGB_A(stroke_color);
@@ -2508,8 +2509,8 @@
SetBitmapMatrix(matrix, width, height, &skMatrix);
m_pCanvas->concat(skMatrix);
SkPaint paint;
- SetBitmapPaint(pSource->IsAlphaMask(), argb, bitmap_alpha, blend_type,
- &paint);
+ SetBitmapPaint(pSource->IsAlphaMask(), !m_FillOptions.aliased_path, argb,
+ bitmap_alpha, blend_type, &paint);
// TODO(caryclark) Once Skia supports 8 bit src to 8 bit dst remove this
if (m_pBitmap && m_pBitmap->GetBPP() == 8 && pSource->GetBPP() == 8) {
SkMatrix inv;
@@ -2642,8 +2643,8 @@
SetBitmapMatrix(matrix, srcWidth, srcHeight, &skMatrix);
m_pCanvas->concat(skMatrix);
SkPaint paint;
- SetBitmapPaint(pSource->IsAlphaMask(), 0xFFFFFFFF, bitmap_alpha, blend_type,
- &paint);
+ SetBitmapPaint(pSource->IsAlphaMask(), !m_FillOptions.aliased_path,
+ 0xFFFFFFFF, bitmap_alpha, blend_type, &paint);
sk_sp<SkImage> skSrc = SkImage::MakeFromBitmap(skBitmap);
sk_sp<SkShader> skSrcShader =
skSrc->makeShader(SkTileMode::kClamp, SkTileMode::kClamp);
diff --git a/core/fxge/skia/fx_skia_device.h b/core/fxge/skia/fx_skia_device.h
index 06ffada..f43038d 100644
--- a/core/fxge/skia/fx_skia_device.h
+++ b/core/fxge/skia/fx_skia_device.h
@@ -180,8 +180,8 @@
#ifdef _SKIA_SUPPORT_PATHS_
std::unique_ptr<CFX_ClipRgn> m_pClipRgn;
std::vector<std::unique_ptr<CFX_ClipRgn>> m_StateStack;
- CFX_FillRenderOptions m_FillOptions;
#endif
+ CFX_FillRenderOptions m_FillOptions;
bool m_bRgbByteOrder;
bool m_bGroupKnockout;
};
diff --git a/fpdfsdk/fpdf_view_embeddertest.cpp b/fpdfsdk/fpdf_view_embeddertest.cpp
index ec969e8..4abe282 100644
--- a/fpdfsdk/fpdf_view_embeddertest.cpp
+++ b/fpdfsdk/fpdf_view_embeddertest.cpp
@@ -1162,16 +1162,14 @@
UnloadPage(page);
}
-// TODO(crbug.com/pdfium/11): Fix this test and enable.
+TEST_F(FPDFViewEmbedderTest, RenderManyRectanglesWithFlags) {
#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
-#define MAYBE_RenderManyRectanglesWithFlags \
- DISABLED_RenderManyRectanglesWithFlags
+ static const char kGrayscaleMD5[] = "b596ac8bbe64e7bff31888ab05e4dcf4";
+ static const char kNoSmoothpathMD5[] = "4d71ed53d9f6e6a761876ebb4ff23e19";
#else
-#define MAYBE_RenderManyRectanglesWithFlags RenderManyRectanglesWithFlags
-#endif
-TEST_F(FPDFViewEmbedderTest, MAYBE_RenderManyRectanglesWithFlags) {
static const char kGrayscaleMD5[] = "7b553f1052069a9c61237a05db0955d6";
static const char kNoSmoothpathMD5[] = "ff6e5c509d1f6984bcdfd18b26a4203a";
+#endif
ASSERT_TRUE(OpenDocument("many_rectangles.pdf"));
FPDF_PAGE page = LoadPage(0);