Mark some RenderDeviceDriver capabilities as Skia-only
Some RenderDeviceDriver capabilities are only supported by Skia. Mark
these capabilities, and associated code paths as conditional, so they
are only built when Skia is available at build time. This makes the code
for the 2 Skia-only capabilities more consistent.
Change-Id: Ie6efac0ae844c14b1d101a43e8a90b728723d819
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/122390
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@google.com>
diff --git a/core/fpdfapi/render/cpdf_rendershading.cpp b/core/fpdfapi/render/cpdf_rendershading.cpp
index aa99a09..f44b1b8 100644
--- a/core/fpdfapi/render/cpdf_rendershading.cpp
+++ b/core/fpdfapi/render/cpdf_rendershading.cpp
@@ -912,10 +912,12 @@
clip_rect_bbox.Intersect(
mtMatrix.TransformRect(pDict->GetRectFor("BBox")).GetOuterRect());
}
- if (pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SHADING &&
+#if defined(PDF_USE_SKIA)
+ if ((pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SHADING) &&
pDevice->DrawShading(*pPattern, mtMatrix, clip_rect_bbox, alpha)) {
return;
}
+#endif // defined(PDF_USE_SKIA)
CPDF_DeviceBuffer buffer(pContext, pDevice, clip_rect_bbox, pCurObj, 150);
RetainPtr<CFX_DIBitmap> pBitmap = buffer.Initialize();
if (!pBitmap) {
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index a8ae574..668fdac 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -700,25 +700,24 @@
}
if (fill && fill_alpha && stroke_alpha < 0xff && fill_options.stroke) {
- if (m_RenderCaps & FXRC_FILLSTROKE_PATH) {
#if defined(PDF_USE_SKIA)
- if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
+ if (m_RenderCaps & FXRC_FILLSTROKE_PATH) {
+ const bool using_skia = CFX_DefaultRenderDevice::UseSkiaRenderer();
+ if (using_skia) {
m_pDeviceDriver->SetGroupKnockout(true);
}
-#endif
bool draw_fillstroke_path_result = m_pDeviceDriver->DrawPath(
path, pObject2Device, pGraphState, fill_color, stroke_color,
fill_options, blend_type);
-#if defined(PDF_USE_SKIA)
- if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
+ if (using_skia) {
// Restore the group knockout status for `m_pDeviceDriver` after
// finishing painting a fill-and-stroke path.
m_pDeviceDriver->SetGroupKnockout(false);
}
-#endif
return draw_fillstroke_path_result;
}
+#endif // defined(PDF_USE_SKIA)
return DrawFillStrokePath(path, pObject2Device, pGraphState, fill_color,
stroke_color, fill_options, blend_type);
}
@@ -1011,6 +1010,13 @@
}
#if defined(PDF_USE_SKIA)
+bool CFX_RenderDevice::DrawShading(const CPDF_ShadingPattern& pattern,
+ const CFX_Matrix& matrix,
+ const FX_RECT& clip_rect,
+ int alpha) {
+ return m_pDeviceDriver->DrawShading(pattern, matrix, clip_rect, alpha);
+}
+
bool CFX_RenderDevice::SetBitsWithMask(RetainPtr<const CFX_DIBBase> bitmap,
RetainPtr<const CFX_DIBBase> mask,
int left,
@@ -1024,7 +1030,7 @@
bool CFX_RenderDevice::SyncInternalBitmaps() {
return m_pDeviceDriver->SyncInternalBitmaps();
}
-#endif
+#endif // defined(PDF_USE_SKIA)
bool CFX_RenderDevice::DrawNormalText(pdfium::span<const TextCharPos> pCharPos,
CFX_Font* pFont,
@@ -1336,13 +1342,6 @@
}
}
-bool CFX_RenderDevice::DrawShading(const CPDF_ShadingPattern& pattern,
- const CFX_Matrix& matrix,
- const FX_RECT& clip_rect,
- int alpha) {
- return m_pDeviceDriver->DrawShading(pattern, matrix, clip_rect, alpha);
-}
-
void CFX_RenderDevice::DrawBorder(const CFX_Matrix* pUser2Device,
const CFX_FloatRect& rect,
float fWidth,
diff --git a/core/fxge/cfx_renderdevice.h b/core/fxge/cfx_renderdevice.h
index 4970a7a..e1c3df4 100644
--- a/core/fxge/cfx_renderdevice.h
+++ b/core/fxge/cfx_renderdevice.h
@@ -194,16 +194,16 @@
int32_t nTransparency,
int32_t nStartGray,
int32_t nEndGray);
- bool DrawShading(const CPDF_ShadingPattern& pattern,
- const CFX_Matrix& matrix,
- const FX_RECT& clip_rect,
- int alpha);
// See RenderDeviceDriverIface methods of the same name.
bool MultiplyAlpha(float alpha);
bool MultiplyAlphaMask(RetainPtr<const CFX_DIBitmap> mask);
#if defined(PDF_USE_SKIA)
+ bool DrawShading(const CPDF_ShadingPattern& pattern,
+ const CFX_Matrix& matrix,
+ const FX_RECT& clip_rect,
+ int alpha);
bool SetBitsWithMask(RetainPtr<const CFX_DIBBase> bitmap,
RetainPtr<const CFX_DIBBase> mask,
int left,
@@ -211,7 +211,7 @@
float alpha,
BlendMode blend_type);
bool SyncInternalBitmaps();
-#endif
+#endif // defined(PDF_USE_SKIA)
protected:
CFX_RenderDevice();
diff --git a/core/fxge/render_defines.h b/core/fxge/render_defines.h
index 055bac3..23c32a0 100644
--- a/core/fxge/render_defines.h
+++ b/core/fxge/render_defines.h
@@ -22,7 +22,11 @@
#define FXRC_BLEND_MODE 0x80
#define FXRC_SOFT_CLIP 0x100
#define FXRC_BYTEMASK_OUTPUT 0x800
+// Assuming these are Skia-only for now. If this assumption changes, update both
+// the #if logic here, as well as the callsites that check these capabilities.
+#if defined(PDF_USE_SKIA)
#define FXRC_FILLSTROKE_PATH 0x2000
#define FXRC_SHADING 0x4000
+#endif
#endif // CORE_FXGE_RENDER_DEFINES_H_
diff --git a/core/fxge/renderdevicedriver_iface.cpp b/core/fxge/renderdevicedriver_iface.cpp
index 7367845..b637735 100644
--- a/core/fxge/renderdevicedriver_iface.cpp
+++ b/core/fxge/renderdevicedriver_iface.cpp
@@ -66,6 +66,7 @@
return 0;
}
+#if defined(PDF_USE_SKIA)
bool RenderDeviceDriverIface::DrawShading(const CPDF_ShadingPattern& pattern,
const CFX_Matrix& matrix,
const FX_RECT& clip_rect,
@@ -73,7 +74,6 @@
return false;
}
-#if defined(PDF_USE_SKIA)
bool RenderDeviceDriverIface::SetBitsWithMask(
RetainPtr<const CFX_DIBBase> bitmap,
RetainPtr<const CFX_DIBBase> mask,
@@ -89,7 +89,7 @@
bool RenderDeviceDriverIface::SyncInternalBitmaps() {
return true;
}
-#endif
+#endif // defined(PDF_USE_SKIA)
RenderDeviceDriverIface::StartResult::StartResult(
bool success,
diff --git a/core/fxge/renderdevicedriver_iface.h b/core/fxge/renderdevicedriver_iface.h
index f61558f..1e37a4c 100644
--- a/core/fxge/renderdevicedriver_iface.h
+++ b/core/fxge/renderdevicedriver_iface.h
@@ -111,11 +111,11 @@
uint32_t color,
const CFX_TextRenderOptions& options);
virtual int GetDriverType() const;
+#if defined(PDF_USE_SKIA)
virtual bool DrawShading(const CPDF_ShadingPattern& pattern,
const CFX_Matrix& matrix,
const FX_RECT& clip_rect,
int alpha);
-#if defined(PDF_USE_SKIA)
virtual bool SetBitsWithMask(RetainPtr<const CFX_DIBBase> bitmap,
RetainPtr<const CFX_DIBBase> mask,
int left,
@@ -128,7 +128,7 @@
// Syncs the current rendering result from the internal buffer to the output
// bitmap if such internal buffer exists.
virtual bool SyncInternalBitmaps();
-#endif
+#endif // defined(PDF_USE_SKIA)
// Multiplies the device by a constant alpha, returning `true` on success.
// Implementations CHECK the following conditions: