code refactoring 03/241303/2
authorHermet Park <chuneon.park@samsung.com>
Wed, 19 Aug 2020 05:50:49 +0000 (14:50 +0900)
committerHermet Park <chuneon.park@samsung.com>
Wed, 19 Aug 2020 05:53:38 +0000 (14:53 +0900)
Now, stabilizing is pretty enough.

Remove assert code so that we never abort process in any cases.
This also reduce the binary size.

Change-Id: Ia7d2d5c5a0757b12481eaebad7a86aade6a89c1e

15 files changed:
src/lib/sw_engine/tvgSwFill.cpp
src/lib/sw_engine/tvgSwMath.cpp
src/lib/sw_engine/tvgSwRenderer.cpp
src/lib/sw_engine/tvgSwRle.cpp
src/lib/sw_engine/tvgSwShape.cpp
src/lib/sw_engine/tvgSwStroke.cpp
src/lib/tvgCommon.h
src/lib/tvgGlCanvas.cpp
src/lib/tvgLinearGradient.cpp
src/lib/tvgRadialGradient.cpp
src/lib/tvgRender.cpp
src/lib/tvgRender.h
src/lib/tvgShapeImpl.h
src/lib/tvgShapePath.h
src/lib/tvgSwCanvas.cpp

index 1539c17..ccc0574 100644 (file)
 
 static bool _updateColorTable(SwFill* fill, const Fill* fdata, SwSurface* surface)
 {
-    assert(fill && fdata);
-
     if (!fill->ctable) {
         fill->ctable = static_cast<uint32_t*>(malloc(GRADIENT_STOP_SIZE * sizeof(uint32_t)));
-        assert(fill->ctable);
+        if (!fill->ctable) return false;
     }
 
     const Fill::ColorStop* colors;
@@ -71,7 +69,6 @@ static bool _updateColorTable(SwFill* fill, const Fill* fdata, SwSurface* surfac
     for (uint32_t j = 0; j < cnt - 1; ++j) {
         auto curr = colors + j;
         auto next = curr + 1;
-        assert(curr && next);
         auto delta = 1.0f / (next->offset - curr->offset);
         if (next->a < 255) fill->translucent = true;
 
@@ -104,8 +101,6 @@ static bool _updateColorTable(SwFill* fill, const Fill* fdata, SwSurface* surfac
 
 bool _prepareLinear(SwFill* fill, const LinearGradient* linear, const Matrix* transform)
 {
-    assert(fill && linear);
-
     float x1, x2, y1, y2;
     if (linear->linear(&x1, &y1, &x2, &y2) != Result::Success) return false;
 
@@ -140,8 +135,6 @@ bool _prepareLinear(SwFill* fill, const LinearGradient* linear, const Matrix* tr
 
 bool _prepareRadial(SwFill* fill, const RadialGradient* radial, const Matrix* transform)
 {
-    assert(fill && radial);
-
     float radius;
     if (radial->radial(&fill->radial.cx, &fill->radial.cy, &radius) != Result::Success) return false;
     if (radius < FLT_EPSILON) return true;
@@ -286,8 +279,6 @@ bool fillGenColorTable(SwFill* fill, const Fill* fdata, const Matrix* transform,
 {
     if (!fill) return false;
 
-    assert(fdata);
-
     fill->spread = fdata->spread();
 
     if (ctable) {
index 5ac3912..5227d79 100644 (file)
@@ -384,8 +384,6 @@ SwFixed mathLength(SwPoint& pt)
 
 void mathSplitCubic(SwPoint* base)
 {
-    assert(base);
-
     SwCoord a, b, c, d;
 
     base[6].x = base[3].x;
index 8d02b40..b173ce4 100644 (file)
@@ -101,7 +101,7 @@ void* SwRenderer::prepare(const Shape& sdata, void* data, const RenderTransform*
     auto shape = static_cast<SwShape*>(data);
     if (!shape) {
         shape = static_cast<SwShape*>(calloc(1, sizeof(SwShape)));
-        assert(shape);
+        if (!shape) return nullptr;
     }
 
     if (flags == RenderUpdateFlag::None) return shape;
index fb4b87b..c9aa6ae 100644 (file)
@@ -145,8 +145,6 @@ static inline SwCoord HYPOT(SwPoint pt)
 
 static void _genSpan(SwRleData* rle, SwSpan* spans, uint32_t count)
 {
-    assert(rle && spans);
-
     auto newSize = rle->size + count;
 
     /* allocate enough memory for new spans */
@@ -155,12 +153,10 @@ static void _genSpan(SwRleData* rle, SwSpan* spans, uint32_t count)
     if (rle->alloc < newSize) {
         rle->alloc = (newSize * 2);
         rle->spans = static_cast<SwSpan*>(realloc(rle->spans, rle->alloc * sizeof(SwSpan)));
-        assert(rle->spans);
     }
 
     //copy the new spans to the allocated memory
     SwSpan* lastSpan = rle->spans + rle->size;
-    assert(lastSpan);
     memcpy(lastSpan, spans, count * sizeof(SwSpan));
 
     rle->size = newSize;
@@ -205,7 +201,6 @@ static void _horizLine(RleWorker& rw, SwCoord x, SwCoord y, SwCoord area, SwCoor
         if (!rw.antiAlias) coverage = 255;
         auto count = rw.spansCnt;
         auto span = rw.spans + count - 1;
-        assert(span);
 
         //see whether we can add this span to the current list
         if ((count > 0) && (rw.ySpan == y) &&
@@ -226,10 +221,8 @@ static void _horizLine(RleWorker& rw, SwCoord x, SwCoord y, SwCoord area, SwCoor
             rw.spansCnt = 0;
             rw.ySpan = 0;
             span = rw.spans;
-            assert(span);
         } else {
             ++span;
-            assert(span);
         }
 
         //Clip x range
@@ -290,7 +283,6 @@ static Cell* _findCell(RleWorker& rw)
     if (x > rw.cellXCnt) x = rw.cellXCnt;
 
     auto pcell = &rw.yCells[rw.cellPos.y];
-    assert(pcell);
 
     while(true) {
         Cell* cell = *pcell;
@@ -302,7 +294,6 @@ static Cell* _findCell(RleWorker& rw)
     if (rw.cellsCnt >= rw.maxCells) longjmp(rw.jmpBuf, 1);
 
     auto cell = rw.cells + rw.cellsCnt++;
-    assert(cell);
     cell->x = x;
     cell->area = 0;
     cell->cover = 0;
@@ -317,7 +308,6 @@ static void _recordCell(RleWorker& rw)
 {
     if (rw.area | rw.cover) {
         auto cell = _findCell(rw);
-        assert(cell);
         cell->area += rw.area;
         cell->cover += rw.cover;
     }
@@ -498,8 +488,6 @@ static void _lineTo(RleWorker& rw, const SwPoint& to)
 static void _cubicTo(RleWorker& rw, const SwPoint& ctrl1, const SwPoint& ctrl2, const SwPoint& to)
 {
     auto arc = rw.bezStack;
-    assert(arc);
-
     arc[0] = to;
     arc[1] = ctrl2;
     arc[2] = ctrl1;
@@ -668,7 +656,6 @@ SwRleData* rleRender(const SwOutline* outline, const SwBBox& bbox, const SwSize&
     rw.clip = clip;
     rw.antiAlias = antiAlias;
     rw.rle = reinterpret_cast<SwRleData*>(calloc(1, sizeof(SwRleData)));
-    assert(rw.rle);
 
     //Generate RLE
     Band bands[BAND_SIZE];
index c94ef26..f14d3b6 100644 (file)
@@ -76,7 +76,6 @@ static void _growOutlineContour(SwOutline& outline, uint32_t n)
     if (outline.reservedCntrsCnt >= outline.cntrsCnt + n) return;
     outline.reservedCntrsCnt = outline.cntrsCnt + n;
     outline.cntrs = static_cast<uint32_t*>(realloc(outline.cntrs, outline.reservedCntrsCnt * sizeof(uint32_t)));
-    assert(outline.cntrs);
 }
 
 
@@ -85,9 +84,7 @@ static void _growOutlinePoint(SwOutline& outline, uint32_t n)
     if (outline.reservedPtsCnt >= outline.ptsCnt + n) return;
     outline.reservedPtsCnt = outline.ptsCnt + n;
     outline.pts = static_cast<SwPoint*>(realloc(outline.pts, outline.reservedPtsCnt * sizeof(SwPoint)));
-    assert(outline.pts);
     outline.types = static_cast<uint8_t*>(realloc(outline.types, outline.reservedPtsCnt * sizeof(uint8_t)));
-    assert(outline.types);
 }
 
 
@@ -114,8 +111,6 @@ static void _outlineEnd(SwOutline& outline)
 
 static void _outlineMoveTo(SwOutline& outline, const Point* to, const Matrix* transform)
 {
-    assert(to);
-
     _growOutlinePoint(outline, 1);
 
     outline.pts[outline.ptsCnt] = _transform(to, transform);
@@ -134,8 +129,6 @@ static void _outlineMoveTo(SwOutline& outline, const Point* to, const Matrix* tr
 
 static void _outlineLineTo(SwOutline& outline, const Point* to, const Matrix* transform)
 {
-    assert(to);
-
     _growOutlinePoint(outline, 1);
 
     outline.pts[outline.ptsCnt] = _transform(to, transform);
@@ -146,8 +139,6 @@ static void _outlineLineTo(SwOutline& outline, const Point* to, const Matrix* tr
 
 static void _outlineCubicTo(SwOutline& outline, const Point* ctrl1, const Point* ctrl2, const Point* to, const Matrix* transform)
 {
-    assert(ctrl1 && ctrl2 && to);
-
     _growOutlinePoint(outline, 3);
 
     outline.pts[outline.ptsCnt] = _transform(ctrl1, transform);
@@ -203,7 +194,6 @@ static bool _updateBBox(SwOutline* outline, SwBBox& bbox)
     if (!outline) return false;
 
     auto pt = outline->pts;
-    assert(pt);
 
     if (outline->ptsCnt <= 0) {
         _initBBox(bbox);
@@ -236,8 +226,6 @@ static bool _updateBBox(SwOutline* outline, SwBBox& bbox)
 
 static bool _checkValid(const SwOutline* outline, const SwBBox& bbox, const SwSize& clip)
 {
-    assert(outline);
-
     if (outline->ptsCnt == 0 || outline->cntrsCnt <= 0) return false;
 
     //Check boundary
@@ -341,8 +329,6 @@ static void _dashCubicTo(SwDashStroke& dash, const Point* ctrl1, const Point* ct
 
 SwOutline* _genDashOutline(const Shape* sdata, const Matrix* transform)
 {
-    assert(sdata);
-
     const PathCommand* cmds = nullptr;
     auto cmdCnt = sdata->pathCommands(&cmds);
 
@@ -361,12 +347,10 @@ SwOutline* _genDashOutline(const Shape* sdata, const Matrix* transform)
 
     const float* pattern;
     dash.cnt = sdata->strokeDash(&pattern);
-    assert(dash.cnt > 0 && pattern);
 
     //Is it safe to mutual exclusive?
     dash.pattern = const_cast<float*>(pattern);
     dash.outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline)));
-    assert(dash.outline);
     dash.outline->opened = true;
 
     //smart reservation
@@ -510,8 +494,6 @@ void shapeReset(SwShape* shape)
 
 bool shapeGenOutline(SwShape* shape, const Shape* sdata, const Matrix* transform)
 {
-    assert(sdata);
-
     const PathCommand* cmds = nullptr;
     auto cmdCnt = sdata->pathCommands(&cmds);
 
@@ -552,7 +534,6 @@ bool shapeGenOutline(SwShape* shape, const Shape* sdata, const Matrix* transform
 
     auto outline = shape->outline;
     if (!outline) outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline)));
-    assert(outline);
     outline->opened = true;
 
     _growOutlinePoint(*outline, outlinePtsCnt);
@@ -638,8 +619,6 @@ void shapeResetStroke(SwShape* shape, const Shape* sdata, const Matrix* transfor
 
 bool shapeGenStrokeRle(SwShape* shape, const Shape* sdata, const Matrix* transform, const SwSize& clip)
 {
-    assert(sdata);
-
     SwOutline* shapeOutline = nullptr;
 
     //Dash Style Stroke
index 94c738c..8400237 100644 (file)
@@ -48,8 +48,6 @@ static inline void SCALE(SwStroke& stroke, SwPoint& pt)
 
 static void _growBorder(SwStrokeBorder* border, uint32_t newPts)
 {
-    assert(border);
-
     auto maxOld = border->maxPts;
     auto maxNew = border->ptsCnt + newPts;
 
@@ -61,21 +59,15 @@ static void _growBorder(SwStrokeBorder* border, uint32_t newPts)
         maxCur += (maxCur >> 1) + 16;
 
     border->pts = static_cast<SwPoint*>(realloc(border->pts, maxCur * sizeof(SwPoint)));
-    assert(border->pts);
-
     border->tags = static_cast<uint8_t*>(realloc(border->tags, maxCur * sizeof(uint8_t)));
-    assert(border->tags);
-
     border->maxPts = maxCur;
 }
 
 
 static void _borderClose(SwStrokeBorder* border, bool reverse)
 {
-    assert(border && border->start >= 0);
-
-    uint32_t start = border->start;
-    uint32_t count = border->ptsCnt;
+    auto start = border->start;
+    auto count = border->ptsCnt;
 
     //Don't record empty paths!
     if (count <= start + 1U) {
@@ -123,8 +115,6 @@ static void _borderClose(SwStrokeBorder* border, bool reverse)
 
 static void _borderCubicTo(SwStrokeBorder* border, SwPoint& ctrl1, SwPoint& ctrl2, SwPoint& to)
 {
-    assert(border && border->start >= 0);
-
     _growBorder(border, 3);
 
     auto pt = border->pts + border->ptsCnt;
@@ -199,8 +189,6 @@ static void _borderArcTo(SwStrokeBorder* border, SwPoint& center, SwFixed radius
 
 static void _borderLineTo(SwStrokeBorder* border, SwPoint& to, bool movable)
 {
-    assert(border && border->start >= 0);
-
     if (border->movable) {
         //move last point
         border->pts[border->ptsCnt - 1] = to;
@@ -221,8 +209,6 @@ static void _borderLineTo(SwStrokeBorder* border, SwPoint& to, bool movable)
 
 static void _borderMoveTo(SwStrokeBorder* border, SwPoint& to)
 {
-    assert(border);
-
     //close current open path if any?
     if (border->start >= 0) _borderClose(border, false);
 
@@ -249,10 +235,7 @@ static void _outside(SwStroke& stroke, int32_t side, SwFixed lineLength)
 {
     constexpr SwFixed MITER_LIMIT = 4 * (1 << 16);
 
-    assert(MITER_LIMIT >= 0x10000);
-
     auto border = stroke.borders + side;
-    assert(border);
 
     if (stroke.join == StrokeJoin::Round) {
         _arcTo(stroke, side);
@@ -640,8 +623,6 @@ static void _addReverseLeft(SwStroke& stroke, bool opened)
 {
     auto right = stroke.borders + 0;
     auto left = stroke.borders + 1;
-    assert(left->start >= 0);
-
     auto newPts = left->ptsCnt - left->start;
 
     if (newPts <= 0) return;
@@ -708,7 +689,6 @@ static void _endSubPath(SwStroke& stroke)
 {
     if (stroke.openSubPath) {
         auto right = stroke.borders;
-        assert(right);
 
         /* all right, this is an opened path, we need to add a cap between
            right & left, add the reverse of left, then add a final cap
@@ -756,8 +736,6 @@ static void _endSubPath(SwStroke& stroke)
 
 static void _getCounts(SwStrokeBorder* border, uint32_t& ptsCnt, uint32_t& cntrsCnt)
 {
-    assert(border);
-
     auto count = border->ptsCnt;
     auto tags = border->tags;
     uint32_t _ptsCnt = 0;
@@ -796,7 +774,6 @@ fail:
 static void _exportBorderOutline(SwStroke& stroke, SwOutline* outline, uint32_t side)
 {
     auto border = stroke.borders + side;
-    assert(border);
 
     if (!border->valid) return;
 
@@ -850,8 +827,6 @@ void strokeFree(SwStroke* stroke)
 
 void strokeReset(SwStroke* stroke, const Shape* sdata, const Matrix* transform)
 {
-    assert(sdata);
-
     if (transform) {
         stroke->sx = sqrt(pow(transform->e11, 2) + pow(transform->e21, 2));
         stroke->sy = sqrt(pow(transform->e12, 2) + pow(transform->e22, 2));
@@ -941,16 +916,9 @@ SwOutline* strokeExportOutline(SwStroke* stroke)
     auto cntrsCnt = count2 + count4;
 
     auto outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline)));
-    assert(outline);
-
     outline->pts = static_cast<SwPoint*>(malloc(sizeof(SwPoint) * ptsCnt));
-    assert(outline->pts);
-
     outline->types = static_cast<uint8_t*>(malloc(sizeof(uint8_t) * ptsCnt));
-    assert(outline->types);
-
     outline->cntrs = static_cast<uint32_t*>(malloc(sizeof(uint32_t) * cntrsCnt));
-    assert(outline->cntrs);
 
     _exportBorderOutline(*stroke, outline, 0);  //left
     _exportBorderOutline(*stroke, outline, 1);  //right
index 0c73b91..66e08bf 100644 (file)
@@ -25,7 +25,6 @@
 #include "config.h"
 
 #include <iostream>
-#include <cassert>
 #include <vector>
 #include <math.h>
 #include <float.h>
index 1ac5732..e1b5c3c 100644 (file)
@@ -81,10 +81,7 @@ Result GlCanvas::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t
 unique_ptr<GlCanvas> GlCanvas::gen() noexcept
 {
 #ifdef THORVG_GL_RASTER_SUPPORT
-    auto canvas = unique_ptr<GlCanvas>(new GlCanvas);
-    assert(canvas);
-
-    return canvas;
+    return unique_ptr<GlCanvas>(new GlCanvas);
 #endif
     return nullptr;
 }
index 68a0d8a..bd2dbc1 100644 (file)
@@ -76,10 +76,7 @@ Result LinearGradient::linear(float* x1, float* y1, float* x2, float* y2) const
 
 unique_ptr<LinearGradient> LinearGradient::gen() noexcept
 {
-    auto fill = unique_ptr<LinearGradient>(new LinearGradient);
-    assert(fill);
-
-    return fill;
+    return unique_ptr<LinearGradient>(new LinearGradient);
 }
 
 #endif /* _TVG_LINEAR_GRADIENT_CPP_ */
\ No newline at end of file
index 179c51e..9f123bf 100644 (file)
@@ -73,10 +73,7 @@ Result RadialGradient::radial(float* cx, float* cy, float* radius) const noexcep
 
 unique_ptr<RadialGradient> RadialGradient::gen() noexcept
 {
-    auto fill = unique_ptr<RadialGradient>(new RadialGradient);
-    assert(fill);
-
-    return fill;
+    return unique_ptr<RadialGradient>(new RadialGradient);
 }
 
 #endif /* _TVG_RADIAL_GRADIENT_CPP_ */
\ No newline at end of file
index b1e8cf0..30bc906 100644 (file)
@@ -107,8 +107,6 @@ RenderTransform::RenderTransform()
 
 RenderTransform::RenderTransform(const RenderTransform* lhs, const RenderTransform* rhs)
 {
-    assert(lhs && rhs);
-
     m.e11 = lhs->m.e11 * rhs->m.e11 + lhs->m.e12 * rhs->m.e21 + lhs->m.e13 * rhs->m.e31;
     m.e12 = lhs->m.e11 * rhs->m.e12 + lhs->m.e12 * rhs->m.e22 + lhs->m.e13 * rhs->m.e32;
     m.e13 = lhs->m.e11 * rhs->m.e13 + lhs->m.e12 * rhs->m.e23 + lhs->m.e13 * rhs->m.e33;
index 3535bf4..c379d0e 100644 (file)
@@ -76,7 +76,6 @@ struct RenderInitializer
 
     static bool init(RenderInitializer& renderInit, RenderMethod* engine)
     {
-        assert(engine);
         if (renderInit.pInst || renderInit.refCnt > 0) return false;
         renderInit.pInst = engine;
         renderInit.refCnt = 0;
@@ -100,7 +99,6 @@ struct RenderInitializer
 
     static uint32_t unref(RenderInitializer& renderInit)
     {
-        assert(renderInit.refCnt > 0);
         --renderInit.refCnt;
 
         //engine has been requested to termination
@@ -115,7 +113,6 @@ struct RenderInitializer
 
     static RenderMethod* inst(RenderInitializer& renderInit)
     {
-        assert(renderInit.pInst);
         return renderInit.pInst;
     }
 
index 1b85c07..612bfe3 100644 (file)
@@ -144,8 +144,6 @@ struct Shape::Impl
 
     bool strokeDash(const float* pattern, uint32_t cnt)
     {
-        assert(pattern);
-
        if (!stroke) stroke = new ShapeStroke();
        if (!stroke) return false;
 
@@ -155,7 +153,6 @@ struct Shape::Impl
         }
 
         if (!stroke->dashPattern) stroke->dashPattern = static_cast<float*>(malloc(sizeof(float) * cnt));
-        assert(stroke->dashPattern);
 
         for (uint32_t i = 0; i < cnt; ++i)
             stroke->dashPattern[i] = pattern[i];
index 75c86ad..04934dc 100644 (file)
@@ -50,7 +50,6 @@ struct ShapePath
         if (cmdCnt <= reservedCmdCnt) return;
         reservedCmdCnt = cmdCnt;
         cmds = static_cast<PathCommand*>(realloc(cmds, sizeof(PathCommand) * reservedCmdCnt));
-        assert(cmds);
     }
 
     void reservePts(uint32_t ptsCnt)
@@ -58,7 +57,6 @@ struct ShapePath
         if (ptsCnt <= reservedPtsCnt) return;
         reservedPtsCnt = ptsCnt;
         pts = static_cast<Point*>(realloc(pts, sizeof(Point) * reservedPtsCnt));
-        assert(pts);
     }
 
     void grow(uint32_t cmdCnt, uint32_t ptsCnt)
index 755d422..5d280fd 100644 (file)
@@ -80,10 +80,7 @@ Result SwCanvas::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t
 unique_ptr<SwCanvas> SwCanvas::gen() noexcept
 {
 #ifdef THORVG_SW_RASTER_SUPPORT
-    auto canvas = unique_ptr<SwCanvas>(new SwCanvas);
-    assert(canvas);
-
-    return canvas;
+    return unique_ptr<SwCanvas>(new SwCanvas);
 #endif
     return nullptr;
 }