Split off CFX_RetainableGraphStateData from CFX_GraphStateData

Fixes the places where we use CFX_GraphStateData in a
non-refcounted manner. This allows the addition of a move
ctor for the non-refcounted version of the class.

Change-Id: I669df0e74450b18ac860784e1152e34833e5b1d0
Reviewed-on: https://pdfium-review.googlesource.com/c/49190
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxge/cfx_graphstate.h b/core/fxge/cfx_graphstate.h
index bf4fccd..05da326 100644
--- a/core/fxge/cfx_graphstate.h
+++ b/core/fxge/cfx_graphstate.h
@@ -38,7 +38,7 @@
   const CFX_GraphStateData* GetObject() const { return m_Ref.GetObject(); }
 
  private:
-  SharedCopyOnWrite<CFX_GraphStateData> m_Ref;
+  SharedCopyOnWrite<CFX_RetainableGraphStateData> m_Ref;
 };
 
 #endif  // CORE_FXGE_CFX_GRAPHSTATE_H_
diff --git a/core/fxge/cfx_graphstatedata.cpp b/core/fxge/cfx_graphstatedata.cpp
index 3bea040..495692c 100644
--- a/core/fxge/cfx_graphstatedata.cpp
+++ b/core/fxge/cfx_graphstatedata.cpp
@@ -8,21 +8,27 @@
 
 CFX_GraphStateData::CFX_GraphStateData() = default;
 
-CFX_GraphStateData::CFX_GraphStateData(const CFX_GraphStateData& src) {
-  *this = src;
-}
+CFX_GraphStateData::CFX_GraphStateData(const CFX_GraphStateData& src) = default;
+
+CFX_GraphStateData::CFX_GraphStateData(CFX_GraphStateData&& src) = default;
 
 CFX_GraphStateData::~CFX_GraphStateData() = default;
 
 CFX_GraphStateData& CFX_GraphStateData::operator=(
-    const CFX_GraphStateData& that) {
-  if (this != &that) {
-    m_LineCap = that.m_LineCap;
-    m_LineJoin = that.m_LineJoin;
-    m_DashPhase = that.m_DashPhase;
-    m_MiterLimit = that.m_MiterLimit;
-    m_LineWidth = that.m_LineWidth;
-    m_DashArray = that.m_DashArray;
-  }
-  return *this;
-}
+    const CFX_GraphStateData& that) = default;
+
+CFX_GraphStateData& CFX_GraphStateData::operator=(CFX_GraphStateData&& that) =
+    default;
+
+CFX_RetainableGraphStateData::CFX_RetainableGraphStateData() = default;
+
+// Note: can't default the copy constructor since Retainable has a deleted
+// copy constructor (as it should). Instead, we want the default Retainable
+// constructor to be invoked so as to create a copy with a ref-count of 1 as
+// of the time it is created, then populate the remainder of the members from
+// the |src| object.
+CFX_RetainableGraphStateData::CFX_RetainableGraphStateData(
+    const CFX_RetainableGraphStateData& src)
+    : CFX_GraphStateData(src) {}
+
+CFX_RetainableGraphStateData::~CFX_RetainableGraphStateData() = default;
diff --git a/core/fxge/cfx_graphstatedata.h b/core/fxge/cfx_graphstatedata.h
index 5604802..4005ce7 100644
--- a/core/fxge/cfx_graphstatedata.h
+++ b/core/fxge/cfx_graphstatedata.h
@@ -12,7 +12,7 @@
 #include "core/fxcrt/fx_system.h"
 #include "core/fxcrt/retain_ptr.h"
 
-class CFX_GraphStateData final : public Retainable {
+class CFX_GraphStateData {
  public:
   enum LineCap : uint8_t {
     LineCapButt = 0,
@@ -28,9 +28,11 @@
 
   CFX_GraphStateData();
   CFX_GraphStateData(const CFX_GraphStateData& src);
-  ~CFX_GraphStateData() override;
+  CFX_GraphStateData(CFX_GraphStateData&& src);
+  ~CFX_GraphStateData();
 
   CFX_GraphStateData& operator=(const CFX_GraphStateData& src);
+  CFX_GraphStateData& operator=(CFX_GraphStateData&& src);
 
   LineCap m_LineCap = LineCapButt;
   LineJoin m_LineJoin = LineJoinMiter;
@@ -40,4 +42,16 @@
   std::vector<float> m_DashArray;
 };
 
+class CFX_RetainableGraphStateData : public Retainable,
+                                     public CFX_GraphStateData {
+ public:
+  template <typename T, typename... Args>
+  friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+
+ private:
+  CFX_RetainableGraphStateData();
+  CFX_RetainableGraphStateData(const CFX_RetainableGraphStateData& src);
+  ~CFX_RetainableGraphStateData() override;
+};
+
 #endif  // CORE_FXGE_CFX_GRAPHSTATEDATA_H_