diff options
author | weili <weili@chromium.org> | 2016-07-21 14:44:17 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-07-21 14:44:17 -0700 |
commit | c38cd6eb274429a5755e04d2e22a606375851717 (patch) | |
tree | 158c1e58b7d66a715cd7ba1459c55d329f08c49d | |
parent | 1d3348ce0092d6d2a40de5f8433c0d0c16a1e12e (diff) | |
download | pdfium-c38cd6eb274429a5755e04d2e22a606375851717.tar.xz |
Use smart pointers for graphics device classes
Use unique_ptr for class owned member variables. Also clean up some
style issues such as removing unused functions and casting to raw pointer.
BUG=pdfium:518
Review-Url: https://codereview.chromium.org/2163103002
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render_image.cpp | 103 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/render_int.h | 5 | ||||
-rw-r--r-- | core/fxcrt/include/fx_memory.h | 7 | ||||
-rw-r--r-- | core/fxge/agg/fx_agg_driver.cpp | 86 | ||||
-rw-r--r-- | core/fxge/agg/fx_agg_driver.h | 11 | ||||
-rw-r--r-- | core/fxge/apple/fx_quartz_device.cpp | 21 | ||||
-rw-r--r-- | core/fxge/dib/fx_dib_main.cpp | 35 | ||||
-rw-r--r-- | core/fxge/ge/fx_ge_device.cpp | 18 | ||||
-rw-r--r-- | core/fxge/include/fx_dib.h | 16 | ||||
-rw-r--r-- | core/fxge/include/fx_ge.h | 10 | ||||
-rw-r--r-- | core/fxge/skia/fx_skia_device.cpp | 8 | ||||
-rw-r--r-- | core/fxge/win32/fx_win32_device.cpp | 12 | ||||
-rw-r--r-- | core/fxge/win32/fx_win32_print.cpp | 6 |
13 files changed, 168 insertions, 170 deletions
diff --git a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp index 0ea4a17684..de9d1099cf 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp @@ -197,98 +197,113 @@ CPDF_DIBTransferFunc::CPDF_DIBTransferFunc( m_RampG = &pTransferFunc->m_Samples[256]; m_RampB = &pTransferFunc->m_Samples[512]; } -void CPDF_DIBTransferFunc::TranslateScanline(uint8_t* dest_buf, - const uint8_t* src_buf) const { - int i; + +void CPDF_DIBTransferFunc::TranslateScanline( + const uint8_t* src_buf, + std::vector<uint8_t>* dest_buf) const { FX_BOOL bSkip = FALSE; switch (m_pSrc->GetFormat()) { case FXDIB_1bppRgb: { - int r0 = m_RampR[0], g0 = m_RampG[0], b0 = m_RampB[0]; - int r1 = m_RampR[255], g1 = m_RampG[255], b1 = m_RampB[255]; - for (i = 0; i < m_Width; i++) { + int r0 = m_RampR[0]; + int g0 = m_RampG[0]; + int b0 = m_RampB[0]; + int r1 = m_RampR[255]; + int g1 = m_RampG[255]; + int b1 = m_RampB[255]; + int index = 0; + for (int i = 0; i < m_Width; i++) { if (src_buf[i / 8] & (1 << (7 - i % 8))) { - *dest_buf++ = b1; - *dest_buf++ = g1; - *dest_buf++ = r1; + (*dest_buf)[index++] = b1; + (*dest_buf)[index++] = g1; + (*dest_buf)[index++] = r1; } else { - *dest_buf++ = b0; - *dest_buf++ = g0; - *dest_buf++ = r0; + (*dest_buf)[index++] = b0; + (*dest_buf)[index++] = g0; + (*dest_buf)[index++] = r0; } #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - dest_buf++; + index++; #endif } break; } case FXDIB_1bppMask: { - int m0 = m_RampR[0], m1 = m_RampR[255]; - for (i = 0; i < m_Width; i++) { - if (src_buf[i / 8] & (1 << (7 - i % 8))) { - *dest_buf++ = m1; - } else { - *dest_buf++ = m0; - } + int m0 = m_RampR[0]; + int m1 = m_RampR[255]; + int index = 0; + for (int i = 0; i < m_Width; i++) { + if (src_buf[i / 8] & (1 << (7 - i % 8))) + (*dest_buf)[index++] = m1; + else + (*dest_buf)[index++] = m0; } break; } case FXDIB_8bppRgb: { FX_ARGB* pPal = m_pSrc->GetPalette(); - for (i = 0; i < m_Width; i++) { + int index = 0; + for (int i = 0; i < m_Width; i++) { if (pPal) { FX_ARGB src_argb = pPal[*src_buf]; - *dest_buf++ = m_RampB[FXARGB_R(src_argb)]; - *dest_buf++ = m_RampG[FXARGB_G(src_argb)]; - *dest_buf++ = m_RampR[FXARGB_B(src_argb)]; + (*dest_buf)[index++] = m_RampB[FXARGB_R(src_argb)]; + (*dest_buf)[index++] = m_RampG[FXARGB_G(src_argb)]; + (*dest_buf)[index++] = m_RampR[FXARGB_B(src_argb)]; } else { uint32_t src_byte = *src_buf; - *dest_buf++ = m_RampB[src_byte]; - *dest_buf++ = m_RampG[src_byte]; - *dest_buf++ = m_RampR[src_byte]; + (*dest_buf)[index++] = m_RampB[src_byte]; + (*dest_buf)[index++] = m_RampG[src_byte]; + (*dest_buf)[index++] = m_RampR[src_byte]; } src_buf++; #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - dest_buf++; + index++; #endif } break; } - case FXDIB_8bppMask: - for (i = 0; i < m_Width; i++) { - *dest_buf++ = m_RampR[*(src_buf++)]; + case FXDIB_8bppMask: { + int index = 0; + for (int i = 0; i < m_Width; i++) { + (*dest_buf)[index++] = m_RampR[*(src_buf++)]; } break; - case FXDIB_Rgb: - for (i = 0; i < m_Width; i++) { - *dest_buf++ = m_RampB[*(src_buf++)]; - *dest_buf++ = m_RampG[*(src_buf++)]; - *dest_buf++ = m_RampR[*(src_buf++)]; + } + case FXDIB_Rgb: { + int index = 0; + for (int i = 0; i < m_Width; i++) { + (*dest_buf)[index++] = m_RampB[*(src_buf++)]; + (*dest_buf)[index++] = m_RampG[*(src_buf++)]; + (*dest_buf)[index++] = m_RampR[*(src_buf++)]; #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - dest_buf++; + index++; #endif } break; + } case FXDIB_Rgb32: bSkip = TRUE; - case FXDIB_Argb: - for (i = 0; i < m_Width; i++) { - *dest_buf++ = m_RampB[*(src_buf++)]; - *dest_buf++ = m_RampG[*(src_buf++)]; - *dest_buf++ = m_RampR[*(src_buf++)]; + case FXDIB_Argb: { + int index = 0; + for (int i = 0; i < m_Width; i++) { + (*dest_buf)[index++] = m_RampB[*(src_buf++)]; + (*dest_buf)[index++] = m_RampG[*(src_buf++)]; + (*dest_buf)[index++] = m_RampR[*(src_buf++)]; if (!bSkip) { - *dest_buf++ = *src_buf; + (*dest_buf)[index++] = *src_buf; #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ } else { - dest_buf++; + index++; #endif } src_buf++; } break; + } default: break; } } + void CPDF_DIBTransferFunc::TranslateDownSamples(uint8_t* dest_buf, const uint8_t* src_buf, int pixels, diff --git a/core/fpdfapi/fpdf_render/render_int.h b/core/fpdfapi/fpdf_render/render_int.h index edbbad53c8..4494b8cefb 100644 --- a/core/fpdfapi/fpdf_render/render_int.h +++ b/core/fpdfapi/fpdf_render/render_int.h @@ -9,6 +9,7 @@ #include <map> #include <memory> +#include <vector> #include "core/fpdfapi/fpdf_page/cpdf_countedobject.h" #include "core/fpdfapi/fpdf_page/cpdf_graphicstates.h" @@ -618,8 +619,8 @@ class CPDF_DIBTransferFunc : public CFX_FilteredDIB { // CFX_FilteredDIB FXDIB_Format GetDestFormat() override; FX_ARGB* GetDestPalette() override; - void TranslateScanline(uint8_t* dest_buf, - const uint8_t* src_buf) const override; + void TranslateScanline(const uint8_t* src_buf, + std::vector<uint8_t>* dest_buf) const override; void TranslateDownSamples(uint8_t* dest_buf, const uint8_t* src_buf, int pixels, diff --git a/core/fxcrt/include/fx_memory.h b/core/fxcrt/include/fx_memory.h index fa8da6067c..53e6b9d1eb 100644 --- a/core/fxcrt/include/fx_memory.h +++ b/core/fxcrt/include/fx_memory.h @@ -23,6 +23,7 @@ void FXMEM_DefaultFree(void* pointer, int flags); #include <stdlib.h> #include <limits> +#include <memory> #include <new> NEVER_INLINE void FX_OutOfMemoryTerminate(); @@ -100,6 +101,12 @@ struct ReleaseDeleter { inline void operator()(T* ptr) const { ptr->Release(); } }; +// Used to help transfer ownership of a raw pointer to std::unique_ptr. +template <typename T> +std::unique_ptr<T> WrapUnique(T* ptr) { + return std::unique_ptr<T>(ptr); +} + class CFX_Deletable { public: virtual ~CFX_Deletable() {} diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp index 2b04b42d19..038637926c 100644 --- a/core/fxge/agg/fx_agg_driver.cpp +++ b/core/fxge/agg/fx_agg_driver.cpp @@ -9,6 +9,7 @@ #include <algorithm> #include "core/fxcodec/include/fx_codec.h" +#include "core/fxcrt/include/fx_memory.h" #include "core/fxge/dib/dib_int.h" #include "core/fxge/ge/fx_text_int.h" #include "core/fxge/include/fx_ge.h" @@ -420,23 +421,19 @@ static void RasterizeStroke(agg::rasterizer_scanline_aa& rasterizer, CFX_AggDeviceDriver::CFX_AggDeviceDriver(CFX_DIBitmap* pBitmap, FX_BOOL bRgbByteOrder, CFX_DIBitmap* pOriDevice, - FX_BOOL bGroupKnockout) { - m_pBitmap = pBitmap; - m_pClipRgn = nullptr; - m_pPlatformBitmap = nullptr; - m_pPlatformGraphics = nullptr; - m_pDwRenderTartget = nullptr; - m_bRgbByteOrder = bRgbByteOrder; - m_pOriDevice = pOriDevice; - m_bGroupKnockout = bGroupKnockout; - m_FillFlags = 0; + FX_BOOL bGroupKnockout) + : m_pBitmap(pBitmap), +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + m_pPlatformGraphics(nullptr), +#endif + m_FillFlags(0), + m_bRgbByteOrder(bRgbByteOrder), + m_pOriDevice(pOriDevice), + m_bGroupKnockout(bGroupKnockout) { InitPlatform(); } CFX_AggDeviceDriver::~CFX_AggDeviceDriver() { - delete m_pClipRgn; - for (int i = 0; i < m_StateStack.GetSize(); i++) - delete m_StateStack[i]; DestroyPlatform(); } @@ -499,29 +496,24 @@ int CFX_AggDeviceDriver::GetDeviceCaps(int caps_id) const { } void CFX_AggDeviceDriver::SaveState() { - CFX_ClipRgn* pClip = nullptr; - if (m_pClipRgn) { - pClip = new CFX_ClipRgn(*m_pClipRgn); - } - m_StateStack.Add(pClip); + std::unique_ptr<CFX_ClipRgn> pClip; + if (m_pClipRgn) + pClip.reset(new CFX_ClipRgn(*m_pClipRgn)); + m_StateStack.push_back(std::move(pClip)); } void CFX_AggDeviceDriver::RestoreState(bool bKeepSaved) { - delete m_pClipRgn; - m_pClipRgn = nullptr; + m_pClipRgn.reset(); - int size = m_StateStack.GetSize(); - if (!size) + if (m_StateStack.empty()) return; - CFX_ClipRgn* pSavedClip = m_StateStack[size - 1]; if (bKeepSaved) { - if (pSavedClip) { - m_pClipRgn = new CFX_ClipRgn(*pSavedClip); - } + if (m_StateStack.back()) + m_pClipRgn.reset(new CFX_ClipRgn(*m_StateStack.back())); } else { - m_StateStack.RemoveAt(size - 1); - m_pClipRgn = pSavedClip; + m_pClipRgn = std::move(m_StateStack.back()); + m_StateStack.pop_back(); } } @@ -555,8 +547,8 @@ FX_BOOL CFX_AggDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData, int fill_mode) { m_FillFlags = fill_mode; if (!m_pClipRgn) { - m_pClipRgn = new CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH), - GetDeviceCaps(FXDC_PIXEL_HEIGHT)); + m_pClipRgn.reset(new CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH), + GetDeviceCaps(FXDC_PIXEL_HEIGHT))); } if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { CFX_FloatRect rectf; @@ -588,8 +580,8 @@ FX_BOOL CFX_AggDeviceDriver::SetClip_PathStroke( const CFX_Matrix* pObject2Device, const CFX_GraphStateData* pGraphState) { if (!m_pClipRgn) { - m_pClipRgn = new CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH), - GetDeviceCaps(FXDC_PIXEL_HEIGHT)); + m_pClipRgn.reset(new CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH), + GetDeviceCaps(FXDC_PIXEL_HEIGHT))); } CAgg_PathData path_data; path_data.BuildPath(pPathData, nullptr); @@ -1444,7 +1436,7 @@ FX_BOOL CFX_AggDeviceDriver::RenderRasterizer( void* pIccTransform) { CFX_DIBitmap* pt = bGroupKnockout ? m_pOriDevice : nullptr; CFX_Renderer render; - if (!render.Init(m_pBitmap, pt, m_pClipRgn, color, bFullCover, + if (!render.Init(m_pBitmap, pt, m_pClipRgn.get(), color, bFullCover, m_bRgbByteOrder, alpha_flag, pIccTransform)) { return FALSE; } @@ -1659,14 +1651,14 @@ FX_BOOL CFX_AggDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, return TRUE; if (pBitmap->IsAlphaMask()) { - return m_pBitmap->CompositeMask(left, top, pSrcRect->Width(), - pSrcRect->Height(), pBitmap, argb, - pSrcRect->left, pSrcRect->top, blend_type, - m_pClipRgn, m_bRgbByteOrder, 0, nullptr); + return m_pBitmap->CompositeMask( + left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, argb, + pSrcRect->left, pSrcRect->top, blend_type, m_pClipRgn.get(), + m_bRgbByteOrder, 0, nullptr); } return m_pBitmap->CompositeBitmap( left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, pSrcRect->left, - pSrcRect->top, blend_type, m_pClipRgn, m_bRgbByteOrder, nullptr); + pSrcRect->top, blend_type, m_pClipRgn.get(), m_bRgbByteOrder, nullptr); } FX_BOOL CFX_AggDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, @@ -1692,8 +1684,8 @@ FX_BOOL CFX_AggDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, FX_RECT dest_clip = dest_rect; dest_clip.Intersect(*pClipRect); CFX_BitmapComposer composer; - composer.Compose(m_pBitmap, m_pClipRgn, 255, argb, dest_clip, FALSE, FALSE, - FALSE, m_bRgbByteOrder, 0, nullptr, blend_type); + composer.Compose(m_pBitmap, m_pClipRgn.get(), 255, argb, dest_clip, FALSE, + FALSE, FALSE, m_bRgbByteOrder, 0, nullptr, blend_type); dest_clip.Offset(-dest_rect.left, -dest_rect.top); CFX_ImageStretcher stretcher(&composer, pSource, dest_width, dest_height, dest_clip, flags); @@ -1713,8 +1705,8 @@ FX_BOOL CFX_AggDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, return TRUE; CFX_ImageRenderer* pRenderer = new CFX_ImageRenderer; - pRenderer->Start(m_pBitmap, m_pClipRgn, pSource, bitmap_alpha, argb, pMatrix, - render_flags, m_bRgbByteOrder, 0, nullptr); + pRenderer->Start(m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb, + pMatrix, render_flags, m_bRgbByteOrder, 0, nullptr); handle = pRenderer; return TRUE; } @@ -1746,9 +1738,8 @@ bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, return false; SetBitmap(pBitmap); - IFX_RenderDeviceDriver* pDriver = new CFX_AggDeviceDriver( - pBitmap, bRgbByteOrder, pOriDevice, bGroupKnockout); - SetDeviceDriver(pDriver); + SetDeviceDriver(WrapUnique(new CFX_AggDeviceDriver( + pBitmap, bRgbByteOrder, pOriDevice, bGroupKnockout))); return true; } @@ -1763,9 +1754,8 @@ bool CFX_FxgeDevice::Create(int width, return false; } SetBitmap(pBitmap); - IFX_RenderDeviceDriver* pDriver = - new CFX_AggDeviceDriver(pBitmap, FALSE, pOriDevice, FALSE); - SetDeviceDriver(pDriver); + SetDeviceDriver( + WrapUnique(new CFX_AggDeviceDriver(pBitmap, FALSE, pOriDevice, FALSE))); return true; } diff --git a/core/fxge/agg/fx_agg_driver.h b/core/fxge/agg/fx_agg_driver.h index 15f9706b3f..ff02ec7251 100644 --- a/core/fxge/agg/fx_agg_driver.h +++ b/core/fxge/agg/fx_agg_driver.h @@ -7,6 +7,9 @@ #ifndef CORE_FXGE_AGG_FX_AGG_DRIVER_H_ #define CORE_FXGE_AGG_FX_AGG_DRIVER_H_ +#include <memory> +#include <vector> + #include "core/fxge/include/ifx_renderdevicedriver.h" #include "third_party/agg23/agg_clip_liang_barsky.h" #include "third_party/agg23/agg_path_storage.h" @@ -108,11 +111,11 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver { private: CFX_DIBitmap* m_pBitmap; - CFX_ClipRgn* m_pClipRgn; - CFX_ArrayTemplate<CFX_ClipRgn*> m_StateStack; + std::unique_ptr<CFX_ClipRgn> m_pClipRgn; + std::vector<std::unique_ptr<CFX_ClipRgn>> m_StateStack; +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ void* m_pPlatformGraphics; - void* m_pPlatformBitmap; - void* m_pDwRenderTartget; +#endif int m_FillFlags; FX_BOOL m_bRgbByteOrder; CFX_DIBitmap* m_pOriDevice; diff --git a/core/fxge/apple/fx_quartz_device.cpp b/core/fxge/apple/fx_quartz_device.cpp index b3591a3da1..a9b9268ae6 100644 --- a/core/fxge/apple/fx_quartz_device.cpp +++ b/core/fxge/apple/fx_quartz_device.cpp @@ -10,6 +10,7 @@ #include "core/fxge/agg/fx_agg_driver.h" #endif +#include "core/fxcrt/include/fx_memory.h" #include "core/fxge/dib/dib_int.h" #include "core/fxge/ge/fx_text_int.h" #include "core/fxge/include/fx_freetype.h" @@ -1018,34 +1019,32 @@ FX_BOOL CFX_QuartzDevice::Attach(CGContextRef context, int32_t nDeviceClass) { } m_pContext = context; CGContextRetain(m_pContext); - IFX_RenderDeviceDriver* pDriver = - new CFX_QuartzDeviceDriver(m_pContext, nDeviceClass); - SetDeviceDriver(pDriver); + SetDeviceDriver( + WrapUnique(new CFX_QuartzDeviceDriver(m_pContext, nDeviceClass))); return TRUE; } + FX_BOOL CFX_QuartzDevice::Attach(CFX_DIBitmap* pBitmap) { SetBitmap(pBitmap); m_pContext = createContextWithBitmap(pBitmap); if (!m_pContext) return FALSE; - IFX_RenderDeviceDriver* pDriver = - new CFX_QuartzDeviceDriver(m_pContext, FXDC_DISPLAY); - SetDeviceDriver(pDriver); + SetDeviceDriver( + WrapUnique(new CFX_QuartzDeviceDriver(m_pContext, FXDC_DISPLAY))); return TRUE; } + FX_BOOL CFX_QuartzDevice::Create(int32_t width, int32_t height, FXDIB_Format format) { if ((uint8_t)format < 32) { return FALSE; } - CFX_DIBitmap* pBitmap = new CFX_DIBitmap; - if (!pBitmap->Create(width, height, format)) { - delete pBitmap; + std::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap); + if (!pBitmap->Create(width, height, format)) return FALSE; - } m_bOwnedBitmap = TRUE; - return Attach(pBitmap); + return Attach(pBitmap.release()); } #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ diff --git a/core/fxge/dib/fx_dib_main.cpp b/core/fxge/dib/fx_dib_main.cpp index b977a6239c..4c294adf5f 100644 --- a/core/fxge/dib/fx_dib_main.cpp +++ b/core/fxge/dib/fx_dib_main.cpp @@ -6,8 +6,8 @@ #include "core/fxge/include/fx_dib.h" -#include <algorithm> #include <limits.h> +#include <algorithm> #include "core/fxcodec/include/fx_codec.h" #include "core/fxge/dib/dib_int.h" @@ -1459,36 +1459,28 @@ CFX_DIBitmap* CFX_DIBSource::FlipImage(FX_BOOL bXFlip, FX_BOOL bYFlip) const { } CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc) { - m_pBitmap = nullptr; if (pSrc->GetBuffer()) { - m_pBitmap = new CFX_DIBitmap; + m_pBitmap.reset(new CFX_DIBitmap); if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(), pSrc->GetFormat(), pSrc->GetBuffer())) { - delete m_pBitmap; - m_pBitmap = nullptr; + m_pBitmap.reset(); return; } m_pBitmap->CopyPalette(pSrc->GetPalette()); m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask); } else { - m_pBitmap = pSrc->Clone(); + m_pBitmap.reset(pSrc->Clone()); } } -CFX_DIBExtractor::~CFX_DIBExtractor() { - delete m_pBitmap; -} +CFX_DIBExtractor::~CFX_DIBExtractor() {} -CFX_FilteredDIB::CFX_FilteredDIB() { - m_pScanline = nullptr; - m_pSrc = nullptr; -} +CFX_FilteredDIB::CFX_FilteredDIB() : m_pSrc(nullptr) {} CFX_FilteredDIB::~CFX_FilteredDIB() { if (m_bAutoDropSrc) { delete m_pSrc; } - FX_Free(m_pScanline); } void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc) { @@ -1501,12 +1493,12 @@ void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc) { m_AlphaFlag = (uint8_t)(format >> 8); m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4; m_pPalette.reset(GetDestPalette()); - m_pScanline = FX_Alloc(uint8_t, m_Pitch); + m_Scanline.resize(m_Pitch); } const uint8_t* CFX_FilteredDIB::GetScanline(int line) const { - TranslateScanline(m_pScanline, m_pSrc->GetScanline(line)); - return m_pScanline; + TranslateScanline(m_pSrc->GetScanline(line), &m_Scanline); + return m_Scanline.data(); } void CFX_FilteredDIB::DownSampleScanline(int line, @@ -1523,14 +1515,11 @@ void CFX_FilteredDIB::DownSampleScanline(int line, CFX_ImageRenderer::CFX_ImageRenderer() { m_Status = 0; - m_pTransformer = nullptr; m_bRgbByteOrder = FALSE; m_BlendType = FXDIB_BLEND_NORMAL; } -CFX_ImageRenderer::~CFX_ImageRenderer() { - delete m_pTransformer; -} +CFX_ImageRenderer::~CFX_ImageRenderer() {} FX_BOOL CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice, const CFX_ClipRgn* pClipRgn, @@ -1587,8 +1576,8 @@ FX_BOOL CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice, return TRUE; } m_Status = 2; - m_pTransformer = - new CFX_ImageTransformer(pSource, &m_Matrix, dib_flags, &m_ClipBox); + m_pTransformer.reset( + new CFX_ImageTransformer(pSource, &m_Matrix, dib_flags, &m_ClipBox)); m_pTransformer->Start(); return TRUE; } diff --git a/core/fxge/ge/fx_ge_device.cpp b/core/fxge/ge/fx_ge_device.cpp index 9bb950beed..571f90cfa1 100644 --- a/core/fxge/ge/fx_ge_device.cpp +++ b/core/fxge/ge/fx_ge_device.cpp @@ -17,21 +17,13 @@ CFX_RenderDevice::CFX_RenderDevice() m_Height(0), m_bpp(0), m_RenderCaps(0), - m_DeviceClass(0), - m_pDeviceDriver(nullptr) {} + m_DeviceClass(0) {} -CFX_RenderDevice::~CFX_RenderDevice() { - delete m_pDeviceDriver; -} - -void CFX_RenderDevice::Flush() { - delete m_pDeviceDriver; - m_pDeviceDriver = nullptr; -} +CFX_RenderDevice::~CFX_RenderDevice() {} -void CFX_RenderDevice::SetDeviceDriver(IFX_RenderDeviceDriver* pDriver) { - delete m_pDeviceDriver; - m_pDeviceDriver = pDriver; +void CFX_RenderDevice::SetDeviceDriver( + std::unique_ptr<IFX_RenderDeviceDriver> pDriver) { + m_pDeviceDriver = std::move(pDriver); InitDeviceInfo(); } diff --git a/core/fxge/include/fx_dib.h b/core/fxge/include/fx_dib.h index c2ca859585..540996cfc1 100644 --- a/core/fxge/include/fx_dib.h +++ b/core/fxge/include/fx_dib.h @@ -8,6 +8,7 @@ #define CORE_FXGE_INCLUDE_FX_DIB_H_ #include <memory> +#include <vector> #include "core/fxcrt/include/fx_basic.h" #include "core/fxcrt/include/fx_coordinates.h" @@ -381,10 +382,10 @@ class CFX_DIBExtractor { explicit CFX_DIBExtractor(const CFX_DIBSource* pSrc); ~CFX_DIBExtractor(); - operator CFX_DIBitmap*() { return m_pBitmap; } + CFX_DIBitmap* GetBitmap() { return m_pBitmap.get(); } private: - CFX_DIBitmap* m_pBitmap; + std::unique_ptr<CFX_DIBitmap> m_pBitmap; }; typedef CFX_CountRef<CFX_DIBitmap> CFX_DIBitmapRef; @@ -399,8 +400,8 @@ class CFX_FilteredDIB : public CFX_DIBSource { virtual uint32_t* GetDestPalette() = 0; - virtual void TranslateScanline(uint8_t* dest_buf, - const uint8_t* src_buf) const = 0; + virtual void TranslateScanline(const uint8_t* src_buf, + std::vector<uint8_t>* dest_buf) const = 0; virtual void TranslateDownSamples(uint8_t* dest_buf, const uint8_t* src_buf, @@ -419,10 +420,8 @@ class CFX_FilteredDIB : public CFX_DIBSource { int clip_width) const override; const CFX_DIBSource* m_pSrc; - FX_BOOL m_bAutoDropSrc; - - uint8_t* m_pScanline; + mutable std::vector<uint8_t> m_Scanline; }; class IFX_ScanlineComposer { @@ -438,6 +437,7 @@ class IFX_ScanlineComposer { FXDIB_Format src_format, uint32_t* pSrcPalette) = 0; }; + class CFX_ScanlineCompositor { public: CFX_ScanlineCompositor(); @@ -663,7 +663,7 @@ class CFX_ImageRenderer { int m_BitmapAlpha; uint32_t m_MaskColor; CFX_Matrix m_Matrix; - CFX_ImageTransformer* m_pTransformer; + std::unique_ptr<CFX_ImageTransformer> m_pTransformer; std::unique_ptr<CFX_ImageStretcher> m_Stretcher; CFX_BitmapComposer m_Composer; int m_Status; diff --git a/core/fxge/include/fx_ge.h b/core/fxge/include/fx_ge.h index dbc4fd0a43..aceaa76a94 100644 --- a/core/fxge/include/fx_ge.h +++ b/core/fxge/include/fx_ge.h @@ -214,9 +214,11 @@ class CFX_RenderDevice { CFX_RenderDevice(); virtual ~CFX_RenderDevice(); - void Flush(); - void SetDeviceDriver(IFX_RenderDeviceDriver* pDriver); - IFX_RenderDeviceDriver* GetDeviceDriver() const { return m_pDeviceDriver; } + // Take ownership of |pDriver|. + void SetDeviceDriver(std::unique_ptr<IFX_RenderDeviceDriver> pDriver); + IFX_RenderDeviceDriver* GetDeviceDriver() const { + return m_pDeviceDriver.get(); + } FX_BOOL StartRendering(); void EndRendering(); @@ -400,7 +402,7 @@ class CFX_RenderDevice { int m_RenderCaps; int m_DeviceClass; FX_RECT m_ClipBox; - IFX_RenderDeviceDriver* m_pDeviceDriver; + std::unique_ptr<IFX_RenderDeviceDriver> m_pDeviceDriver; }; class CFX_FxgeDevice : public CFX_RenderDevice { diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp index 55fe580086..5f874e5ffb 100644 --- a/core/fxge/skia/fx_skia_device.cpp +++ b/core/fxge/skia/fx_skia_device.cpp @@ -7,6 +7,7 @@ #include <vector> #include "core/fxcodec/include/fx_codec.h" +#include "core/fxcrt/include/fx_memory.h" #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h" #include "core/fpdfapi/fpdf_page/pageint.h" @@ -1461,8 +1462,7 @@ CFX_FxgeDevice::CFX_FxgeDevice() { } SkPictureRecorder* CFX_FxgeDevice::CreateRecorder(int size_x, int size_y) { - CFX_SkiaDeviceDriver* skDriver = new CFX_SkiaDeviceDriver(size_x, size_y); - SetDeviceDriver(skDriver); + SetDeviceDriver(WrapUnique(new CFX_SkiaDeviceDriver(size_x, size_y))); return skDriver->GetRecorder(); } @@ -1473,8 +1473,8 @@ bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, if (!pBitmap) return false; SetBitmap(pBitmap); - SetDeviceDriver(new CFX_SkiaDeviceDriver(pBitmap, bRgbByteOrder, pOriDevice, - bGroupKnockout)); + SetDeviceDriver(WrapUnique(new CFX_SkiaDeviceDriver( + pBitmap, bRgbByteOrder, pOriDevice, bGroupKnockout))); return true; } diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp index 0b08bba8df..78abd5da1d 100644 --- a/core/fxge/win32/fx_win32_device.cpp +++ b/core/fxge/win32/fx_win32_device.cpp @@ -14,6 +14,7 @@ #include <crtdbg.h> #include "core/fxcodec/include/fx_codec.h" +#include "core/fxcrt/include/fx_memory.h" #ifndef _SKIA_SUPPORT_ #include "core/fxge/agg/fx_agg_driver.h" @@ -1253,7 +1254,7 @@ FX_BOOL CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource, return SetDIBits(&bitmap, 0, &src_rect, left, top, FXDIB_BLEND_NORMAL); } CFX_DIBExtractor temp(pSource); - CFX_DIBitmap* pBitmap = temp; + CFX_DIBitmap* pBitmap = temp.GetBitmap(); if (!pBitmap) return FALSE; return GDI_SetDIBits(pBitmap, pSrcRect, left, top); @@ -1335,7 +1336,7 @@ FX_BOOL CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource, (CWin32Platform*)CFX_GEModule::Get()->GetPlatformData(); if (pPlatform->m_GdiplusExt.IsAvailable() && !pSource->IsCmykImage()) { CFX_DIBExtractor temp(pSource); - CFX_DIBitmap* pBitmap = temp; + CFX_DIBitmap* pBitmap = temp.GetBitmap(); if (!pBitmap) return FALSE; return pPlatform->m_GdiplusExt.StretchDIBits( @@ -1346,7 +1347,7 @@ FX_BOOL CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource, dest_width, dest_height, pClipRect, flags); } CFX_DIBExtractor temp(pSource); - CFX_DIBitmap* pBitmap = temp; + CFX_DIBitmap* pBitmap = temp.GetBitmap(); if (!pBitmap) return FALSE; return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width, @@ -1364,7 +1365,7 @@ FX_BOOL CGdiDisplayDriver::StartDIBits(const CFX_DIBSource* pBitmap, } CFX_WindowsDevice::CFX_WindowsDevice(HDC hDC) { - SetDeviceDriver(CreateDriver(hDC)); + SetDeviceDriver(WrapUnique(CreateDriver(hDC))); } CFX_WindowsDevice::~CFX_WindowsDevice() {} @@ -1407,8 +1408,7 @@ CFX_WinBitmapDevice::CFX_WinBitmapDevice(int width, SetBitmap(pBitmap); m_hDC = ::CreateCompatibleDC(nullptr); m_hOldBitmap = (HBITMAP)SelectObject(m_hDC, m_hBitmap); - IFX_RenderDeviceDriver* pDriver = new CGdiDisplayDriver(m_hDC); - SetDeviceDriver(pDriver); + SetDeviceDriver(WrapUnique(new CGdiDisplayDriver(m_hDC))); } CFX_WinBitmapDevice::~CFX_WinBitmapDevice() { diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp index e1071e79f0..9e19873577 100644 --- a/core/fxge/win32/fx_win32_print.cpp +++ b/core/fxge/win32/fx_win32_print.cpp @@ -86,7 +86,7 @@ FX_BOOL CGdiPrinterDriver::SetDIBits(const CFX_DIBSource* pSource, return FALSE; CFX_DIBExtractor temp(pSource); - CFX_DIBitmap* pBitmap = temp; + CFX_DIBitmap* pBitmap = temp.GetBitmap(); if (!pBitmap) return FALSE; @@ -124,7 +124,7 @@ FX_BOOL CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource, } CFX_DIBExtractor temp(pSource); - CFX_DIBitmap* pBitmap = temp; + CFX_DIBitmap* pBitmap = temp.GetBitmap(); if (!pBitmap) return FALSE; return GDI_StretchBitMask(pBitmap, dest_left, dest_top, dest_width, @@ -150,7 +150,7 @@ FX_BOOL CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource, } CFX_DIBExtractor temp(pSource); - CFX_DIBitmap* pBitmap = temp; + CFX_DIBitmap* pBitmap = temp.GetBitmap(); if (!pBitmap) return FALSE; return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width, |