mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
common: binary optimization. (#65)
removed unique_ptr usages from pImpl pattern. that increased binary size. 2204082 -> 2045672
This commit is contained in:
parent
87fbff63cb
commit
eef7620bc8
16 changed files with 178 additions and 184 deletions
|
@ -23,7 +23,7 @@ extern "C" {
|
|||
#define _TVG_DECLARE_PRIVATE(A) \
|
||||
protected: \
|
||||
struct Impl; \
|
||||
std::unique_ptr<Impl> pImpl; \
|
||||
Impl* pImpl; \
|
||||
A(const A&) = delete; \
|
||||
const A& operator=(const A&) = delete; \
|
||||
A()
|
||||
|
@ -91,7 +91,6 @@ public:
|
|||
Result translate(float x, float y) noexcept;
|
||||
Result transform(const Matrix& m) noexcept;
|
||||
Result bounds(float* x, float* y, float* w, float* h) const noexcept;
|
||||
|
||||
std::unique_ptr<Paint> duplicate() const noexcept;
|
||||
|
||||
_TVG_DECLARE_ACCESSOR();
|
||||
|
|
|
@ -26,50 +26,51 @@
|
|||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
Canvas::Canvas(RenderMethod *pRenderer):pImpl(make_unique<Impl>(pRenderer))
|
||||
Canvas::Canvas(RenderMethod *pRenderer):pImpl(new Impl(pRenderer))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Canvas::~Canvas()
|
||||
{
|
||||
delete(pImpl);
|
||||
}
|
||||
|
||||
|
||||
Result Canvas::reserve(uint32_t n) noexcept
|
||||
{
|
||||
IMPL->paints.reserve(n);
|
||||
pImpl->paints.reserve(n);
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
|
||||
Result Canvas::push(unique_ptr<Paint> paint) noexcept
|
||||
{
|
||||
return IMPL->push(move(paint));
|
||||
return pImpl->push(move(paint));
|
||||
}
|
||||
|
||||
|
||||
Result Canvas::clear() noexcept
|
||||
{
|
||||
return IMPL->clear();
|
||||
return pImpl->clear();
|
||||
}
|
||||
|
||||
|
||||
Result Canvas::draw() noexcept
|
||||
{
|
||||
return IMPL->draw();
|
||||
return pImpl->draw();
|
||||
}
|
||||
|
||||
|
||||
Result Canvas::update(Paint* paint) noexcept
|
||||
{
|
||||
return IMPL->update(paint);
|
||||
return pImpl->update(paint);
|
||||
}
|
||||
|
||||
|
||||
Result Canvas::sync() noexcept
|
||||
{
|
||||
if (IMPL->renderer->flush()) return Result::Success;
|
||||
if (pImpl->renderer->flush()) return Result::Success;
|
||||
|
||||
return Result::InsufficientCondition;
|
||||
}
|
|
@ -60,7 +60,7 @@ struct Canvas::Impl
|
|||
if (!renderer->clear()) return Result::InsufficientCondition;
|
||||
|
||||
for (auto paint : paints) {
|
||||
paint->IMPL->dispose(*renderer);
|
||||
paint->pImpl->dispose(*renderer);
|
||||
delete(paint);
|
||||
}
|
||||
paints.clear();
|
||||
|
@ -74,13 +74,13 @@ struct Canvas::Impl
|
|||
|
||||
//Update single paint node
|
||||
if (paint) {
|
||||
if (!paint->IMPL->update(*renderer, nullptr, RenderUpdateFlag::None)) {
|
||||
if (!paint->pImpl->update(*renderer, nullptr, RenderUpdateFlag::None)) {
|
||||
return Result::InsufficientCondition;
|
||||
}
|
||||
//Update retained all paint nodes
|
||||
} else {
|
||||
for(auto paint: paints) {
|
||||
if (!paint->IMPL->update(*renderer, nullptr, RenderUpdateFlag::None)) {
|
||||
if (!paint->pImpl->update(*renderer, nullptr, RenderUpdateFlag::None)) {
|
||||
return Result::InsufficientCondition;
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ struct Canvas::Impl
|
|||
if (!renderer->preRender()) return Result::InsufficientCondition;
|
||||
|
||||
for(auto paint: paints) {
|
||||
if(!paint->IMPL->render(*renderer)) return Result::InsufficientCondition;
|
||||
if(!paint->pImpl->render(*renderer)) return Result::InsufficientCondition;
|
||||
}
|
||||
|
||||
if (!renderer->postRender()) return Result::InsufficientCondition;
|
||||
|
|
|
@ -37,8 +37,6 @@
|
|||
using namespace std;
|
||||
using namespace tvg;
|
||||
|
||||
#define IMPL pImpl.get()
|
||||
|
||||
#define FILL_ID_LINEAR 0
|
||||
#define FILL_ID_RADIAL 1
|
||||
|
||||
|
|
|
@ -43,35 +43,34 @@ struct Fill::Impl
|
|||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
Fill::Fill():pImpl(make_unique<Impl>())
|
||||
Fill::Fill():pImpl(new Impl())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Fill::~Fill()
|
||||
{
|
||||
delete(pImpl);
|
||||
}
|
||||
|
||||
|
||||
Result Fill::colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept
|
||||
{
|
||||
auto impl = pImpl.get();
|
||||
|
||||
if (cnt == 0) {
|
||||
if (impl->colorStops) {
|
||||
free(impl->colorStops);
|
||||
impl->colorStops = nullptr;
|
||||
impl->cnt = cnt;
|
||||
if (pImpl->colorStops) {
|
||||
free(pImpl->colorStops);
|
||||
pImpl->colorStops = nullptr;
|
||||
pImpl->cnt = cnt;
|
||||
}
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
if (impl->cnt != cnt) {
|
||||
impl->colorStops = static_cast<ColorStop*>(realloc(impl->colorStops, cnt * sizeof(ColorStop)));
|
||||
if (pImpl->cnt != cnt) {
|
||||
pImpl->colorStops = static_cast<ColorStop*>(realloc(pImpl->colorStops, cnt * sizeof(ColorStop)));
|
||||
}
|
||||
|
||||
impl->cnt = cnt;
|
||||
memcpy(impl->colorStops, colorStops, cnt * sizeof(ColorStop));
|
||||
pImpl->cnt = cnt;
|
||||
memcpy(pImpl->colorStops, colorStops, cnt * sizeof(ColorStop));
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -79,15 +78,15 @@ Result Fill::colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept
|
|||
|
||||
uint32_t Fill::colorStops(const ColorStop** colorStops) const noexcept
|
||||
{
|
||||
if (colorStops) *colorStops = IMPL->colorStops;
|
||||
if (colorStops) *colorStops = pImpl->colorStops;
|
||||
|
||||
return IMPL->cnt;
|
||||
return pImpl->cnt;
|
||||
}
|
||||
|
||||
|
||||
Result Fill::spread(FillSpread s) noexcept
|
||||
{
|
||||
IMPL->spread = s;
|
||||
pImpl->spread = s;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -95,5 +94,5 @@ Result Fill::spread(FillSpread s) noexcept
|
|||
|
||||
FillSpread Fill::spread() const noexcept
|
||||
{
|
||||
return IMPL->spread;
|
||||
return pImpl->spread;
|
||||
}
|
|
@ -37,7 +37,6 @@
|
|||
|
||||
struct GlCanvas::Impl
|
||||
{
|
||||
Impl() {}
|
||||
};
|
||||
|
||||
|
||||
|
@ -46,9 +45,9 @@ struct GlCanvas::Impl
|
|||
/************************************************************************/
|
||||
|
||||
#ifdef THORVG_GL_RASTER_SUPPORT
|
||||
GlCanvas::GlCanvas() : Canvas(GlRenderer::gen()), pImpl(make_unique<Impl>())
|
||||
GlCanvas::GlCanvas() : Canvas(GlRenderer::gen()), pImpl(new Impl)
|
||||
#else
|
||||
GlCanvas::GlCanvas() : Canvas(nullptr), pImpl(make_unique<Impl>())
|
||||
GlCanvas::GlCanvas() : Canvas(nullptr), pImpl(new Impl)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
@ -57,6 +56,7 @@ GlCanvas::GlCanvas() : Canvas(nullptr), pImpl(make_unique<Impl>())
|
|||
|
||||
GlCanvas::~GlCanvas()
|
||||
{
|
||||
delete(pImpl);
|
||||
}
|
||||
|
||||
|
||||
|
@ -64,7 +64,7 @@ Result GlCanvas::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t
|
|||
{
|
||||
#ifdef THORVG_GL_RASTER_SUPPORT
|
||||
//We know renderer type, avoid dynamic_cast for performance.
|
||||
auto renderer = static_cast<GlRenderer*>(Canvas::pImpl.get()->renderer);
|
||||
auto renderer = static_cast<GlRenderer*>(Canvas::pImpl->renderer);
|
||||
if (!renderer) return Result::MemoryCorruption;
|
||||
|
||||
if (!renderer->target(buffer, stride, w, h)) return Result::Unknown;
|
||||
|
|
|
@ -27,14 +27,17 @@
|
|||
|
||||
struct LinearGradient::Impl
|
||||
{
|
||||
float x1, y1, x2, y2;
|
||||
float x1 = 0;
|
||||
float y1 = 0;
|
||||
float x2 = 0;
|
||||
float y2 = 0;
|
||||
};
|
||||
|
||||
/************************************************************************/
|
||||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
LinearGradient::LinearGradient():pImpl(make_unique<Impl>())
|
||||
LinearGradient::LinearGradient():pImpl(new Impl())
|
||||
{
|
||||
_id = FILL_ID_LINEAR;
|
||||
}
|
||||
|
@ -42,6 +45,7 @@ LinearGradient::LinearGradient():pImpl(make_unique<Impl>())
|
|||
|
||||
LinearGradient::~LinearGradient()
|
||||
{
|
||||
delete(pImpl);
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,10 +54,10 @@ Result LinearGradient::linear(float x1, float y1, float x2, float y2) noexcept
|
|||
if (fabsf(x2 - x1) < FLT_EPSILON && fabsf(y2 - y1) < FLT_EPSILON)
|
||||
return Result::InvalidArguments;
|
||||
|
||||
IMPL->x1 = x1;
|
||||
IMPL->y1 = y1;
|
||||
IMPL->x2 = x2;
|
||||
IMPL->y2 = y2;
|
||||
pImpl->x1 = x1;
|
||||
pImpl->y1 = y1;
|
||||
pImpl->x2 = x2;
|
||||
pImpl->y2 = y2;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -61,10 +65,10 @@ Result LinearGradient::linear(float x1, float y1, float x2, float y2) noexcept
|
|||
|
||||
Result LinearGradient::linear(float* x1, float* y1, float* x2, float* y2) const noexcept
|
||||
{
|
||||
if (x1) *x1 = IMPL->x1;
|
||||
if (x2) *x2 = IMPL->x2;
|
||||
if (y1) *y1 = IMPL->y1;
|
||||
if (y2) *y2 = IMPL->y2;
|
||||
if (x1) *x1 = pImpl->x1;
|
||||
if (x2) *x2 = pImpl->x2;
|
||||
if (y1) *y1 = pImpl->y1;
|
||||
if (y2) *y2 = pImpl->y2;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
|
|
@ -25,13 +25,14 @@
|
|||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
Paint :: Paint() : pImpl(make_unique<Impl>())
|
||||
Paint :: Paint() : pImpl(new Impl())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Paint :: ~Paint()
|
||||
{
|
||||
delete(pImpl);
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,39 +42,39 @@ Paint :: ~Paint()
|
|||
|
||||
Result Paint::rotate(float degree) noexcept
|
||||
{
|
||||
if (IMPL->rotate(degree)) return Result::Success;
|
||||
if (pImpl->rotate(degree)) return Result::Success;
|
||||
return Result::FailedAllocation;
|
||||
}
|
||||
|
||||
|
||||
Result Paint::scale(float factor) noexcept
|
||||
{
|
||||
if (IMPL->scale(factor)) return Result::Success;
|
||||
if (pImpl->scale(factor)) return Result::Success;
|
||||
return Result::FailedAllocation;
|
||||
}
|
||||
|
||||
|
||||
Result Paint::translate(float x, float y) noexcept
|
||||
{
|
||||
if (IMPL->translate(x, y)) return Result::Success;
|
||||
if (pImpl->translate(x, y)) return Result::Success;
|
||||
return Result::FailedAllocation;
|
||||
}
|
||||
|
||||
|
||||
Result Paint::transform(const Matrix& m) noexcept
|
||||
{
|
||||
if (IMPL->transform(m)) return Result::Success;
|
||||
if (pImpl->transform(m)) return Result::Success;
|
||||
return Result::FailedAllocation;
|
||||
}
|
||||
|
||||
|
||||
Result Paint::bounds(float* x, float* y, float* w, float* h) const noexcept
|
||||
{
|
||||
if (IMPL->bounds(x, y, w, h)) return Result::Success;
|
||||
if (pImpl->bounds(x, y, w, h)) return Result::Success;
|
||||
return Result::InsufficientCondition;
|
||||
}
|
||||
|
||||
unique_ptr<Paint> Paint::duplicate() const noexcept
|
||||
{
|
||||
return IMPL->duplicate();
|
||||
return pImpl->duplicate();
|
||||
}
|
|
@ -25,14 +25,15 @@
|
|||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
Picture::Picture() : pImpl(make_unique<Impl>())
|
||||
Picture::Picture() : pImpl(new Impl())
|
||||
{
|
||||
Paint::IMPL->method(new PaintMethod<Picture::Impl>(IMPL));
|
||||
Paint::pImpl->method(new PaintMethod<Picture::Impl>(pImpl));
|
||||
}
|
||||
|
||||
|
||||
Picture::~Picture()
|
||||
{
|
||||
delete(pImpl);
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,7 +47,7 @@ Result Picture::load(const std::string& path) noexcept
|
|||
{
|
||||
if (path.empty()) return Result::InvalidArguments;
|
||||
|
||||
return IMPL->load(path);
|
||||
return pImpl->load(path);
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,12 +55,12 @@ Result Picture::load(const char* data, uint32_t size) noexcept
|
|||
{
|
||||
if (!data || size <= 0) return Result::InvalidArguments;
|
||||
|
||||
return IMPL->load(data, size);
|
||||
return pImpl->load(data, size);
|
||||
}
|
||||
|
||||
|
||||
Result Picture::viewbox(float* x, float* y, float* w, float* h) const noexcept
|
||||
{
|
||||
if (IMPL->viewbox(x, y, w, h)) return Result::Success;
|
||||
if (pImpl->viewbox(x, y, w, h)) return Result::Success;
|
||||
return Result::InsufficientCondition;
|
||||
}
|
|
@ -37,7 +37,7 @@ struct Picture::Impl
|
|||
{
|
||||
if (!paint) return false;
|
||||
|
||||
paint->IMPL->dispose(renderer);
|
||||
paint->pImpl->dispose(renderer);
|
||||
delete(paint);
|
||||
|
||||
return true;
|
||||
|
@ -56,13 +56,13 @@ struct Picture::Impl
|
|||
|
||||
if (!paint) return false;
|
||||
|
||||
return paint->IMPL->update(renderer, transform, flag);
|
||||
return paint->pImpl->update(renderer, transform, flag);
|
||||
}
|
||||
|
||||
bool render(RenderMethod &renderer)
|
||||
{
|
||||
if (!paint) return false;
|
||||
return paint->IMPL->render(renderer);
|
||||
return paint->pImpl->render(renderer);
|
||||
}
|
||||
|
||||
bool viewbox(float* x, float* y, float* w, float* h)
|
||||
|
@ -78,7 +78,7 @@ struct Picture::Impl
|
|||
bool bounds(float* x, float* y, float* w, float* h)
|
||||
{
|
||||
if (!paint) return false;
|
||||
return paint->IMPL->bounds(x, y, w, h);
|
||||
return paint->pImpl->bounds(x, y, w, h);
|
||||
}
|
||||
|
||||
Result load(const string& path)
|
||||
|
|
|
@ -27,7 +27,9 @@
|
|||
|
||||
struct RadialGradient::Impl
|
||||
{
|
||||
float cx, cy, radius;
|
||||
float cx = 0;
|
||||
float cy = 0;
|
||||
float radius = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -35,7 +37,7 @@ struct RadialGradient::Impl
|
|||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
RadialGradient::RadialGradient():pImpl(make_unique<Impl>())
|
||||
RadialGradient::RadialGradient():pImpl(new Impl())
|
||||
{
|
||||
_id = FILL_ID_RADIAL;
|
||||
}
|
||||
|
@ -43,6 +45,7 @@ RadialGradient::RadialGradient():pImpl(make_unique<Impl>())
|
|||
|
||||
RadialGradient::~RadialGradient()
|
||||
{
|
||||
delete(pImpl);
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,9 +53,9 @@ Result RadialGradient::radial(float cx, float cy, float radius) noexcept
|
|||
{
|
||||
if (radius < FLT_EPSILON) return Result::InvalidArguments;
|
||||
|
||||
IMPL->cx = cx;
|
||||
IMPL->cy = cy;
|
||||
IMPL->radius = radius;
|
||||
pImpl->cx = cx;
|
||||
pImpl->cy = cy;
|
||||
pImpl->radius = radius;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -60,9 +63,9 @@ Result RadialGradient::radial(float cx, float cy, float radius) noexcept
|
|||
|
||||
Result RadialGradient::radial(float* cx, float* cy, float* radius) const noexcept
|
||||
{
|
||||
if (cx) *cx = IMPL->cx;
|
||||
if (cy) *cy = IMPL->cy;
|
||||
if (radius) *radius = IMPL->radius;
|
||||
if (cx) *cx = pImpl->cx;
|
||||
if (cy) *cy = pImpl->cy;
|
||||
if (radius) *radius = pImpl->radius;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
|
|
@ -25,14 +25,15 @@
|
|||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
Scene::Scene() : pImpl(make_unique<Impl>())
|
||||
Scene::Scene() : pImpl(new Impl())
|
||||
{
|
||||
Paint::IMPL->method(new PaintMethod<Scene::Impl>(IMPL));
|
||||
Paint::pImpl->method(new PaintMethod<Scene::Impl>(pImpl));
|
||||
}
|
||||
|
||||
|
||||
Scene::~Scene()
|
||||
{
|
||||
delete(pImpl);
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,7 +47,7 @@ Result Scene::push(unique_ptr<Paint> paint) noexcept
|
|||
{
|
||||
auto p = paint.release();
|
||||
if (!p) return Result::MemoryCorruption;
|
||||
IMPL->paints.push_back(p);
|
||||
pImpl->paints.push_back(p);
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -54,7 +55,7 @@ Result Scene::push(unique_ptr<Paint> paint) noexcept
|
|||
|
||||
Result Scene::reserve(uint32_t size) noexcept
|
||||
{
|
||||
IMPL->paints.reserve(size);
|
||||
pImpl->paints.reserve(size);
|
||||
|
||||
return Result::Success;
|
||||
}
|
|
@ -35,7 +35,7 @@ struct Scene::Impl
|
|||
bool dispose(RenderMethod& renderer)
|
||||
{
|
||||
for (auto paint : paints) {
|
||||
paint->IMPL->dispose(renderer);
|
||||
paint->pImpl->dispose(renderer);
|
||||
delete(paint);
|
||||
}
|
||||
paints.clear();
|
||||
|
@ -46,7 +46,7 @@ struct Scene::Impl
|
|||
bool update(RenderMethod &renderer, const RenderTransform* transform, RenderUpdateFlag flag)
|
||||
{
|
||||
for(auto paint: paints) {
|
||||
if (!paint->IMPL->update(renderer, transform, static_cast<uint32_t>(flag))) return false;
|
||||
if (!paint->pImpl->update(renderer, transform, static_cast<uint32_t>(flag))) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ struct Scene::Impl
|
|||
bool render(RenderMethod &renderer)
|
||||
{
|
||||
for(auto paint: paints) {
|
||||
if(!paint->IMPL->render(renderer)) return false;
|
||||
if(!paint->pImpl->render(renderer)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ struct Scene::Impl
|
|||
auto w2 = 0.0f;
|
||||
auto h2 = 0.0f;
|
||||
|
||||
if (paint->IMPL->bounds(&x2, &y2, &w2, &h2)) return false;
|
||||
if (paint->pImpl->bounds(&x2, &y2, &w2, &h2)) return false;
|
||||
|
||||
//Merge regions
|
||||
if (x2 < x) x = x2;
|
||||
|
|
|
@ -32,14 +32,15 @@ constexpr auto PATH_KAPPA = 0.552284f;
|
|||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
Shape :: Shape() : pImpl(make_unique<Impl>(this))
|
||||
Shape :: Shape() : pImpl(new Impl(this))
|
||||
{
|
||||
Paint::IMPL->method(new PaintMethod<Shape::Impl>(IMPL));
|
||||
Paint::pImpl->method(new PaintMethod<Shape::Impl>(pImpl));
|
||||
}
|
||||
|
||||
|
||||
Shape :: ~Shape()
|
||||
{
|
||||
delete(pImpl);
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,9 +52,9 @@ unique_ptr<Shape> Shape::gen() noexcept
|
|||
|
||||
Result Shape::reset() noexcept
|
||||
{
|
||||
IMPL->path->reset();
|
||||
pImpl->path->reset();
|
||||
|
||||
IMPL->flag |= RenderUpdateFlag::Path;
|
||||
pImpl->flag |= RenderUpdateFlag::Path;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -63,9 +64,9 @@ uint32_t Shape::pathCommands(const PathCommand** cmds) const noexcept
|
|||
{
|
||||
if (!cmds) return 0;
|
||||
|
||||
*cmds = IMPL->path->cmds;
|
||||
*cmds = pImpl->path->cmds;
|
||||
|
||||
return IMPL->path->cmdCnt;
|
||||
return pImpl->path->cmdCnt;
|
||||
}
|
||||
|
||||
|
||||
|
@ -73,9 +74,9 @@ uint32_t Shape::pathCoords(const Point** pts) const noexcept
|
|||
{
|
||||
if (!pts) return 0;
|
||||
|
||||
*pts = IMPL->path->pts;
|
||||
*pts = pImpl->path->pts;
|
||||
|
||||
return IMPL->path->ptsCnt;
|
||||
return pImpl->path->ptsCnt;
|
||||
}
|
||||
|
||||
|
||||
|
@ -83,10 +84,10 @@ Result Shape::appendPath(const PathCommand *cmds, uint32_t cmdCnt, const Point*
|
|||
{
|
||||
if (cmdCnt == 0 || ptsCnt == 0 || !pts || !ptsCnt) return Result::InvalidArguments;
|
||||
|
||||
IMPL->path->grow(cmdCnt, ptsCnt);
|
||||
IMPL->path->append(cmds, cmdCnt, pts, ptsCnt);
|
||||
pImpl->path->grow(cmdCnt, ptsCnt);
|
||||
pImpl->path->append(cmds, cmdCnt, pts, ptsCnt);
|
||||
|
||||
IMPL->flag |= RenderUpdateFlag::Path;
|
||||
pImpl->flag |= RenderUpdateFlag::Path;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -94,9 +95,9 @@ Result Shape::appendPath(const PathCommand *cmds, uint32_t cmdCnt, const Point*
|
|||
|
||||
Result Shape::moveTo(float x, float y) noexcept
|
||||
{
|
||||
IMPL->path->moveTo(x, y);
|
||||
pImpl->path->moveTo(x, y);
|
||||
|
||||
IMPL->flag |= RenderUpdateFlag::Path;
|
||||
pImpl->flag |= RenderUpdateFlag::Path;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -104,9 +105,9 @@ Result Shape::moveTo(float x, float y) noexcept
|
|||
|
||||
Result Shape::lineTo(float x, float y) noexcept
|
||||
{
|
||||
IMPL->path->lineTo(x, y);
|
||||
pImpl->path->lineTo(x, y);
|
||||
|
||||
IMPL->flag |= RenderUpdateFlag::Path;
|
||||
pImpl->flag |= RenderUpdateFlag::Path;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -114,9 +115,9 @@ Result Shape::lineTo(float x, float y) noexcept
|
|||
|
||||
Result Shape::cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept
|
||||
{
|
||||
IMPL->path->cubicTo(cx1, cy1, cx2, cy2, x, y);
|
||||
pImpl->path->cubicTo(cx1, cy1, cx2, cy2, x, y);
|
||||
|
||||
IMPL->flag |= RenderUpdateFlag::Path;
|
||||
pImpl->flag |= RenderUpdateFlag::Path;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -124,9 +125,9 @@ Result Shape::cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float
|
|||
|
||||
Result Shape::close() noexcept
|
||||
{
|
||||
IMPL->path->close();
|
||||
pImpl->path->close();
|
||||
|
||||
IMPL->flag |= RenderUpdateFlag::Path;
|
||||
pImpl->flag |= RenderUpdateFlag::Path;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -134,20 +135,18 @@ Result Shape::close() noexcept
|
|||
|
||||
Result Shape::appendCircle(float cx, float cy, float rx, float ry) noexcept
|
||||
{
|
||||
auto impl = pImpl.get();
|
||||
|
||||
auto rxKappa = rx * PATH_KAPPA;
|
||||
auto ryKappa = ry * PATH_KAPPA;
|
||||
|
||||
impl->path->grow(6, 13);
|
||||
impl->path->moveTo(cx, cy - ry);
|
||||
impl->path->cubicTo(cx + rxKappa, cy - ry, cx + rx, cy - ryKappa, cx + rx, cy);
|
||||
impl->path->cubicTo(cx + rx, cy + ryKappa, cx + rxKappa, cy + ry, cx, cy + ry);
|
||||
impl->path->cubicTo(cx - rxKappa, cy + ry, cx - rx, cy + ryKappa, cx - rx, cy);
|
||||
impl->path->cubicTo(cx - rx, cy - ryKappa, cx - rxKappa, cy - ry, cx, cy - ry);
|
||||
impl->path->close();
|
||||
pImpl->path->grow(6, 13);
|
||||
pImpl->path->moveTo(cx, cy - ry);
|
||||
pImpl->path->cubicTo(cx + rxKappa, cy - ry, cx + rx, cy - ryKappa, cx + rx, cy);
|
||||
pImpl->path->cubicTo(cx + rx, cy + ryKappa, cx + rxKappa, cy + ry, cx, cy + ry);
|
||||
pImpl->path->cubicTo(cx - rxKappa, cy + ry, cx - rx, cy + ryKappa, cx - rx, cy);
|
||||
pImpl->path->cubicTo(cx - rx, cy - ryKappa, cx - rxKappa, cy - ry, cx, cy - ry);
|
||||
pImpl->path->close();
|
||||
|
||||
impl->flag |= RenderUpdateFlag::Path;
|
||||
pImpl->flag |= RenderUpdateFlag::Path;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -159,8 +158,6 @@ Result Shape::appendArc(float cx, float cy, float radius, float startAngle, floa
|
|||
//just circle
|
||||
if (sweep >= 360) return appendCircle(cx, cy, radius, radius);
|
||||
|
||||
auto impl = pImpl.get();
|
||||
|
||||
startAngle = (startAngle * M_PI) / 180;
|
||||
sweep = sweep * M_PI / 180;
|
||||
|
||||
|
@ -172,10 +169,10 @@ Result Shape::appendArc(float cx, float cy, float radius, float startAngle, floa
|
|||
Point start = {radius * cos(startAngle), radius * sin(startAngle)};
|
||||
|
||||
if (pie) {
|
||||
impl->path->moveTo(cx, cy);
|
||||
impl->path->lineTo(start.x + cx, start.y + cy);
|
||||
pImpl->path->moveTo(cx, cy);
|
||||
pImpl->path->lineTo(start.x + cx, start.y + cy);
|
||||
}else {
|
||||
impl->path->moveTo(start.x + cx, start.y + cy);
|
||||
pImpl->path->moveTo(start.x + cx, start.y + cy);
|
||||
}
|
||||
|
||||
for (int i = 0; i < nCurves; ++i) {
|
||||
|
@ -203,17 +200,17 @@ Result Shape::appendArc(float cx, float cy, float radius, float startAngle, floa
|
|||
Point ctrl1 = {ax - k2 * ay + cx, ay + k2 * ax + cy};
|
||||
Point ctrl2 = {bx + k2 * by + cx, by - k2 * bx + cy};
|
||||
|
||||
impl->path->cubicTo(ctrl1.x, ctrl1.y, ctrl2.x, ctrl2.y, end.x, end.y);
|
||||
pImpl->path->cubicTo(ctrl1.x, ctrl1.y, ctrl2.x, ctrl2.y, end.x, end.y);
|
||||
|
||||
startAngle = endAngle;
|
||||
}
|
||||
|
||||
if (pie) {
|
||||
impl->path->moveTo(cx, cy);
|
||||
impl->path->close();
|
||||
pImpl->path->moveTo(cx, cy);
|
||||
pImpl->path->close();
|
||||
}
|
||||
|
||||
IMPL->flag |= RenderUpdateFlag::Path;
|
||||
pImpl->flag |= RenderUpdateFlag::Path;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -221,8 +218,6 @@ Result Shape::appendArc(float cx, float cy, float radius, float startAngle, floa
|
|||
|
||||
Result Shape::appendRect(float x, float y, float w, float h, float rx, float ry) noexcept
|
||||
{
|
||||
auto impl = pImpl.get();
|
||||
|
||||
auto halfW = w * 0.5f;
|
||||
auto halfH = h * 0.5f;
|
||||
|
||||
|
@ -232,32 +227,32 @@ Result Shape::appendRect(float x, float y, float w, float h, float rx, float ry)
|
|||
|
||||
//rectangle
|
||||
if (rx == 0 && ry == 0) {
|
||||
impl->path->grow(5, 4);
|
||||
impl->path->moveTo(x, y);
|
||||
impl->path->lineTo(x + w, y);
|
||||
impl->path->lineTo(x + w, y + h);
|
||||
impl->path->lineTo(x, y + h);
|
||||
impl->path->close();
|
||||
pImpl->path->grow(5, 4);
|
||||
pImpl->path->moveTo(x, y);
|
||||
pImpl->path->lineTo(x + w, y);
|
||||
pImpl->path->lineTo(x + w, y + h);
|
||||
pImpl->path->lineTo(x, y + h);
|
||||
pImpl->path->close();
|
||||
//circle
|
||||
} else if (fabsf(rx - halfW) < FLT_EPSILON && fabsf(ry - halfH) < FLT_EPSILON) {
|
||||
return appendCircle(x + (w * 0.5f), y + (h * 0.5f), rx, ry);
|
||||
} else {
|
||||
auto hrx = rx * 0.5f;
|
||||
auto hry = ry * 0.5f;
|
||||
impl->path->grow(10, 17);
|
||||
impl->path->moveTo(x + rx, y);
|
||||
impl->path->lineTo(x + w - rx, y);
|
||||
impl->path->cubicTo(x + w - rx + hrx, y, x + w, y + ry - hry, x + w, y + ry);
|
||||
impl->path->lineTo(x + w, y + h - ry);
|
||||
impl->path->cubicTo(x + w, y + h - ry + hry, x + w - rx + hrx, y + h, x + w - rx, y + h);
|
||||
impl->path->lineTo(x + rx, y + h);
|
||||
impl->path->cubicTo(x + rx - hrx, y + h, x, y + h - ry + hry, x, y + h - ry);
|
||||
impl->path->lineTo(x, y + ry);
|
||||
impl->path->cubicTo(x, y + ry - hry, x + rx - hrx, y, x + rx, y);
|
||||
impl->path->close();
|
||||
pImpl->path->grow(10, 17);
|
||||
pImpl->path->moveTo(x + rx, y);
|
||||
pImpl->path->lineTo(x + w - rx, y);
|
||||
pImpl->path->cubicTo(x + w - rx + hrx, y, x + w, y + ry - hry, x + w, y + ry);
|
||||
pImpl->path->lineTo(x + w, y + h - ry);
|
||||
pImpl->path->cubicTo(x + w, y + h - ry + hry, x + w - rx + hrx, y + h, x + w - rx, y + h);
|
||||
pImpl->path->lineTo(x + rx, y + h);
|
||||
pImpl->path->cubicTo(x + rx - hrx, y + h, x, y + h - ry + hry, x, y + h - ry);
|
||||
pImpl->path->lineTo(x, y + ry);
|
||||
pImpl->path->cubicTo(x, y + ry - hry, x + rx - hrx, y, x + rx, y);
|
||||
pImpl->path->close();
|
||||
}
|
||||
|
||||
impl->flag |= RenderUpdateFlag::Path;
|
||||
pImpl->flag |= RenderUpdateFlag::Path;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -265,18 +260,16 @@ Result Shape::appendRect(float x, float y, float w, float h, float rx, float ry)
|
|||
|
||||
Result Shape::fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept
|
||||
{
|
||||
auto impl = pImpl.get();
|
||||
pImpl->color[0] = r;
|
||||
pImpl->color[1] = g;
|
||||
pImpl->color[2] = b;
|
||||
pImpl->color[3] = a;
|
||||
pImpl->flag |= RenderUpdateFlag::Color;
|
||||
|
||||
impl->color[0] = r;
|
||||
impl->color[1] = g;
|
||||
impl->color[2] = b;
|
||||
impl->color[3] = a;
|
||||
impl->flag |= RenderUpdateFlag::Color;
|
||||
|
||||
if (impl->fill) {
|
||||
delete(impl->fill);
|
||||
impl->fill = nullptr;
|
||||
impl->flag |= RenderUpdateFlag::Gradient;
|
||||
if (pImpl->fill) {
|
||||
delete(pImpl->fill);
|
||||
pImpl->fill = nullptr;
|
||||
pImpl->flag |= RenderUpdateFlag::Gradient;
|
||||
}
|
||||
|
||||
return Result::Success;
|
||||
|
@ -285,14 +278,12 @@ Result Shape::fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept
|
|||
|
||||
Result Shape::fill(unique_ptr<Fill> f) noexcept
|
||||
{
|
||||
auto impl = pImpl.get();
|
||||
|
||||
auto p = f.release();
|
||||
if (!p) return Result::MemoryCorruption;
|
||||
|
||||
if (impl->fill && impl->fill != p) delete(impl->fill);
|
||||
impl->fill = p;
|
||||
impl->flag |= RenderUpdateFlag::Gradient;
|
||||
if (pImpl->fill && pImpl->fill != p) delete(pImpl->fill);
|
||||
pImpl->fill = p;
|
||||
pImpl->flag |= RenderUpdateFlag::Gradient;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -300,25 +291,23 @@ Result Shape::fill(unique_ptr<Fill> f) noexcept
|
|||
|
||||
Result Shape::fill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept
|
||||
{
|
||||
auto impl = pImpl.get();
|
||||
|
||||
if (r) *r = impl->color[0];
|
||||
if (g) *g = impl->color[1];
|
||||
if (b) *b = impl->color[2];
|
||||
if (a) *a = impl->color[3];
|
||||
if (r) *r = pImpl->color[0];
|
||||
if (g) *g = pImpl->color[1];
|
||||
if (b) *b = pImpl->color[2];
|
||||
if (a) *a = pImpl->color[3];
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
const Fill* Shape::fill() const noexcept
|
||||
{
|
||||
return IMPL->fill;
|
||||
return pImpl->fill;
|
||||
}
|
||||
|
||||
|
||||
Result Shape::stroke(float width) noexcept
|
||||
{
|
||||
if (!IMPL->strokeWidth(width)) return Result::FailedAllocation;
|
||||
if (!pImpl->strokeWidth(width)) return Result::FailedAllocation;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -326,14 +315,14 @@ Result Shape::stroke(float width) noexcept
|
|||
|
||||
float Shape::strokeWidth() const noexcept
|
||||
{
|
||||
if (!IMPL->stroke) return 0;
|
||||
return IMPL->stroke->width;
|
||||
if (!pImpl->stroke) return 0;
|
||||
return pImpl->stroke->width;
|
||||
}
|
||||
|
||||
|
||||
Result Shape::stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept
|
||||
{
|
||||
if (!IMPL->strokeColor(r, g, b, a)) return Result::FailedAllocation;
|
||||
if (!pImpl->strokeColor(r, g, b, a)) return Result::FailedAllocation;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -341,14 +330,12 @@ Result Shape::stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept
|
|||
|
||||
Result Shape::strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept
|
||||
{
|
||||
auto impl = pImpl.get();
|
||||
if (!pImpl->stroke) return Result::InsufficientCondition;
|
||||
|
||||
if (!impl->stroke) return Result::InsufficientCondition;
|
||||
|
||||
if (r) *r = impl->stroke->color[0];
|
||||
if (g) *g = impl->stroke->color[1];
|
||||
if (b) *b = impl->stroke->color[2];
|
||||
if (a) *a = impl->stroke->color[3];
|
||||
if (r) *r = pImpl->stroke->color[0];
|
||||
if (g) *g = pImpl->stroke->color[1];
|
||||
if (b) *b = pImpl->stroke->color[2];
|
||||
if (a) *a = pImpl->stroke->color[3];
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -358,7 +345,7 @@ Result Shape::stroke(const float* dashPattern, uint32_t cnt) noexcept
|
|||
{
|
||||
if (cnt < 2 || !dashPattern) return Result::InvalidArguments;
|
||||
|
||||
if (!IMPL->strokeDash(dashPattern, cnt)) return Result::FailedAllocation;
|
||||
if (!pImpl->strokeDash(dashPattern, cnt)) return Result::FailedAllocation;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -366,16 +353,16 @@ Result Shape::stroke(const float* dashPattern, uint32_t cnt) noexcept
|
|||
|
||||
uint32_t Shape::strokeDash(const float** dashPattern) const noexcept
|
||||
{
|
||||
if (!IMPL->stroke) return 0;
|
||||
if (!pImpl->stroke) return 0;
|
||||
|
||||
if (dashPattern) *dashPattern = IMPL->stroke->dashPattern;
|
||||
return IMPL->stroke->dashCnt;
|
||||
if (dashPattern) *dashPattern = pImpl->stroke->dashPattern;
|
||||
return pImpl->stroke->dashCnt;
|
||||
}
|
||||
|
||||
|
||||
Result Shape::stroke(StrokeCap cap) noexcept
|
||||
{
|
||||
if (!IMPL->strokeCap(cap)) return Result::FailedAllocation;
|
||||
if (!pImpl->strokeCap(cap)) return Result::FailedAllocation;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -383,7 +370,7 @@ Result Shape::stroke(StrokeCap cap) noexcept
|
|||
|
||||
Result Shape::stroke(StrokeJoin join) noexcept
|
||||
{
|
||||
if (!IMPL->strokeJoin(join)) return Result::FailedAllocation;
|
||||
if (!pImpl->strokeJoin(join)) return Result::FailedAllocation;
|
||||
|
||||
return Result::Success;
|
||||
}
|
||||
|
@ -391,15 +378,15 @@ Result Shape::stroke(StrokeJoin join) noexcept
|
|||
|
||||
StrokeCap Shape::strokeCap() const noexcept
|
||||
{
|
||||
if (!IMPL->stroke) return StrokeCap::Square;
|
||||
if (!pImpl->stroke) return StrokeCap::Square;
|
||||
|
||||
return IMPL->stroke->cap;
|
||||
return pImpl->stroke->cap;
|
||||
}
|
||||
|
||||
|
||||
StrokeJoin Shape::strokeJoin() const noexcept
|
||||
{
|
||||
if (!IMPL->stroke) return StrokeJoin::Bevel;
|
||||
if (!pImpl->stroke) return StrokeJoin::Bevel;
|
||||
|
||||
return IMPL->stroke->join;
|
||||
}
|
||||
return pImpl->stroke->join;
|
||||
}
|
|
@ -181,7 +181,7 @@ struct Shape::Impl
|
|||
auto ret = Shape::gen();
|
||||
if (!ret) return nullptr;
|
||||
|
||||
auto dup = ret.get()->pImpl.get();
|
||||
auto dup = ret.get()->pImpl;
|
||||
|
||||
//Color
|
||||
memcpy(dup->color, color, sizeof(color));
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
|
||||
struct SwCanvas::Impl
|
||||
{
|
||||
Impl() {}
|
||||
};
|
||||
|
||||
|
||||
|
@ -46,9 +45,9 @@ struct SwCanvas::Impl
|
|||
/************************************************************************/
|
||||
|
||||
#ifdef THORVG_SW_RASTER_SUPPORT
|
||||
SwCanvas::SwCanvas() : Canvas(SwRenderer::gen()), pImpl(make_unique<Impl>())
|
||||
SwCanvas::SwCanvas() : Canvas(SwRenderer::gen()), pImpl(new Impl)
|
||||
#else
|
||||
SwCanvas::SwCanvas() : Canvas(nullptr), pImpl(make_unique<Impl>())
|
||||
SwCanvas::SwCanvas() : Canvas(nullptr), pImpl(new Impl)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
@ -56,6 +55,7 @@ SwCanvas::SwCanvas() : Canvas(nullptr), pImpl(make_unique<Impl>())
|
|||
|
||||
SwCanvas::~SwCanvas()
|
||||
{
|
||||
delete(pImpl);
|
||||
}
|
||||
|
||||
|
||||
|
@ -63,7 +63,7 @@ Result SwCanvas::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t
|
|||
{
|
||||
#ifdef THORVG_SW_RASTER_SUPPORT
|
||||
//We know renderer type, avoid dynamic_cast for performance.
|
||||
auto renderer = static_cast<SwRenderer*>(Canvas::pImpl.get()->renderer);
|
||||
auto renderer = static_cast<SwRenderer*>(Canvas::pImpl->renderer);
|
||||
if (!renderer) return Result::MemoryCorruption;
|
||||
|
||||
if (!renderer->target(buffer, stride, w, h, cs)) return Result::InvalidArguments;
|
||||
|
|
Loading…
Add table
Reference in a new issue