7 #define TVG_EXPORT __attribute__ ((visibility ("default")))
23 #define _TVG_DECLARE_PRIVATE(A) \
26 std::unique_ptr<Impl> pImpl; \
27 A(const A&) = delete; \
28 const A& operator=(const A&) = delete; \
31 #define _TVG_DISABLE_CTOR(A) \
35 #define _TVG_DECLARE_ACCESSOR() \
40 #define _TVG_DECALRE_IDENTIFIER() \
41 auto id() const { return _id; } \
54 enum class TVG_EXPORT Result { Success = 0, InvalidArguments, InsufficientCondition, FailedAllocation, MemoryCorruption, NonSupport, Unknown };
55 enum class TVG_EXPORT PathCommand { Close = 0, MoveTo, LineTo, CubicTo };
56 enum class TVG_EXPORT StrokeCap { Square = 0, Round, Butt };
57 enum class TVG_EXPORT StrokeJoin { Bevel = 0, Round, Miter };
58 enum class TVG_EXPORT FillSpread { Pad = 0, Reflect, Repeat };
59 enum class TVG_EXPORT CanvasEngine { Sw = 0, Gl };
81 * @brief description...
84 class TVG_EXPORT Paint
89 Result rotate(float degree) noexcept;
90 Result scale(float factor) noexcept;
91 Result translate(float x, float y) noexcept;
92 Result transform(const Matrix& m) noexcept;
93 Result bounds(float* x, float* y, float* w, float* h) const noexcept;
95 _TVG_DECLARE_ACCESSOR();
96 _TVG_DECLARE_PRIVATE(Paint);
105 * @brief description...
108 class TVG_EXPORT Fill
119 Result colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept;
120 Result spread(FillSpread s) noexcept;
122 uint32_t colorStops(const ColorStop** colorStops) const noexcept;
123 FillSpread spread() const noexcept;
125 _TVG_DECALRE_IDENTIFIER();
126 _TVG_DECLARE_PRIVATE(Fill);
135 * @brief description...
138 class TVG_EXPORT Canvas
141 Canvas(RenderMethod*);
144 Result reserve(uint32_t n) noexcept;
145 virtual Result push(std::unique_ptr<Paint> paint) noexcept;
146 virtual Result clear() noexcept;
147 virtual Result update(Paint* paint) noexcept;
148 virtual Result draw() noexcept;
149 virtual Result sync() noexcept;
151 _TVG_DECLARE_PRIVATE(Canvas);
156 * @class LinearGradient
160 * @brief description...
163 class TVG_EXPORT LinearGradient final : public Fill
168 Result linear(float x1, float y1, float x2, float y2) noexcept;
169 Result linear(float* x1, float* y1, float* x2, float* y2) const noexcept;
171 static std::unique_ptr<LinearGradient> gen() noexcept;
173 _TVG_DECLARE_PRIVATE(LinearGradient);
178 * @class RadialGradient
182 * @brief description...
185 class TVG_EXPORT RadialGradient final : public Fill
190 Result radial(float cx, float cy, float radius) noexcept;
191 Result radial(float* cx, float* cy, float* radius) const noexcept;
193 static std::unique_ptr<RadialGradient> gen() noexcept;
195 _TVG_DECLARE_PRIVATE(RadialGradient);
205 * @brief description...
208 class TVG_EXPORT Shape final : public Paint
213 Result reset() noexcept;
216 Result moveTo(float x, float y) noexcept;
217 Result lineTo(float x, float y) noexcept;
218 Result cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept;
219 Result close() noexcept;
222 Result appendRect(float x, float y, float w, float h, float rx, float ry) noexcept;
223 Result appendCircle(float cx, float cy, float rx, float ry) noexcept;
224 Result appendArc(float cx, float cy, float radius, float startAngle, float sweep, bool pie) noexcept;
225 Result appendPath(const PathCommand* cmds, uint32_t cmdCnt, const Point* pts, uint32_t ptsCnt) noexcept;
228 Result stroke(float width) noexcept;
229 Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
230 Result stroke(const float* dashPattern, uint32_t cnt) noexcept;
231 Result stroke(StrokeCap cap) noexcept;
232 Result stroke(StrokeJoin join) noexcept;
235 Result fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
236 Result fill(std::unique_ptr<Fill> f) noexcept;
239 uint32_t pathCommands(const PathCommand** cmds) const noexcept;
240 uint32_t pathCoords(const Point** pts) const noexcept;
241 Result fill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
242 const Fill* fill() const noexcept;
244 float strokeWidth() const noexcept;
245 Result strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
246 uint32_t strokeDash(const float** dashPattern) const noexcept;
247 StrokeCap strokeCap() const noexcept;
248 StrokeJoin strokeJoin() const noexcept;
250 static std::unique_ptr<Shape> gen() noexcept;
252 _TVG_DECLARE_PRIVATE(Shape);
261 * @brief description...
264 class TVG_EXPORT Picture final : public Paint
269 Result load(const std::string& path) noexcept;
270 Result load(const char* data, uint32_t size) noexcept;
271 Result viewbox(float* x, float* y, float* w, float* h) const noexcept;
273 static std::unique_ptr<Picture> gen() noexcept;
275 _TVG_DECLARE_PRIVATE(Picture);
284 * @brief description...
287 class TVG_EXPORT Scene final : public Paint
292 Result push(std::unique_ptr<Paint> paint) noexcept;
293 Result reserve(uint32_t size) noexcept;
295 static std::unique_ptr<Scene> gen() noexcept;
297 _TVG_DECLARE_PRIVATE(Scene);
306 @brief description...
309 class TVG_EXPORT SwCanvas final : public Canvas
314 enum Colorspace { ABGR8888 = 0, ARGB8888 };
316 Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, Colorspace cs) noexcept;
318 static std::unique_ptr<SwCanvas> gen() noexcept;
320 _TVG_DECLARE_PRIVATE(SwCanvas);
329 * @brief description...
332 class TVG_EXPORT GlCanvas final : public Canvas
337 //TODO: Gl Specific methods. Need gl backend configuration methods as well.
338 Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h) noexcept;
340 static std::unique_ptr<GlCanvas> gen() noexcept;
342 _TVG_DECLARE_PRIVATE(GlCanvas);
351 * @brief description...
354 class TVG_EXPORT Initializer final
369 static Result init(CanvasEngine engine) noexcept;
370 static Result term(CanvasEngine engine) noexcept;
371 static Result threads(uint32_t cnt) noexcept;
372 static uint32_t threads() noexcept;
374 _TVG_DISABLE_CTOR(Initializer);