2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FGrp_CanvasGpPrimitive.h
20 * @brief This is the header file for 2D Primitive classes.
24 #ifndef _FGRP_INTERNAL_CANVAS_GP_PRIMITIVE_H_
25 #define _FGRP_INTERNAL_CANVAS_GP_PRIMITIVE_H_
28 #include <FBaseErrors.h>
29 #include <FGrpCanvasCommon.h>
32 namespace Tizen { namespace Graphics
38 const int _MAX_SLL_BLOCK = 25;
39 const int _MAX_INT = 0x7fffffff;
40 const int _MIN_INT = (-_MAX_INT - 1);
41 const float _PI = (3.14159265358979323846f);
44 inline T GP_ABS(T value)
46 return (value < 0) ? -value : value;
50 inline void GP_SWAP(T& a, T& b)
58 inline T GP_MIN(T a, T b)
60 return (a < b) ? a : b;
64 inline T GP_MAX(T a, T b)
66 return (a < b) ? b : a;
69 inline int _GP_RADIAN2DEGREE(float radian)
71 return int(radian * 180.0f / _PI + 0.5f);
74 inline float _GP_DEGREE2RADIAN(float degree)
76 return degree * _PI / 180.0f;
106 bool SetBounds(int rcX, int rcY, int rcW, int rcH)
155 struct _GpEdgeTableEntry
164 _GpEdgeTableEntry* pNext;
165 _GpEdgeTableEntry* pBack;
166 _GpEdgeTableEntry* pWNext;
170 struct _GpScanLineList
173 _GpEdgeTableEntry* pEdgeList;
174 _GpScanLineList* pNext;
181 _GpScanLineList scanLines;
184 struct _GpScanLineListBlock
186 _GpScanLineList scanLineList[_MAX_SLL_BLOCK];
187 _GpScanLineListBlock* pNext;
203 unsigned long color32;
204 unsigned short color16;
205 bool isClipBoundsSet;
216 , isClipBoundsSet(false)
224 GP_RESULT_SUCCESS = 0x00000001,
225 GP_RESULT_OUTOFBOUNDS = 0x00000002,
226 GP_RESULT_FAIL = 0x00000004
230 _IsEqual(float f1, float f2)
232 return (((f1 > f2) ? f1 - f2 : f2 - f1) < 0.00001f); // epsilon is assumed to be 0.0001, not 1.192092896e-07f
240 : pFuncSetPixel(null)
241 , pFuncHorizontalLine(null)
242 , pFuncVerticalLine(null)
245 _SetClipFunction(true);
248 virtual ~_CanvasLine(void) { }
250 // Sets the line width.
251 bool SetLineWidth(int lineWidth);
252 // Gets the line width.
253 int GetLineWidth(void) const;
255 result DrawLine(const _GpPoint& startPt, const _GpPoint& endPt, const _GpBufferInfo& bufInfo);
257 result DrawPolyLine(int pointCount, _GpPoint* pPoints, const _GpBufferInfo& bufInfo);
259 result DrawPolygon(int pointCount, _GpPoint* pPoints, const _GpBufferInfo& bufInfo);
262 _GpResult _DrawUnitLineVertical(int x, int startY, int endY, const _GpBufferInfo& bufInfo);
263 _GpResult _DrawUnitLineHorizontal(int startX, int endX, int y, const _GpBufferInfo& bufInfo);
264 _GpResult _DrawWideLineVertical(int x, int startY, int endY, const _GpBufferInfo& bufInfo);
265 _GpResult _DrawWideLineHorizontal(int startX, int endX, int y, const _GpBufferInfo& bufInfo);
266 _GpResult _DrawUnitLineSlant(const _GpPoint& pt1, const _GpPoint& pt2, const _GpBufferInfo& bufInfo);
267 _GpResult _DrawPixel(int x, int y, const _GpBufferInfo& bufInfo);
269 _GpResult _DrawUnitLineVerticalWithClipping(int x, int startY, int endY, const _GpBufferInfo& bufInfo);
270 _GpResult _DrawUnitLineHorizontalWithClipping(int startX, int endX, int y, const _GpBufferInfo& bufInfo);
271 _GpResult _DrawWideLineVerticalWithClipping(int x, int startY, int endY, const _GpBufferInfo& bufInfo);
272 _GpResult _DrawWideLineHorizontalWithClipping(int startX, int endX, int y, const _GpBufferInfo& bufInfo);
273 _GpResult _DrawPixelWithClipping(int x, int y, const _GpBufferInfo& bufInfo);
275 bool _DrawPolyLine(int pointCount, _GpPoint* pPoints, bool isConnected, const _GpBufferInfo& bufInfo);
276 void _FreePolygon(_GpPolygon* pPolygon) const;
277 bool _FillPolygon(int pointCount, _GpPoint* pPoints, bool isEvenOdd, const _GpBufferInfo& bufInfo);
278 bool _GetOrientationUnitVector(_GpPoint& startPt, _GpPoint& endPt, float* pOx, float* pOy) const;
279 bool _PatchThickContinuousLine(_GpPolygon* pPolygon, _GpPoint& pt1, _GpPoint& pt2, float ox1, float oy1, float ox2, float oy2) const;
280 bool _AddPolygonVertex(_GpPolygon* pPolygon, int x, int y, int pos) const;
282 bool _CreateEtAndAet(int pointCount, _GpPoint* pPoints, _GpEdgeTable* pEdgeTable, _GpEdgeTableEntry* pEdgeTableEntry, _GpEdgeTableEntry* pEteBuffer, _GpScanLineListBlock* pSllb) const;
283 void _FreeSllb(_GpScanLineListBlock* pScanLineListBlock) const;
284 void _LoadAet(_GpEdgeTableEntry* pAet, _GpEdgeTableEntry* pEte) const;
285 bool _InsertionSort(_GpEdgeTableEntry* pAet) const;
286 void _ComputeWaet(_GpEdgeTableEntry* pAet) const;
288 bool _PatchJoint(_GpPolygon* pPolygon, int x, int y, float ox1, float oy1, float ox2, float oy2) const;
289 bool _PatchRoundCap(_GpPolygon* pPolygon, int x, int y, float ox, float oy, bool isStart) const;
291 int _MakeEllipseArcPointArray(_GpFloatPoint** pPoint, _GpFloatPoint** pNorm, float x, float y, float w, float h, int a1, int a2, int rot) const;
293 void _Rotate2DPoint(float x, float y, long rot, float* pRx, float* pRy) const;
295 bool _IsInClipRect(int rectX, int rectY, int rectW, int rectH, const _GpBufferInfo& bufInfo) const;
296 bool _SetNotClipFunction(bool isWidelineSet);
297 bool _SetClipFunction(bool isWidelineSet) const;
300 bool __DrawWideLine(const _GpPoint& startPt, const _GpPoint& endPt, const _GpBufferInfo& bufInfo);
301 bool __DrawWideLineWithOpacity32(const _GpPoint& startPt, const _GpPoint& endPt, const _GpBufferInfo& bufInfo);
302 bool __DrawThickContinuousPolyline(int listCount, _GpPoint* pPoints, bool isConnected, const _GpBufferInfo& bufInfo);
303 _GpResult __DrawHorizontalLineWithOpacity32(int startX, int endX, int y, const _GpBufferInfo& bufInfo);
305 int __CheckDupVertexForPolygon(int pointCount, _GpPoint* pPoints, bool isConnected) const;
306 void __GetBrushEndPoint(float ox, float oy, int w, int* plx, int* ply, int* prx, int* pry) const;
307 bool __InsertEdge(_GpEdgeTable* pEdgeTable, _GpEdgeTableEntry* pEdgeTableEntry, int scanLine, _GpScanLineListBlock** ppSllb, int* pIsLineListBlock) const;
309 bool __PatchArc(_GpPolygon* pPolygon, float x, float y, float w, float h, int d0, int d1, int pos) const;
312 typedef _GpResult (_CanvasLine::* DrawPixelFunc)(int x, int y, const _GpBufferInfo& bufInfo);
313 typedef _GpResult (_CanvasLine::* DrawHorizontalLine)(int startX, int endX, int y, const _GpBufferInfo& bufInfo);
314 typedef _GpResult (_CanvasLine::* DrawVerticalLine)(int x, int startY, int endY, const _GpBufferInfo& bufInfo);
316 mutable DrawPixelFunc pFuncSetPixel;
317 mutable DrawHorizontalLine pFuncHorizontalLine;
318 mutable DrawVerticalLine pFuncVerticalLine;
323 friend class _CanvasTriangle;
324 friend class _CanvasArc;
325 friend class _CanvasEllipse;
326 friend class _CanvasFillPolygon;
327 friend class _CanvasRoundRect;
331 class _CanvasFillPolygon
335 _CanvasFillPolygon(void)
341 virtual ~_CanvasFillPolygon(void) { }
343 // Sets the line width
344 bool SetLineWidth(int lineWidth);
345 // Gets the line width.
346 int GetLineWidth(void) const;
347 // draws the filled polygon.
348 result FillPolygon(int pointCount, _GpPoint* pPoints, const _GpBufferInfo& bufInfo);
365 virtual ~_CanvasEllipse(void) { }
366 // Sets the line width
367 bool SetLineWidth(int lineWidth);
368 // Gets the line width.
369 int GetLineWidth(void) const;
371 result DrawEllipse(int rectX, int rectY, int rectW, int rectH, const _GpBufferInfo& bufInfo) const;
372 // bool __DrawEllipseWithWidth(int rectX, int rectY, int rectW, int rectH, _GpBufferInfo& bufInfo);
373 // Draws the filled ellipse.
374 result FillElliepse(int rectX, int rectY, int rectW, int rectH, const _GpBufferInfo& bufInfo) const;
377 bool __DrawEllipseWithWidth(int rectX, int rectY, int rectW, int rectH, const _GpBufferInfo& bufInfo) const;
390 DIFF_RESULT_EQUAL = 0,
408 virtual ~_CanvasArc(void) { }
409 // Sets the line width
410 bool SetLineWidth(int lineWidth);
411 // Gets the line width.
412 int GetLineWidth(void) const;
414 result DrawArc(int rectX, int rectY, int rectW, int rectH, int startAngle, int endAngle, Tizen::Graphics::ArcStyle arcType, const _GpBufferInfo& bufInfo);
416 void _CalcLeftRightWidth(float* pWidthLeft, float* pWidthRight) const;
419 bool __GetArcVertices(int radiusX, int radiusY, int theta, int* pX, int* pY) const;
420 float __Sine(int degree) const;
421 float __Cosine(int degree) const;
422 bool __SaveLine(int x1, int y1, int x2, int y2, _GpPoint* pPionts, int* pPixelCount) const;
423 bool __FillArcWithEvenOdd(_GpPoint* pPionts, int pixelCount, bool clip, const _GpBufferInfo& bufInfo) const;
424 void __QuickSort(_GpPoint* pPionts, int left, int right) const;
426 bool __Draw32BitArc(int rectX, int rectY, int rectW, int rectH, int d0, int d1, Tizen::Graphics::ArcStyle arcType, const _GpBufferInfo& bufInfo);
427 bool __DrawThickContinuousArc(int cx, int cy, int halfW, int halfH, int d0, int d1, const _GpBufferInfo& bufInfo) const;
428 bool __DrawThickContinuousPie(int cx, int cy, int halfW, int halfH, int d0, int d1, const _GpBufferInfo& bufInfo) const;
429 bool __DrawThickContinuousChord(int cx, int cy, int halfW, int halfH, int d0, int d1, const _GpBufferInfo& bufInfo) const;
436 class _CanvasTriangle
440 _CanvasTriangle(void)
445 virtual ~_CanvasTriangle(void) { }
446 // Sets the line width
447 bool SetLineWidth(int lineWidth);
448 // Gets the line width.
449 int GetLineWidth(void) const;
451 result DrawTriangle(const _GpPoint& pt1, const _GpPoint& pt2, const _GpPoint& pt3, const _GpBufferInfo& bufInfo);
452 // Draws the filled triangle.
453 result FillTriangle(int vertexX1, int vertexY1, int vertexX2, int vertexY2, int vertexX3, int vertexY3, const _GpBufferInfo& bufInfo) const;
456 bool __FillTriangleEx(int x1, int y1, int x2, int y2, int x3, int y3, const _GpBufferInfo& bufInfo) const;
463 class _CanvasRoundRect
467 _CanvasRoundRect(void)
472 virtual ~_CanvasRoundRect(void) { }
473 // Sets the line width
474 bool SetLineWidth(int lineWidth);
475 // Gets the line width.
476 int GetLineWidth(void) const;
477 // Draws a roundRect.
478 result DrawRoundRect(int rectX, int rectY, int rectW, int rectH, int radiusX, int radiusY, const _GpBufferInfo& bufInfo);
479 // Draws the roundRect.
480 result FillRoundRectangle(int rectX, int rectY, int rectW, int rectH, int radiusX, int radiusY, const _GpBufferInfo& bufInfo) const;
483 bool __Draw32BitsRoundRect(int rectX, int rectY, int rectW, int rectH, int radiusX, int radiusY, const _GpBufferInfo& bufInfo);
484 int __MakeEllipseArcPointArrayForRoundRectN(_GpFloatPoint** pPoint, _GpFloatPoint** pNorm, float x, float y, float w, float h, int a1, int a2, int rot) const;
490 }} // Tizen::Graphics
492 #endif //_FGRP_INTERNAL_CANVAS_GP_PRIMITIVE_H_