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
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;
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;
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;
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;
{
if (!fill) return false;
- assert(fdata);
-
fill->spread = fdata->spread();
if (ctable) {
void mathSplitCubic(SwPoint* base)
{
- assert(base);
-
SwCoord a, b, c, d;
base[6].x = base[3].x;
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;
static void _genSpan(SwRleData* rle, SwSpan* spans, uint32_t count)
{
- assert(rle && spans);
-
auto newSize = rle->size + count;
/* allocate enough memory for new spans */
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;
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) &&
rw.spansCnt = 0;
rw.ySpan = 0;
span = rw.spans;
- assert(span);
} else {
++span;
- assert(span);
}
//Clip x range
if (x > rw.cellXCnt) x = rw.cellXCnt;
auto pcell = &rw.yCells[rw.cellPos.y];
- assert(pcell);
while(true) {
Cell* cell = *pcell;
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;
{
if (rw.area | rw.cover) {
auto cell = _findCell(rw);
- assert(cell);
cell->area += rw.area;
cell->cover += rw.cover;
}
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;
rw.clip = clip;
rw.antiAlias = antiAlias;
rw.rle = reinterpret_cast<SwRleData*>(calloc(1, sizeof(SwRleData)));
- assert(rw.rle);
//Generate RLE
Band bands[BAND_SIZE];
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);
}
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);
}
static void _outlineMoveTo(SwOutline& outline, const Point* to, const Matrix* transform)
{
- assert(to);
-
_growOutlinePoint(outline, 1);
outline.pts[outline.ptsCnt] = _transform(to, transform);
static void _outlineLineTo(SwOutline& outline, const Point* to, const Matrix* transform)
{
- assert(to);
-
_growOutlinePoint(outline, 1);
outline.pts[outline.ptsCnt] = _transform(to, transform);
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);
if (!outline) return false;
auto pt = outline->pts;
- assert(pt);
if (outline->ptsCnt <= 0) {
_initBBox(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
SwOutline* _genDashOutline(const Shape* sdata, const Matrix* transform)
{
- assert(sdata);
-
const PathCommand* cmds = nullptr;
auto cmdCnt = sdata->pathCommands(&cmds);
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
bool shapeGenOutline(SwShape* shape, const Shape* sdata, const Matrix* transform)
{
- assert(sdata);
-
const PathCommand* cmds = nullptr;
auto cmdCnt = sdata->pathCommands(&cmds);
auto outline = shape->outline;
if (!outline) outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline)));
- assert(outline);
outline->opened = true;
_growOutlinePoint(*outline, outlinePtsCnt);
bool shapeGenStrokeRle(SwShape* shape, const Shape* sdata, const Matrix* transform, const SwSize& clip)
{
- assert(sdata);
-
SwOutline* shapeOutline = nullptr;
//Dash Style Stroke
static void _growBorder(SwStrokeBorder* border, uint32_t newPts)
{
- assert(border);
-
auto maxOld = border->maxPts;
auto maxNew = border->ptsCnt + 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) {
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;
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;
static void _borderMoveTo(SwStrokeBorder* border, SwPoint& to)
{
- assert(border);
-
//close current open path if any?
if (border->start >= 0) _borderClose(border, false);
{
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);
{
auto right = stroke.borders + 0;
auto left = stroke.borders + 1;
- assert(left->start >= 0);
-
auto newPts = left->ptsCnt - left->start;
if (newPts <= 0) return;
{
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
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;
static void _exportBorderOutline(SwStroke& stroke, SwOutline* outline, uint32_t side)
{
auto border = stroke.borders + side;
- assert(border);
if (!border->valid) return;
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));
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
#include "config.h"
#include <iostream>
-#include <cassert>
#include <vector>
#include <math.h>
#include <float.h>
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;
}
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
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
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;
static bool init(RenderInitializer& renderInit, RenderMethod* engine)
{
- assert(engine);
if (renderInit.pInst || renderInit.refCnt > 0) return false;
renderInit.pInst = engine;
renderInit.refCnt = 0;
static uint32_t unref(RenderInitializer& renderInit)
{
- assert(renderInit.refCnt > 0);
--renderInit.refCnt;
//engine has been requested to termination
static RenderMethod* inst(RenderInitializer& renderInit)
{
- assert(renderInit.pInst);
return renderInit.pInst;
}
bool strokeDash(const float* pattern, uint32_t cnt)
{
- assert(pattern);
-
if (!stroke) stroke = new ShapeStroke();
if (!stroke) return false;
}
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];
if (cmdCnt <= reservedCmdCnt) return;
reservedCmdCnt = cmdCnt;
cmds = static_cast<PathCommand*>(realloc(cmds, sizeof(PathCommand) * reservedCmdCnt));
- assert(cmds);
}
void reservePts(uint32_t ptsCnt)
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)
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;
}