common: code refactoring 46/239746/2
authorHermet Park <chuneon.park@samsung.com>
Wed, 29 Jul 2020 10:47:28 +0000 (19:47 +0900)
committerHermet Park <chuneon.park@samsung.com>
Wed, 29 Jul 2020 10:53:45 +0000 (19:53 +0900)
remove exceptional handling which is inevitable scenario.

Change-Id: I761a59a38f4578291ee8bc044c5ca989feedbe79

src/lib/tvgCanvas.cpp
src/lib/tvgCommon.h
src/lib/tvgFill.cpp
src/lib/tvgLinearGradient.cpp
src/lib/tvgPaint.cpp
src/lib/tvgRadialGradient.cpp
src/lib/tvgScene.cpp
src/lib/tvgShape.cpp

index 01fcae1..d110aee 100644 (file)
@@ -36,59 +36,44 @@ Canvas::~Canvas()
 
 Result Canvas::reserve(uint32_t n) noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-    impl->paints.reserve(n);
+    IMPL->paints.reserve(n);
     return Result::Success;
 }
 
 
 Result Canvas::push(unique_ptr<Paint> paint) noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-    return impl->push(move(paint));
+    return IMPL->push(move(paint));
 }
 
 
 Result Canvas::clear() noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-    return impl->clear();
+    return IMPL->clear();
 }
 
 
 Result Canvas::draw(bool async) noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-    return impl->draw();
+    return IMPL->draw();
 }
 
 
 Result Canvas::update() noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-    return impl->update();
+    return IMPL->update();
 }
 
 
 Result Canvas::update(Paint* paint) noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-    return impl->update(paint);
+    return IMPL->update(paint);
 }
 
 
 Result Canvas::sync() noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-
-    if (impl->renderer->flush()) return Result::Success;
+    if (IMPL->renderer->flush()) return Result::Success;
 
     return Result::InsufficientCondition;
 }
index 3c390b1..2e5bd13 100644 (file)
@@ -30,6 +30,7 @@
 using namespace std;
 using namespace tvg;
 
+#define IMPL pImpl.get()
 #define SCENE_IMPL scene->pImpl.get()
 #define SHAPE_IMPL shape->pImpl.get()
 
index bfef7a6..fe3ef3f 100644 (file)
@@ -54,7 +54,6 @@ Fill::~Fill()
 Result Fill::colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept
 {
     auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
 
     if (cnt == 0) {
         if (impl->colorStops) {
@@ -78,21 +77,15 @@ Result Fill::colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept
 
 uint32_t Fill::colorStops(const ColorStop** colorStops) const noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return 0;
-
-    if (colorStops) *colorStops = impl->colorStops;
+    if (colorStops) *colorStops = IMPL->colorStops;
 
-    return impl->cnt;
+    return IMPL->cnt;
 }
 
 
 Result Fill::spread(FillSpread s) noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-
-    impl->spread = s;
+    IMPL->spread = s;
 
     return Result::Success;
 }
@@ -100,10 +93,7 @@ Result Fill::spread(FillSpread s) noexcept
 
 FillSpread Fill::spread() const noexcept
 {
-    auto impl = pImpl.get();
-    assert(impl);
-
-    return impl->spread;
+    return IMPL->spread;
 }
 
 #endif /* _TVG_FILL_CPP_ */
\ No newline at end of file
index 4499454..88be20c 100644 (file)
@@ -49,13 +49,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;
 
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-
-    impl->x1 = x1;
-    impl->y1 = y1;
-    impl->x2 = x2;
-    impl->y2 = y2;
+    IMPL->x1 = x1;
+    IMPL->y1 = y1;
+    IMPL->x2 = x2;
+    IMPL->y2 = y2;
 
     return Result::Success;
 }
@@ -63,13 +60,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
 {
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-
-    if (x1) *x1 = impl->x1;
-    if (x2) *x2 = impl->x2;
-    if (y1) *y1 = impl->y1;
-    if (y2) *y2 = impl->y2;
+    if (x1) *x1 = IMPL->x1;
+    if (x2) *x2 = IMPL->x2;
+    if (y1) *y1 = IMPL->y1;
+    if (y2) *y2 = IMPL->y2;
 
     return Result::Success;
 }
index 7eeca19..b33b764 100644 (file)
@@ -39,35 +39,35 @@ Paint :: ~Paint()
 
 Result Paint::rotate(float degree) noexcept
 {
-    if (pImpl.get()->ts->rotate(degree)) return Result::Success;
+    if (IMPL->ts->rotate(degree)) return Result::Success;
     return Result::FailedAllocation;
 }
 
 
 Result Paint::scale(float factor) noexcept
 {
-    if (pImpl.get()->ts->scale(factor)) return Result::Success;
+    if (IMPL->ts->scale(factor)) return Result::Success;
     return Result::FailedAllocation;
 }
 
 
 Result Paint::translate(float x, float y) noexcept
 {
-    if (pImpl.get()->ts->translate(x, y)) return Result::Success;
+    if (IMPL->ts->translate(x, y)) return Result::Success;
     return Result::FailedAllocation;
 }
 
 
 Result Paint::transform(const Matrix& m) noexcept
 {
-    if (pImpl.get()->ts->transform(m)) return Result::Success;
+    if (IMPL->ts->transform(m)) return Result::Success;
     return Result::FailedAllocation;
 }
 
 
 Result Paint::bounds(float* x, float* y, float* w, float* h) const noexcept
 {
-    if (pImpl.get()->ts->bounds(x, y, w, h)) return Result::Success;
+    if (IMPL->ts->bounds(x, y, w, h)) return Result::Success;
     return Result::InsufficientCondition;
 }
 
index 895cccb..154e163 100644 (file)
@@ -46,15 +46,11 @@ RadialGradient::~RadialGradient()
 
 Result RadialGradient::radial(float cx, float cy, float radius) noexcept
 {
-    if (radius < FLT_EPSILON)
-        return Result::InvalidArguments;
+    if (radius < FLT_EPSILON) return Result::InvalidArguments;
 
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-
-    impl->cx = cx;
-    impl->cy = cy;
-    impl->radius = radius;
+    IMPL->cx = cx;
+    IMPL->cy = cy;
+    IMPL->radius = radius;
 
     return Result::Success;
 }
@@ -62,12 +58,9 @@ Result RadialGradient::radial(float cx, float cy, float radius) noexcept
 
 Result RadialGradient::radial(float* cx, float* cy, float* radius) const noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-
-    if (cx) *cx = impl->cx;
-    if (cy) *cy = impl->cy;
-    if (radius) *radius = impl->radius;
+    if (cx) *cx = IMPL->cx;
+    if (cy) *cy = IMPL->cy;
+    if (radius) *radius = IMPL->radius;
 
     return Result::Success;
 }
index 78ca868..adbbe09 100644 (file)
@@ -44,12 +44,9 @@ unique_ptr<Scene> Scene::gen() noexcept
 
 Result Scene::push(unique_ptr<Paint> paint) noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-
     auto p = paint.release();
     if (!p) return Result::MemoryCorruption;
-    impl->paints.push_back(p);
+    IMPL->paints.push_back(p);
 
     return Result::Success;
 }
@@ -57,10 +54,7 @@ Result Scene::push(unique_ptr<Paint> paint) noexcept
 
 Result Scene::reserve(uint32_t size) noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-
-    impl->paints.reserve(size);
+    IMPL->paints.reserve(size);
 
     return Result::Success;
 }
@@ -70,10 +64,7 @@ Result Scene::load(const std::string& path) noexcept
 {
     if (path.empty()) return Result::InvalidArguments;
 
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-
-     return impl->load(path);
+     return IMPL->load(path);
 }
 
 #endif /* _TVG_SCENE_CPP_ */
\ No newline at end of file
index c822f94..ddd3ef0 100644 (file)
@@ -50,12 +50,9 @@ unique_ptr<Shape> Shape::gen() noexcept
 
 Result Shape::reset() noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl || !impl->path) return Result::MemoryCorruption;
-
-    impl->path->reset();
+    IMPL->path->reset();
 
-    impl->flag |= RenderUpdateFlag::Path;
+    IMPL->flag |= RenderUpdateFlag::Path;
 
     return Result::Success;
 }
@@ -65,12 +62,9 @@ uint32_t Shape::pathCommands(const PathCommand** cmds) const noexcept
 {
     if (!cmds) return 0;
 
-    auto impl = pImpl.get();
-    if (!impl || !impl->path) return 0;
-
-    *cmds = impl->path->cmds;
+    *cmds = IMPL->path->cmds;
 
-    return impl->path->cmdCnt;
+    return IMPL->path->cmdCnt;
 }
 
 
@@ -78,12 +72,9 @@ uint32_t Shape::pathCoords(const Point** pts) const noexcept
 {
     if (!pts) return 0;
 
-    auto impl = pImpl.get();
-    if (!impl || !impl->path) return 0;
+    *pts = IMPL->path->pts;
 
-    *pts = impl->path->pts;
-
-    return impl->path->ptsCnt;
+    return IMPL->path->ptsCnt;
 }
 
 
@@ -91,13 +82,10 @@ Result Shape::appendPath(const PathCommand *cmds, uint32_t cmdCnt, const Point*
 {
     if (cmdCnt < 0 || ptsCnt < 0 || !pts || !ptsCnt) return Result::InvalidArguments;
 
-    auto impl = pImpl.get();
-    if (!impl || !impl->path) return Result::MemoryCorruption;
+    IMPL->path->grow(cmdCnt, ptsCnt);
+    IMPL->path->append(cmds, cmdCnt, pts, ptsCnt);
 
-    impl->path->grow(cmdCnt, ptsCnt);
-    impl->path->append(cmds, cmdCnt, pts, ptsCnt);
-
-    impl->flag |= RenderUpdateFlag::Path;
+    IMPL->flag |= RenderUpdateFlag::Path;
 
     return Result::Success;
 }
@@ -105,12 +93,9 @@ Result Shape::appendPath(const PathCommand *cmds, uint32_t cmdCnt, const Point*
 
 Result Shape::moveTo(float x, float y) noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl || !impl->path) return Result::MemoryCorruption;
+    IMPL->path->moveTo(x, y);
 
-    impl->path->moveTo(x, y);
-
-    impl->flag |= RenderUpdateFlag::Path;
+    IMPL->flag |= RenderUpdateFlag::Path;
 
     return Result::Success;
 }
@@ -118,12 +103,9 @@ Result Shape::moveTo(float x, float y) noexcept
 
 Result Shape::lineTo(float x, float y) noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl || !impl->path) return Result::MemoryCorruption;
+    IMPL->path->lineTo(x, y);
 
-    impl->path->lineTo(x, y);
-
-    impl->flag |= RenderUpdateFlag::Path;
+    IMPL->flag |= RenderUpdateFlag::Path;
 
     return Result::Success;
 }
@@ -131,12 +113,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
 {
-    auto impl = pImpl.get();
-    if (!impl || !impl->path) return Result::MemoryCorruption;
+    IMPL->path->cubicTo(cx1, cy1, cx2, cy2, x, y);
 
-    impl->path->cubicTo(cx1, cy1, cx2, cy2, x, y);
-
-    impl->flag |= RenderUpdateFlag::Path;
+    IMPL->flag |= RenderUpdateFlag::Path;
 
     return Result::Success;
 }
@@ -144,12 +123,9 @@ Result Shape::cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float
 
 Result Shape::close() noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl || !impl->path) return Result::MemoryCorruption;
+    IMPL->path->close();
 
-    impl->path->close();
-
-    impl->flag |= RenderUpdateFlag::Path;
+    IMPL->flag |= RenderUpdateFlag::Path;
 
     return Result::Success;
 }
@@ -158,7 +134,6 @@ Result Shape::close() noexcept
 Result Shape::appendCircle(float cx, float cy, float rx, float ry) noexcept
 {
     auto impl = pImpl.get();
-    if (!impl || !impl->path) return Result::MemoryCorruption;
 
     auto rxKappa = rx * PATH_KAPPA;
     auto ryKappa = ry * PATH_KAPPA;
@@ -180,7 +155,6 @@ Result Shape::appendCircle(float cx, float cy, float rx, float ry) noexcept
 Result Shape::appendRect(float x, float y, float w, float h, float rx, float ry) noexcept
 {
     auto impl = pImpl.get();
-    if (!impl || !impl->path) return Result::MemoryCorruption;
 
     auto halfW = w * 0.5f;
     auto halfH = h * 0.5f;
@@ -225,7 +199,6 @@ 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();
-    if (!impl) return Result::MemoryCorruption;
 
     impl->color[0] = r;
     impl->color[1] = g;
@@ -246,7 +219,6 @@ 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();
-    if (!impl) return Result::MemoryCorruption;
 
     auto p = f.release();
     if (!p) return Result::MemoryCorruption;
@@ -262,7 +234,6 @@ 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 (!impl) return Result::MemoryCorruption;
 
     if (r) *r = impl->color[0];
     if (g) *g = impl->color[1];
@@ -274,19 +245,13 @@ Result Shape::fill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcep
 
 const Fill* Shape::fill() const noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return nullptr;
-
-    return impl->fill;
+    return IMPL->fill;
 }
 
 
 Result Shape::stroke(float width) noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-
-    if (!impl->strokeWidth(width)) return Result::FailedAllocation;
+    if (!IMPL->strokeWidth(width)) return Result::FailedAllocation;
 
     return Result::Success;
 }
@@ -294,20 +259,14 @@ Result Shape::stroke(float width) noexcept
 
 float Shape::strokeWidth() const noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return 0;
-
-    if (!impl->stroke) return 0;
-    return impl->stroke->width;
+    if (!IMPL->stroke) return 0;
+    return IMPL->stroke->width;
 }
 
 
 Result Shape::stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-
-    if (!impl->strokeColor(r, g, b, a)) return Result::FailedAllocation;
+    if (!IMPL->strokeColor(r, g, b, a)) return Result::FailedAllocation;
 
     return Result::Success;
 }
@@ -316,7 +275,6 @@ 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 (!impl) return Result::MemoryCorruption;
 
     if (!impl->stroke) return Result::InsufficientCondition;
 
@@ -333,10 +291,7 @@ Result Shape::stroke(const float* dashPattern, uint32_t cnt) noexcept
 {
     if (cnt < 2 || !dashPattern) return Result::InvalidArguments;
 
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-
-    if (!impl->strokeDash(dashPattern, cnt)) return Result::FailedAllocation;
+    if (!IMPL->strokeDash(dashPattern, cnt)) return Result::FailedAllocation;
 
     return Result::Success;
 }
@@ -344,22 +299,16 @@ Result Shape::stroke(const float* dashPattern, uint32_t cnt) noexcept
 
 uint32_t Shape::strokeDash(const float** dashPattern) const noexcept
 {
-    auto impl = pImpl.get();
-    assert(impl);
-
-    if (!impl->stroke) return 0;
+    if (!IMPL->stroke) return 0;
 
-    if (dashPattern) *dashPattern = impl->stroke->dashPattern;
-    return impl->stroke->dashCnt;
+    if (dashPattern) *dashPattern = IMPL->stroke->dashPattern;
+    return IMPL->stroke->dashCnt;
 }
 
 
 Result Shape::stroke(StrokeCap cap) noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-
-    if (!impl->strokeCap(cap)) return Result::FailedAllocation;
+    if (!IMPL->strokeCap(cap)) return Result::FailedAllocation;
 
     return Result::Success;
 }
@@ -367,10 +316,7 @@ Result Shape::stroke(StrokeCap cap) noexcept
 
 Result Shape::stroke(StrokeJoin join) noexcept
 {
-    auto impl = pImpl.get();
-    if (!impl) return Result::MemoryCorruption;
-
-    if (!impl->strokeJoin(join)) return Result::FailedAllocation;
+    if (!IMPL->strokeJoin(join)) return Result::FailedAllocation;
 
     return Result::Success;
 }
@@ -378,23 +324,17 @@ Result Shape::stroke(StrokeJoin join) noexcept
 
 StrokeCap Shape::strokeCap() const noexcept
 {
-    auto impl = pImpl.get();
-    assert(impl);
-
-    if (!impl->stroke) return StrokeCap::Square;
+    if (!IMPL->stroke) return StrokeCap::Square;
 
-    return impl->stroke->cap;
+    return IMPL->stroke->cap;
 }
 
 
 StrokeJoin Shape::strokeJoin() const noexcept
 {
-    auto impl = pImpl.get();
-    assert(impl);
-
-    if (!impl->stroke) return StrokeJoin::Bevel;
+    if (!IMPL->stroke) return StrokeJoin::Bevel;
 
-    return impl->stroke->join;
+    return IMPL->stroke->join;
 }