2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #define TVG_EXPORT __attribute__ ((visibility ("default")))
39 #define _TVG_DECLARE_PRIVATE(A) \
42 std::unique_ptr<Impl> pImpl; \
43 A(const A&) = delete; \
44 const A& operator=(const A&) = delete; \
47 #define _TVG_DISABLE_CTOR(A) \
51 #define _TVG_DECLARE_ACCESSOR(A) \
54 #define _TVG_DECALRE_IDENTIFIER() \
55 auto id() const { return _id; } \
67 enum class TVG_EXPORT Result { Success = 0, InvalidArguments, InsufficientCondition, FailedAllocation, MemoryCorruption, NonSupport, Unknown };
68 enum class TVG_EXPORT PathCommand { Close = 0, MoveTo, LineTo, CubicTo };
69 enum class TVG_EXPORT StrokeCap { Square = 0, Round, Butt };
70 enum class TVG_EXPORT StrokeJoin { Bevel = 0, Round, Miter };
71 enum class TVG_EXPORT FillSpread { Pad = 0, Reflect, Repeat };
72 enum class TVG_EXPORT CanvasEngine { Sw = 0, Gl };
94 * @brief description...
97 class TVG_EXPORT Paint
102 Result rotate(float degree) noexcept;
103 Result scale(float factor) noexcept;
104 Result translate(float x, float y) noexcept;
105 Result transform(const Matrix& m) noexcept;
106 Result bounds(float* x, float* y, float* w, float* h) const noexcept;
108 _TVG_DECLARE_PRIVATE(Paint);
109 _TVG_DECLARE_ACCESSOR(Canvas);
110 _TVG_DECLARE_ACCESSOR(Scene);
119 * @brief description...
122 class TVG_EXPORT Fill
133 Result colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept;
134 Result spread(FillSpread s) noexcept;
136 uint32_t colorStops(const ColorStop** colorStops) const noexcept;
137 FillSpread spread() const noexcept;
139 _TVG_DECALRE_IDENTIFIER();
140 _TVG_DECLARE_PRIVATE(Fill);
149 * @brief description...
152 class TVG_EXPORT Canvas
155 Canvas(RenderMethod*);
158 Result reserve(uint32_t n) noexcept;
159 virtual Result push(std::unique_ptr<Paint> paint) noexcept;
160 virtual Result clear() noexcept;
161 virtual Result update(Paint* paint) noexcept;
162 virtual Result draw() noexcept;
163 virtual Result sync() noexcept;
165 _TVG_DECLARE_PRIVATE(Canvas);
171 * @class LinearGradient
175 * @brief description...
178 class TVG_EXPORT LinearGradient final : public Fill
183 Result linear(float x1, float y1, float x2, float y2) noexcept;
184 Result linear(float* x1, float* y1, float* x2, float* y2) const noexcept;
186 static std::unique_ptr<LinearGradient> gen() noexcept;
188 _TVG_DECLARE_PRIVATE(LinearGradient);
193 * @class RadialGradient
197 * @brief description...
200 class TVG_EXPORT RadialGradient final : public Fill
205 Result radial(float cx, float cy, float radius) noexcept;
206 Result radial(float* cx, float* cy, float* radius) const noexcept;
208 static std::unique_ptr<RadialGradient> gen() noexcept;
210 _TVG_DECLARE_PRIVATE(RadialGradient);
220 * @brief description...
223 class TVG_EXPORT Shape final : public Paint
228 Result reset() noexcept;
231 Result moveTo(float x, float y) noexcept;
232 Result lineTo(float x, float y) noexcept;
233 Result cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept;
234 Result close() noexcept;
237 Result appendRect(float x, float y, float w, float h, float rx, float ry) noexcept;
238 Result appendCircle(float cx, float cy, float rx, float ry) noexcept;
239 Result appendPath(const PathCommand* cmds, uint32_t cmdCnt, const Point* pts, uint32_t ptsCnt) noexcept;
242 Result stroke(float width) noexcept;
243 Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
244 Result stroke(const float* dashPattern, uint32_t cnt) noexcept;
245 Result stroke(StrokeCap cap) noexcept;
246 Result stroke(StrokeJoin join) noexcept;
249 Result fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
250 Result fill(std::unique_ptr<Fill> f) noexcept;
253 uint32_t pathCommands(const PathCommand** cmds) const noexcept;
254 uint32_t pathCoords(const Point** pts) const noexcept;
255 Result fill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
256 const Fill* fill() const noexcept;
258 float strokeWidth() const noexcept;
259 Result strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
260 uint32_t strokeDash(const float** dashPattern) const noexcept;
261 StrokeCap strokeCap() const noexcept;
262 StrokeJoin strokeJoin() const noexcept;
264 static std::unique_ptr<Shape> gen() noexcept;
266 _TVG_DECLARE_PRIVATE(Shape);
275 * @brief description...
278 class TVG_EXPORT Picture final : public Paint
283 Result load(const std::string& path) noexcept;
284 Result size(float* w, float* h) const noexcept;
286 static std::unique_ptr<Picture> gen() noexcept;
288 _TVG_DECLARE_PRIVATE(Picture);
297 * @brief description...
300 class TVG_EXPORT Scene final : public Paint
305 Result push(std::unique_ptr<Paint> paint) noexcept;
306 Result reserve(uint32_t size) noexcept;
308 static std::unique_ptr<Scene> gen() noexcept;
310 _TVG_DECLARE_PRIVATE(Scene);
311 _TVG_DECLARE_ACCESSOR(Picture);
320 @brief description...
323 class TVG_EXPORT SwCanvas final : public Canvas
328 Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h) noexcept;
330 static std::unique_ptr<SwCanvas> gen() noexcept;
332 _TVG_DECLARE_PRIVATE(SwCanvas);
341 * @brief description...
344 class TVG_EXPORT GlCanvas final : public Canvas
349 //TODO: Gl Specific methods. Need gl backend configuration methods as well.
350 Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h) noexcept;
352 static std::unique_ptr<GlCanvas> gen() noexcept;
354 _TVG_DECLARE_PRIVATE(GlCanvas);
363 * @brief description...
366 class TVG_EXPORT Initializer final
381 static Result init(CanvasEngine engine) noexcept;
382 static Result term(CanvasEngine engine) noexcept;
384 _TVG_DISABLE_CTOR(Initializer);