summaryrefslogtreecommitdiff
path: root/xfa/fxgraphics
diff options
context:
space:
mode:
authorweili <weili@chromium.org>2016-08-09 10:33:10 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-09 10:33:10 -0700
commit16fccc51456dbab7e392c3952cc367723f9694f6 (patch)
tree0bd44bec6b81213db9d1dc487237164cdcaa43a4 /xfa/fxgraphics
parentaf7ab33c73f58f18d0db0c90d93fa0aab0bc83f3 (diff)
downloadpdfium-16fccc51456dbab7e392c3952cc367723f9694f6.tar.xz
Use smart pointers for class owned pointers
For classes under xfa/fxfa/fm2js, and xfa/fxgraphics, use smart pointers instead of raw pointer to make memory management easier. Also fix some styling issues along the changes. BUG=pdfium:518 Review-Url: https://codereview.chromium.org/2222203002
Diffstat (limited to 'xfa/fxgraphics')
-rw-r--r--xfa/fxgraphics/cfx_graphics.cpp10
-rw-r--r--xfa/fxgraphics/cfx_path.cpp15
-rw-r--r--xfa/fxgraphics/cfx_path.h12
-rw-r--r--xfa/fxgraphics/cfx_path_generator.cpp22
-rw-r--r--xfa/fxgraphics/cfx_path_generator.h7
-rw-r--r--xfa/fxgraphics/include/cfx_graphics.h4
6 files changed, 36 insertions, 34 deletions
diff --git a/xfa/fxgraphics/cfx_graphics.cpp b/xfa/fxgraphics/cfx_graphics.cpp
index 90225d4e19..0e18d65e2d 100644
--- a/xfa/fxgraphics/cfx_graphics.cpp
+++ b/xfa/fxgraphics/cfx_graphics.cpp
@@ -567,9 +567,7 @@ const FX_HATCHDATA hatchBitmapData[FX_HATCHSTYLE_Total] = {
} // namespace
CFX_Graphics::CFX_Graphics()
- : m_type(FX_CONTEXT_None),
- m_renderDevice(nullptr),
- m_aggGraphics(nullptr) {}
+ : m_type(FX_CONTEXT_None), m_renderDevice(nullptr) {}
FWL_Error CFX_Graphics::Create(CFX_RenderDevice* renderDevice,
FX_BOOL isAntialiasing) {
@@ -596,13 +594,11 @@ FWL_Error CFX_Graphics::Create(int32_t width,
m_type = FX_CONTEXT_Device;
m_info.isAntialiasing = isAntialiasing;
- m_aggGraphics = new CAGG_Graphics;
+ m_aggGraphics.reset(new CAGG_Graphics);
return m_aggGraphics->Create(this, width, height, format);
}
-CFX_Graphics::~CFX_Graphics() {
- delete m_aggGraphics;
-}
+CFX_Graphics::~CFX_Graphics() {}
FWL_Error CFX_Graphics::GetDeviceCap(const int32_t capID,
FX_DeviceCap& capVal) {
diff --git a/xfa/fxgraphics/cfx_path.cpp b/xfa/fxgraphics/cfx_path.cpp
index 892a339469..5adeded977 100644
--- a/xfa/fxgraphics/cfx_path.cpp
+++ b/xfa/fxgraphics/cfx_path.cpp
@@ -9,22 +9,17 @@
#include "core/fxge/include/cfx_pathdata.h"
#include "xfa/fxgraphics/cfx_path_generator.h"
-CFX_Path::CFX_Path() {
- m_generator = nullptr;
-}
+CFX_Path::CFX_Path() {}
FWL_Error CFX_Path::Create() {
if (m_generator)
return FWL_Error::PropertyInvalid;
- m_generator = new CFX_PathGenerator;
- m_generator->Create();
+ m_generator.reset(new CFX_PathGenerator());
return FWL_Error::Succeeded;
}
-CFX_Path::~CFX_Path() {
- delete m_generator;
-}
+CFX_Path::~CFX_Path() {}
FWL_Error CFX_Path::MoveTo(FX_FLOAT x, FX_FLOAT y) {
if (!m_generator)
@@ -167,7 +162,7 @@ FWL_Error CFX_Path::Clear() {
return FWL_Error::Succeeded;
}
-FX_BOOL CFX_Path::IsEmpty() {
+FX_BOOL CFX_Path::IsEmpty() const {
if (!m_generator)
return FALSE;
if (m_generator->GetPathData()->GetPointCount() == 0)
@@ -175,7 +170,7 @@ FX_BOOL CFX_Path::IsEmpty() {
return FALSE;
}
-CFX_PathData* CFX_Path::GetPathData() {
+CFX_PathData* CFX_Path::GetPathData() const {
if (!m_generator)
return nullptr;
return m_generator->GetPathData();
diff --git a/xfa/fxgraphics/cfx_path.h b/xfa/fxgraphics/cfx_path.h
index f42586f0de..bfef04e591 100644
--- a/xfa/fxgraphics/cfx_path.h
+++ b/xfa/fxgraphics/cfx_path.h
@@ -7,16 +7,18 @@
#ifndef XFA_FXGRAPHICS_CFX_PATH_H_
#define XFA_FXGRAPHICS_CFX_PATH_H_
+#include <memory>
+
#include "core/fxcrt/include/fx_system.h"
#include "xfa/fxgraphics/include/cfx_graphics.h"
class CFX_PathData;
class CFX_PathGenerator;
-class CFX_Path {
+class CFX_Path final {
public:
CFX_Path();
- virtual ~CFX_Path();
+ ~CFX_Path();
FWL_Error Create();
FWL_Error MoveTo(FX_FLOAT x, FX_FLOAT y);
@@ -68,11 +70,11 @@ class CFX_Path {
FWL_Error AddSubpath(CFX_Path* path);
FWL_Error Clear();
- FX_BOOL IsEmpty();
- CFX_PathData* GetPathData();
+ FX_BOOL IsEmpty() const;
+ CFX_PathData* GetPathData() const;
private:
- CFX_PathGenerator* m_generator;
+ std::unique_ptr<CFX_PathGenerator> m_generator;
};
#endif // XFA_FXGRAPHICS_CFX_PATH_H_
diff --git a/xfa/fxgraphics/cfx_path_generator.cpp b/xfa/fxgraphics/cfx_path_generator.cpp
index f2dc182b55..aadaa85ad0 100644
--- a/xfa/fxgraphics/cfx_path_generator.cpp
+++ b/xfa/fxgraphics/cfx_path_generator.cpp
@@ -8,15 +8,9 @@
#include "core/fxge/include/cfx_pathdata.h"
-CFX_PathGenerator::CFX_PathGenerator() : m_pPathData(nullptr) {}
+CFX_PathGenerator::CFX_PathGenerator() : m_pPathData(new CFX_PathData) {}
-void CFX_PathGenerator::Create() {
- m_pPathData = new CFX_PathData;
-}
-
-CFX_PathGenerator::~CFX_PathGenerator() {
- delete m_pPathData;
-}
+CFX_PathGenerator::~CFX_PathGenerator() {}
void CFX_PathGenerator::AddPathData(CFX_PathData* pPathData) {
if (pPathData && pPathData->GetPointCount() > 0) {
@@ -25,6 +19,7 @@ void CFX_PathGenerator::AddPathData(CFX_PathData* pPathData) {
AddPathData(pPoints, nCount);
}
}
+
void CFX_PathGenerator::AddPathData(FX_PATHPOINT* pPoints, int nCount) {
if (pPoints && nCount > 0) {
int nOldCount = m_pPathData->GetPointCount();
@@ -34,14 +29,17 @@ void CFX_PathGenerator::AddPathData(FX_PATHPOINT* pPoints, int nCount) {
sizeof(FX_PATHPOINT) * nCount);
}
}
+
void CFX_PathGenerator::MoveTo(FX_FLOAT x, FX_FLOAT y) {
m_pPathData->AddPointCount(1);
m_pPathData->SetPoint(m_pPathData->GetPointCount() - 1, x, y, FXPT_MOVETO);
}
+
void CFX_PathGenerator::LineTo(FX_FLOAT x, FX_FLOAT y) {
m_pPathData->AddPointCount(1);
m_pPathData->SetPoint(m_pPathData->GetPointCount() - 1, x, y, FXPT_LINETO);
}
+
void CFX_PathGenerator::BezierTo(FX_FLOAT ctrl_x1,
FX_FLOAT ctrl_y1,
FX_FLOAT ctrl_x2,
@@ -54,6 +52,7 @@ void CFX_PathGenerator::BezierTo(FX_FLOAT ctrl_x1,
m_pPathData->SetPoint(old_count + 1, ctrl_x2, ctrl_y2, FXPT_BEZIERTO);
m_pPathData->SetPoint(old_count + 2, to_x, to_y, FXPT_BEZIERTO);
}
+
void CFX_PathGenerator::Close() {
if (m_pPathData->GetPointCount() > 0) {
int index = m_pPathData->GetPointCount() - 1;
@@ -61,6 +60,7 @@ void CFX_PathGenerator::Close() {
pPoints[index].m_Flag |= FXPT_CLOSEFIGURE;
}
}
+
void CFX_PathGenerator::AddLine(FX_FLOAT x1,
FX_FLOAT y1,
FX_FLOAT x2,
@@ -70,6 +70,7 @@ void CFX_PathGenerator::AddLine(FX_FLOAT x1,
m_pPathData->SetPoint(old_count, x1, y1, FXPT_MOVETO);
m_pPathData->SetPoint(old_count + 1, x2, y2, FXPT_LINETO);
}
+
void CFX_PathGenerator::AddBezier(FX_FLOAT start_x,
FX_FLOAT start_y,
FX_FLOAT ctrl_x1,
@@ -85,18 +86,21 @@ void CFX_PathGenerator::AddBezier(FX_FLOAT start_x,
m_pPathData->SetPoint(old_count + 2, ctrl_x2, ctrl_y2, FXPT_BEZIERTO);
m_pPathData->SetPoint(old_count + 3, end_x, end_y, FXPT_BEZIERTO);
}
+
void CFX_PathGenerator::AddRectangle(FX_FLOAT x1,
FX_FLOAT y1,
FX_FLOAT x2,
FX_FLOAT y2) {
m_pPathData->AppendRect(x1, y1, x2, y2);
}
+
void CFX_PathGenerator::AddEllipse(FX_FLOAT x,
FX_FLOAT y,
FX_FLOAT width,
FX_FLOAT height) {
AddArc(x, y, width, height, 0, FX_PI * 2);
}
+
void CFX_PathGenerator::ArcTo(FX_FLOAT x,
FX_FLOAT y,
FX_FLOAT width,
@@ -127,6 +131,7 @@ void CFX_PathGenerator::ArcTo(FX_FLOAT x,
bezier_y = y + (height * FXSYS_sin(start_angle + sweep_angle));
m_pPathData->SetPoint(old_count + 2, bezier_x, bezier_y, FXPT_BEZIERTO);
}
+
void CFX_PathGenerator::AddArc(FX_FLOAT x,
FX_FLOAT y,
FX_FLOAT width,
@@ -178,6 +183,7 @@ void CFX_PathGenerator::AddArc(FX_FLOAT x,
start_angle += local_sweep;
} while (!done);
}
+
void CFX_PathGenerator::AddPie(FX_FLOAT x,
FX_FLOAT y,
FX_FLOAT width,
diff --git a/xfa/fxgraphics/cfx_path_generator.h b/xfa/fxgraphics/cfx_path_generator.h
index 186178e516..0fed30f93f 100644
--- a/xfa/fxgraphics/cfx_path_generator.h
+++ b/xfa/fxgraphics/cfx_path_generator.h
@@ -7,6 +7,8 @@
#ifndef XFA_FXGRAPHICS_CFX_PATH_GENERATOR_H_
#define XFA_FXGRAPHICS_CFX_PATH_GENERATOR_H_
+#include <memory>
+
#include "core/fxge/include/cfx_pathdata.h"
#include "core/fxge/include/fx_ge.h"
@@ -15,8 +17,7 @@ class CFX_PathGenerator {
CFX_PathGenerator();
~CFX_PathGenerator();
- void Create();
- CFX_PathData* GetPathData() const { return m_pPathData; }
+ CFX_PathData* GetPathData() const { return m_pPathData.get(); }
void AddPathData(CFX_PathData* path_data);
void AddPathData(FX_PATHPOINT* points, int count);
@@ -62,7 +63,7 @@ class CFX_PathGenerator {
FX_FLOAT sweep_angle);
protected:
- CFX_PathData* m_pPathData;
+ std::unique_ptr<CFX_PathData> m_pPathData;
};
#endif // XFA_FXGRAPHICS_CFX_PATH_GENERATOR_H_
diff --git a/xfa/fxgraphics/include/cfx_graphics.h b/xfa/fxgraphics/include/cfx_graphics.h
index 916fba57c7..e581089aec 100644
--- a/xfa/fxgraphics/include/cfx_graphics.h
+++ b/xfa/fxgraphics/include/cfx_graphics.h
@@ -7,6 +7,8 @@
#ifndef XFA_FXGRAPHICS_INCLUDE_CFX_GRAPHICS_H_
#define XFA_FXGRAPHICS_INCLUDE_CFX_GRAPHICS_H_
+#include <memory>
+
#include "core/fxcrt/include/fx_system.h"
#include "core/fxge/include/fx_dib.h"
#include "core/fxge/include/fx_ge.h"
@@ -230,7 +232,7 @@ class CFX_Graphics {
CFX_RenderDevice* m_renderDevice;
CFX_ArrayTemplate<TInfo*> m_infoStack;
- CAGG_Graphics* m_aggGraphics;
+ std::unique_ptr<CAGG_Graphics> m_aggGraphics;
friend class CAGG_Graphics;
};