Update the CFX_FillRenderOptions used for flushing paths

Currently, CFX_SkiaDeviceDriver::PaintStroke() sets SkPaint based on
the most up-to-date CFX_FillRenderOptions `m_FillOptions`. But this
CFX_FillRenderOptions is not the same as the cached fill options
`m_fillOptions` in SkiaState when multiple paths with different
CFX_FillRenderOptions need drawing.

When CFX_SkiaDeviceDriver::PaintStroke() is called by
SkiaState::FlushPath(), it should set the SkPaint based on
`m_fillOptions` in the cached SkiaState, since FlushPath() is trying
to draw the already cached commands.

This CL makes the following improvements:
- Check if fill options have changed when determine when to flush
  cached paths.
- Make CFX_SkiaDeviceDriver::PaintStroke() take an
  CFX_FillRenderOptions as the input, so that the correct fill options
  can be used depending on the call site.

Change-Id: I120071431969d494afee7a0237d0b90273541527
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/103872
Commit-Queue: Nigi <nigi@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/cfx_fillrenderoptions.h b/core/fxge/cfx_fillrenderoptions.h
index 72aaf88..d123f72 100644
--- a/core/fxge/cfx_fillrenderoptions.h
+++ b/core/fxge/cfx_fillrenderoptions.h
@@ -46,6 +46,20 @@
         text_mode(false),
         zero_area(false) {}
 
+  bool operator==(const CFX_FillRenderOptions& other) const {
+    return fill_type == other.fill_type &&
+           adjust_stroke == other.adjust_stroke &&
+           aliased_path == other.aliased_path &&
+           full_cover == other.full_cover && rect_aa == other.rect_aa &&
+           stroke == other.stroke &&
+           stroke_text_mode == other.stroke_text_mode &&
+           text_mode == other.text_mode && zero_area == other.zero_area;
+  }
+
+  bool operator!=(const CFX_FillRenderOptions& other) const {
+    return !(*this == other);
+  }
+
   // Fill type.
   FillType fill_type;
 
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index c2da0aa..ea67f43 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -32,6 +32,7 @@
 #include "core/fxcrt/stl_util.h"
 #include "core/fxge/calculate_pitch.h"
 #include "core/fxge/cfx_defaultrenderdevice.h"
+#include "core/fxge/cfx_fillrenderoptions.h"
 #include "core/fxge/cfx_font.h"
 #include "core/fxge/cfx_graphstatedata.h"
 #include "core/fxge/cfx_path.h"
@@ -749,7 +750,7 @@
     if (Accumulator::kText == m_type || drawIndex != m_commandIndex ||
         (Accumulator::kPath == m_type &&
          DrawChanged(pMatrix, pDrawState, fill_color, stroke_color,
-                     fill_options.fill_type, blend_type,
+                     fill_options, blend_type,
                      m_pDriver->GetGroupKnockout()))) {
       Flush();
     }
@@ -786,7 +787,7 @@
       skPaint.setBlendMode(SkBlendMode::kPlus);
     int stroke_alpha = FXARGB_A(m_strokeColor);
     if (stroke_alpha)
-      m_pDriver->PaintStroke(&skPaint, &m_drawState, skMatrix);
+      m_pDriver->PaintStroke(&skPaint, &m_drawState, skMatrix, m_fillOptions);
     SkCanvas* skCanvas = m_pDriver->SkiaCanvas();
     SkAutoCanvasRestore scoped_save_restore(skCanvas, /*doSave=*/true);
     skCanvas->concat(skMatrix);
@@ -831,6 +832,7 @@
     m_drawIndex = std::numeric_limits<size_t>::max();
     m_type = Accumulator::kNone;
     m_drawMatrix = CFX_Matrix();
+    m_fillOptions = CFX_FillRenderOptions();
   }
 
   bool HasRSX(pdfium::span<const TextCharPos> char_pos,
@@ -1062,7 +1064,7 @@
     SkPath skPath = BuildPath(path);
     SkMatrix skMatrix = ToSkMatrix(*pMatrix);
     SkPaint skPaint;
-    m_pDriver->PaintStroke(&skPaint, pGraphState, skMatrix);
+    m_pDriver->PaintStroke(&skPaint, pGraphState, skMatrix, m_fillOptions);
     SkPath dst_path;
     skpathutils::FillPathWithPaint(skPath, skPaint, &dst_path);
     dst_path.transform(skMatrix);
@@ -1122,13 +1124,15 @@
                    const CFX_GraphStateData* pState,
                    uint32_t fill_color,
                    uint32_t stroke_color,
-                   CFX_FillRenderOptions::FillType fill_type,
+                   const CFX_FillRenderOptions& fill_options,
                    BlendMode blend_type,
                    bool group_knockout) const {
     return MatrixChanged(pMatrix) || StateChanged(pState, m_drawState) ||
            fill_color != m_fillColor || stroke_color != m_strokeColor ||
            IsEvenOddFillType(m_skPath.getFillType()) ||
-           fill_type == CFX_FillRenderOptions::FillType::kEvenOdd ||
+           fill_options != m_fillOptions ||
+           fill_options.fill_type ==
+               CFX_FillRenderOptions::FillType::kEvenOdd ||
            blend_type != m_blendType || group_knockout != m_groupKnockout;
   }
 
@@ -1284,9 +1288,11 @@
 };
 
 // convert a stroking path to scanlines
-void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint,
-                                       const CFX_GraphStateData* pGraphState,
-                                       const SkMatrix& matrix) {
+void CFX_SkiaDeviceDriver::PaintStroke(
+    SkPaint* spaint,
+    const CFX_GraphStateData* pGraphState,
+    const SkMatrix& matrix,
+    const CFX_FillRenderOptions& fill_options) {
   SkPaint::Cap cap;
   switch (pGraphState->m_LineCap) {
     case CFX_GraphStateData::LineCap::kRound:
@@ -1341,7 +1347,7 @@
         pGraphState->m_DashPhase));
   }
   spaint->setStyle(SkPaint::kStroke_Style);
-  spaint->setAntiAlias(!m_FillOptions.aliased_path);
+  spaint->setAntiAlias(!fill_options.aliased_path);
   spaint->setStrokeWidth(width);
   spaint->setStrokeMiter(pGraphState->m_MiterLimit);
   spaint->setStrokeCap(cap);
@@ -1671,7 +1677,7 @@
   SkPath skPath = BuildPath(path);
   SkMatrix skMatrix = ToSkMatrix(*pObject2Device);
   SkPaint skPaint;
-  PaintStroke(&skPaint, pGraphState, skMatrix);
+  PaintStroke(&skPaint, pGraphState, skMatrix, m_FillOptions);
   SkPath dst_path;
   skpathutils::FillPathWithPaint(skPath, skPaint, &dst_path);
   dst_path.transform(skMatrix);
diff --git a/core/fxge/skia/fx_skia_device.h b/core/fxge/skia/fx_skia_device.h
index 71109a7..8c99963 100644
--- a/core/fxge/skia/fx_skia_device.h
+++ b/core/fxge/skia/fx_skia_device.h
@@ -141,7 +141,8 @@
 
   void PaintStroke(SkPaint* spaint,
                    const CFX_GraphStateData* pGraphState,
-                   const SkMatrix& matrix);
+                   const SkMatrix& matrix,
+                   const CFX_FillRenderOptions& fill_options);
   void Clear(uint32_t color);
   void Flush() override;
   SkCanvas* SkiaCanvas() { return m_pCanvas; }