Add RetainPtr::<T>::operator==(T*) method.

Allow comparions against raw pointers without having to invoke
the .Get() method directly.

Change-Id: Ic4e87eebbaf42e6cb8c231c366b35666abeb725c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/53770
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_contentmarks.cpp b/core/fpdfapi/page/cpdf_contentmarks.cpp
index 75d5034..45d3621 100644
--- a/core/fpdfapi/page/cpdf_contentmarks.cpp
+++ b/core/fpdfapi/page/cpdf_contentmarks.cpp
@@ -110,7 +110,7 @@
 bool CPDF_ContentMarks::MarkData::ContainsItem(
     const CPDF_ContentMarkItem* pItem) const {
   for (const auto pMark : m_Marks) {
-    if (pMark.Get() == pItem)
+    if (pMark == pItem)
       return true;
   }
   return false;
@@ -158,7 +158,7 @@
 
 bool CPDF_ContentMarks::MarkData::RemoveMark(CPDF_ContentMarkItem* pMarkItem) {
   for (auto it = m_Marks.begin(); it != m_Marks.end(); ++it) {
-    if (it->Get() == pMarkItem) {
+    if (*it == pMarkItem) {
       m_Marks.erase(it);
       return true;
     }
diff --git a/core/fxcrt/retain_ptr.h b/core/fxcrt/retain_ptr.h
index e6b8ac7..683ea74 100644
--- a/core/fxcrt/retain_ptr.h
+++ b/core/fxcrt/retain_ptr.h
@@ -73,6 +73,16 @@
   bool operator==(const RetainPtr& that) const { return Get() == that.Get(); }
   bool operator!=(const RetainPtr& that) const { return !(*this == that); }
 
+  template <typename U>
+  bool operator==(const U& that) const {
+    return Get() == that;
+  }
+
+  template <typename U>
+  bool operator!=(const U& that) const {
+    return !(*this == that);
+  }
+
   bool operator<(const RetainPtr& that) const {
     return std::less<T*>()(Get(), that.Get());
   }
diff --git a/core/fxcrt/retain_ptr_unittest.cpp b/core/fxcrt/retain_ptr_unittest.cpp
index 5548e9b..4405cd2 100644
--- a/core/fxcrt/retain_ptr_unittest.cpp
+++ b/core/fxcrt/retain_ptr_unittest.cpp
@@ -203,9 +203,11 @@
   {
     RetainPtr<PseudoRetainable> null_ptr2;
     EXPECT_TRUE(null_ptr1 == null_ptr2);
+    EXPECT_TRUE(null_ptr1 == nullptr);
 
     RetainPtr<PseudoRetainable> obj1_ptr2(&obj1);
     EXPECT_TRUE(obj1_ptr1 == obj1_ptr2);
+    EXPECT_TRUE(obj1_ptr2 == &obj1);
 
     RetainPtr<PseudoRetainable> obj2_ptr2(&obj2);
     EXPECT_TRUE(obj2_ptr1 == obj2_ptr2);
diff --git a/xfa/fgas/font/cfgas_gefont.cpp b/xfa/fgas/font/cfgas_gefont.cpp
index 7698aa7..62ceb6c 100644
--- a/xfa/fgas/font/cfgas_gefont.cpp
+++ b/xfa/fgas/font/cfgas_gefont.cpp
@@ -154,7 +154,7 @@
   int32_t iGlyph;
   std::tie(iGlyph, pFont) = GetGlyphIndexAndFont(wUnicode, true);
   if (iGlyph != 0xFFFF && pFont) {
-    if (pFont.Get() == this) {
+    if (pFont == this) {
       *pWidth = m_pFont->GetGlyphWidth(iGlyph);
       if (*pWidth < 0)
         *pWidth = -1;
@@ -242,7 +242,7 @@
   if (!pFont)
     pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), nullptr);
 #endif
-  if (!pFont || pFont.Get() == this)  // Avoids direct cycles below.
+  if (!pFont || pFont == this)  // Avoids direct cycles below.
     return {0xFFFF, nullptr};
 
   m_FontMapper[wUnicode] = pFont;
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 8f45335..368da29 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -1570,7 +1570,7 @@
     return;
   }
 
-  ASSERT(pNode->xml_node_.Get() == xml_node_.Get());
+  ASSERT(pNode->xml_node_ == xml_node_);
   CFX_XMLElement* pXMLElement = ToXMLElement(pNode->xml_node_.Get());
   if (pXMLElement) {
     WideString wsAttributeName =