2 * Copyright (c) 2020 - 2023 the ThorVG project. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #ifndef _TVG_RENDER_H_
24 #define _TVG_RENDER_H_
26 #include "tvgCommon.h"
32 enum RenderUpdateFlag {None = 0, Path = 1, Color = 2, Gradient = 4, Stroke = 8, Transform = 16, Image = 32, GradientStroke = 64, All = 255};
36 //TODO: Union for multiple types
43 using RenderData = void*;
47 CompositeMethod method;
55 void intersect(const RenderRegion& rhs)
59 auto x2 = rhs.x + rhs.w;
60 auto y2 = rhs.y + rhs.h;
62 x = (x > rhs.x) ? x : rhs.x;
63 y = (y > rhs.y) ? y : rhs.y;
64 w = ((x1 < x2) ? x1 : x2) - x;
65 h = ((y1 < y2) ? y1 : y2) - y;
72 struct RenderTransform
74 Matrix m; //3x3 Matrix Elements
77 float degree = 0.0f; //rotation degree
78 float scale = 1.0f; //scale factor
79 bool overriding = false; //user transform?
82 void override(const Matrix& m);
85 RenderTransform(const RenderTransform* lhs, const RenderTransform* rhs);
92 virtual ~RenderMethod() {}
93 virtual RenderData prepare(const Shape& shape, RenderData data, const RenderTransform* transform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag flags, bool clipper) = 0;
94 virtual RenderData prepare(Surface* image, Polygon* triangles, uint32_t triangleCnt, RenderData data, const RenderTransform* transform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag flags) = 0;
95 virtual bool preRender() = 0;
96 virtual bool renderShape(RenderData data) = 0;
97 virtual bool renderImage(RenderData data) = 0;
98 virtual bool renderImageMesh(RenderData data) = 0;
99 virtual bool postRender() = 0;
100 virtual bool dispose(RenderData data) = 0;
101 virtual RenderRegion region(RenderData data) = 0;
102 virtual RenderRegion viewport() = 0;
103 virtual bool viewport(const RenderRegion& vp) = 0;
105 virtual bool clear() = 0;
106 virtual bool sync() = 0;
108 virtual Compositor* target(const RenderRegion& region) = 0;
109 virtual bool beginComposite(Compositor* cmp, CompositeMethod method, uint32_t opacity) = 0;
110 virtual bool endComposite(Compositor* cmp) = 0;
115 #endif //_TVG_RENDER_H_