More unique_ptr returns from DIB methods.

Review-Url: https://codereview.chromium.org/2572293002
diff --git a/core/fxge/dib/fx_dib_main.cpp b/core/fxge/dib/fx_dib_main.cpp
index f90cbc1..8e6366d 100644
--- a/core/fxge/dib/fx_dib_main.cpp
+++ b/core/fxge/dib/fx_dib_main.cpp
@@ -1342,12 +1342,12 @@
   return true;
 }
 
-CFX_DIBitmap* CFX_DIBSource::FlipImage(bool bXFlip, bool bYFlip) const {
-  CFX_DIBitmap* pFlipped = new CFX_DIBitmap;
-  if (!pFlipped->Create(m_Width, m_Height, GetFormat())) {
-    delete pFlipped;
+std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::FlipImage(bool bXFlip,
+                                                       bool bYFlip) const {
+  auto pFlipped = pdfium::MakeUnique<CFX_DIBitmap>();
+  if (!pFlipped->Create(m_Width, m_Height, GetFormat()))
     return nullptr;
-  }
+
   pFlipped->SetPalette(m_pPalette.get());
   uint8_t* pDestBuffer = pFlipped->GetBuffer();
   int Bpp = m_bpp / 8;
diff --git a/core/fxge/dib/fx_dib_transform.cpp b/core/fxge/dib/fx_dib_transform.cpp
index e56e7fc..1c29ada 100644
--- a/core/fxge/dib/fx_dib_transform.cpp
+++ b/core/fxge/dib/fx_dib_transform.cpp
@@ -178,22 +178,23 @@
     y1 /= base;
   }
 };
-CFX_DIBitmap* CFX_DIBSource::SwapXY(bool bXFlip,
-                                    bool bYFlip,
-                                    const FX_RECT* pDestClip) const {
+
+std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::SwapXY(
+    bool bXFlip,
+    bool bYFlip,
+    const FX_RECT* pDestClip) const {
   FX_RECT dest_clip(0, 0, m_Height, m_Width);
-  if (pDestClip) {
+  if (pDestClip)
     dest_clip.Intersect(*pDestClip);
-  }
-  if (dest_clip.IsEmpty()) {
+  if (dest_clip.IsEmpty())
     return nullptr;
-  }
-  CFX_DIBitmap* pTransBitmap = new CFX_DIBitmap;
-  int result_height = dest_clip.Height(), result_width = dest_clip.Width();
-  if (!pTransBitmap->Create(result_width, result_height, GetFormat())) {
-    delete pTransBitmap;
+
+  auto pTransBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
+  int result_height = dest_clip.Height();
+  int result_width = dest_clip.Width();
+  if (!pTransBitmap->Create(result_width, result_height, GetFormat()))
     return nullptr;
-  }
+
   pTransBitmap->SetPalette(m_pPalette.get());
   int dest_pitch = pTransBitmap->GetPitch();
   uint8_t* dest_buf = pTransBitmap->GetBuffer();
@@ -276,6 +277,7 @@
   }
   return pTransBitmap;
 }
+
 #define FIX16_005 0.05f
 FX_RECT FXDIB_SwapClipBox(FX_RECT& clip,
                           int width,
@@ -415,9 +417,8 @@
       return true;
 
     if (m_Storer.GetBitmap()) {
-      std::unique_ptr<CFX_DIBitmap> swapped(
+      m_Storer.Replace(
           m_Storer.GetBitmap()->SwapXY(m_pMatrix->c > 0, m_pMatrix->b < 0));
-      m_Storer.Replace(std::move(swapped));
     }
     return false;
   }
diff --git a/core/fxge/fx_dib.h b/core/fxge/fx_dib.h
index c083bf7..14be05f 100644
--- a/core/fxge/fx_dib.h
+++ b/core/fxge/fx_dib.h
@@ -218,7 +218,6 @@
 
   std::unique_ptr<CFX_DIBitmap> Clone(const FX_RECT* pClip = nullptr) const;
   std::unique_ptr<CFX_DIBitmap> CloneConvert(FXDIB_Format format) const;
-
   std::unique_ptr<CFX_DIBitmap> StretchTo(int dest_width,
                                           int dest_height,
                                           uint32_t flags = 0,
@@ -229,6 +228,10 @@
       int& top,
       uint32_t flags = 0,
       const FX_RECT* pClip = nullptr) const;
+  std::unique_ptr<CFX_DIBitmap> SwapXY(bool bXFlip,
+                                       bool bYFlip,
+                                       const FX_RECT* pClip = nullptr) const;
+  std::unique_ptr<CFX_DIBitmap> FlipImage(bool bXFlip, bool bYFlip) const;
 
   std::unique_ptr<CFX_DIBitmap> CloneAlphaMask(
       const FX_RECT* pClip = nullptr) const;
@@ -237,11 +240,6 @@
   bool SetAlphaMask(const CFX_DIBSource* pAlphaMask,
                     const FX_RECT* pClip = nullptr);
 
-  CFX_DIBitmap* SwapXY(bool bXFlip,
-                       bool bYFlip,
-                       const FX_RECT* pClip = nullptr) const;
-
-  CFX_DIBitmap* FlipImage(bool bXFlip, bool bYFlip) const;
 
   void GetOverlapRect(int& dest_left,
                       int& dest_top,
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp
index 2746587..6794791 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -795,7 +795,7 @@
                                      int left,
                                      int top) {
   if (m_DeviceClass == FXDC_PRINTER) {
-    std::unique_ptr<CFX_DIBitmap> pBitmap(pBitmap1->FlipImage(false, true));
+    std::unique_ptr<CFX_DIBitmap> pBitmap = pBitmap1->FlipImage(false, true);
     if (!pBitmap)
       return false;
 
@@ -814,7 +814,7 @@
                     dst_height, pBuffer, (BITMAPINFO*)info.c_str(),
                     DIB_RGB_COLORS, SRCCOPY);
   } else {
-    CFX_DIBitmap* pBitmap = pBitmap1;
+    CFX_MaybeOwned<CFX_DIBitmap> pBitmap(pBitmap1);
     if (pBitmap->IsCmykImage()) {
       pBitmap = pBitmap->CloneConvert(FXDIB_Rgb).release();
       if (!pBitmap)
@@ -822,14 +822,11 @@
     }
     int width = pSrcRect->Width(), height = pSrcRect->Height();
     LPBYTE pBuffer = pBitmap->GetBuffer();
-    CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
+    CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap.Get());
     ::SetDIBitsToDevice(m_hDC, left, top, width, height, pSrcRect->left,
                         pBitmap->GetHeight() - pSrcRect->bottom, 0,
                         pBitmap->GetHeight(), pBuffer,
                         (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS);
-    if (pBitmap != pBitmap1) {
-      delete pBitmap;
-    }
   }
   return true;
 }
diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp
index 5a1a01a..2ff072f 100644
--- a/core/fxge/win32/fx_win32_print.cpp
+++ b/core/fxge/win32/fx_win32_print.cpp
@@ -108,8 +108,8 @@
       return false;
 
     if (dest_width < 0 || dest_height < 0) {
-      std::unique_ptr<CFX_DIBitmap> pFlipped(
-          pSource->FlipImage(dest_width < 0, dest_height < 0));
+      std::unique_ptr<CFX_DIBitmap> pFlipped =
+          pSource->FlipImage(dest_width < 0, dest_height < 0);
       if (!pFlipped)
         return false;
 
@@ -135,8 +135,8 @@
     return false;
 
   if (dest_width < 0 || dest_height < 0) {
-    std::unique_ptr<CFX_DIBitmap> pFlipped(
-        pSource->FlipImage(dest_width < 0, dest_height < 0));
+    std::unique_ptr<CFX_DIBitmap> pFlipped =
+        pSource->FlipImage(dest_width < 0, dest_height < 0);
     if (!pFlipped)
       return false;
 
@@ -184,8 +184,8 @@
   if (FXSYS_fabs(pMatrix->a) >= 0.5f || FXSYS_fabs(pMatrix->d) >= 0.5f)
     return false;
 
-  std::unique_ptr<CFX_DIBitmap> pTransformed(
-      pSource->SwapXY(pMatrix->c > 0, pMatrix->b < 0));
+  std::unique_ptr<CFX_DIBitmap> pTransformed =
+      pSource->SwapXY(pMatrix->c > 0, pMatrix->b < 0);
   if (!pTransformed)
     return false;
 
diff --git a/xfa/fxgraphics/cfx_graphics.cpp b/xfa/fxgraphics/cfx_graphics.cpp
index 5b3bc8c..059872f 100644
--- a/xfa/fxgraphics/cfx_graphics.cpp
+++ b/xfa/fxgraphics/cfx_graphics.cpp
@@ -1230,8 +1230,8 @@
          point.x, point.y);
   m2.Concat(m1);
   int32_t left, top;
-  std::unique_ptr<CFX_DIBitmap> bmp1(source->FlipImage(false, true));
-  std::unique_ptr<CFX_DIBitmap> bmp2(bmp1->TransformTo(&m2, left, top));
+  std::unique_ptr<CFX_DIBitmap> bmp1 = source->FlipImage(false, true);
+  std::unique_ptr<CFX_DIBitmap> bmp2 = bmp1->TransformTo(&m2, left, top);
   CFX_RectF r;
   GetClipRect(r);
   CFX_DIBitmap* bitmap = m_renderDevice->GetBitmap();
@@ -1257,14 +1257,14 @@
   if (matrix) {
     m1.Concat(*matrix);
   }
-  std::unique_ptr<CFX_DIBitmap> bmp1(
-      source->StretchTo((int32_t)rect.Width(), (int32_t)rect.Height()));
+  std::unique_ptr<CFX_DIBitmap> bmp1 =
+      source->StretchTo((int32_t)rect.Width(), (int32_t)rect.Height());
   CFX_Matrix m2;
   m2.Set(rect.Width(), 0.0, 0.0, rect.Height(), rect.left, rect.top);
   m2.Concat(m1);
   int32_t left, top;
-  std::unique_ptr<CFX_DIBitmap> bmp2(bmp1->FlipImage(false, true));
-  std::unique_ptr<CFX_DIBitmap> bmp3(bmp2->TransformTo(&m2, left, top));
+  std::unique_ptr<CFX_DIBitmap> bmp2 = bmp1->FlipImage(false, true);
+  std::unique_ptr<CFX_DIBitmap> bmp3 = bmp2->TransformTo(&m2, left, top);
   CFX_RectF r;
   GetClipRect(r);
   CFX_DIBitmap* bitmap = m_renderDevice->GetBitmap();
@@ -1487,8 +1487,8 @@
           0);
     m.Concat(*matrix);
     int32_t left, top;
-    std::unique_ptr<CFX_DIBitmap> bmp1(source->FlipImage(false, true));
-    std::unique_ptr<CFX_DIBitmap> bmp2(bmp1->TransformTo(&m, left, top));
+    std::unique_ptr<CFX_DIBitmap> bmp1 = source->FlipImage(false, true);
+    std::unique_ptr<CFX_DIBitmap> bmp2 = bmp1->TransformTo(&m, left, top);
     m_renderDevice->SetDIBits(bmp2.get(), left, top);
   }
   return FWL_Error::Succeeded;