summaryrefslogtreecommitdiff
path: root/core/fxge
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-09-24 17:55:00 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-09-24 17:55:00 +0000
commitfed6e124109f089a38e24e37b104d983231bee78 (patch)
tree6c1aa45a97eb27c67611dbe7480bdbcd26710d14 /core/fxge
parent97f4483de007c2ff248696f24d34634e0adbf894 (diff)
downloadpdfium-fed6e124109f089a38e24e37b104d983231bee78.tar.xz
Give CFX_GraphStateData a work-over.chromium/3561
Use std::vector<float> for dash array. Use compiler-generated default operations. Squeeze some enums. Fix obvious logic botch in DashChanged(). Change-Id: If1d809cc46a3cf2db98a09a3f5a49d22138c0640 Reviewed-on: https://pdfium-review.googlesource.com/42613 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxge')
-rw-r--r--core/fxge/agg/fx_agg_driver.cpp6
-rw-r--r--core/fxge/cfx_graphstate.cpp2
-rw-r--r--core/fxge/cfx_graphstatedata.cpp52
-rw-r--r--core/fxge/cfx_graphstatedata.h36
-rw-r--r--core/fxge/cfx_renderdevice.cpp5
-rw-r--r--core/fxge/skia/fx_skia_device.cpp27
-rw-r--r--core/fxge/win32/cfx_psrenderer.cpp11
-rw-r--r--core/fxge/win32/fx_win32_device.cpp14
-rw-r--r--core/fxge/win32/fx_win32_gdipext.cpp10
9 files changed, 65 insertions, 98 deletions
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp
index 063f36d600..69006b6083 100644
--- a/core/fxge/agg/fx_agg_driver.cpp
+++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -285,14 +285,14 @@ void RasterizeStroke(agg::rasterizer_scanline_aa* rasterizer,
1.0f / ((pObject2Device->GetXUnit() + pObject2Device->GetYUnit()) / 2);
}
width = std::max(width, unit);
- if (pGraphState->m_DashArray) {
+ if (!pGraphState->m_DashArray.empty()) {
typedef agg::conv_dash<agg::path_storage> dash_converter;
dash_converter dash(*path_data);
- for (int i = 0; i < (pGraphState->m_DashCount + 1) / 2; i++) {
+ for (size_t i = 0; i < (pGraphState->m_DashArray.size() + 1) / 2; i++) {
float on = pGraphState->m_DashArray[i * 2];
if (on <= 0.000001f)
on = 1.0f / 10;
- float off = i * 2 + 1 == pGraphState->m_DashCount
+ float off = i * 2 + 1 == pGraphState->m_DashArray.size()
? on
: pGraphState->m_DashArray[i * 2 + 1];
off = std::max(off, 0.0f);
diff --git a/core/fxge/cfx_graphstate.cpp b/core/fxge/cfx_graphstate.cpp
index ad6b5fc6c7..919faa39c6 100644
--- a/core/fxge/cfx_graphstate.cpp
+++ b/core/fxge/cfx_graphstate.cpp
@@ -22,7 +22,7 @@ void CFX_GraphState::Emplace() {
void CFX_GraphState::SetLineDash(CPDF_Array* pArray, float phase, float scale) {
CFX_GraphStateData* pData = m_Ref.GetPrivateCopy();
pData->m_DashPhase = phase * scale;
- pData->SetDashCount(static_cast<int>(pArray->GetCount()));
+ pData->m_DashArray.resize(pArray->GetCount());
for (size_t i = 0; i < pArray->GetCount(); i++)
pData->m_DashArray[i] = pArray->GetNumberAt(i) * scale;
}
diff --git a/core/fxge/cfx_graphstatedata.cpp b/core/fxge/cfx_graphstatedata.cpp
index 82fede176a..3bea040793 100644
--- a/core/fxge/cfx_graphstatedata.cpp
+++ b/core/fxge/cfx_graphstatedata.cpp
@@ -6,47 +6,23 @@
#include "core/fxge/cfx_graphstatedata.h"
-#include "core/fxcrt/fx_memory.h"
-#include "core/fxcrt/fx_system.h"
-
-CFX_GraphStateData::CFX_GraphStateData()
- : m_LineCap(LineCapButt),
- m_DashCount(0),
- m_DashArray(nullptr),
- m_DashPhase(0),
- m_LineJoin(LineJoinMiter),
- m_MiterLimit(10 * 1.0f),
- m_LineWidth(1.0f) {}
+CFX_GraphStateData::CFX_GraphStateData() = default;
CFX_GraphStateData::CFX_GraphStateData(const CFX_GraphStateData& src) {
- m_DashArray = nullptr;
- Copy(src);
+ *this = src;
}
-void CFX_GraphStateData::Copy(const CFX_GraphStateData& src) {
- m_LineCap = src.m_LineCap;
- m_DashCount = src.m_DashCount;
- FX_Free(m_DashArray);
- m_DashArray = nullptr;
- m_DashPhase = src.m_DashPhase;
- m_LineJoin = src.m_LineJoin;
- m_MiterLimit = src.m_MiterLimit;
- m_LineWidth = src.m_LineWidth;
- if (m_DashCount) {
- m_DashArray = FX_Alloc(float, m_DashCount);
- memcpy(m_DashArray, src.m_DashArray, m_DashCount * sizeof(float));
+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;
}
-}
-
-CFX_GraphStateData::~CFX_GraphStateData() {
- FX_Free(m_DashArray);
-}
-
-void CFX_GraphStateData::SetDashCount(int count) {
- FX_Free(m_DashArray);
- m_DashArray = nullptr;
- m_DashCount = count;
- if (count == 0)
- return;
- m_DashArray = FX_Alloc(float, count);
+ return *this;
}
diff --git a/core/fxge/cfx_graphstatedata.h b/core/fxge/cfx_graphstatedata.h
index a907f2a922..5604802449 100644
--- a/core/fxge/cfx_graphstatedata.h
+++ b/core/fxge/cfx_graphstatedata.h
@@ -7,33 +7,37 @@
#ifndef CORE_FXGE_CFX_GRAPHSTATEDATA_H_
#define CORE_FXGE_CFX_GRAPHSTATEDATA_H_
+#include <vector>
+
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/retain_ptr.h"
class CFX_GraphStateData final : public Retainable {
public:
- enum LineCap { LineCapButt = 0, LineCapRound = 1, LineCapSquare = 2 };
+ enum LineCap : uint8_t {
+ LineCapButt = 0,
+ LineCapRound = 1,
+ LineCapSquare = 2
+ };
+
+ enum LineJoin : uint8_t {
+ LineJoinMiter = 0,
+ LineJoinRound = 1,
+ LineJoinBevel = 2
+ };
CFX_GraphStateData();
CFX_GraphStateData(const CFX_GraphStateData& src);
~CFX_GraphStateData() override;
- void Copy(const CFX_GraphStateData& src);
- void SetDashCount(int count);
-
- LineCap m_LineCap;
- int m_DashCount;
- float* m_DashArray;
- float m_DashPhase;
+ CFX_GraphStateData& operator=(const CFX_GraphStateData& src);
- enum LineJoin {
- LineJoinMiter = 0,
- LineJoinRound = 1,
- LineJoinBevel = 2,
- };
- LineJoin m_LineJoin;
- float m_MiterLimit;
- float m_LineWidth;
+ LineCap m_LineCap = LineCapButt;
+ LineJoin m_LineJoin = LineJoinMiter;
+ float m_DashPhase = 0.0f;
+ float m_MiterLimit = 10.0f;
+ float m_LineWidth = 1.0f;
+ std::vector<float> m_DashArray;
};
#endif // CORE_FXGE_CFX_GRAPHSTATEDATA_H_
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index ab57391401..f00d7f9d01 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -1231,11 +1231,8 @@ void CFX_RenderDevice::DrawBorder(const CFX_Matrix* pUser2Device,
FXPT_TYPE::LineTo, false);
CFX_GraphStateData gsd;
- gsd.SetDashCount(2);
- gsd.m_DashArray[0] = 3.0f;
- gsd.m_DashArray[1] = 3.0f;
+ gsd.m_DashArray = {3.0f, 3.0f};
gsd.m_DashPhase = 0;
-
gsd.m_LineWidth = fWidth;
DrawPath(&path, pUser2Device, &gsd, 0, color.ToFXColor(nTransparency),
FXFILL_WINDING);
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index 2ffd446023..a06fcaaa55 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -734,7 +734,7 @@ class SkiaState {
? SkPath::kEvenOdd_FillType
: SkPath::kWinding_FillType);
if (pDrawState)
- m_drawState.Copy(*pDrawState);
+ m_drawState = *pDrawState;
m_fillColor = fill_color;
m_strokeColor = stroke_color;
m_blendType = blend_type;
@@ -1139,20 +1139,13 @@ class SkiaState {
bool DashChanged(const CFX_GraphStateData* pState,
const CFX_GraphStateData& refState) const {
- bool dashArray = pState && pState->m_DashArray;
- if (!dashArray && !refState.m_DashArray)
+ bool dashArray = pState && !pState->m_DashArray.empty();
+ if (!dashArray && refState.m_DashArray.empty())
return false;
- if (!dashArray || !refState.m_DashArray)
+ if (!dashArray || refState.m_DashArray.empty())
return true;
- if (pState->m_DashPhase != refState.m_DashPhase ||
- pState->m_DashCount != refState.m_DashCount) {
- return true;
- }
- for (int index = 0; index < pState->m_DashCount; ++index) {
- if (pState->m_DashArray[index] != refState.m_DashArray[index])
- return true;
- }
- return true;
+ return pState->m_DashPhase != refState.m_DashPhase ||
+ pState->m_DashArray != refState.m_DashArray;
}
void AdjustClip(int limit) {
@@ -1476,16 +1469,16 @@ void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint,
float width =
SkTMax(pGraphState->m_LineWidth,
SkTMin(deviceUnits[0].length(), deviceUnits[1].length()));
- if (pGraphState->m_DashArray) {
- int count = (pGraphState->m_DashCount + 1) / 2;
+ if (!pGraphState->m_DashArray.empty()) {
+ size_t count = (pGraphState->m_DashArray.size() + 1) / 2;
std::unique_ptr<SkScalar, FxFreeDeleter> intervals(
FX_Alloc2D(SkScalar, count, sizeof(SkScalar)));
// Set dash pattern
- for (int i = 0; i < count; i++) {
+ for (size_t i = 0; i < count; i++) {
float on = pGraphState->m_DashArray[i * 2];
if (on <= 0.000001f)
on = 1.f / 10;
- float off = i * 2 + 1 == pGraphState->m_DashCount
+ float off = i * 2 + 1 == pGraphState->m_DashArray.size()
? on
: pGraphState->m_DashArray[i * 2 + 1];
if (off < 0)
diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp
index dbc212123c..12795d0cc5 100644
--- a/core/fxge/win32/cfx_psrenderer.cpp
+++ b/core/fxge/win32/cfx_psrenderer.cpp
@@ -311,13 +311,10 @@ void CFX_PSRenderer::SetGraphState(const CFX_GraphStateData* pGraphState) {
buf << pGraphState->m_LineCap << " J\n";
}
if (!m_bGraphStateSet ||
- m_CurGraphState.m_DashCount != pGraphState->m_DashCount ||
- memcmp(m_CurGraphState.m_DashArray, pGraphState->m_DashArray,
- sizeof(float) * m_CurGraphState.m_DashCount)) {
+ m_CurGraphState.m_DashArray != pGraphState->m_DashArray) {
buf << "[";
- for (int i = 0; i < pGraphState->m_DashCount; ++i)
- buf << pGraphState->m_DashArray[i] << " ";
-
+ for (const auto& dash : pGraphState->m_DashArray)
+ buf << dash << " ";
buf << "]" << pGraphState->m_DashPhase << " d\n";
}
if (!m_bGraphStateSet ||
@@ -332,7 +329,7 @@ void CFX_PSRenderer::SetGraphState(const CFX_GraphStateData* pGraphState) {
m_CurGraphState.m_MiterLimit != pGraphState->m_MiterLimit) {
buf << pGraphState->m_MiterLimit << " M\n";
}
- m_CurGraphState.Copy(*pGraphState);
+ m_CurGraphState = *pGraphState;
m_bGraphStateSet = true;
WriteToStream(&buf);
}
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp
index c8f049704f..526eea58f3 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -103,7 +103,7 @@ HPEN CreateExtPen(const CFX_GraphStateData* pGraphState,
float width = std::max(scale * pGraphState->m_LineWidth, 1.0f);
uint32_t PenStyle = PS_GEOMETRIC;
- if (pGraphState->m_DashCount)
+ if (!pGraphState->m_DashArray.empty())
PenStyle |= PS_USERSTYLE;
else
PenStyle |= PS_SOLID;
@@ -137,9 +137,9 @@ HPEN CreateExtPen(const CFX_GraphStateData* pGraphState,
lb.lbStyle = BS_SOLID;
lb.lbHatch = 0;
std::vector<uint32_t> dashes;
- if (pGraphState->m_DashCount) {
- dashes.resize(pGraphState->m_DashCount);
- for (int i = 0; i < pGraphState->m_DashCount; i++) {
+ if (!pGraphState->m_DashArray.empty()) {
+ dashes.resize(pGraphState->m_DashArray.size());
+ for (size_t i = 0; i < pGraphState->m_DashArray.size(); i++) {
dashes[i] = FXSYS_round(
pMatrix ? pMatrix->TransformDistance(pGraphState->m_DashArray[i])
: pGraphState->m_DashArray[i]);
@@ -147,7 +147,7 @@ HPEN CreateExtPen(const CFX_GraphStateData* pGraphState,
}
}
return ExtCreatePen(PenStyle, (DWORD)ceil(width), &lb,
- pGraphState->m_DashCount,
+ pGraphState->m_DashArray.size(),
reinterpret_cast<const DWORD*>(dashes.data()));
}
@@ -994,7 +994,7 @@ bool CGdiDeviceDriver::DrawPath(const CFX_PathData* pPathData,
if (pPlatform->m_GdiplusExt.IsAvailable()) {
if (bDrawAlpha ||
((m_DeviceClass != FXDC_PRINTER && !(fill_mode & FXFILL_FULLCOVER)) ||
- (pGraphState && pGraphState->m_DashCount))) {
+ (pGraphState && !pGraphState->m_DashArray.empty()))) {
if (!((!pMatrix || !pMatrix->WillScale()) && pGraphState &&
pGraphState->m_LineWidth == 1.0f &&
(pPathData->GetPoints().size() == 5 ||
@@ -1023,7 +1023,7 @@ bool CGdiDeviceDriver::DrawPath(const CFX_PathData* pPathData,
hBrush = (HBRUSH)SelectObject(m_hDC, hBrush);
}
if (pPathData->GetPoints().size() == 2 && pGraphState &&
- pGraphState->m_DashCount) {
+ !pGraphState->m_DashArray.empty()) {
CFX_PointF pos1 = pPathData->GetPoint(0);
CFX_PointF pos2 = pPathData->GetPoint(1);
if (pMatrix) {
diff --git a/core/fxge/win32/fx_win32_gdipext.cpp b/core/fxge/win32/fx_win32_gdipext.cpp
index eee6b8798a..8d361e7c5e 100644
--- a/core/fxge/win32/fx_win32_gdipext.cpp
+++ b/core/fxge/win32/fx_win32_gdipext.cpp
@@ -770,15 +770,15 @@ GpPen* GdipCreatePenImpl(const CFX_GraphStateData* pGraphState,
break;
}
CallFunc(GdipSetPenLineJoin)(pPen, lineJoin);
- if (pGraphState->m_DashCount) {
- float* pDashArray = FX_Alloc(
- float, pGraphState->m_DashCount + pGraphState->m_DashCount % 2);
+ if (!pGraphState->m_DashArray.empty()) {
+ float* pDashArray =
+ FX_Alloc(float, (pGraphState->m_DashArray.size() + 1) & ~1);
int nCount = 0;
float on_leftover = 0, off_leftover = 0;
- for (int i = 0; i < pGraphState->m_DashCount; i += 2) {
+ for (size_t i = 0; i < pGraphState->m_DashArray.size(); i += 2) {
float on_phase = pGraphState->m_DashArray[i];
float off_phase;
- if (i == pGraphState->m_DashCount - 1)
+ if (i == pGraphState->m_DashArray.size() - 1)
off_phase = on_phase;
else
off_phase = pGraphState->m_DashArray[i + 1];