Clean up RenderDeviceDriverIface::DrawShading()

- Make always non-null pointer parameters references instead.
- Remove unused parameter.
- Fix some variable names in the only actual implementation.

Change-Id: I5d102515e8beb33a33ec4bcf30aa54afc31c133c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/122370
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Tom Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_rendershading.cpp b/core/fpdfapi/render/cpdf_rendershading.cpp
index b742215..aa99a09 100644
--- a/core/fpdfapi/render/cpdf_rendershading.cpp
+++ b/core/fpdfapi/render/cpdf_rendershading.cpp
@@ -912,10 +912,8 @@
     clip_rect_bbox.Intersect(
         mtMatrix.TransformRect(pDict->GetRectFor("BBox")).GetOuterRect());
   }
-  bool bAlphaMode = options.ColorModeIs(CPDF_RenderOptions::kAlpha);
   if (pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SHADING &&
-      pDevice->DrawShading(pPattern, &mtMatrix, clip_rect_bbox, alpha,
-                           bAlphaMode)) {
+      pDevice->DrawShading(*pPattern, mtMatrix, clip_rect_bbox, alpha)) {
     return;
   }
   CPDF_DeviceBuffer buffer(pContext, pDevice, clip_rect_bbox, pCurObj, 150);
@@ -981,12 +979,12 @@
       break;
     }
   }
-  if (bAlphaMode) {
-    pBitmap->SetRedFromAlpha();
-  }
 
-  if (options.ColorModeIs(CPDF_RenderOptions::kGray))
+  if (options.ColorModeIs(CPDF_RenderOptions::kAlpha)) {
+    pBitmap->SetRedFromAlpha();
+  } else if (options.ColorModeIs(CPDF_RenderOptions::kGray)) {
     pBitmap->ConvertColorScale(0, 0xffffff);
+  }
 
   buffer.OutputToDevice();
 }
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index f9cb32c..a8ae574 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -1336,13 +1336,11 @@
   }
 }
 
-bool CFX_RenderDevice::DrawShading(const CPDF_ShadingPattern* pPattern,
-                                   const CFX_Matrix* pMatrix,
+bool CFX_RenderDevice::DrawShading(const CPDF_ShadingPattern& pattern,
+                                   const CFX_Matrix& matrix,
                                    const FX_RECT& clip_rect,
-                                   int alpha,
-                                   bool bAlphaMode) {
-  return m_pDeviceDriver->DrawShading(pPattern, pMatrix, clip_rect, alpha,
-                                      bAlphaMode);
+                                   int alpha) {
+  return m_pDeviceDriver->DrawShading(pattern, matrix, clip_rect, alpha);
 }
 
 void CFX_RenderDevice::DrawBorder(const CFX_Matrix* pUser2Device,
diff --git a/core/fxge/cfx_renderdevice.h b/core/fxge/cfx_renderdevice.h
index 2381b8a..4970a7a 100644
--- a/core/fxge/cfx_renderdevice.h
+++ b/core/fxge/cfx_renderdevice.h
@@ -194,11 +194,10 @@
                   int32_t nTransparency,
                   int32_t nStartGray,
                   int32_t nEndGray);
-  bool DrawShading(const CPDF_ShadingPattern* pPattern,
-                   const CFX_Matrix* pMatrix,
+  bool DrawShading(const CPDF_ShadingPattern& pattern,
+                   const CFX_Matrix& matrix,
                    const FX_RECT& clip_rect,
-                   int alpha,
-                   bool bAlphaMode);
+                   int alpha);
 
   // See RenderDeviceDriverIface methods of the same name.
   bool MultiplyAlpha(float alpha);
diff --git a/core/fxge/renderdevicedriver_iface.cpp b/core/fxge/renderdevicedriver_iface.cpp
index 1809898..7367845 100644
--- a/core/fxge/renderdevicedriver_iface.cpp
+++ b/core/fxge/renderdevicedriver_iface.cpp
@@ -66,11 +66,10 @@
   return 0;
 }
 
-bool RenderDeviceDriverIface::DrawShading(const CPDF_ShadingPattern* pPattern,
-                                          const CFX_Matrix* pMatrix,
+bool RenderDeviceDriverIface::DrawShading(const CPDF_ShadingPattern& pattern,
+                                          const CFX_Matrix& matrix,
                                           const FX_RECT& clip_rect,
-                                          int alpha,
-                                          bool bAlphaMode) {
+                                          int alpha) {
   return false;
 }
 
diff --git a/core/fxge/renderdevicedriver_iface.h b/core/fxge/renderdevicedriver_iface.h
index 9294cec..f61558f 100644
--- a/core/fxge/renderdevicedriver_iface.h
+++ b/core/fxge/renderdevicedriver_iface.h
@@ -111,11 +111,10 @@
                               uint32_t color,
                               const CFX_TextRenderOptions& options);
   virtual int GetDriverType() const;
-  virtual bool DrawShading(const CPDF_ShadingPattern* pPattern,
-                           const CFX_Matrix* pMatrix,
+  virtual bool DrawShading(const CPDF_ShadingPattern& pattern,
+                           const CFX_Matrix& matrix,
                            const FX_RECT& clip_rect,
-                           int alpha,
-                           bool bAlphaMode);
+                           int alpha);
 #if defined(PDF_USE_SKIA)
   virtual bool SetBitsWithMask(RetainPtr<const CFX_DIBBase> bitmap,
                                RetainPtr<const CFX_DIBBase> mask,
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index 2cc5dc2..d9a2379 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -1167,32 +1167,32 @@
   return true;
 }
 
-bool CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern,
-                                       const CFX_Matrix* pMatrix,
+bool CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern& pattern,
+                                       const CFX_Matrix& matrix,
                                        const FX_RECT& clip_rect,
-                                       int alpha,
-                                       bool bAlphaMode) {
-  ShadingType shadingType = pPattern->GetShadingType();
-  if (kAxialShading != shadingType && kRadialShading != shadingType &&
-      kCoonsPatchMeshShading != shadingType) {
+                                       int alpha) {
+  const ShadingType shading_type = pattern.GetShadingType();
+  if (shading_type != kAxialShading && shading_type != kRadialShading &&
+      shading_type != kCoonsPatchMeshShading) {
     // TODO(caryclark) more types
     return false;
   }
-  CPDF_ColorSpace::Family csFamily = pPattern->GetCS()->GetFamily();
-  if (CPDF_ColorSpace::Family::kDeviceRGB != csFamily &&
-      CPDF_ColorSpace::Family::kDeviceGray != csFamily) {
+  CPDF_ColorSpace::Family cs_family = pattern.GetCS()->GetFamily();
+  if (CPDF_ColorSpace::Family::kDeviceRGB != cs_family &&
+      CPDF_ColorSpace::Family::kDeviceGray != cs_family) {
     return false;
   }
   const std::vector<std::unique_ptr<CPDF_Function>>& pFuncs =
-      pPattern->GetFuncs();
+      pattern.GetFuncs();
   size_t nFuncs = pFuncs.size();
   if (nFuncs > 1)  // TODO(caryclark) remove this restriction
     return false;
   RetainPtr<const CPDF_Dictionary> pDict =
-      pPattern->GetShadingObject()->GetDict();
+      pattern.GetShadingObject()->GetDict();
   RetainPtr<const CPDF_Array> pCoords = pDict->GetArrayFor("Coords");
-  if (!pCoords && kCoonsPatchMeshShading != shadingType)
+  if (!pCoords && shading_type != kCoonsPatchMeshShading) {
     return false;
+  }
   // TODO(caryclark) Respect Domain[0], Domain[1]. (Don't know what they do
   // yet.)
   DataVector<SkColor> sk_colors;
@@ -1229,12 +1229,12 @@
   SkPaint paint;
   paint.setAntiAlias(true);
   paint.setAlpha(alpha);
-  SkMatrix skMatrix = ToSkMatrix(*pMatrix);
+  SkMatrix skMatrix = ToSkMatrix(matrix);
   SkRect skRect = SkRect::MakeLTRB(clip_rect.left, clip_rect.top,
                                    clip_rect.right, clip_rect.bottom);
   SkPath skClip;
   SkPath skPath;
-  if (kAxialShading == shadingType) {
+  if (shading_type == kAxialShading) {
     float start_x = pCoords->GetFloatAt(0);
     float start_y = pCoords->GetFloatAt(1);
     float end_x = pCoords->GetFloatAt(2);
@@ -1274,7 +1274,7 @@
     }
     skPath.addRect(skRect);
     skMatrix.setIdentity();
-  } else if (kRadialShading == shadingType) {
+  } else if (shading_type == kRadialShading) {
     float start_x = pCoords->GetFloatAt(0);
     float start_y = pCoords->GetFloatAt(1);
     float start_r = pCoords->GetFloatAt(2);
@@ -1301,13 +1301,12 @@
     skPath.addRect(skRect);
     skPath.transform(inverse);
   } else {
-    DCHECK_EQ(kCoonsPatchMeshShading, shadingType);
-    RetainPtr<const CPDF_Stream> pStream =
-        ToStream(pPattern->GetShadingObject());
+    CHECK_EQ(kCoonsPatchMeshShading, shading_type);
+    RetainPtr<const CPDF_Stream> pStream = ToStream(pattern.GetShadingObject());
     if (!pStream)
       return false;
-    CPDF_MeshStream stream(shadingType, pPattern->GetFuncs(),
-                           std::move(pStream), pPattern->GetCS());
+    CPDF_MeshStream stream(shading_type, pattern.GetFuncs(), std::move(pStream),
+                           pattern.GetCS());
     if (!stream.Load())
       return false;
     SkPoint cubics[12];
diff --git a/core/fxge/skia/fx_skia_device.h b/core/fxge/skia/fx_skia_device.h
index 06a2d02..1435de1 100644
--- a/core/fxge/skia/fx_skia_device.h
+++ b/core/fxge/skia/fx_skia_device.h
@@ -117,11 +117,10 @@
                       uint32_t color,
                       const CFX_TextRenderOptions& options) override;
   int GetDriverType() const override;
-  bool DrawShading(const CPDF_ShadingPattern* pPattern,
-                   const CFX_Matrix* pMatrix,
+  bool DrawShading(const CPDF_ShadingPattern& pattern,
+                   const CFX_Matrix& matrix,
                    const FX_RECT& clip_rect,
-                   int alpha,
-                   bool bAlphaMode) override;
+                   int alpha) override;
 
   bool MultiplyAlpha(float alpha) override;
   bool MultiplyAlphaMask(RetainPtr<const CFX_DIBitmap> mask) override;