common interface: concrete return type. 04/235704/5
authorHermet Park <chuneon.park@samsung.com>
Tue, 9 Jun 2020 05:18:58 +0000 (14:18 +0900)
committerHermet Park <chuneon.park@samsung.com>
Tue, 9 Jun 2020 06:16:25 +0000 (15:16 +0900)
Introduce Result type for notifying caller more detailed info.

We should implement the result values for each apis, with practical values.

Change-Id: Ia47abcb56a8efca7094ac3eed0178aeac8aa2910

inc/tizenvg.h
src/lib/sw_engine/tvgSwRenderer.cpp
src/lib/tvgCanvas.cpp
src/lib/tvgCanvasImpl.h
src/lib/tvgEngine.cpp
src/lib/tvgGlCanvas.cpp
src/lib/tvgScene.cpp
src/lib/tvgSceneImpl.h
src/lib/tvgShape.cpp
src/lib/tvgShapeImpl.h
src/lib/tvgSwCanvas.cpp

index 18db842..16e60f0 100644 (file)
@@ -53,6 +53,7 @@ protected: \
 namespace tvg
 {
 
+enum class TIZENVG_EXPORT Result { Success = 0, InvalidArguments, InsufficientCondition, FailedAllocation, MemoryCorruption, Unknown };
 enum class TIZENVG_EXPORT PathCommand { Close = 0, MoveTo, LineTo, CubicTo };
 enum class TIZENVG_EXPORT StrokeCap { Square = 0, Round, Butt };
 enum class TIZENVG_EXPORT StrokeJoin { Bevel = 0, Round, Miter };
@@ -79,11 +80,11 @@ class TIZENVG_EXPORT Paint
 public:
     virtual ~Paint() {}
 
-    virtual int rotate(float degree) = 0;
-    virtual int scale(float factor) = 0;
-    virtual int translate(float x, float y) = 0;
+    virtual Result rotate(float degree) = 0;
+    virtual Result scale(float factor) = 0;
+    virtual Result translate(float x, float y) = 0;
 
-    virtual int bounds(float* x, float* y, float* w, float* h) const = 0;
+    virtual Result bounds(float* x, float* y, float* w, float* h) const = 0;
 };
 
 
@@ -101,13 +102,13 @@ public:
     Canvas(RenderMethod*);
     virtual ~Canvas();
 
-    int reserve(size_t n) noexcept;
-    virtual int push(std::unique_ptr<Paint> paint) noexcept;
-    virtual int clear() noexcept;
-    virtual int update() noexcept;
-    virtual int update(Paint* paint) noexcept;
-    virtual int draw(bool async = true) noexcept;
-    virtual int sync() = 0;
+    Result reserve(size_t n) noexcept;
+    virtual Result push(std::unique_ptr<Paint> paint) noexcept;
+    virtual Result clear() noexcept;
+    virtual Result update() noexcept;
+    virtual Result update(Paint* paint) noexcept;
+    virtual Result draw(bool async = true) noexcept;
+    virtual Result sync() = 0;
 
     _TIZENVG_DECLARE_ACCESSOR(Scene);
     _TIZENVG_DECLARE_PRIVATE(Canvas);
@@ -127,42 +128,42 @@ class TIZENVG_EXPORT Shape final : public Paint
 public:
     ~Shape();
 
-    int reset() noexcept;
+    Result reset() noexcept;
 
     //Path
-    int moveTo(float x, float y) noexcept;
-    int lineTo(float x, float y) noexcept;
-    int cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept;
-    int close() noexcept;
+    Result moveTo(float x, float y) noexcept;
+    Result lineTo(float x, float y) noexcept;
+    Result cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept;
+    Result close() noexcept;
 
     //Shape
-    int appendRect(float x, float y, float w, float h, float cornerRadius) noexcept;
-    int appendCircle(float cx, float cy, float radiusW, float radiusH) noexcept;
-    int appendPath(const PathCommand* cmds, size_t cmdCnt, const Point* pts, size_t ptsCnt) noexcept;
+    Result appendRect(float x, float y, float w, float h, float cornerRadius) noexcept;
+    Result appendCircle(float cx, float cy, float radiusW, float radiusH) noexcept;
+    Result appendPath(const PathCommand* cmds, size_t cmdCnt, const Point* pts, size_t ptsCnt) noexcept;
 
     //Stroke
-    int stroke(float width) noexcept;
-    int stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
-    int stroke(const float* dashPattern, size_t cnt) noexcept;
-    int stroke(StrokeCap cap) noexcept;
-    int stroke(StrokeJoin join) noexcept;
+    Result stroke(float width) noexcept;
+    Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
+    Result stroke(const float* dashPattern, size_t cnt) noexcept;
+    Result stroke(StrokeCap cap) noexcept;
+    Result stroke(StrokeJoin join) noexcept;
 
     //Fill
-    int fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
+    Result fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
 
     //Transform
-    int rotate(float degree) noexcept override;
-    int scale(float factor) noexcept override;
-    int translate(float x, float y) noexcept override;
+    Result rotate(float degree) noexcept override;
+    Result scale(float factor) noexcept override;
+    Result translate(float x, float y) noexcept override;
 
     //Getters
     size_t pathCommands(const PathCommand** cmds) const noexcept;
     size_t pathCoords(const Point** pts) const noexcept;
-    int fill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
-    int bounds(float* x, float* y, float* w, float* h) const noexcept override;
+    Result fill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
+    Result bounds(float* x, float* y, float* w, float* h) const noexcept override;
 
     float strokeWidth() const noexcept;
-    int strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
+    Result strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
     size_t strokeDash(const float** dashPattern) const noexcept;
     StrokeCap strokeCap() const noexcept;
     StrokeJoin strokeJoin() const noexcept;
@@ -188,14 +189,14 @@ class TIZENVG_EXPORT Scene final : public Paint
 public:
     ~Scene();
 
-    int push(std::unique_ptr<Paint> shape) noexcept;
-    int reserve(size_t size) noexcept;
+    Result push(std::unique_ptr<Paint> shape) noexcept;
+    Result reserve(size_t size) noexcept;
 
-    int rotate(float degree) noexcept override;
-    int scale(float factor) noexcept override;
-    int translate(float x, float y) noexcept override;
+    Result rotate(float degree) noexcept override;
+    Result scale(float factor) noexcept override;
+    Result translate(float x, float y) noexcept override;
 
-    int bounds(float* x, float* y, float* w, float* h) const noexcept override;
+    Result bounds(float* x, float* y, float* w, float* h) const noexcept override;
 
     static std::unique_ptr<Scene> gen() noexcept;
 
@@ -217,8 +218,8 @@ class TIZENVG_EXPORT SwCanvas final : public Canvas
 public:
     ~SwCanvas();
 
-    int target(uint32_t* buffer, size_t stride, size_t w, size_t h) noexcept;
-    int sync() noexcept override;
+    Result target(uint32_t* buffer, size_t stride, size_t w, size_t h) noexcept;
+    Result sync() noexcept override;
     static std::unique_ptr<SwCanvas> gen() noexcept;
 
     _TIZENVG_DECLARE_PRIVATE(SwCanvas);
@@ -240,8 +241,8 @@ public:
 
     //TODO: Gl Specific methods. Need gl backend configuration methods as well.
 
-    int target(uint32_t* buffer, size_t stride, size_t w, size_t h) noexcept;
-    int sync() noexcept override;
+    Result target(uint32_t* buffer, size_t stride, size_t w, size_t h) noexcept;
+    Result sync() noexcept override;
     static std::unique_ptr<GlCanvas> gen() noexcept;
 
     _TIZENVG_DECLARE_PRIVATE(GlCanvas);
@@ -270,8 +271,8 @@ public:
      *
      * @see ...
      */
-    static int init() noexcept;
-    static int term() noexcept;
+    static Result init() noexcept;
+    static Result term() noexcept;
 
     _TIZENVG_DISABLE_CTOR(Engine);
 };
index 5461abe..60c3a6d 100644 (file)
@@ -47,7 +47,7 @@ bool SwRenderer::clear()
 
 bool SwRenderer::target(uint32_t* buffer, size_t stride, size_t w, size_t h)
 {
-    assert(buffer && stride > 0 && w > 0 && h > 0);
+    if (!buffer || stride == 0 || w == 0 || h == 0) return false;
 
     surface.buffer = buffer;
     surface.stride = stride;
@@ -77,7 +77,7 @@ bool SwRenderer::render(const Shape& shape, void *data)
 bool SwRenderer::dispose(const Shape& shape, void *data)
 {
     auto sdata = static_cast<SwShape*>(data);
-    if (!sdata) return false;
+    if (!sdata) return true;
     shapeFree(sdata);
     return true;
 }
index f31373e..79057c7 100644 (file)
@@ -34,52 +34,51 @@ Canvas::~Canvas()
 }
 
 
-int Canvas::reserve(size_t n) noexcept
+Result Canvas::reserve(size_t n) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
     impl->paints.reserve(n);
-    return 0;
+    return Result::Success;
 }
 
 
-int Canvas::push(unique_ptr<Paint> paint) noexcept
+Result Canvas::push(unique_ptr<Paint> paint) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
-
+    if (!impl) return Result::MemoryCorruption;
     return impl->push(move(paint));
 }
 
 
-int Canvas::clear() noexcept
+Result Canvas::clear() noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
     return impl->clear();
 }
 
 
-int Canvas::draw(bool async) noexcept
+Result Canvas::draw(bool async) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
     return impl->draw();
 }
 
 
-int Canvas::update() noexcept
+Result Canvas::update() noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
     return impl->update();
 }
 
 
-int Canvas::update(Paint* paint) noexcept
+Result Canvas::update(Paint* paint) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
     return impl->update(paint);
 }
 
index afa2a0b..782dd94 100644 (file)
@@ -39,7 +39,7 @@ struct Canvas::Impl
         renderer->unref();
     }
 
-    int push(unique_ptr<Paint> paint)
+    Result push(unique_ptr<Paint> paint)
     {
         auto p = paint.release();
         assert(p);
@@ -48,64 +48,64 @@ struct Canvas::Impl
         return update(p);
     }
 
-    int clear()
+    Result clear()
     {
         assert(renderer);
 
         for (auto paint : paints) {
             if (auto scene = dynamic_cast<Scene*>(paint)) {
-                if (!SCENE_IMPL->clear(*renderer)) return -1;
+                if (!SCENE_IMPL->clear(*renderer)) return Result::InsufficientCondition;
             } else if (auto shape = dynamic_cast<Shape*>(paint)) {
-                if (!SHAPE_IMPL->dispose(*shape, *renderer)) return -1;
+                if (!SHAPE_IMPL->dispose(*shape, *renderer)) return Result::InsufficientCondition;
             }
             delete(paint);
         }
         paints.clear();
 
-        return 0;
+        return Result::Success;
     }
 
-    int update()
+    Result update()
     {
         assert(renderer);
 
         for(auto paint: paints) {
             if (auto scene = dynamic_cast<Scene*>(paint)) {
-                if (!SCENE_IMPL->update(*renderer, nullptr)) return -1;
+                if (!SCENE_IMPL->update(*renderer, nullptr)) return Result::InsufficientCondition;
             } else if (auto shape = dynamic_cast<Shape*>(paint)) {
-                if (!SHAPE_IMPL->update(*shape, *renderer, nullptr)) return -1;
+                if (!SHAPE_IMPL->update(*shape, *renderer, nullptr)) return Result::InsufficientCondition;
             }
         }
-        return 0;
+        return Result::Success;
     }
 
-    int update(Paint* paint)
+    Result update(Paint* paint)
     {
         assert(renderer);
 
         if (auto scene = dynamic_cast<Scene*>(paint)) {
-            if (!SCENE_IMPL->update(*renderer)) return -1;
+            if (!SCENE_IMPL->update(*renderer)) return Result::InsufficientCondition;
         } else if (auto shape = dynamic_cast<Shape*>(paint)) {
-            if (!SHAPE_IMPL->update(*shape, *renderer)) return -1;
+            if (!SHAPE_IMPL->update(*shape, *renderer)) return Result::InsufficientCondition;
         }
-        return 0;
+        return Result::Success;
     }
 
-    int draw()
+    Result draw()
     {
         assert(renderer);
 
         //Clear render target before drawing
-        if (!renderer->clear()) return -1;
+        if (!renderer->clear()) return Result::InsufficientCondition;
 
         for(auto paint: paints) {
             if (auto scene = dynamic_cast<Scene*>(paint)) {
-                if(!SCENE_IMPL->render(*renderer)) return -1;
+                if(!SCENE_IMPL->render(*renderer)) return Result::InsufficientCondition;
             } else if (auto shape = dynamic_cast<Shape*>(paint)) {
-                if(!SHAPE_IMPL->render(*shape, *renderer)) return -1;
+                if(!SHAPE_IMPL->render(*shape, *renderer)) return Result::InsufficientCondition;
             }
         }
-        return 0;
+        return Result::Success;
     }
 };
 
index fa005dc..40b1308 100644 (file)
@@ -30,7 +30,7 @@
 /* External Class Implementation                                        */
 /************************************************************************/
 
-int Engine::init() noexcept
+Result Engine::init() noexcept
 {
     //TODO: Initialize Raster engines by configuration.
 
@@ -38,17 +38,17 @@ int Engine::init() noexcept
     ret |= SwRenderer::init();
     ret |= GlRenderer::init();
 
-    return ret;
+    return Result::Success;
 }
 
 
-int Engine::term() noexcept
+Result Engine::term() noexcept
 {
     int ret = 0;
     ret |= SwRenderer::term();
     ret |= GlRenderer::term();
 
-    return ret;
+    return Result::Success;
 }
 
 #endif /* _TVG_ENGINE_CPP_ */
index c1b7aeb..2bf3868 100644 (file)
@@ -45,20 +45,20 @@ GlCanvas::~GlCanvas()
 }
 
 
-int GlCanvas::target(uint32_t* buffer, size_t stride, size_t w, size_t h) noexcept
+Result GlCanvas::target(uint32_t* buffer, size_t stride, size_t w, size_t h) noexcept
 {
     auto renderer = dynamic_cast<GlRenderer*>(Canvas::pImpl.get()->renderer);
-    assert(renderer);
+    if (!renderer) return Result::MemoryCorruption;
 
-    if (!renderer->target(buffer, stride, w, h)) return -1;
+    if (!renderer->target(buffer, stride, w, h)) return Result::Unknown;
 
-    return 0;
+    return Result::Success;
 }
 
 
-int GlCanvas::sync() noexcept
+Result GlCanvas::sync() noexcept
 {
-    return 0;
+    return Result::Success;
 }
 
 
index 93a64b1..12b96ec 100644 (file)
@@ -40,65 +40,71 @@ unique_ptr<Scene> Scene::gen() noexcept
 }
 
 
-int Scene::push(unique_ptr<Paint> paint) noexcept
+Result Scene::push(unique_ptr<Paint> paint) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
 
     auto p = paint.release();
-    assert(p);
+    if (!p) return Result::MemoryCorruption;
     impl->paints.push_back(p);
 
-    return 0;
+    return Result::Success;
 }
 
 
-int Scene::reserve(size_t size) noexcept
+Result Scene::reserve(size_t size) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
 
     impl->paints.reserve(size);
 
-    return 0;
+    return Result::Success;
 }
 
 
-int Scene::scale(float factor) noexcept
+Result Scene::scale(float factor) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
 
-    return impl->scale(factor);
+    if (!impl->scale(factor)) return Result::FailedAllocation;
+
+    return Result::Success;
 }
 
 
-int Scene::rotate(float degree) noexcept
+Result Scene::rotate(float degree) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
+
+    if (!impl->rotate(degree)) return Result::FailedAllocation;
 
-    return impl->rotate(degree);
+    return Result::Success;
 }
 
 
-int Scene::translate(float x, float y) noexcept
+Result Scene::translate(float x, float y) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
+
+    if (!impl->translate(x, y)) return Result::FailedAllocation;
 
-    return impl->translate(x, y);
+    return Result::Success;
 }
 
 
-int Scene::bounds(float* x, float* y, float* w, float* h) const noexcept
+Result Scene::bounds(float* x, float* y, float* w, float* h) const noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
 
-    if (!impl->bounds(x, y, w, h)) return -1;
+    if (!impl->bounds(x, y, w, h)) return Result::InsufficientCondition;
 
-    return 0;
+    return Result::Success;
 }
 
 #endif /* _TVG_SCENE_CPP_ */
\ No newline at end of file
index 9064b53..a08afc6 100644 (file)
@@ -66,7 +66,7 @@ struct Scene::Impl
     bool update(RenderMethod &renderer, const RenderTransform* pTransform = nullptr, size_t pFlag = 0)
     {
         if (flag & RenderUpdateFlag::Transform) {
-            assert(transform);
+            if (!transform) return false;
             if (!transform->update()) {
                 delete(transform);
                 transform = nullptr;
@@ -137,47 +137,47 @@ struct Scene::Impl
     bool scale(float factor)
     {
         if (transform) {
-            if (fabsf(factor - transform->factor) <= FLT_EPSILON) return -1;
+            if (fabsf(factor - transform->factor) <= FLT_EPSILON) return true;
         } else {
-            if (fabsf(factor) <= FLT_EPSILON) return -1;
+            if (fabsf(factor) <= FLT_EPSILON) return true;
             transform = new RenderTransform();
-            assert(transform);
+            if (!transform) return false;
         }
         transform->factor = factor;
         flag |= RenderUpdateFlag::Transform;
 
-        return 0;
+        return true;
     }
 
     bool rotate(float degree)
     {
         if (transform) {
-            if (fabsf(degree - transform->degree) <= FLT_EPSILON) return -1;
+            if (fabsf(degree - transform->degree) <= FLT_EPSILON) return true;
         } else {
-            if (fabsf(degree) <= FLT_EPSILON) return -1;
+            if (fabsf(degree) <= FLT_EPSILON) return true;
             transform = new RenderTransform();
-            assert(transform);
+            if (!transform) return false;
         }
         transform->degree = degree;
         flag |= RenderUpdateFlag::Transform;
 
-        return 0;
+        return true;
     }
 
     bool translate(float x, float y)
     {
         if (transform) {
-            if (fabsf(x - transform->x) <= FLT_EPSILON && fabsf(y - transform->y) <= FLT_EPSILON) return -1;
+            if (fabsf(x - transform->x) <= FLT_EPSILON && fabsf(y - transform->y) <= FLT_EPSILON) return true;
         } else {
-            if (fabsf(x) <= FLT_EPSILON && fabsf(y) <= FLT_EPSILON) return -1;
+            if (fabsf(x) <= FLT_EPSILON && fabsf(y) <= FLT_EPSILON) return true;
             transform = new RenderTransform();
-            assert(transform);
+            if (!transform) return false;
         }
         transform->x = x;
         transform->y = y;
         flag |= RenderUpdateFlag::Transform;
 
-        return 0;
+        return true;
     }
 };
 
index 67d5ab7..c41c6b1 100644 (file)
@@ -46,23 +46,25 @@ unique_ptr<Shape> Shape::gen() noexcept
 }
 
 
-int Shape::reset() noexcept
+Result Shape::reset() noexcept
 {
     auto impl = pImpl.get();
-    assert(impl && impl->path);
+    if (!impl || !impl->path) return Result::MemoryCorruption;
 
     impl->path->reset();
 
     impl->flag |= RenderUpdateFlag::Path;
 
-    return 0;
+    return Result::Success;
 }
 
 
 size_t Shape::pathCommands(const PathCommand** cmds) const noexcept
 {
+    if (!cmds) return 0;
+
     auto impl = pImpl.get();
-    assert(impl && impl->path && cmds);
+    if (!impl || !impl->path) return 0;
 
     *cmds = impl->path->cmds;
 
@@ -72,8 +74,10 @@ size_t Shape::pathCommands(const PathCommand** cmds) const noexcept
 
 size_t Shape::pathCoords(const Point** pts) const noexcept
 {
+    if (!pts) return 0;
+
     auto impl = pImpl.get();
-    assert(impl && impl->path && pts);
+    if (!impl || !impl->path) return 0;
 
     *pts = impl->path->pts;
 
@@ -81,79 +85,78 @@ size_t Shape::pathCoords(const Point** pts) const noexcept
 }
 
 
-int Shape::appendPath(const PathCommand *cmds, size_t cmdCnt, const Point* pts, size_t ptsCnt) noexcept
+Result Shape::appendPath(const PathCommand *cmds, size_t cmdCnt, const Point* pts, size_t ptsCnt) noexcept
 {
-    if (cmdCnt < 0 || ptsCnt < 0) return -1;
-    assert(cmds && pts);
+    if (cmdCnt < 0 || ptsCnt < 0 || !pts || !ptsCnt) return Result::InvalidArguments;
 
     auto impl = pImpl.get();
-    assert(impl && impl->path);
+    if (!impl || !impl->path) return Result::MemoryCorruption;
 
     impl->path->grow(cmdCnt, ptsCnt);
     impl->path->append(cmds, cmdCnt, pts, ptsCnt);
 
     impl->flag |= RenderUpdateFlag::Path;
 
-    return 0;
+    return Result::Success;
 }
 
 
-int Shape::moveTo(float x, float y) noexcept
+Result Shape::moveTo(float x, float y) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl && impl->path);
+    if (!impl || !impl->path) return Result::MemoryCorruption;
 
     impl->path->moveTo(x, y);
 
     impl->flag |= RenderUpdateFlag::Path;
 
-    return 0;
+    return Result::Success;
 }
 
 
-int Shape::lineTo(float x, float y) noexcept
+Result Shape::lineTo(float x, float y) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl && impl->path);
+    if (!impl || !impl->path) return Result::MemoryCorruption;
 
     impl->path->lineTo(x, y);
 
     impl->flag |= RenderUpdateFlag::Path;
 
-    return 0;
+    return Result::Success;
 }
 
 
-int Shape::cubicTo(float cx1, float cy1, float cx2, float cy2, 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();
-    assert(impl && impl->path);
+    if (!impl || !impl->path) return Result::MemoryCorruption;
 
     impl->path->cubicTo(cx1, cy1, cx2, cy2, x, y);
 
     impl->flag |= RenderUpdateFlag::Path;
 
-    return 0;
+    return Result::Success;
 }
 
 
-int Shape::close() noexcept
+Result Shape::close() noexcept
 {
     auto impl = pImpl.get();
-    assert(impl && impl->path);
+    if (!impl || !impl->path) return Result::MemoryCorruption;
 
     impl->path->close();
 
     impl->flag |= RenderUpdateFlag::Path;
 
-    return 0;
+    return Result::Success;
 }
 
 
-int Shape::appendCircle(float cx, float cy, float radiusW, float radiusH) noexcept
+Result Shape::appendCircle(float cx, float cy, float radiusW, float radiusH) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl && impl->path);
+    if (!impl || !impl->path) return Result::MemoryCorruption;
 
     auto halfKappaW = radiusW * PATH_KAPPA;
     auto halfKappaH = radiusH * PATH_KAPPA;
@@ -168,14 +171,14 @@ int Shape::appendCircle(float cx, float cy, float radiusW, float radiusH) noexce
 
     impl->flag |= RenderUpdateFlag::Path;
 
-    return 0;
+    return Result::Success;
 }
 
 
-int Shape::appendRect(float x, float y, float w, float h, float cornerRadius) noexcept
+Result Shape::appendRect(float x, float y, float w, float h, float cornerRadius) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl && impl->path);
+    if (!impl || !impl->path) return Result::MemoryCorruption;
 
     //clamping cornerRadius by minimum size
     auto min = (w < h ? w : h) * 0.5f;
@@ -209,14 +212,14 @@ int Shape::appendRect(float x, float y, float w, float h, float cornerRadius) no
 
     impl->flag |= RenderUpdateFlag::Path;
 
-    return 0;
+    return Result::Success;
 }
 
 
-int Shape::fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept
+Result Shape::fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
 
     impl->color[0] = r;
     impl->color[1] = g;
@@ -224,120 +227,126 @@ int Shape::fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept
     impl->color[3] = a;
     impl->flag |= RenderUpdateFlag::Fill;
 
-    return 0;
+    return Result::Success;
 }
 
 
-int Shape::fill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept
+Result Shape::fill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
 
     if (r) *r = impl->color[0];
     if (g) *g = impl->color[1];
     if (b) *b = impl->color[2];
     if (a) *a = impl->color[3];
 
-    return 0;
+    return Result::Success;
 }
 
 
-int Shape::scale(float factor) noexcept
+Result Shape::scale(float factor) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
 
-    return impl->scale(factor);
+    if (!impl->scale(factor)) return Result::FailedAllocation;
+
+    return Result::Success;
 }
 
 
-int Shape::rotate(float degree) noexcept
+Result Shape::rotate(float degree) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
 
-    return impl->rotate(degree);
+    if (!impl->rotate(degree)) return Result::FailedAllocation;
+
+    return Result::Success;
 }
 
 
-int Shape::translate(float x, float y) noexcept
+Result Shape::translate(float x, float y) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
 
-    return impl->translate(x, y);
+    impl->translate(x, y);
+
+    return Result::Success;
 }
 
 
-int Shape::bounds(float* x, float* y, float* w, float* h) const noexcept
+Result Shape::bounds(float* x, float* y, float* w, float* h) const noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
 
-    if (!impl->bounds(x, y, w, h)) return -1;
+    if (!impl->bounds(x, y, w, h)) return Result::InsufficientCondition;
 
-    return 0;
+    return Result::Success;
 }
 
 
-int Shape::stroke(float width) noexcept
+Result Shape::stroke(float width) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
 
-    if (!impl->strokeWidth(width)) return -1;
+    if (!impl->strokeWidth(width)) return Result::FailedAllocation;
 
-    return 0;
+    return Result::Success;
 }
 
 
 float Shape::strokeWidth() const noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return 0;
 
     if (!impl->stroke) return 0;
     return impl->stroke->width;
 }
 
 
-int Shape::stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept
+Result Shape::stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
 
-    if (!impl->strokeColor(r, g, b, a)) return -1;
+    if (!impl->strokeColor(r, g, b, a)) return Result::FailedAllocation;
 
-    return 0;
+    return Result::Success;
 }
 
 
-int Shape::strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept
+Result Shape::strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
 
-    if (!impl->stroke) return -1;
+    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];
 
-    return 0;
+    return Result::Success;
 }
 
 
-int Shape::stroke(const float* dashPattern, size_t cnt) noexcept
+Result Shape::stroke(const float* dashPattern, size_t cnt) noexcept
 {
-    if (cnt < 2 || !dashPattern) return -1;
+    if (cnt < 2 || !dashPattern) return Result::InvalidArguments;
 
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
 
-    if (!impl->strokeDash(dashPattern, cnt)) return -1;
+    if (!impl->strokeDash(dashPattern, cnt)) return Result::FailedAllocation;
 
-    return 0;
+    return Result::Success;
 }
 
 
@@ -353,25 +362,25 @@ size_t Shape::strokeDash(const float** dashPattern) const noexcept
 }
 
 
-int Shape::stroke(StrokeCap cap) noexcept
+Result Shape::stroke(StrokeCap cap) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
 
-    if (!impl->strokeCap(cap)) return -1;
+    if (!impl->strokeCap(cap)) return Result::FailedAllocation;
 
-    return 0;
+    return Result::Success;
 }
 
 
-int Shape::stroke(StrokeJoin join) noexcept
+Result Shape::stroke(StrokeJoin join) noexcept
 {
     auto impl = pImpl.get();
-    assert(impl);
+    if (!impl) return Result::MemoryCorruption;
 
-    if (!impl->strokeJoin(join)) return -1;
+    if (!impl->strokeJoin(join)) return Result::FailedAllocation;
 
-    return 0;
+    return Result::Success;
 }
 
 
index 09956be..9218417 100644 (file)
@@ -80,7 +80,7 @@ struct Shape::Impl
     bool update(Shape& shape, RenderMethod& renderer, const RenderTransform* pTransform = nullptr, size_t pFlag = 0)
     {
         if (flag & RenderUpdateFlag::Transform) {
-            assert(transform);
+            if (!transform) return false;
             if (!transform->update()) {
                 delete(transform);
                 transform = nullptr;
@@ -103,54 +103,54 @@ struct Shape::Impl
 
     bool bounds(float* x, float* y, float* w, float* h)
     {
-        assert(path);
+        if (!path) return false;
         return path->bounds(x, y, w, h);
     }
 
     bool scale(float factor)
     {
         if (transform) {
-            if (fabsf(factor - transform->factor) <= FLT_EPSILON) return -1;
+            if (fabsf(factor - transform->factor) <= FLT_EPSILON) return true;
         } else {
-            if (fabsf(factor) <= FLT_EPSILON) return -1;
+            if (fabsf(factor) <= FLT_EPSILON) return true;
             transform = new RenderTransform();
-            assert(transform);
+            if (!transform) return false;
         }
         transform->factor = factor;
         flag |= RenderUpdateFlag::Transform;
 
-        return 0;
+        return true;
     }
 
     bool rotate(float degree)
     {
         if (transform) {
-            if (fabsf(degree - transform->degree) <= FLT_EPSILON) return -1;
+            if (fabsf(degree - transform->degree) <= FLT_EPSILON) return true;
         } else {
-            if (fabsf(degree) <= FLT_EPSILON) return -1;
+            if (fabsf(degree) <= FLT_EPSILON) return true;
             transform = new RenderTransform();
-            assert(transform);
+            if (!transform) return false;
         }
         transform->degree = degree;
         flag |= RenderUpdateFlag::Transform;
 
-        return 0;
+        return true;
     }
 
     bool translate(float x, float y)
     {
         if (transform) {
-            if (fabsf(x - transform->x) <= FLT_EPSILON && fabsf(y - transform->y) <= FLT_EPSILON) return -1;
+            if (fabsf(x - transform->x) <= FLT_EPSILON && fabsf(y - transform->y) <= FLT_EPSILON) return true;
         } else {
-            if (fabsf(x) <= FLT_EPSILON && fabsf(y) <= FLT_EPSILON) return -1;
+            if (fabsf(x) <= FLT_EPSILON && fabsf(y) <= FLT_EPSILON) return true;
             transform = new RenderTransform();
-            assert(transform);
+            if (!transform) return false;
         }
         transform->x = x;
         transform->y = y;
         flag |= RenderUpdateFlag::Transform;
 
-        return 0;
+        return true;
     }
 
     bool strokeWidth(float width)
@@ -158,40 +158,40 @@ struct Shape::Impl
         //TODO: Size Exception?
 
         if (!stroke) stroke = new ShapeStroke();
-        assert(stroke);
+        if (!stroke) return false;
 
         stroke->width = width;
         flag |= RenderUpdateFlag::Stroke;
 
-        return 0;
+        return true;
     }
 
     bool strokeCap(StrokeCap cap)
     {
         if (!stroke) stroke = new ShapeStroke();
-        assert(stroke);
+        if (!stroke) return false;
 
         stroke->cap = cap;
         flag |= RenderUpdateFlag::Stroke;
 
-        return 0;
+        return true;
     }
 
     bool strokeJoin(StrokeJoin join)
     {
         if (!stroke) stroke = new ShapeStroke();
-        assert(stroke);
+        if (!stroke) return false;
 
         stroke->join = join;
         flag |= RenderUpdateFlag::Stroke;
 
-        return 0;
+        return true;
     }
 
     bool strokeColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
     {
         if (!stroke) stroke = new ShapeStroke();
-        assert(stroke);
+        if (!stroke) return false;
 
         stroke->color[0] = r;
         stroke->color[1] = g;
@@ -200,7 +200,7 @@ struct Shape::Impl
 
         flag |= RenderUpdateFlag::Stroke;
 
-        return 0;
+        return true;
     }
 
     bool strokeDash(const float* pattern, size_t cnt)
@@ -208,7 +208,7 @@ struct Shape::Impl
         assert(pattern);
 
        if (!stroke) stroke = new ShapeStroke();
-        assert(stroke);
+       if (!stroke) return false;
 
         if (stroke->dashCnt != cnt) {
             if (stroke->dashPattern) free(stroke->dashPattern);
@@ -224,8 +224,7 @@ struct Shape::Impl
         stroke->dashCnt = cnt;
         flag |= RenderUpdateFlag::Stroke;
 
-        return 0;
-
+        return true;
     }
 };
 
index ea95e98..ec18dbf 100644 (file)
@@ -45,20 +45,20 @@ SwCanvas::~SwCanvas()
 {
 }
 
-int SwCanvas::target(uint32_t* buffer, size_t stride, size_t w, size_t h) noexcept
+Result SwCanvas::target(uint32_t* buffer, size_t stride, size_t w, size_t h) noexcept
 {
     auto renderer = dynamic_cast<SwRenderer*>(Canvas::pImpl.get()->renderer);
-    assert(renderer);
+    if (!renderer) return Result::MemoryCorruption;
 
-    if (!renderer->target(buffer, stride, w, h)) return -1;
+    if (!renderer->target(buffer, stride, w, h)) return Result::InvalidArguments;
 
-    return 0;
+    return Result::Success;
 }
 
 
-int SwCanvas::sync() noexcept
+Result SwCanvas::sync() noexcept
 {
-    return 0;
+    return Result::Success;
 }