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() \
56 #define _TVG_DECALRE_IDENTIFIER() \
57 auto id() const { return _id; } \
70 enum class TVG_EXPORT Result { Success = 0, InvalidArguments, InsufficientCondition, FailedAllocation, MemoryCorruption, NonSupport, Unknown };
71 enum class TVG_EXPORT PathCommand { Close = 0, MoveTo, LineTo, CubicTo };
72 enum class TVG_EXPORT StrokeCap { Square = 0, Round, Butt };
73 enum class TVG_EXPORT StrokeJoin { Bevel = 0, Round, Miter };
74 enum class TVG_EXPORT FillSpread { Pad = 0, Reflect, Repeat };
75 enum class TVG_EXPORT CanvasEngine { Sw = 0, Gl };
97 * @brief description...
100 class TVG_EXPORT Paint
105 Result rotate(float degree) noexcept;
106 Result scale(float factor) noexcept;
107 Result translate(float x, float y) noexcept;
108 Result transform(const Matrix& m) noexcept;
109 Result bounds(float* x, float* y, float* w, float* h) const noexcept;
111 _TVG_DECLARE_ACCESSOR();
112 _TVG_DECLARE_PRIVATE(Paint);
121 * @brief description...
124 class TVG_EXPORT Fill
135 Result colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept;
136 Result spread(FillSpread s) noexcept;
138 uint32_t colorStops(const ColorStop** colorStops) const noexcept;
139 FillSpread spread() const noexcept;
141 _TVG_DECALRE_IDENTIFIER();
142 _TVG_DECLARE_PRIVATE(Fill);
151 * @brief description...
154 class TVG_EXPORT Canvas
157 Canvas(RenderMethod*);
160 Result reserve(uint32_t n) noexcept;
161 virtual Result push(std::unique_ptr<Paint> paint) noexcept;
162 virtual Result clear() noexcept;
163 virtual Result update(Paint* paint) noexcept;
164 virtual Result draw() noexcept;
165 virtual Result sync() noexcept;
167 _TVG_DECLARE_PRIVATE(Canvas);
172 * @class LinearGradient
176 * @brief description...
179 class TVG_EXPORT LinearGradient final : public Fill
184 Result linear(float x1, float y1, float x2, float y2) noexcept;
185 Result linear(float* x1, float* y1, float* x2, float* y2) const noexcept;
187 static std::unique_ptr<LinearGradient> gen() noexcept;
189 _TVG_DECLARE_PRIVATE(LinearGradient);
194 * @class RadialGradient
198 * @brief description...
201 class TVG_EXPORT RadialGradient final : public Fill
206 Result radial(float cx, float cy, float radius) noexcept;
207 Result radial(float* cx, float* cy, float* radius) const noexcept;
209 static std::unique_ptr<RadialGradient> gen() noexcept;
211 _TVG_DECLARE_PRIVATE(RadialGradient);
221 * @brief description...
224 class TVG_EXPORT Shape final : public Paint
229 Result reset() noexcept;
232 Result moveTo(float x, float y) noexcept;
233 Result lineTo(float x, float y) noexcept;
234 Result cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept;
235 Result close() noexcept;
238 Result appendRect(float x, float y, float w, float h, float rx, float ry) noexcept;
239 Result appendCircle(float cx, float cy, float rx, float ry) noexcept;
240 Result appendArc(float x, float y, float w, float h, float startAngle, float sweep) noexcept;
241 Result appendPath(const PathCommand* cmds, uint32_t cmdCnt, const Point* pts, uint32_t ptsCnt) noexcept;
244 Result stroke(float width) noexcept;
245 Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
246 Result stroke(const float* dashPattern, uint32_t cnt) noexcept;
247 Result stroke(StrokeCap cap) noexcept;
248 Result stroke(StrokeJoin join) noexcept;
251 Result fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
252 Result fill(std::unique_ptr<Fill> f) noexcept;
255 uint32_t pathCommands(const PathCommand** cmds) const noexcept;
256 uint32_t pathCoords(const Point** pts) const noexcept;
257 Result fill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
258 const Fill* fill() const noexcept;
260 float strokeWidth() const noexcept;
261 Result strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
262 uint32_t strokeDash(const float** dashPattern) const noexcept;
263 StrokeCap strokeCap() const noexcept;
264 StrokeJoin strokeJoin() const noexcept;
266 static std::unique_ptr<Shape> gen() noexcept;
268 _TVG_DECLARE_PRIVATE(Shape);
277 * @brief description...
280 class TVG_EXPORT Picture final : public Paint
285 Result load(const std::string& path) noexcept;
286 Result viewbox(float* x, float* y, float* w, float* h) const noexcept;
288 static std::unique_ptr<Picture> gen() noexcept;
290 _TVG_DECLARE_PRIVATE(Picture);
299 * @brief description...
302 class TVG_EXPORT Scene final : public Paint
307 Result push(std::unique_ptr<Paint> paint) noexcept;
308 Result reserve(uint32_t size) noexcept;
310 static std::unique_ptr<Scene> gen() noexcept;
312 _TVG_DECLARE_PRIVATE(Scene);
321 @brief description...
324 class TVG_EXPORT SwCanvas final : public Canvas
329 Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h) noexcept;
331 static std::unique_ptr<SwCanvas> gen() noexcept;
333 _TVG_DECLARE_PRIVATE(SwCanvas);
342 * @brief description...
345 class TVG_EXPORT GlCanvas final : public Canvas
350 //TODO: Gl Specific methods. Need gl backend configuration methods as well.
351 Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h) noexcept;
353 static std::unique_ptr<GlCanvas> gen() noexcept;
355 _TVG_DECLARE_PRIVATE(GlCanvas);
364 * @brief description...
367 class TVG_EXPORT Initializer final
382 static Result init(CanvasEngine engine) noexcept;
383 static Result term(CanvasEngine engine) noexcept;
385 _TVG_DISABLE_CTOR(Initializer);