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_CanvasGpFillPolygon.cpp
20 * @brief This is the implementation file for _CanvasFillPolygon class.
27 #include <FBaseSysLog.h>
29 #include "FGrp_CanvasGpPrimitive.h"
30 #include "util/FGrp_UtilScratchpad.h"
33 using namespace Tizen::Base;
34 using namespace Tizen::Graphics;
36 typedef unsigned long SystemPixel;
38 namespace Tizen { namespace Graphics
42 _CanvasFillPolygon::SetLineWidth(int lineWidth)
44 __lineWidth = lineWidth;
49 _CanvasFillPolygon::GetLineWidth(void) const
55 _CanvasFillPolygon::FillPolygon(int ptCount, _GpPoint* pPoints, const _GpBufferInfo& bufInfo)
58 _GpEdgeTableEntry aet;
59 _GpEdgeTableEntry* pPrevAet = null;
60 _GpEdgeTableEntry* pAetPtr = null;
61 _GpEdgeTableEntry* pWetePtr = null;
62 _GpEdgeTableEntry* pEteBuf = null;
63 _GpScanLineListBlock* pSllb = null;
64 _GpScanLineList* pSll = null;
70 _CanvasTriangle triangle;
71 _GpPoint* pTempPoints = null;
79 line.SetLineWidth(__lineWidth);
80 triangle.SetLineWidth(__lineWidth);
84 return (line._DrawPixelWithClipping(pPoints[0].x, pPoints[0].y, bufInfo) == GP_RESULT_FAIL ? E_SYSTEM : E_SUCCESS);
86 else if (ptCount == 2)
88 return line.DrawLine(pPoints[0], pPoints[1], bufInfo);
90 else if (ptCount == 3)
92 return triangle.FillTriangle(pPoints[0].x, pPoints[0].y, pPoints[1].x, pPoints[1].y, pPoints[2].x, pPoints[2].y, bufInfo);
94 else if (ptCount == 4)
96 if (pPoints[0].x == pPoints[3].x && pPoints[1].x == pPoints[2].x && pPoints[0].y == pPoints[1].y && pPoints[2].y == pPoints[3].y)
98 if (bufInfo.bitsPerPixel == 32)
103 rectX = GP_MIN(pPoints[0].x, pPoints[1].x);
104 rectY = GP_MIN(pPoints[0].y, pPoints[2].y);
106 _Util::ScratchPad<SystemPixel> rect((unsigned long*) bufInfo.pPixels, bufInfo.width, bufInfo.height, bufInfo.pixelPerLine);
107 rect.FillRect(rectX, rectY, GP_ABS(pPoints[1].x - pPoints[0].x) + 1, GP_ABS(pPoints[3].y - pPoints[0].y) + 1, bufInfo.color32);
112 SysLog(NID_GRP, "FillPolygon: not support 16 bpp -1!\n");
118 else if (pPoints[0].y == pPoints[3].y && pPoints[1].y == pPoints[2].y && pPoints[0].x == pPoints[1].x && pPoints[2].x == pPoints[3].x)
120 if (bufInfo.bitsPerPixel == 32)
125 rectX = GP_MIN(pPoints[0].x, pPoints[2].x);
126 rectY = GP_MIN(pPoints[0].y, pPoints[1].y);
128 _Util::ScratchPad<SystemPixel> rect((unsigned long*) bufInfo.pPixels, bufInfo.width, bufInfo.height, bufInfo.pixelPerLine);
129 rect.FillRect(rectX, rectY, GP_ABS(pPoints[3].x - pPoints[0].x) + 1, GP_ABS(pPoints[1].y - pPoints[0].y) + 1, bufInfo.color32);
133 SysLog(NID_GRP, "FillPolygon: not support 16 bpp -2!\n");
141 pEteBuf = new (std::nothrow) _GpEdgeTableEntry[ptCount];
145 SysLog(NID_GRP, "FillPolygon: EteBuf allcation is failed!\n");
150 pSllb = new (std::nothrow) _GpScanLineListBlock;
155 SysLog(NID_GRP, "FillPolygon: pSllb allcation is failed!\n");
160 memset(pSllb, 0, sizeof(*pSllb));
162 pTempPoints = new (std::nothrow) _GpPoint[ptCount];
164 if (pTempPoints == null)
168 line._FreeSllb(pSllb);
173 for (i = 0; i < ptCount; i++)
175 pTempPoints[i] = pPoints[i];
178 if (line._CreateEtAndAet(ptCount, pTempPoints, &et, &aet, pEteBuf, pSllb) == null)
182 line._FreeSllb(pSllb);
183 SysLog(NID_GRP, "FillPolygon: _CreateEtAndAet is failed!\n");
185 delete[] pTempPoints;
190 pSll = et.scanLines.pNext;
193 if (bufInfo.isClipBoundsSet)
195 clipRect = bufInfo.clipBounds;
199 clipRect.SetBounds(0, 0, bufInfo.width, bufInfo.height);
202 for (y = et.minY; y < et.maxY + stitch; y++)
204 if (pSll != null && y == pSll->scanLine)
206 line._LoadAet(&aet, pSll->pEdgeList);
207 line._ComputeWaet(&aet);
215 while (pAetPtr != null)
217 if (pWetePtr == pAetPtr)
220 int x1 = pAetPtr->minor;
221 int x2 = pAetPtr->pWNext->minor + stitch - 1;
225 //if (pGC->bMemGC == null)
227 // x1 += pGC->rcGC.x;
228 // x2 += pGC->rcGC.x;
229 // horY += pGC->rcGC.y;
232 clipEndX = clipRect.x + clipRect.width - 1;
240 if (y < clipRect.y || y > (clipRect.y + clipRect.height - 1))
245 if (x1 > clipEndX || x2 < clipRect.x)
260 // draw primitive line
261 if ((bufInfo.color32 & 0xFF000000) == 0xFF000000)
263 unsigned long* pFrmbuf32 = (unsigned long*) bufInfo.pPixels;
266 pFrmbuf32[bufInfo.pixelPerLine * horY + x1] = bufInfo.color32;
272 if (line.__DrawHorizontalLineWithOpacity32(x1, x2, horY, bufInfo) == GP_RESULT_FAIL)
283 pWetePtr = pWetePtr->pWNext;
284 while (pWetePtr != pAetPtr)
291 if (pAetPtr->maxY == y)
293 pPrevAet->pNext = pAetPtr->pNext;
294 pAetPtr = pPrevAet->pNext;
298 pAetPtr->pBack = pPrevAet;
303 if (pAetPtr->gradient1 > 0)
305 if (pAetPtr->direction > 0)
307 pAetPtr->minor += pAetPtr->gradient1;
308 pAetPtr->direction += pAetPtr->inc1;
312 pAetPtr->minor += pAetPtr->gradient;
313 pAetPtr->direction += pAetPtr->inc2;
318 if (pAetPtr->direction >= 0)
320 pAetPtr->minor += pAetPtr->gradient1;
321 pAetPtr->direction += pAetPtr->inc1;
325 pAetPtr->minor += pAetPtr->gradient;
326 pAetPtr->direction += pAetPtr->inc2;
330 pAetPtr = pAetPtr->pNext;
333 pWetePtr = pWetePtr->pWNext;
341 if (pAetPtr->maxY == y)
343 pPrevAet->pNext = pAetPtr->pNext;
344 pAetPtr = pPrevAet->pNext;
349 pAetPtr->pBack = pPrevAet;
354 if (pAetPtr->gradient1 > 0)
356 if (pAetPtr->direction > 0)
358 pAetPtr->minor += pAetPtr->gradient1;
359 pAetPtr->direction += pAetPtr->inc1;
363 pAetPtr->minor += pAetPtr->gradient;
364 pAetPtr->direction += pAetPtr->inc2;
369 if (pAetPtr->direction >= 0)
371 pAetPtr->minor += pAetPtr->gradient1;
372 pAetPtr->direction += pAetPtr->inc1;
376 pAetPtr->minor += pAetPtr->gradient;
377 pAetPtr->direction += pAetPtr->inc2;
382 pAetPtr = pAetPtr->pNext;
386 if (line._InsertionSort(&aet) || fixWaet)
388 line._ComputeWaet(&aet);
393 delete[] pTempPoints;
397 line._FreeSllb(pSllb);
402 }} // Tizen::Graphics