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.
17 #ifndef _TVG_SW_COMMON_H_
18 #define _TVG_SW_COMMON_H_
22 #include "tvgCommon.h"
26 static double timeStamp()
29 gettimeofday(&tv, NULL);
30 return (tv.tv_sec + tv.tv_usec / 1000000.0);
36 #define SW_CURVE_TYPE_POINT 0
37 #define SW_CURVE_TYPE_CUBIC 1
38 #define SW_OUTLINE_FILL_WINDING 0
39 #define SW_OUTLINE_FILL_EVEN_ODD 1
40 #define SW_ANGLE_PI (180L << 16)
41 #define SW_ANGLE_2PI (SW_ANGLE_PI << 1)
42 #define SW_ANGLE_PI2 (SW_ANGLE_PI >> 1)
43 #define SW_ANGLE_PI4 (SW_ANGLE_PI >> 2)
45 using SwCoord = signed long;
46 using SwFixed = signed long long;
52 SwPoint& operator+=(const SwPoint& rhs) {
58 SwPoint operator+(const SwPoint& rhs) const {
59 return {x + rhs.x, y + rhs.y};
62 SwPoint operator-(const SwPoint& rhs) const {
63 return {x - rhs.x, y - rhs.y};
66 bool operator==(const SwPoint& rhs ) const {
67 return (x == rhs.x && y == rhs.y);
70 bool operator!=(const SwPoint& rhs) const {
71 return (x != rhs.x || y != rhs.y);
76 if (x == 0 && y == 0) return true;
83 if (abs(x) < 2 && abs(y) < 2) return true;
96 uint32_t* cntrs; //the contour end points
97 uint32_t cntrsCnt; //number of contours in glyph
98 uint32_t reservedCntrsCnt;
99 SwPoint* pts; //the outline's points
100 uint32_t ptsCnt; //number of points in the glyph
101 uint32_t reservedPtsCnt;
102 uint8_t* types; //curve type
103 uint8_t fillMode; //outline fill mode
104 bool opened; //opened path?
126 struct SwStrokeBorder
132 int32_t start; //index of current sub-path start point
133 bool movable; //true: for ends of lineto borders
143 SwFixed subPathAngle;
144 SwPoint ptStartSubPath;
145 SwFixed subPathLineLength;
150 StrokeJoin joinSaved;
152 SwStrokeBorder borders[2];
156 bool handleWideStrokes;
201 SwRleData* strokeRle;
211 const Matrix* transform;
212 RenderUpdateFlag flags;
213 future<void> prepared;
216 static inline SwPoint TO_SWPOINT(const Point* pt)
218 return {SwCoord(pt->x * 64), SwCoord(pt->y * 64)};
222 static inline SwCoord TO_SWCOORD(float val)
224 return SwCoord(val * 64);
228 static inline uint32_t COLOR_ALPHA(uint32_t rgba)
230 return (rgba >> 24) & 0xff;
234 static inline uint32_t COLOR_ALPHA_BLEND(uint32_t rgba, uint32_t alpha)
236 return (((((rgba >> 8) & 0x00ff00ff) * alpha) & 0xff00ff00) +
237 ((((rgba & 0x00ff00ff) * alpha) >> 8) & 0x00ff00ff));
241 static inline uint32_t COLOR_INTERPOLATE(uint32_t rgba1, uint32_t a, uint32_t rgba2, uint32_t b)
243 auto t = (((rgba1 & 0xff00ff) * a + (rgba2 & 0xff00ff) * b) >> 8) & 0xff00ff;
244 rgba1 = (((rgba1 >> 8) & 0xff00ff) * a + ((rgba2 >> 8) & 0xff00ff) * b) & 0xff00ff00;
249 static inline uint32_t COLOR_ARGB_JOIN(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
251 return (a << 24 | r << 16 | g << 8 | b);
255 static inline void COLOR_SET(uint32_t *dst, uint32_t val, uint32_t len)
257 while (len--) *dst++ = val;
261 int64_t mathMultiply(int64_t a, int64_t b);
262 int64_t mathDivide(int64_t a, int64_t b);
263 int64_t mathMulDiv(int64_t a, int64_t b, int64_t c);
264 void mathRotate(SwPoint& pt, SwFixed angle);
265 SwFixed mathTan(SwFixed angle);
266 SwFixed mathAtan(const SwPoint& pt);
267 SwFixed mathCos(SwFixed angle);
268 SwFixed mathSin(SwFixed angle);
269 void mathSplitCubic(SwPoint* base);
270 SwFixed mathDiff(SwFixed angle1, SwFixed angle2);
271 SwFixed mathLength(SwPoint& pt);
272 bool mathSmallCubic(SwPoint* base, SwFixed& angleIn, SwFixed& angleMid, SwFixed& angleOut);
273 SwFixed mathMean(SwFixed angle1, SwFixed angle2);
275 void shapeReset(SwShape& shape);
276 bool shapeGenOutline(SwShape& shape, const Shape* sdata);
277 bool shapeGenRle(SwShape& shape, const Shape* sdata, const SwSize& clip, const Matrix* transform);
278 void shapeDelOutline(SwShape& shape);
279 void shapeResetStroke(SwShape& shape, const Shape* sdata);
280 bool shapeGenStrokeRle(SwShape& shape, const Shape* sdata, const SwSize& clip);
281 void shapeFree(SwShape& shape);
282 void shapeDelStroke(SwShape& shape);
283 bool shapeGenFillColors(SwShape& shape, const Fill* fill, const Matrix* transform, bool ctable);
284 void shapeResetFill(SwShape& shape);
285 void shapeDelFill(SwShape& shape);
287 void strokeReset(SwStroke& stroke, const Shape* shape);
288 bool strokeParseOutline(SwStroke& stroke, const SwOutline& outline);
289 SwOutline* strokeExportOutline(SwStroke& stroke);
290 void strokeFree(SwStroke* stroke);
292 bool fillGenColorTable(SwFill* fill, const Fill* fdata, const Matrix* transform, bool ctable);
293 void fillReset(SwFill* fill);
294 void fillFree(SwFill* fill);
295 void fillFetchLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len);
296 void fillFetchRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len);
298 SwRleData* rleRender(const SwOutline* outline, const SwBBox& bbox, const SwSize& clip);
299 void rleFree(SwRleData* rle);
301 bool rasterGradientShape(Surface& surface, SwShape& shape, unsigned id);
302 bool rasterSolidShape(Surface& surface, SwShape& shape, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
303 bool rasterStroke(Surface& surface, SwShape& shape, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
304 bool rasterClear(Surface& surface);
306 #endif /* _TVG_SW_COMMON_H_ */