mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-11 07:02:31 +00:00
binary size optimization.
replaced new/delete with malloc/free saved 936 bytes
This commit is contained in:
parent
b289950a5f
commit
eadb7fc4af
7 changed files with 41 additions and 36 deletions
|
@ -163,10 +163,10 @@ void GlProgram::linkProgram(std::shared_ptr<GlShader> shader)
|
||||||
glGetProgramiv(progObj, GL_INFO_LOG_LENGTH, &infoLen);
|
glGetProgramiv(progObj, GL_INFO_LOG_LENGTH, &infoLen);
|
||||||
if (infoLen > 0)
|
if (infoLen > 0)
|
||||||
{
|
{
|
||||||
char* infoLog = new char[infoLen];
|
auto infoLog = static_cast<char*>(malloc(sizeof(char) * infoLen));
|
||||||
glGetProgramInfoLog(progObj, infoLen, NULL, infoLog);
|
glGetProgramInfoLog(progObj, infoLen, NULL, infoLog);
|
||||||
TVGERR("GL_ENGINE", "Error linking shader: %s", infoLog);
|
TVGERR("GL_ENGINE", "Error linking shader: %s", infoLog);
|
||||||
delete[] infoLog;
|
free(infoLog);
|
||||||
|
|
||||||
}
|
}
|
||||||
glDeleteProgram(progObj);
|
glDeleteProgram(progObj);
|
||||||
|
|
|
@ -84,7 +84,7 @@ uint32_t GlShader::complileShader(uint32_t type, char* shaderSrc)
|
||||||
|
|
||||||
if (infoLen > 0)
|
if (infoLen > 0)
|
||||||
{
|
{
|
||||||
char* infoLog = new char[infoLen];
|
auto infoLog = static_cast<char*>(malloc(sizeof(char)*infoLen));
|
||||||
glGetShaderInfoLog(shader, infoLen, NULL, infoLog);
|
glGetShaderInfoLog(shader, infoLen, NULL, infoLog);
|
||||||
TVGERR("GL_ENGINE", "Error compiling shader: %s", infoLog);
|
TVGERR("GL_ENGINE", "Error compiling shader: %s", infoLog);
|
||||||
delete[] infoLog;
|
delete[] infoLog;
|
||||||
|
|
|
@ -251,9 +251,9 @@ struct SwCompositor : Compositor
|
||||||
|
|
||||||
struct SwMpool
|
struct SwMpool
|
||||||
{
|
{
|
||||||
SwOutline* outline = nullptr;
|
SwOutline* outline;
|
||||||
SwOutline* strokeOutline = nullptr;
|
SwOutline* strokeOutline;
|
||||||
unsigned allocSize = 0;
|
unsigned allocSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline SwCoord TO_SWCOORD(float val)
|
static inline SwCoord TO_SWCOORD(float val)
|
||||||
|
|
|
@ -61,7 +61,7 @@ SwMpool* mpoolInit(unsigned threads)
|
||||||
{
|
{
|
||||||
if (threads == 0) threads = 1;
|
if (threads == 0) threads = 1;
|
||||||
|
|
||||||
auto mpool = new SwMpool;
|
auto mpool = static_cast<SwMpool*>(calloc(sizeof(SwMpool), 1));
|
||||||
mpool->outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * threads));
|
mpool->outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * threads));
|
||||||
if (!mpool->outline) goto err;
|
if (!mpool->outline) goto err;
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ err:
|
||||||
free(mpool->strokeOutline);
|
free(mpool->strokeOutline);
|
||||||
mpool->strokeOutline = nullptr;
|
mpool->strokeOutline = nullptr;
|
||||||
}
|
}
|
||||||
delete(mpool);
|
free(mpool);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ bool mpoolTerm(SwMpool* mpool)
|
||||||
mpool->strokeOutline = nullptr;
|
mpool->strokeOutline = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(mpool);
|
free(mpool);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
|
@ -89,7 +89,9 @@ FillSpread Fill::spread() const noexcept
|
||||||
|
|
||||||
Result Fill::transform(const Matrix& m) noexcept
|
Result Fill::transform(const Matrix& m) noexcept
|
||||||
{
|
{
|
||||||
if (!pImpl->transform) pImpl->transform = new Matrix();
|
if (!pImpl->transform) {
|
||||||
|
pImpl->transform = static_cast<Matrix*>(malloc(sizeof(Matrix)));
|
||||||
|
}
|
||||||
*pImpl->transform = m;
|
*pImpl->transform = m;
|
||||||
return Result::Success;
|
return Result::Success;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,8 +58,8 @@ struct Fill::Impl
|
||||||
~Impl()
|
~Impl()
|
||||||
{
|
{
|
||||||
if (dup) delete(dup);
|
if (dup) delete(dup);
|
||||||
if (colorStops) free(colorStops);
|
free(colorStops);
|
||||||
if (transform) delete(transform);
|
free(transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
void method(DuplicateMethod<Fill>* dup)
|
void method(DuplicateMethod<Fill>* dup)
|
||||||
|
@ -77,7 +77,7 @@ struct Fill::Impl
|
||||||
ret->pImpl->colorStops = static_cast<ColorStop*>(malloc(sizeof(ColorStop) * cnt));
|
ret->pImpl->colorStops = static_cast<ColorStop*>(malloc(sizeof(ColorStop) * cnt));
|
||||||
memcpy(ret->pImpl->colorStops, colorStops, sizeof(ColorStop) * cnt);
|
memcpy(ret->pImpl->colorStops, colorStops, sizeof(ColorStop) * cnt);
|
||||||
if (transform) {
|
if (transform) {
|
||||||
ret->pImpl->transform = new Matrix;
|
ret->pImpl->transform = static_cast<Matrix*>(malloc(sizeof(Matrix)));
|
||||||
*ret->pImpl->transform = *transform;
|
*ret->pImpl->transform = *transform;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -31,22 +31,21 @@
|
||||||
|
|
||||||
struct ShapeStroke
|
struct ShapeStroke
|
||||||
{
|
{
|
||||||
float width = 0;
|
float width;
|
||||||
uint8_t color[4] = {0, 0, 0, 0};
|
uint8_t color[4];
|
||||||
Fill *fill = nullptr;
|
Fill *fill;
|
||||||
float* dashPattern = nullptr;
|
float* dashPattern;
|
||||||
uint32_t dashCnt = 0;
|
uint32_t dashCnt;
|
||||||
StrokeCap cap = StrokeCap::Square;
|
StrokeCap cap;
|
||||||
StrokeJoin join = StrokeJoin::Bevel;
|
StrokeJoin join;
|
||||||
|
|
||||||
ShapeStroke() {}
|
void copy(const ShapeStroke* src)
|
||||||
|
|
||||||
ShapeStroke(const ShapeStroke* src)
|
|
||||||
: width(src->width),
|
|
||||||
dashCnt(src->dashCnt),
|
|
||||||
cap(src->cap),
|
|
||||||
join(src->join)
|
|
||||||
{
|
{
|
||||||
|
width = src->width;
|
||||||
|
dashCnt = src->dashCnt;
|
||||||
|
cap = src->cap;
|
||||||
|
join = src->join;
|
||||||
|
|
||||||
memcpy(color, src->color, sizeof(color));
|
memcpy(color, src->color, sizeof(color));
|
||||||
if (dashCnt > 0) {
|
if (dashCnt > 0) {
|
||||||
dashPattern = static_cast<float*>(malloc(sizeof(float) * dashCnt));
|
dashPattern = static_cast<float*>(malloc(sizeof(float) * dashCnt));
|
||||||
|
@ -55,7 +54,7 @@ struct ShapeStroke
|
||||||
if (src->fill) fill = src->fill->duplicate();
|
if (src->fill) fill = src->fill->duplicate();
|
||||||
}
|
}
|
||||||
|
|
||||||
~ShapeStroke()
|
void clear()
|
||||||
{
|
{
|
||||||
if (dashPattern) free(dashPattern);
|
if (dashPattern) free(dashPattern);
|
||||||
if (fill) delete(fill);
|
if (fill) delete(fill);
|
||||||
|
@ -215,7 +214,10 @@ struct Shape::Impl
|
||||||
~Impl()
|
~Impl()
|
||||||
{
|
{
|
||||||
if (fill) delete(fill);
|
if (fill) delete(fill);
|
||||||
if (stroke) delete(stroke);
|
if (stroke) {
|
||||||
|
stroke->clear();
|
||||||
|
free (stroke);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dispose(RenderMethod& renderer)
|
bool dispose(RenderMethod& renderer)
|
||||||
|
@ -260,7 +262,7 @@ struct Shape::Impl
|
||||||
{
|
{
|
||||||
//TODO: Size Exception?
|
//TODO: Size Exception?
|
||||||
|
|
||||||
if (!stroke) stroke = new ShapeStroke();
|
if (!stroke) stroke = static_cast<ShapeStroke*>(calloc(sizeof(ShapeStroke), 1));
|
||||||
stroke->width = width;
|
stroke->width = width;
|
||||||
flag |= RenderUpdateFlag::Stroke;
|
flag |= RenderUpdateFlag::Stroke;
|
||||||
|
|
||||||
|
@ -269,7 +271,7 @@ struct Shape::Impl
|
||||||
|
|
||||||
bool strokeCap(StrokeCap cap)
|
bool strokeCap(StrokeCap cap)
|
||||||
{
|
{
|
||||||
if (!stroke) stroke = new ShapeStroke();
|
if (!stroke) stroke = static_cast<ShapeStroke*>(calloc(sizeof(ShapeStroke), 1));
|
||||||
stroke->cap = cap;
|
stroke->cap = cap;
|
||||||
flag |= RenderUpdateFlag::Stroke;
|
flag |= RenderUpdateFlag::Stroke;
|
||||||
|
|
||||||
|
@ -278,7 +280,7 @@ struct Shape::Impl
|
||||||
|
|
||||||
bool strokeJoin(StrokeJoin join)
|
bool strokeJoin(StrokeJoin join)
|
||||||
{
|
{
|
||||||
if (!stroke) stroke = new ShapeStroke();
|
if (!stroke) stroke = static_cast<ShapeStroke*>(calloc(sizeof(ShapeStroke), 1));
|
||||||
stroke->join = join;
|
stroke->join = join;
|
||||||
flag |= RenderUpdateFlag::Stroke;
|
flag |= RenderUpdateFlag::Stroke;
|
||||||
|
|
||||||
|
@ -287,7 +289,7 @@ struct Shape::Impl
|
||||||
|
|
||||||
bool strokeColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
bool strokeColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
||||||
{
|
{
|
||||||
if (!stroke) stroke = new ShapeStroke();
|
if (!stroke) stroke = static_cast<ShapeStroke*>(calloc(sizeof(ShapeStroke), 1));
|
||||||
if (stroke->fill) {
|
if (stroke->fill) {
|
||||||
delete(stroke->fill);
|
delete(stroke->fill);
|
||||||
stroke->fill = nullptr;
|
stroke->fill = nullptr;
|
||||||
|
@ -309,7 +311,7 @@ struct Shape::Impl
|
||||||
auto p = f.release();
|
auto p = f.release();
|
||||||
if (!p) return Result::MemoryCorruption;
|
if (!p) return Result::MemoryCorruption;
|
||||||
|
|
||||||
if (!stroke) stroke = new ShapeStroke();
|
if (!stroke) stroke = static_cast<ShapeStroke*>(calloc(sizeof(ShapeStroke), 1));
|
||||||
if (stroke->fill && stroke->fill != p) delete(stroke->fill);
|
if (stroke->fill && stroke->fill != p) delete(stroke->fill);
|
||||||
stroke->fill = p;
|
stroke->fill = p;
|
||||||
|
|
||||||
|
@ -326,7 +328,7 @@ struct Shape::Impl
|
||||||
free(stroke->dashPattern);
|
free(stroke->dashPattern);
|
||||||
stroke->dashPattern = nullptr;
|
stroke->dashPattern = nullptr;
|
||||||
} else {
|
} else {
|
||||||
if (!stroke) stroke = new ShapeStroke();
|
if (!stroke) stroke = static_cast<ShapeStroke*>(calloc(sizeof(ShapeStroke), 1));
|
||||||
if (stroke->dashCnt != cnt) {
|
if (stroke->dashCnt != cnt) {
|
||||||
free(stroke->dashPattern);
|
free(stroke->dashPattern);
|
||||||
stroke->dashPattern = nullptr;
|
stroke->dashPattern = nullptr;
|
||||||
|
@ -363,7 +365,8 @@ struct Shape::Impl
|
||||||
|
|
||||||
//Stroke
|
//Stroke
|
||||||
if (stroke) {
|
if (stroke) {
|
||||||
dup->stroke = new ShapeStroke(stroke);
|
dup->stroke = static_cast<ShapeStroke*>(calloc(sizeof(ShapeStroke), 1));
|
||||||
|
dup->stroke->copy(stroke);
|
||||||
dup->flag |= RenderUpdateFlag::Stroke;
|
dup->flag |= RenderUpdateFlag::Stroke;
|
||||||
|
|
||||||
if (stroke->fill)
|
if (stroke->fill)
|
||||||
|
|
Loading…
Add table
Reference in a new issue