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_Canvas.cpp
20 * @brief This is the implementation file for _Canvas class.
30 #include <unique_ptr.h>
34 #include <FGrpBufferInfo.h>
36 #include <FBaseInternalTypes.h>
37 #include <FApp_AppInfo.h>
39 #include <FBaseSysLog.h>
41 #include "FGrp_BufferInfoImpl.h"
42 #include "FGrp_Callback.h"
43 #include "FGrp_Canvas.h"
44 #include "FGrp_CanvasGpPrimitive.h"
45 #include "FGrp_CanvasRasterOp.h"
46 #include "FGrp_Bitmap.h"
47 #include "FGrp_Font.h"
48 #include "FGrp_Screen.h"
49 #include "FGrp_ResUtil.h"
50 #include "FGrp_CanvasCairo.h"
51 #include "FGrp_CanvasPixman.h"
52 #include "util/FGrp_Util.h"
53 #include "effect/FGrp_Effect.h"
55 ////////////////////////////////////////////////////////////////////////////////
58 #define M_PI 3.14159265358979323846
63 ////////////////////////////////////////////////////////////////////////////////
65 #define SET_CAIRO_DASH_STYLE \
66 _Cairo::SetDash(pCairo->pCairo, this->__dashData.pattern.Begin(), int(this->__dashData.pattern.Size()), this->__dashData.offset)
68 #define RESET_CAIRO_DASH_STYLE \
69 _Cairo::ResetDash(pCairo->pCairo)
71 #define SET_CAIRO_CLIPPING \
72 if (this->__isClipBoundsSet) \
74 _Cairo::SetClip(pCairo->pCairo, this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height); \
77 #define RESET_CAIRO_CLIPPING \
78 if (this->__isClipBoundsSet) \
80 _Cairo::ResetClip(pCairo->pCairo); \
83 #define SET_CAIRO_BLENDING \
84 _Cairo::SetBlending(pCairo->pCairo, _ConvertParam<cairo_operator_t>(this->__blendingMode));
86 #define RESET_CAIRO_BLENDING \
87 _Cairo::SetBlending(pCairo->pCairo, CAIRO_OPERATOR_OVER);
90 ////////////////////////////////////////////////////////////////////////////////
92 using namespace Tizen::Base;
93 using namespace Tizen::Base::Collection;
94 using namespace Tizen::Base::Utility;
96 ////////////////////////////////////////////////////////////////////////////////
102 template<typename Dest, typename Sour>
103 Dest _ConvertParam(Sour val);
106 Tizen::Graphics::_Effect::Rop
107 _ConvertParam(Tizen::Graphics::_Canvas::BlendOption blendOption)
111 case Tizen::Graphics::_Canvas::BLEND_COPY:
112 return Tizen::Graphics::_Effect::ROP_COPY;
113 case Tizen::Graphics::_Canvas::BLEND_ALPHABLEND:
114 return Tizen::Graphics::_Effect::ROP_ALPHABLEND;
116 return Tizen::Graphics::_Effect::ROP_ALPHABLEND;
122 _ConvertParam(Tizen::Graphics::BlendingMode blendingMode)
124 switch (blendingMode)
126 case Tizen::Graphics::BLENDING_MODE_CLEAR:
127 return CAIRO_OPERATOR_CLEAR;
128 case Tizen::Graphics::BLENDING_MODE_SRC:
129 return CAIRO_OPERATOR_SOURCE;
130 case Tizen::Graphics::BLENDING_MODE_DST:
131 return CAIRO_OPERATOR_DEST;
132 case Tizen::Graphics::BLENDING_MODE_SRC_OVER:
133 return CAIRO_OPERATOR_OVER;
134 case Tizen::Graphics::BLENDING_MODE_DST_OVER:
135 return CAIRO_OPERATOR_DEST_OVER;
136 case Tizen::Graphics::BLENDING_MODE_SRC_IN:
137 return CAIRO_OPERATOR_IN;
138 case Tizen::Graphics::BLENDING_MODE_DST_IN:
139 return CAIRO_OPERATOR_DEST_IN;
140 case Tizen::Graphics::BLENDING_MODE_SRC_OUT:
141 return CAIRO_OPERATOR_OUT;
142 case Tizen::Graphics::BLENDING_MODE_DST_OUT:
143 return CAIRO_OPERATOR_DEST_OUT;
144 case Tizen::Graphics::BLENDING_MODE_SRC_ATOP:
145 return CAIRO_OPERATOR_ATOP;
146 case Tizen::Graphics::BLENDING_MODE_DST_ATOP:
147 return CAIRO_OPERATOR_DEST_ATOP;
148 case Tizen::Graphics::BLENDING_MODE_DST_XOR:
149 return CAIRO_OPERATOR_XOR;
150 case Tizen::Graphics::BLENDING_MODE_ADD:
151 return CAIRO_OPERATOR_ADD;
152 case Tizen::Graphics::BLENDING_MODE_SATURATE:
153 return CAIRO_OPERATOR_SATURATE;
155 return CAIRO_OPERATOR_OVER;
159 inline unsigned short
160 _ConvertRGB888ToRGB565(unsigned char red, unsigned char green, unsigned char blue)
162 typedef unsigned short ColorType;
164 return (ColorType(red >> 3) << 11) | (ColorType(green >> 2) << 5) | ColorType(blue >> 3);
168 _GetWindowSourceObject(Handle handle)
170 Evas_Object* pSourceObject = evas_object_image_source_get((Evas_Object*) handle);
172 return (pSourceObject) ? pSourceObject : (Evas_Object*) handle;
176 _GetWindowWidth(Handle handle)
181 evas_object_image_size_get(_GetWindowSourceObject(handle), &width, &height);
187 _GetWindowHeight(Handle handle)
192 evas_object_image_size_get(_GetWindowSourceObject(handle), &width, &height);
197 ///////////////////////////////////////////////
198 // class _GenericBufferFrameBuffer
200 template<typename Pixel>
201 class _GenericBufferFrameBuffer
202 : public Tizen::Graphics::_Util::GenericBufferBase<Pixel>
205 _GenericBufferFrameBuffer(Handle handle, int _width, int _height)
207 this->__pAssociatedBuffer = this->_pBuffer = (Pixel*) evas_object_image_data_get(_GetWindowSourceObject(handle), EINA_TRUE);
209 int pitch = evas_object_image_stride_get(_GetWindowSourceObject(handle)) / int(sizeof(Pixel));
210 pitch = (pitch) ? pitch : _width;
212 if (this->_pBuffer == null)
214 SysLog(NID_GRP, "[] evas_object_image_data_get(%d) failed!", handle);
217 this->_pitch = pitch;
218 this->_padding = this->_pitch - _width;
221 this->_rect.w = _width;
222 this->_rect.h = _height;
223 this->_pHandle = reinterpret_cast<void*>(handle);
225 this->__associatedHandle = handle;
226 this->__hasOwnership = false;
229 _GenericBufferFrameBuffer(Handle handle, int _x, int _y, int _width, int _height, int pitch)
231 this->__pAssociatedBuffer = this->_pBuffer = (Pixel*) evas_object_image_data_get(_GetWindowSourceObject(handle), EINA_TRUE);
235 pitch = evas_object_image_stride_get(_GetWindowSourceObject(handle)) / int(sizeof(Pixel));
236 pitch = (pitch) ? pitch : _GetWindowWidth(handle);
239 if (this->_pBuffer == null)
241 SysLog(NID_GRP, "[] evas_object_image_data_get(%d) failed!", handle);
244 this->_pBuffer += (_y * pitch + _x);
246 this->_pitch = pitch;
247 this->_padding = this->_pitch - _width;
250 this->_rect.w = _width;
251 this->_rect.h = _height;
252 this->_pHandle = reinterpret_cast<void*>(handle);
254 this->__associatedHandle = handle;
255 this->__hasOwnership = false;
258 _GenericBufferFrameBuffer(int width, int height)
259 : __pAssociatedBuffer(0)
261 this->_pBuffer = new (std::nothrow) Pixel[width * height];
263 if (this->_pBuffer == null)
269 this->_pitch = width;
270 this->_padding = this->_pitch - width;
273 this->_rect.w = width;
274 this->_rect.h = height;
277 this->__associatedHandle = 0;
278 this->__hasOwnership = (this->_pBuffer != null);
281 _GenericBufferFrameBuffer(Pixel* pBuffer, int width, int height, int pitch)
282 : __pAssociatedBuffer(0)
284 this->_pBuffer = pBuffer;
286 this->_pitch = pitch;
287 this->_padding = this->_pitch - width;
290 this->_rect.w = width;
291 this->_rect.h = height;
294 this->__associatedHandle = 0;
295 this->__hasOwnership = false;
298 virtual ~_GenericBufferFrameBuffer(void)
300 if (this->__associatedHandle != 0 && this->__pAssociatedBuffer != null)
302 evas_object_image_data_set(_GetWindowSourceObject(this->__associatedHandle), this->__pAssociatedBuffer);
305 if (this->__hasOwnership)
307 delete[] this->_pBuffer;
313 _GenericBufferFrameBuffer(const _GenericBufferFrameBuffer&);
314 _GenericBufferFrameBuffer& operator =(const _GenericBufferFrameBuffer&);
316 void* __pAssociatedBuffer;
317 Handle __associatedHandle;
330 CLIP_REJECT, // Clipped rejected
331 CLIP_CLIPPED, // Clipped accepted
332 CLIP_ACCEPT // Accepted
336 _ClipRectangle(int& srcX, int& srcY, int& srcW, int& srcH, int clipX, int clipY, int clipW, int clipH)
338 if (clipW <= 0 || clipH <= 0)
343 _ClipResult returnValue = CLIP_ACCEPT;
345 int srcEndX = srcX + srcW - 1;
346 int srcEndY = srcY + srcH - 1;
347 int clipEndX = clipX + clipW - 1;
348 int clipEndY = clipY + clipH - 1;
350 if (srcX > clipEndX || srcEndX < clipX)
355 if (srcY > clipEndY || srcEndY < clipY)
364 returnValue = CLIP_CLIPPED;
367 if (srcEndX > clipEndX)
371 returnValue = CLIP_CLIPPED;
378 returnValue = CLIP_CLIPPED;
381 if (srcEndY > clipEndY)
385 returnValue = CLIP_CLIPPED;
388 srcW = srcEndX - srcX + 1;
389 srcH = srcEndY - srcY + 1;
395 _ComposeColor(unsigned long color32, int opacity)
397 unsigned char alpha = (unsigned char) (((color32) >> 24));
398 unsigned char red = (unsigned char) (((color32) >> 16));
399 unsigned char green = (unsigned char) (((color32) >> 8));
400 unsigned char blue = (unsigned char) ((color32));
402 alpha = (unsigned char) ((alpha * opacity + 255) >> 8);
403 red = (unsigned char) ((red * opacity + 255) >> 8);
404 green = (unsigned char) ((green * opacity + 255) >> 8);
405 blue = (unsigned char) ((blue * opacity + 255) >> 8);
407 return (unsigned long) (((unsigned long) (alpha) << 24) | ((unsigned long) (red) << 16) | ((unsigned long) (green) << 8) | (unsigned long) (blue));
410 template<typename Pixel>
412 _ClearRectangleWithClip(Tizen::Graphics::_Util::ScratchPad<Pixel>* pScratchPad, Pixel color, const Tizen::Graphics::_Util::Rectangle<int>& rect, const Tizen::Graphics::_Util::Rectangle<int>& clip)
414 if (pScratchPad == null)
422 int x2 = x1 + rect.w;
423 int y2 = y1 + rect.h;
425 x1 = (x1 >= clip.x) ? x1 : clip.x;
426 y1 = (y1 >= clip.y) ? y1 : clip.y;
428 x2 = (x2 <= clip.x + clip.w) ? x2 : clip.x + clip.w;
429 y2 = (y2 <= clip.y + clip.h) ? y2 : clip.y + clip.h;
431 if ((x2 - x1) > 0 && (y2 - y1) > 0)
433 pScratchPad->FillRect(x1, y1, x2 - x1, y2 - y1, color);
437 template<typename Pixel>
439 _FillRectangleWithClip(Tizen::Graphics::_Util::ScratchPad<Pixel>* pScratchPad, Pixel color, const Tizen::Graphics::_Util::Rectangle<int>& rect, const Tizen::Graphics::_Util::Rectangle<int>& clip)
441 if (pScratchPad == null)
446 // alpha-fill-rect() applied
447 pScratchPad->RegisterFillRect(Tizen::Graphics::_RasterOp::FnFillRectAlpha32Bit);
448 _ClearRectangleWithClip(pScratchPad, color, rect, clip);
449 pScratchPad->RegisterFillRect(null);
457 typedef Tizen::Graphics::_Canvas::SystemPixel _SystemPixel;
458 typedef Tizen::Graphics::_Util::ScratchPad<_SystemPixel> _ScratchPad32;
460 static std::unique_ptr<_SystemPixel[]> _systemFontBuffer;
461 static std::auto_ptr<_ScratchPad32> _systemFont;
465 ////////////////////////////////////////////////////////////////////////////////
466 // Tizen::Graphics::_Canvas
468 namespace Tizen { namespace Graphics
471 bool _CanvasShowFromMemory(int xDest, int yDest, int xSour, int ySour, int wSour, int hSour, void* pMemory, int width, int height, int depth, int bytesPerLine);
472 void _FlushCanvas(void);
478 _ApplySrcBitmapAttrib(_Util::Pixmap& srcImage, const _Bitmap& bitmap, long isOpaque)
482 if (bitmap.GetBitsPerPixel() == 16)
484 if (bitmap.GetMaskingColor(maskingColor) == E_SUCCESS)
486 srcImage.enableColorKey = 1;
487 srcImage.colorKey = _ConvertRGB888ToRGB565(maskingColor.GetRed(), maskingColor.GetGreen(), maskingColor.GetBlue());
491 srcImage.isOpaque = isOpaque;
492 srcImage.isPremultiplied = bitmap.IsPremultiplied();
495 // retrieving bounds rectangle which has (0,0,w,h).
497 _GetBoundsRel(const _Canvas& canvas)
499 Rectangle rect = canvas.GetBounds();
508 _FillRectangleWithClip32(_Util::ScratchPad<unsigned long>* pScratchPad, unsigned long color, const _Util::Rectangle<int>& rect, const _Util::Rectangle<int>& clip)
510 _FillRectangleWithClip(pScratchPad, color, rect, clip);
513 struct _NativeGfxEngine
516 cairo_surface_t* pCairoSurface;
527 cairo_destroy(pCairo);
532 cairo_surface_destroy(pCairoSurface);
538 _Canvas::_Canvas(void)
539 : _pNativeGfxEngine(static_cast<void*>(new (std::nothrow)_NativeGfxEngine))
543 , __windowHandle(INVALID_HANDLE)
544 , __blendOption(Tizen::Graphics::_Canvas::BLEND_ALPHABLEND)
550 , __fgColor(0xFFFFFFFF)
551 , __bgColor(0x00000000)
555 , __lineStyle(LINE_STYLE_SOLID)
556 , __isClipBoundsSet(false)
557 , __textOrigin(TEXT_ORIGIN_LEFT_TOP)
559 , __bitmapDrawingQuality(BITMAP_DRAWING_QUALITY_LOW)
560 , __blendingMode(BLENDING_MODE_SRC_OVER)
561 , __useStableRenderer(true)
563 __fgColorNative = Color(__fgColor);
564 __bgColorNative = Color(__bgColor);
566 __dashData.offset = 0;
572 _Canvas::~_Canvas(void)
574 delete __pScratchPad;
577 if (_pNativeGfxEngine)
579 delete static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
584 _Canvas::Construct(void)
586 return this->Construct(Rectangle(0, 0, _Screen::GetWidth(), _Screen::GetHeight()));
590 _Canvas::Construct(const Rectangle& rect)
592 result r = E_SUCCESS;
594 _GenericBufferFrameBuffer<SystemPixel>* pTemp = new (std::nothrow) _GenericBufferFrameBuffer<SystemPixel>(rect.width, rect.height);
596 SysTryReturnResult(NID_GRP, pTemp, E_OUT_OF_MEMORY, " _GenericBufferFrameBuffer<> cannot be allocated.");
598 this->__pSurface = new (std::nothrow) _Util::GenericBuffer<SystemPixel>(pTemp);
600 SysTryCatch(NID_GRP, this->__pSurface, delete pTemp;
601 r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] _Util::GenericBuffer<> cannot be allocated.");
603 this->__pBuffer = (unsigned long*) __pSurface->GetBufferAddr();
604 this->__pScratchPad = new (std::nothrow) _Util::ScratchPad<SystemPixel>(__pBuffer, rect.width, rect.height, rect.width);
606 SysTryCatch(NID_GRP, this->__pScratchPad, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] _Util::ScratchPad<> cannot be allocated.");
608 this->__pScratchPad->FillRect(0, 0, this->__pScratchPad->GetWidth(), this->__pScratchPad->GetHeight(), 0x00000000);
610 this->__xBufferPos = rect.x;
611 this->__yBufferPos = rect.y;
613 #if defined(USE_CAIRO)
615 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
619 pCairo->pCairoSurface = cairo_image_surface_create_for_data((unsigned char*) this->__pBuffer, CAIRO_FORMAT_ARGB32, rect.width, rect.height, rect.width * 4);
620 pCairo->pCairo = cairo_create(pCairo->pCairoSurface);
625 __InitFgBgColorFromTheme();
630 delete this->__pScratchPad;
631 this->__pScratchPad = null;
633 delete this->__pSurface;
634 this->__pSurface = null;
640 _Canvas::Construct(Handle windowHandle, const Rectangle& rect)
642 SysTryReturnResult(NID_GRP, rect.width >= 0 && rect.height >= 0, E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.\n", rect.width, rect.height);
644 result r = E_SUCCESS;
648 int x2 = x1 + rect.width;
649 int y2 = y1 + rect.height;
661 if (x2 > _GetWindowWidth(windowHandle))
663 x2 = _GetWindowWidth(windowHandle);
666 if (y2 > _GetWindowHeight(windowHandle))
668 y2 = _GetWindowHeight(windowHandle);
671 SysTryReturnResult(NID_GRP, (x2 - x1 >= 0) && (y2 - y1 >= 0), E_OUT_OF_RANGE, "The given rectangle(x1:%d,y1:%d,x2:%d,y2:%d) is out of range.", x1, y1, x2, y2);
673 int bufferWidth = x2 - x1;
674 int bufferHeight = y2 - y1;
677 _GenericBufferFrameBuffer<SystemPixel>* pTemp = new (std::nothrow) _GenericBufferFrameBuffer<SystemPixel>(windowHandle, x1, y1, bufferWidth, bufferHeight, 0);
679 SysTryReturnResult(NID_GRP, pTemp, E_OUT_OF_MEMORY, "_GenericBufferFrameBuffer<> cannot be allocated.");
681 this->__pSurface = new (std::nothrow) _Util::GenericBuffer<SystemPixel>(pTemp);
683 SysTryCatch(NID_GRP, this->__pSurface, delete pTemp;
684 r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] _Util::GenericBuffer<> cannot be allocated.");
686 this->__pBuffer = (unsigned long*) __pSurface->GetBufferAddr();
687 sourcePitch = __pSurface->GetPitch();
689 this->__pScratchPad = new (std::nothrow) _Util::ScratchPad<SystemPixel>(__pBuffer, bufferWidth, bufferHeight, sourcePitch);
691 SysTryCatch(NID_GRP, this->__pScratchPad, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] _Util::ScratchPad<> cannot be allocated.");
693 this->__windowHandle = windowHandle;
695 this->__xBufferPos = x1;
696 this->__yBufferPos = y1;
698 #if defined(USE_CAIRO)
700 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
704 pCairo->pCairoSurface = cairo_image_surface_create_for_data((unsigned char*) this->__pBuffer, CAIRO_FORMAT_ARGB32, bufferWidth, bufferHeight, sourcePitch * 4);
705 pCairo->pCairo = cairo_create(pCairo->pCairoSurface);
710 __InitFgBgColorFromTheme();
715 delete this->__pScratchPad;
716 this->__pScratchPad = null;
718 delete this->__pSurface;
719 this->__pSurface = null;
725 _Canvas::Construct(_Canvas* pSourceCanvas, const Rectangle& subRegion)
727 SysTryReturnResult(NID_GRP, pSourceCanvas, E_INVALID_ARG, "The source canvas is invalid");
729 SysTryReturnResult(NID_GRP, pSourceCanvas->IsValid(), E_INVALID_ARG, "The source canvas is invalid");
731 result r = E_SUCCESS;
733 int x1 = subRegion.x;
734 int y1 = subRegion.y;
735 int x2 = x1 + subRegion.width;
736 int y2 = y1 + subRegion.height;
748 if (x2 > pSourceCanvas->GetBounds().width)
750 x2 = pSourceCanvas->GetBounds().width;
753 if (y2 > pSourceCanvas->GetBounds().height)
755 y2 = pSourceCanvas->GetBounds().height;
758 SysTryReturnResult(NID_GRP, (x2 - x1 > 0) && (y2 - y1 > 0), E_OUT_OF_RANGE, "The given rectangle(x1:%d,y1:%d,x2:%d,y2:%d) is out of range.", subRegion.x, subRegion.y, subRegion.width, subRegion.height);
760 int bufferWidth = x2 - x1;
761 int bufferHeight = y2 - y1;
763 int sourcePitch = pSourceCanvas->__pSurface->GetPitch();
765 if (pSourceCanvas->__windowHandle != INVALID_HANDLE)
767 _GenericBufferFrameBuffer<SystemPixel>* pTemp = new (std::nothrow) _GenericBufferFrameBuffer<SystemPixel>(pSourceCanvas->__windowHandle, x1, y1, bufferWidth, bufferHeight, sourcePitch);
769 SysTryReturnResult(NID_GRP, pTemp, E_OUT_OF_MEMORY, "_GenericBufferFrameBuffer<> cannot be allocated.");
771 this->__pSurface = new (std::nothrow) _Util::GenericBuffer<SystemPixel>(pTemp);
773 if (this->__pSurface == null)
776 SysTryReturnResult(NID_GRP, false, E_OUT_OF_MEMORY, "_Util::GenericBuffer<> cannot be allocated.");
781 SystemPixel* pBuffer = pSourceCanvas->__pSurface->GetBufferAddr();
782 pBuffer += y1 * sourcePitch + x1;
784 _GenericBufferFrameBuffer<SystemPixel>* pTemp = new (std::nothrow) _GenericBufferFrameBuffer<SystemPixel>(pBuffer, bufferWidth, bufferHeight, sourcePitch);
786 SysTryReturnResult(NID_GRP, pTemp, E_OUT_OF_MEMORY, "_GenericBufferFrameBuffer<> cannot be allocated.");
788 this->__pSurface = new (std::nothrow) _Util::GenericBuffer<SystemPixel>(pTemp);
790 if (this->__pSurface == null)
793 SysTryReturnResult(NID_GRP, false, E_OUT_OF_MEMORY, "_Util::GenericBuffer<> cannot be allocated.");
797 this->__pBuffer = (unsigned long*) __pSurface->GetBufferAddr();
798 this->__pScratchPad = new (std::nothrow) _Util::ScratchPad<SystemPixel>(__pBuffer, bufferWidth, bufferHeight, sourcePitch);
800 SysTryCatch(NID_GRP, this->__pScratchPad, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] _Util::ScratchPad<> cannot be allocated.");
802 this->__pParent = pSourceCanvas;
803 this->__xBufferPos = x1;
804 this->__yBufferPos = y1;
807 // must re-assign by _CanvasImpl::GetSubCanvasN()
808 this->__pFont = pSourceCanvas->__pFont;
810 this->__pPriorityFont = pSourceCanvas->__pPriorityFont;
813 this->__windowHandle = pSourceCanvas->__windowHandle;
814 this->__blendOption = pSourceCanvas->__blendOption;
815 this->__fgColor = pSourceCanvas->__fgColor;
816 this->__bgColor = pSourceCanvas->__bgColor;
817 this->__fgColorNative = pSourceCanvas->__fgColorNative;
818 this->__bgColorNative = pSourceCanvas->__bgColorNative;
819 this->__fgOpacity = pSourceCanvas->__fgOpacity;
820 this->__bgOpacity = pSourceCanvas->__bgOpacity;
821 this->__lineWidth = pSourceCanvas->__lineWidth;
822 this->__lineStyle = pSourceCanvas->__lineStyle;
825 this->__isClipBoundsSet = false;
826 this->__clipBounds = Rectangle(0, 0, bufferWidth, bufferHeight);
828 #if defined(USE_CAIRO)
830 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
834 pCairo->pCairoSurface = cairo_image_surface_create_for_data((unsigned char*) this->__pBuffer, CAIRO_FORMAT_ARGB32, bufferWidth, bufferHeight, sourcePitch * 4);
835 pCairo->pCairo = cairo_create(pCairo->pCairoSurface);
843 delete this->__pScratchPad;
844 this->__pScratchPad = null;
846 delete this->__pSurface;
847 this->__pSurface = null;
853 _Canvas::Construct(const BufferInfo& bufferInfo)
855 // all parameters checked
857 result r = E_SUCCESS;
859 _GenericBufferFrameBuffer<SystemPixel>* pTemp = new (std::nothrow) _GenericBufferFrameBuffer<SystemPixel>(static_cast<SystemPixel*>(bufferInfo.pPixels), bufferInfo.width, bufferInfo.height, bufferInfo.pitch * 8 / bufferInfo.bitsPerPixel);
861 SysTryReturnResult(NID_GRP
864 , " _GenericBufferFrameBuffer<> cannot be allocated.");
866 this->__pSurface = new (std::nothrow) _Util::GenericBuffer<SystemPixel>(pTemp);
870 , delete pTemp; r = E_OUT_OF_MEMORY
872 , "[E_OUT_OF_MEMORY] _Util::GenericBuffer<> cannot be allocated.");
874 this->__pBuffer = (unsigned long*) __pSurface->GetBufferAddr();
875 this->__pScratchPad = new (std::nothrow) _Util::ScratchPad<SystemPixel>(__pBuffer, bufferInfo.width, bufferInfo.height, bufferInfo.pitch * 8 / bufferInfo.bitsPerPixel);
878 , this->__pScratchPad
879 , r = E_OUT_OF_MEMORY
881 , "[E_OUT_OF_MEMORY] _Util::ScratchPad<> cannot be allocated.");
883 this->__xBufferPos = 0;
884 this->__yBufferPos = 0;
886 #if defined(USE_CAIRO)
888 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
892 pCairo->pCairoSurface = cairo_image_surface_create_for_data((unsigned char*) this->__pBuffer, CAIRO_FORMAT_ARGB32, bufferInfo.width, bufferInfo.height, bufferInfo.pitch);
893 pCairo->pCairo = cairo_create(pCairo->pCairoSurface);
898 __InitFgBgColorFromTheme();
903 delete this->__pScratchPad;
904 this->__pScratchPad = null;
906 delete this->__pSurface;
907 this->__pSurface = null;
913 _Canvas::IsValid() const
915 return (this && this->__pSurface);
921 if (this->__isClipBoundsSet)
923 _Util::Rectangle<int> clip =
925 this->__clipBounds.x,
926 this->__clipBounds.y,
927 this->__clipBounds.width,
928 this->__clipBounds.height
931 _Util::Rectangle<int> rect =
935 __pScratchPad->GetWidth(),
936 __pScratchPad->GetHeight()
939 _ClearRectangleWithClip(__pScratchPad, __bgColor, rect, clip);
943 __pScratchPad->FillRect(0, 0, __pScratchPad->GetWidth(), __pScratchPad->GetHeight(), __bgColor);
950 _Canvas::Clear(const Rectangle& rect)
952 if ((rect.width == 0) || (rect.height == 0))
957 if (this->__isClipBoundsSet)
959 _Util::Rectangle<int> clip =
961 this->__clipBounds.x,
962 this->__clipBounds.y,
963 this->__clipBounds.width,
964 this->__clipBounds.height
967 _Util::Rectangle<int> rect1 =
975 _ClearRectangleWithClip(__pScratchPad, __bgColor, rect1, clip);
979 __pScratchPad->FillRect(rect.x, rect.y, rect.width, rect.height, __bgColor);
986 _Canvas::Copy(const Point& destPoint, const _Canvas& canvas, const Rectangle& srcRect)
989 if (srcRect.width == 0 || srcRect.height == 0)
994 return this->__Copy(destPoint, canvas, srcRect);
998 _Canvas::Copy(const Rectangle& destRect, const _Canvas& canvas, const Rectangle& srcRect)
1001 if (srcRect.width == 0 || srcRect.height == 0 || destRect.width == 0 || destRect.height == 0)
1006 return this->__Copy(destRect, canvas, srcRect);
1010 _Canvas::Copy(const Point& destPoint, const _Canvas& canvas, const Rectangle& srcRect, BlendingMode blendingMode)
1012 _Util::LockManager srcLock(canvas);
1013 _Util::LockManager dstLock(*this);
1015 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source canvas cannot be locked.");
1016 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked");
1018 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1019 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1022 _Util::Pixmap srcImageUnclipped(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1023 _Util::Pixmap srcImage = srcImageUnclipped.GetSubBitmap(srcRect.x, srcRect.y, srcRect.width, srcRect.height);
1025 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1026 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(destPoint.x, destPoint.y, srcRect.width, srcRect.height);
1028 _Pixman::CopyPixmap(dstImage, srcImage, GetDrawingQuality(), blendingMode);
1035 _Canvas::CopyReverse(const Point& destPoint, const _Canvas& srcCanvas, const Rectangle& srcRect)
1038 if (srcRect.width == 0 || srcRect.height == 0)
1043 if (__pScratchPad == null)
1048 const _Canvas* pSrcCanvas = &srcCanvas;
1050 if (pSrcCanvas == null)
1055 if (pSrcCanvas->__pScratchPad == null)
1060 Rectangle clippedSrcRect(srcRect);
1062 if (_ClipRectangle(clippedSrcRect.x, clippedSrcRect.y, clippedSrcRect.width, clippedSrcRect.height, 0, 0, pSrcCanvas->__pScratchPad->GetWidth(), pSrcCanvas->__pScratchPad->GetHeight()) == CLIP_REJECT)
1067 __pScratchPad->RegisterBitBlt(_RasterOp::FnBitBlt32BitCopyReverse);
1068 __pScratchPad->BitBlt(destPoint.x, destPoint.y, pSrcCanvas->__pScratchPad, clippedSrcRect.x, clippedSrcRect.y, clippedSrcRect.width, clippedSrcRect.height);
1069 __pScratchPad->RegisterBitBlt(null);
1077 // spec. from SDK 1.0
1079 template<typename T>
1081 _ReviseAngle(T& startAngle, T& endAngle)
1087 // startAngle = startAngle % twoPi;
1088 int mod = int(startAngle / twoPi);
1089 startAngle = startAngle - twoPi * mod;
1091 //endAngle = endAngle % twoPi;
1092 mod = int(endAngle / twoPi);
1093 endAngle = endAngle - twoPi * mod;
1096 if (startAngle < zeroPi || endAngle < zeroPi)
1098 startAngle += twoPi;
1102 if (startAngle > endAngle)
1111 _Canvas::DrawArc(const _Util::Rectangle<double>& bounds, double startAngle, double endAngle, ArcStyle arcStyle)
1113 if ((bounds.w <= 0.0) || (bounds.h <= 0.0))
1118 // this->__lineWidth is always greater than 0
1120 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
1122 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
1124 if (pCairo && pCairo->pCairo)
1126 SET_CAIRO_DASH_STYLE;
1129 double startDstAngle = (180.0 / M_PI) * atan2(sin(startAngle*M_PI / 180.0) * bounds.w / bounds.h, cos(startAngle * M_PI / 180.0));
1130 double endDstAngle = (180.0 / M_PI) * atan2(sin(endAngle * M_PI / 180.0) * bounds.w / bounds.h, cos(endAngle * M_PI / 180.0));
1132 startDstAngle += (abs(startAngle - startDstAngle) <= 90.0) ? 0.0 : (startDstAngle < 0.0 && startAngle >= 0.0) ? 360.0 : (startDstAngle >= 0.0 && startAngle < 0.0) ? -360.0 : 0.0;
1133 endDstAngle += (abs(endAngle - endDstAngle) <= 90.0) ? 0.0 : (endDstAngle < 0.0 && endAngle >= 0.0) ? 360.0 : (endDstAngle >= 0.0 && endAngle < 0.0) ? -360.0 : 0.0;
1135 _ReviseAngle(startDstAngle, endDstAngle);
1139 case ARC_STYLE_ONLY:
1140 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
1142 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_ARC);
1146 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_ARC);
1151 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
1153 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_PIE);
1157 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_PIE);
1161 case ARC_STYLE_CHORD:
1162 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
1164 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_CHORD);
1168 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_CHORD);
1172 case ARC_STYLE_FILLED_PIE:
1173 _Cairo::FillArc(pCairo->pCairo, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::FILL_ARC_STYLE_PIE);
1176 case ARC_STYLE_FILLED_CHORD:
1177 _Cairo::FillArc(pCairo->pCairo, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::FILL_ARC_STYLE_CHORD);
1184 RESET_CAIRO_CLIPPING;
1185 RESET_CAIRO_DASH_STYLE;
1194 memset(&info, 0, sizeof(info));
1196 SystemPixel* pBufferAddr = null;
1197 int bufferPitch = 0;
1199 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
1201 info.width = __pScratchPad->GetWidth();
1202 info.height = __pScratchPad->GetHeight();
1203 info.bitsPerPixel = 32;
1204 info.pixelPerLine = bufferPitch;
1205 info.pPixels = (void*) pBufferAddr;
1206 info.color32 = composedColor;
1207 info.isClipBoundsSet = this->__isClipBoundsSet;
1208 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
1210 arc.SetLineWidth(this->__lineWidth.asInteger);
1212 _ReviseAngle(startAngle, endAngle);
1214 return arc.DrawArc(int(bounds.x), int(bounds.y), int(bounds.w), int(bounds.h), int(startAngle), int(endAngle), arcStyle, info);
1219 _Canvas::DrawBitmap(const Rectangle& rect, const _Bitmap& bitmap)
1221 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1223 if (rect.width <= 0 || rect.height <= 0)
1228 int alphaConstant = this->_GetAlphaAttenuation(bitmap);
1232 this->__GetClipBounds(clipRect);
1234 if (alphaConstant >= 255)
1238 _Util::LockManager srcLock(bitmap);
1239 _Util::LockManager dstLock(*this);
1241 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1242 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1244 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1245 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1248 if (!this->__useStableRenderer && srcBufferInfo.bitsPerPixel == 32)
1250 _Util::Rectangle<int> outRect = { 0, 0, -1, -1 };
1251 _Util::Rectangle<int> dstRect = { rect.x, rect.y, rect.width, rect.height };
1252 _Util::Rectangle<int> tgtRect = { clipRect.x, clipRect.y, clipRect.width, clipRect.height };
1254 _Util::IntersectRect(outRect, tgtRect, dstRect);
1256 // assert(rect.width > 0 && rect.height > 0);
1258 _Util::Bounds<int> outBounds = { outRect.x, outRect.y, outRect.x + outRect.w, outRect.y + outRect.h };
1259 _Util::Bounds<int> dstBounds = { dstRect.x, dstRect.y, dstRect.x + dstRect.w, dstRect.y + dstRect.h };
1260 _Util::Bounds<int> srcBounds =
1262 (outBounds.x1 - dstBounds.x1) * srcBufferInfo.width / (dstBounds.x2 - dstBounds.x1),
1263 (outBounds.y1 - dstBounds.y1) * srcBufferInfo.height / (dstBounds.y2 - dstBounds.y1),
1264 srcBufferInfo.width + (outBounds.x2 - dstBounds.x2) * srcBufferInfo.width / (dstBounds.x2 - dstBounds.x1),
1265 srcBufferInfo.height + (outBounds.y2 - dstBounds.y2) * srcBufferInfo.height / (dstBounds.y2 - dstBounds.y1),
1268 srcBounds.x1 = (srcBounds.x1 >= 0) ? srcBounds.x1 : 0;
1269 srcBounds.y1 = (srcBounds.y1 >= 0) ? srcBounds.y1 : 0;
1270 srcBounds.x2 = (srcBounds.x2 <= srcBufferInfo.width) ? srcBounds.x2 : srcBufferInfo.width;
1271 srcBounds.y2 = (srcBounds.y2 <= srcBufferInfo.height) ? srcBounds.y2 : srcBufferInfo.height;
1273 _Util::Pixmap srcImageUnclipped(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1274 _Util::Pixmap srcImage = srcImageUnclipped.GetSubBitmap(srcBounds.x1, srcBounds.y1, srcBounds.x2 - srcBounds.x1, srcBounds.y2 - srcBounds.y1);
1275 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1277 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1278 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(outRect.x, outRect.y, outRect.w, outRect.h);
1280 pass = _Pixman::ScalePixmap(dstImage, srcImage, GetDrawingQuality());
1285 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1286 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1288 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1289 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1291 pass = Tizen::Graphics::_Effect::ScaleImage(dstImage, rect.x - clipRect.x, rect.y - clipRect.y, rect.width, rect.height, srcImage, _ConvertParam<_Effect::Rop>(this->__blendOption));
1296 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1302 _Util::Pixmap tmpImage(rect.width, rect.height, bitmap.GetBitsPerPixel());
1304 // copies the source bitmap to the scaled bitmap
1306 // ykahn, 2011/10/11 patched
1308 _ApplySrcBitmapAttrib(tmpImage, bitmap, bitmap.__isOpaqueAllOver);
1310 if (tmpImage.depth == 16)
1312 if (tmpImage.enableColorKey)
1314 typedef unsigned short Pixel;
1316 Pixel colorKey = (Pixel) tmpImage.colorKey;
1317 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
1318 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
1320 while (pDest < pDestEnd)
1322 *pDest++ = colorKey;
1330 else if (tmpImage.depth == 32)
1332 typedef unsigned long Pixel;
1334 Pixel fillColor = 0;
1335 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
1336 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
1338 while (pDest < pDestEnd)
1340 *pDest++ = fillColor;
1348 _Util::LockManager srcLock(bitmap);
1349 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1351 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1354 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1355 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1357 pass = Tizen::Graphics::_Effect::ScaleImage(tmpImage, 0, 0, rect.width, rect.height, srcImage, Tizen::Graphics::_Effect::ROP_COPY);
1361 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1368 _Util::LockManager dstLock(*this);
1369 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1371 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1374 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1375 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1377 pass = Tizen::Graphics::_Effect::DrawImageWithAlpha(dstImage, rect.x - clipRect.x, rect.y - clipRect.y, tmpImage, alphaConstant);
1381 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1390 _Canvas::DrawBitmap(const Point& point, const _Bitmap& bitmap)
1392 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1394 int alphaConstant = this->_GetAlphaAttenuation(bitmap);
1399 this->__GetClipBounds(clipRect);
1404 _Util::LockManager srcLock(bitmap);
1405 _Util::LockManager dstLock(*this);
1407 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1408 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1410 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1411 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1414 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1415 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1417 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1418 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1420 if (srcBufferInfo.pixelFormat == PIXEL_FORMAT_RGB565 && srcImage.enableColorKey == 0 && dstBufferInfo.pixelFormat == PIXEL_FORMAT_ARGB8888 && !this->__isClipBoundsSet)
1422 pixman_image_t* pPixmanSrc = pixman_image_create_bits(PIXMAN_r5g6b5, srcBufferInfo.width, srcBufferInfo.height, (uint32_t*)srcBufferInfo.pPixels, srcBufferInfo.pitch);
1423 pixman_image_t* pPixmanDst = pixman_image_create_bits(PIXMAN_a8r8g8b8, dstBufferInfo.width, dstBufferInfo.height, (uint32_t*)dstBufferInfo.pPixels, dstBufferInfo.pitch);
1425 if (pPixmanSrc && pPixmanDst)
1427 pixman_image_composite32(PIXMAN_OP_SRC, pPixmanSrc, NULL, pPixmanDst, 0, 0, 0, 0, point.x, point.y, srcBufferInfo.width, srcBufferInfo.height);
1433 pixman_image_unref(pPixmanDst);
1438 pixman_image_unref(pPixmanSrc);
1444 bool isPixmanSupported = !this->__useStableRenderer && bitmap.GetMaskingColor(color ) != E_SUCCESS && alphaConstant >= 255;
1445 if (isPixmanSupported)
1447 _Util::Rectangle<int> outRect = { 0, 0, -1, -1 };
1448 _Util::Rectangle<int> dstRect = { point.x, point.y, srcBufferInfo.width, srcBufferInfo.height };
1449 _Util::Rectangle<int> tgtRect = { clipRect.x, clipRect.y, clipRect.width, clipRect.height };
1451 if (_Util::IntersectRect(outRect, tgtRect, dstRect))
1453 // assert(rect.width > 0 && rect.height > 0);
1455 _Util::Bounds<int> outBounds = { outRect.x, outRect.y, outRect.x + outRect.w, outRect.y + outRect.h };
1456 _Util::Bounds<int> dstBounds = { dstRect.x, dstRect.y, dstRect.x + dstRect.w, dstRect.y + dstRect.h };
1457 _Util::Bounds<int> srcBounds =
1459 (outBounds.x1 - dstBounds.x1),
1460 (outBounds.y1 - dstBounds.y1),
1461 srcBufferInfo.width + (outBounds.x2 - dstBounds.x2),
1462 srcBufferInfo.height + (outBounds.y2 - dstBounds.y2),
1465 srcBounds.x1 = (srcBounds.x1 >= 0) ? srcBounds.x1 : 0;
1466 srcBounds.y1 = (srcBounds.y1 >= 0) ? srcBounds.y1 : 0;
1467 srcBounds.x2 = (srcBounds.x2 <= srcBufferInfo.width) ? srcBounds.x2 : srcBufferInfo.width;
1468 srcBounds.y2 = (srcBounds.y2 <= srcBufferInfo.height) ? srcBounds.y2 : srcBufferInfo.height;
1470 _Util::Pixmap srcImageUnclipped(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1471 _Util::Pixmap srcImage = srcImageUnclipped.GetSubBitmap(srcBounds.x1, srcBounds.y1, srcBounds.x2 - srcBounds.x1, srcBounds.y2 - srcBounds.y1);
1472 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1474 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1475 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(outRect.x, outRect.y, outRect.w, outRect.h);
1477 pass = _Pixman::CopyPixmap(dstImage, srcImage, GetDrawingQuality(), BLENDING_MODE_SRC_OVER);
1483 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1484 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1486 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1487 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1489 pass = Tizen::Graphics::_Effect::DrawImageWithAlpha(dstImage, point.x - clipRect.x, point.y - clipRect.y, srcImage, alphaConstant);
1494 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1501 _Canvas::DrawBitmap(const Rectangle& destRect, const _Bitmap& srcBitmap, const Rectangle& srcRect)
1503 SysTryReturnResult(NID_GRP, &srcBitmap && srcBitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1505 if (srcRect.width == 0 || srcRect.height == 0)
1510 if (destRect.width == 0 || destRect.height == 0)
1515 int alphaConstant = this->_GetAlphaAttenuation(srcBitmap);
1519 this->__GetClipBounds(clipRect);
1521 if (alphaConstant >= 255)
1525 _Util::LockManager srcLock(srcBitmap);
1526 _Util::LockManager dstLock(*this);
1528 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1529 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1531 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1532 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1535 if (!this->__useStableRenderer && srcBufferInfo.bitsPerPixel == 32)
1537 _Util::Rectangle<int> outRect = { 0, 0, -1, -1 };
1538 _Util::Rectangle<int> dstRect = { destRect.x, destRect.y, destRect.width, destRect.height };
1539 _Util::Rectangle<int> tgtRect = { clipRect.x, clipRect.y, clipRect.width, clipRect.height };
1541 _Util::IntersectRect(outRect, tgtRect, dstRect);
1543 // assert(destRect.width > 0 && destRect.height > 0);
1545 _Util::Bounds<int> outBounds = { outRect.x, outRect.y, outRect.x + outRect.w, outRect.y + outRect.h };
1546 _Util::Bounds<int> dstBounds = { dstRect.x, dstRect.y, dstRect.x + dstRect.w, dstRect.y + dstRect.h };
1547 _Util::Bounds<int> srcBounds =
1549 srcRect.x + (outBounds.x1 - dstBounds.x1) * srcRect.width / (dstBounds.x2 - dstBounds.x1),
1550 srcRect.y + (outBounds.y1 - dstBounds.y1) * srcRect.height / (dstBounds.y2 - dstBounds.y1),
1551 (srcRect.x + srcRect.width) + (outBounds.x2 - dstBounds.x2) * srcRect.width / (dstBounds.x2 - dstBounds.x1),
1552 (srcRect.y + srcRect.height) + (outBounds.y2 - dstBounds.y2) * srcRect.height / (dstBounds.y2 - dstBounds.y1),
1555 srcBounds.x1 = (srcBounds.x1 >= srcRect.x) ? srcBounds.x1 : srcRect.x;
1556 srcBounds.y1 = (srcBounds.y1 >= srcRect.y) ? srcBounds.y1 : srcRect.y;
1557 srcBounds.x2 = (srcBounds.x2 <= (srcRect.x + srcRect.width)) ? srcBounds.x2 : (srcRect.x + srcRect.width);
1558 srcBounds.y2 = (srcBounds.y2 <= (srcRect.y + srcRect.height)) ? srcBounds.y2 : (srcRect.y + srcRect.height);
1560 _Util::Pixmap srcImageUnclipped(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1561 _Util::Pixmap srcImage = srcImageUnclipped.GetSubBitmap(srcBounds.x1, srcBounds.y1, srcBounds.x2 - srcBounds.x1, srcBounds.y2 - srcBounds.y1);
1562 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1564 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1565 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(outRect.x, outRect.y, outRect.w, outRect.h);
1567 pass = _Pixman::ScalePixmap(dstImage, srcImage, GetDrawingQuality());
1572 unsigned char* pPixels = (unsigned char*) srcBufferInfo.pPixels + srcRect.y * srcBufferInfo.pitch + srcRect.x * (srcBufferInfo.bitsPerPixel / 8);
1574 _Util::Pixmap srcImage(srcRect.width, srcRect.height, srcBufferInfo.bitsPerPixel, (void*) pPixels, srcBufferInfo.pitch);
1575 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1577 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1578 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1580 pass = Tizen::Graphics::_Effect::ScaleImage(dstImage, destRect.x - clipRect.x, destRect.y - clipRect.y, destRect.width, destRect.height, srcImage, _ConvertParam<_Effect::Rop>(this->__blendOption));
1585 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1591 _Util::Pixmap tmpImage(destRect.width, destRect.height, srcBitmap.GetBitsPerPixel());
1593 // copies the source bitmap to the scaled bitmap
1595 // ykahn, 2011/10/11 patched
1597 _ApplySrcBitmapAttrib(tmpImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1599 if (tmpImage.depth == 16)
1601 if (tmpImage.enableColorKey)
1603 typedef unsigned short Pixel;
1605 Pixel colorKey = (Pixel) tmpImage.colorKey;
1606 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
1607 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
1609 while (pDest < pDestEnd)
1611 *pDest++ = colorKey;
1618 else if (tmpImage.depth == 32)
1620 typedef unsigned long Pixel;
1622 Pixel fillColor = 0;
1623 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
1624 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
1626 while (pDest < pDestEnd)
1628 *pDest++ = fillColor;
1636 _Util::LockManager srcLock(srcBitmap);
1637 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1639 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1642 unsigned char* pPixels = (unsigned char*) srcBufferInfo.pPixels + srcRect.y * srcBufferInfo.pitch + srcRect.x * (srcBufferInfo.bitsPerPixel / 8);
1644 _Util::Pixmap srcImage(srcRect.width, srcRect.height, srcBufferInfo.bitsPerPixel, (void*) pPixels, srcBufferInfo.pitch);
1645 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1647 pass = Tizen::Graphics::_Effect::ScaleImage(tmpImage, 0, 0, destRect.width, destRect.height, srcImage, Tizen::Graphics::_Effect::ROP_COPY);
1651 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1658 _Util::LockManager dstLock(*this);
1659 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1661 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1664 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1665 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1667 pass = Tizen::Graphics::_Effect::DrawImageWithAlpha(dstImage, destRect.x - clipRect.x, destRect.y - clipRect.y, tmpImage, alphaConstant);
1671 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1679 _Canvas::DrawBitmapForNinePatchedBitmap(const Rectangle& destRect, const _Bitmap& srcBitmap, const Rectangle& srcRect)
1681 SysTryReturnResult(NID_GRP, &srcBitmap && srcBitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1683 if (srcRect.width == 0 || srcRect.height == 0)
1688 if (destRect.width == 0 || destRect.height == 0)
1693 int alphaConstant = this->_GetAlphaAttenuation(srcBitmap);
1697 this->__GetClipBounds(clipRect);
1699 if (alphaConstant >= 255)
1703 _Util::LockManager srcLock(srcBitmap);
1704 _Util::LockManager dstLock(*this);
1706 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1707 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1709 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1710 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1713 if (srcBufferInfo.bitsPerPixel == 32)
1715 _Util::Rectangle<int> outRect = { 0, 0, -1, -1 };
1716 _Util::Rectangle<int> dstRect = { destRect.x, destRect.y, destRect.width, destRect.height };
1717 _Util::Rectangle<int> tgtRect = { clipRect.x, clipRect.y, clipRect.width, clipRect.height };
1719 _Util::IntersectRect(outRect, tgtRect, dstRect);
1721 // assert(destRect.width > 0 && destRect.height > 0);
1723 _Util::Bounds<int> outBounds = { outRect.x, outRect.y, outRect.x + outRect.w, outRect.y + outRect.h };
1724 _Util::Bounds<int> dstBounds = { dstRect.x, dstRect.y, dstRect.x + dstRect.w, dstRect.y + dstRect.h };
1725 _Util::Bounds<int> srcBounds =
1727 srcRect.x + (outBounds.x1 - dstBounds.x1) * srcRect.width / (dstBounds.x2 - dstBounds.x1),
1728 srcRect.y + (outBounds.y1 - dstBounds.y1) * srcRect.height / (dstBounds.y2 - dstBounds.y1),
1729 (srcRect.x + srcRect.width) + (outBounds.x2 - dstBounds.x2) * srcRect.width / (dstBounds.x2 - dstBounds.x1),
1730 (srcRect.y + srcRect.height) + (outBounds.y2 - dstBounds.y2) * srcRect.height / (dstBounds.y2 - dstBounds.y1),
1733 srcBounds.x1 = (srcBounds.x1 >= srcRect.x) ? srcBounds.x1 : srcRect.x;
1734 srcBounds.y1 = (srcBounds.y1 >= srcRect.y) ? srcBounds.y1 : srcRect.y;
1735 srcBounds.x2 = (srcBounds.x2 <= (srcRect.x + srcRect.width)) ? srcBounds.x2 : (srcRect.x + srcRect.width);
1736 srcBounds.y2 = (srcBounds.y2 <= (srcRect.y + srcRect.height)) ? srcBounds.y2 : (srcRect.y + srcRect.height);
1738 _Util::Pixmap srcImageUnclipped(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1739 _Util::Pixmap srcImage = srcImageUnclipped.GetSubBitmap(srcBounds.x1, srcBounds.y1, srcBounds.x2 - srcBounds.x1, srcBounds.y2 - srcBounds.y1);
1740 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1742 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1743 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(outRect.x, outRect.y, outRect.w, outRect.h);
1745 pass = _Pixman::ScalePixmap(dstImage, srcImage, GetDrawingQuality(), GetBlendingMode());
1750 unsigned char* pPixels = (unsigned char*) srcBufferInfo.pPixels + srcRect.y * srcBufferInfo.pitch + srcRect.x * (srcBufferInfo.bitsPerPixel / 8);
1752 _Util::Pixmap srcImage(srcRect.width, srcRect.height, srcBufferInfo.bitsPerPixel, (void*) pPixels, srcBufferInfo.pitch);
1753 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1755 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1756 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1758 pass = Tizen::Graphics::_Effect::ScaleImage(dstImage, destRect.x - clipRect.x, destRect.y - clipRect.y, destRect.width, destRect.height, srcImage, _ConvertParam<_Effect::Rop>(this->__blendOption));
1763 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1769 _Util::Pixmap tmpImage(destRect.width, destRect.height, srcBitmap.GetBitsPerPixel());
1771 // copies the source bitmap to the scaled bitmap
1773 // ykahn, 2011/10/11 patched
1775 _ApplySrcBitmapAttrib(tmpImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1777 if (tmpImage.depth == 16)
1779 if (tmpImage.enableColorKey)
1781 typedef unsigned short Pixel;
1783 Pixel colorKey = (Pixel) tmpImage.colorKey;
1784 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
1785 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
1787 while (pDest < pDestEnd)
1789 *pDest++ = colorKey;
1796 else if (tmpImage.depth == 32)
1798 typedef unsigned long Pixel;
1800 Pixel fillColor = 0;
1801 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
1802 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
1804 while (pDest < pDestEnd)
1806 *pDest++ = fillColor;
1814 _Util::LockManager srcLock(srcBitmap);
1815 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1817 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1820 unsigned char* pPixels = (unsigned char*) srcBufferInfo.pPixels + srcRect.y * srcBufferInfo.pitch + srcRect.x * (srcBufferInfo.bitsPerPixel / 8);
1822 _Util::Pixmap srcImage(srcRect.width, srcRect.height, srcBufferInfo.bitsPerPixel, (void*) pPixels, srcBufferInfo.pitch);
1823 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1825 pass = Tizen::Graphics::_Effect::ScaleImage(tmpImage, 0, 0, destRect.width, destRect.height, srcImage, Tizen::Graphics::_Effect::ROP_COPY);
1829 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1836 _Util::LockManager dstLock(*this);
1837 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1839 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1842 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1843 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1845 pass = Tizen::Graphics::_Effect::DrawImageWithAlpha(dstImage, destRect.x - clipRect.x, destRect.y - clipRect.y, tmpImage, alphaConstant);
1849 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1857 _Canvas::DrawBitmap(const Point& point, const _Bitmap& bitmap, FlipDirection dir)
1859 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1861 int alphaConstant = this->_GetAlphaAttenuation(bitmap);
1865 this->__GetClipBounds(clipRect);
1868 _Util::Pixmap* pFlippedImage = 0;
1871 _Util::LockManager srcLock(bitmap);
1872 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1874 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1876 Tizen::Graphics::_Effect::Flip flip = (dir == FLIP_DIRECTION_HORIZONTAL) ? Tizen::Graphics::_Effect::FLIP_HORIZONTAL : Tizen::Graphics::_Effect::FLIP_VERTICAL;
1879 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1881 pFlippedImage = Tizen::Graphics::_Effect::GetFlippedImage(srcImage, flip);
1885 SysTryReturnResult(NID_GRP, pFlippedImage, E_INVALID_ARG, "The source bitmap is invalid.\n");
1887 _ApplySrcBitmapAttrib(*pFlippedImage, bitmap, bitmap.__isOpaqueAllOver);
1889 std::auto_ptr<_Util::Pixmap> autoReleasingImage(pFlippedImage);
1895 _Util::LockManager dstLock(*this);
1896 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1898 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1901 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1902 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1904 pass = Tizen::Graphics::_Effect::DrawImageWithAlpha(dstImage, point.x - clipRect.x, point.y - clipRect.y, *pFlippedImage, alphaConstant);
1908 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1916 _Canvas::DrawBitmap(const Point& point, const _Bitmap& bitmap, const Point& pivot, int degree)
1918 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1922 this->__GetClipBounds(clipRect);
1924 int alphaConstant = this->_GetAlphaAttenuation(bitmap);
1926 if (alphaConstant >= 255 && !bitmap.__hasMaskingColor)
1930 _Util::LockManager srcLock(bitmap);
1931 _Util::LockManager dstLock(*this);
1933 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.");
1934 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.");
1936 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1937 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1939 if (!this->__useStableRenderer)
1941 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1942 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1944 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1945 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1947 pass = _Pixman::RotatePixmap(dstImage, srcImage, GetDrawingQuality(), point.x - clipRect.x, point.y - clipRect.y, double(degree), pivot.x, pivot.y);
1957 if (alphaConstant >= 255)
1959 return pCanvasInterface->DrawBitmap(point.x, point.y, *((IBitmapPi*)*(IBitmapPi**)bitmap.__pImpl), pivot.x, pivot.y, degree);
1964 _Util::LockManager srcLock(bitmap);
1965 _Util::LockManager dstLock(*this);
1967 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1968 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1970 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1971 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1973 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1974 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1975 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1977 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1979 // angle, xOffset, yOffset
1980 Tizen::Graphics::_Effect::RotateDesc rotateDesc = { degree, pivot.x, pivot.y };
1981 bool pass = Tizen::Graphics::_Effect::RotateImage(dstImage, point.x - clipRect.x, point.y - clipRect.y, srcImage, rotateDesc, alphaConstant);
1983 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1990 _Canvas::DrawNinePatchedBitmap(const Rectangle& rect, const _Bitmap& bitmap)
1992 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1994 // down-scales the source bitmap
1995 if (rect.width < bitmap.GetWidth() - 2 || rect.height < bitmap.GetHeight() - 2)
1998 int dstW = rect.width;
1999 int dstH = rect.height;
2000 int srcW = bitmap.GetWidth() - 2;
2001 int srcH = bitmap.GetHeight() - 2;
2003 if (dstW <= 0 || dstH <= 0)
2008 if (dstW * srcH < dstH * srcW)
2012 dstH = dstH * srcW / dstW;
2017 dstW = dstW * srcH / dstH;
2024 const int PADDING = 1;
2026 _Bitmap expandedBitmap;
2028 r = expandedBitmap.Construct(Dimension(dstW + PADDING * 2, dstH + PADDING * 2), BITMAP_PIXEL_FORMAT_ARGB8888);
2030 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2032 _Util::LockManager dstBitmap(expandedBitmap);
2035 const BufferInfo& dstBufferInfo = dstBitmap.GetBufferInfo();
2037 memset(dstBufferInfo.pPixels, 0, dstBufferInfo.pitch * dstBufferInfo.height);
2039 _Canvas expandedCanvas;
2041 r = expandedCanvas.Construct(dstBufferInfo);
2043 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2045 expandedCanvas.SetDrawingQuality(BITMAP_DRAWING_QUALITY_HIGH);
2046 expandedCanvas.SetBlendingMode(BLENDING_MODE_SRC);
2048 _Util::Pixmap dstImage(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, (void*) dstBufferInfo.pPixels, dstBufferInfo.pitch);
2050 _Util::AccumList<_Util::Pair<_Util::Rectangle<int>, _Util::Rectangle<int> > > boundsList;
2052 r = _Util::GetPatchList(boundsList, Rectangle(PADDING, PADDING, dstBufferInfo.width - PADDING * 2, dstBufferInfo.height - PADDING * 2), bitmap);
2054 SysTryReturn(NID_GRP, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] _Util::GetPatchList() failed (error = %#x)", r);
2056 _Util::AccumList<_Util::Pair<_Util::Rectangle<int>, _Util::Rectangle<int> > >::Iterator iter = boundsList.Begin();
2058 int alphaConstant = bitmap.GetAlphaConstant();
2059 const_cast<_Bitmap*>(&bitmap)->SetAlphaConstant(255);
2061 while (iter != boundsList.End())
2063 Rectangle destRect(iter->first.x, iter->first.y, iter->first.w, iter->first.h);
2064 Rectangle sourRect(iter->second.x, iter->second.y, iter->second.w, iter->second.h);
2066 expandedCanvas.DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect);
2071 const_cast<_Bitmap*>(&bitmap)->SetAlphaConstant(alphaConstant);
2072 expandedBitmap.SetAlphaConstant(alphaConstant);
2075 // not <- PADDING * 2>
2076 Tizen::Graphics::Rectangle srcRect(PADDING, PADDING, expandedBitmap.GetWidth() - PADDING, expandedBitmap.GetHeight() - PADDING);
2078 return this->DrawBitmap(rect, expandedBitmap, srcRect);
2082 Tizen::Graphics::Rectangle srcRect(1, 1, bitmap.GetWidth() - 2, bitmap.GetHeight() - 2);
2084 return this->DrawBitmap(rect, bitmap, srcRect);
2088 _Util::AccumList<_Util::Pair<_Util::Rectangle<int>, _Util::Rectangle<int> > > boundsList;
2090 result r = _Util::GetPatchList(boundsList, rect, bitmap);
2094 _Util::AccumList<_Util::Pair<_Util::Rectangle<int>, _Util::Rectangle<int> > >::Iterator iter = boundsList.Begin();
2096 while (iter != boundsList.End())
2098 Rectangle destRect(iter->first.x, iter->first.y, iter->first.w, iter->first.h);
2099 Rectangle sourRect(iter->second.x, iter->second.y, iter->second.w, iter->second.h);
2101 DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect);
2111 _Canvas::DrawEllipse(const _Util::Rectangle<int>& bounds)
2113 _Util::Rectangle<double> doubleBounds =
2121 return this->DrawEllipse(doubleBounds);
2125 _Canvas::DrawEllipse(const _Util::Rectangle<double>& bounds)
2127 if ((bounds.w <= 0.0) || (bounds.h <= 0.0))
2132 // this->__lineWidth is always greater than 0
2134 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2136 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2138 int x1 = this->GetBounds().x;
2139 int y1 = this->GetBounds().y;
2140 int x2 = x1 + this->GetBounds().width;
2141 int y2 = y1 + this->GetBounds().height;
2143 if (this->__isClipBoundsSet)
2145 x1 = (this->__clipBounds.x > x1) ? this->__clipBounds.x : x1;
2146 y1 = (this->__clipBounds.y > y1) ? this->__clipBounds.y : y1;
2147 x2 = (this->__clipBounds.x + this->__clipBounds.width < x2) ? this->__clipBounds.x + this->__clipBounds.width : x2;
2148 y2 = (this->__clipBounds.y + this->__clipBounds.height < y2) ? this->__clipBounds.y + this->__clipBounds.height : y2;
2151 bool shouldWorkaround = ((bounds.x < x1) || (bounds.y < y1) || (bounds.x + bounds.w > x2) || (bounds.y + bounds.h > y2)) && (__dashData.pattern.Size() == 0);
2153 if (!shouldWorkaround && pCairo && pCairo->pCairo)
2155 SET_CAIRO_DASH_STYLE;
2158 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2160 _Cairo::DrawEllipse(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, bounds);
2164 _Cairo::DrawEllipse(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, bounds);
2167 RESET_CAIRO_CLIPPING;
2168 RESET_CAIRO_DASH_STYLE;
2174 _CanvasEllipse ellipse;
2177 memset(&info, 0, sizeof(info));
2179 SystemPixel* pBufferAddr = null;
2180 int bufferPitch = 0;
2182 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2184 info.width = __pScratchPad->GetWidth();
2185 info.height = __pScratchPad->GetHeight();
2186 info.bitsPerPixel = 32;
2187 info.pixelPerLine = bufferPitch;
2188 info.pPixels = (void*) pBufferAddr;
2189 info.color32 = composedColor;
2190 info.isClipBoundsSet = this->__isClipBoundsSet;
2191 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2193 ellipse.SetLineWidth(this->__lineWidth.asInteger);
2195 return ellipse.DrawEllipse(int(bounds.x), int(bounds.y), int(bounds.w), int(bounds.h), info);
2200 _Canvas::DrawLine(const _Util::Point<int>& point1, const _Util::Point<int>& point2)
2202 _Util::Point<double> doublePoint1 =
2208 _Util::Point<double> doublePoint2 =
2214 return this->DrawLine(doublePoint1, doublePoint2);
2218 _Canvas::DrawLine(const _Util::Point<double>& point1, const _Util::Point<double>& point2)
2220 // this->__lineWidth is always greater than 0
2222 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2224 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2226 if (pCairo && pCairo->pCairo)
2228 _Util::Point<double> point[] =
2230 { point1.x, point1.y },
2231 { point2.x, point2.y }
2234 SET_CAIRO_DASH_STYLE;
2237 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2239 _Cairo::Drawline(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, point, 2);
2243 _Cairo::Drawline(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, point, 2);
2246 RESET_CAIRO_CLIPPING;
2247 RESET_CAIRO_DASH_STYLE;
2268 memset(&info, 0, sizeof(info));
2270 SystemPixel* pBufferAddr = null;
2271 int bufferPitch = 0;
2273 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2275 info.width = __pScratchPad->GetWidth();
2276 info.height = __pScratchPad->GetHeight();
2277 info.bitsPerPixel = 32;
2278 info.pixelPerLine = bufferPitch;
2279 info.pPixels = (void*) pBufferAddr;
2280 info.color32 = composedColor;
2281 info.isClipBoundsSet = this->__isClipBoundsSet;
2282 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2284 line.SetLineWidth(this->__lineWidth.asInteger);
2286 if (this->__lineWidth.asInteger == 1)
2288 if ((startPt.x == endPt.x) && (startPt.y == endPt.y))
2290 this->SetPixel(point1);
2295 return line.DrawLine(startPt, endPt, info);
2300 _Canvas::DrawPolygon(const _Util::Point<double>* pPoints, unsigned int pointCount)
2302 // this->__lineWidth is always greater than 0
2304 if (pointCount == 1)
2306 return this->SetPixel(pPoints[0]);
2309 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2311 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2313 if (pCairo && pCairo->pCairo)
2315 SET_CAIRO_DASH_STYLE;
2318 _Cairo::DrawPolygon(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, pPoints, pointCount);
2320 RESET_CAIRO_CLIPPING;
2321 RESET_CAIRO_DASH_STYLE;
2327 std::unique_ptr<_GpPoint[]> tempPoints(new (std::nothrow) _GpPoint[pointCount]);
2329 _GpPoint* pTempPoints = tempPoints.get();
2331 if (pTempPoints == null)
2336 for (unsigned int i = 0; i < pointCount; i++)
2338 pTempPoints[i].x = int(pPoints[i].x);
2339 pTempPoints[i].y = int(pPoints[i].y);
2345 memset(&info, 0, sizeof(info));
2347 SystemPixel* pBufferAddr = null;
2348 int bufferPitch = 0;
2350 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2352 info.width = __pScratchPad->GetWidth();
2353 info.height = __pScratchPad->GetHeight();
2354 info.bitsPerPixel = 32;
2355 info.pixelPerLine = bufferPitch;
2356 info.pPixels = (void*) pBufferAddr;
2357 info.color32 = composedColor;
2358 info.isClipBoundsSet = this->__isClipBoundsSet;
2359 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2361 line.SetLineWidth(this->__lineWidth.asInteger);
2363 result r = line.DrawPolygon(int(pointCount), pTempPoints, info);
2370 _Canvas::DrawPolyline(const _Util::Point<double>* pPoints, unsigned int pointCount)
2372 // this->__lineWidth is always greater than 0
2374 if (pointCount == 1)
2376 return this->SetPixel(pPoints[0]);
2379 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2381 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2383 if (pCairo && pCairo->pCairo)
2385 SET_CAIRO_DASH_STYLE;
2388 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2390 _Cairo::DrawPolyline(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, pPoints, pointCount);
2394 _Cairo::DrawPolyline(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, pPoints, pointCount);
2397 RESET_CAIRO_CLIPPING;
2398 RESET_CAIRO_DASH_STYLE;
2404 std::unique_ptr<_GpPoint[]> tempPoints(new (std::nothrow) _GpPoint[pointCount]);
2406 _GpPoint* pTempPoints = tempPoints.get();
2408 if (pTempPoints == null)
2413 for (unsigned int i = 0; i < pointCount; i++)
2415 pTempPoints[i].x = int(pPoints[i].x);
2416 pTempPoints[i].y = int(pPoints[i].y);
2422 memset(&info, 0, sizeof(info));
2424 SystemPixel* pBufferAddr = null;
2425 int bufferPitch = 0;
2427 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2429 info.width = __pScratchPad->GetWidth();
2430 info.height = __pScratchPad->GetHeight();
2431 info.bitsPerPixel = 32;
2432 info.pixelPerLine = bufferPitch;
2433 info.pPixels = (void*) pBufferAddr;
2434 info.color32 = composedColor;
2435 info.isClipBoundsSet = this->__isClipBoundsSet;
2436 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2438 line.SetLineWidth(this->__lineWidth.asInteger);
2440 result r = line.DrawPolyLine(int(pointCount), pTempPoints, info);
2447 _Canvas::DrawRectangle(const _Util::Rectangle<int>& rect)
2449 _Util::Rectangle<double> doubleRect =
2457 return this->DrawRectangle(doubleRect);
2461 _Canvas::DrawRectangle(const _Util::Rectangle<double>& rectangle)
2463 if ((rectangle.w <= 0.0) || (rectangle.h <= 0.0))
2468 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2470 bool tryToDrawWithCairo = (__lineWidth.applied == _Util::ScalarHolder::AS_DOUBLE || __lineWidth.asInteger > 1 || __dashData.pattern.Size() > 0);
2472 if (tryToDrawWithCairo)
2474 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2476 if (pCairo && pCairo->pCairo)
2478 SET_CAIRO_DASH_STYLE;
2481 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2483 _Cairo::DrawRectangle(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, rectangle);
2487 _Cairo::DrawRectangle(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, rectangle);
2490 RESET_CAIRO_CLIPPING;
2491 RESET_CAIRO_DASH_STYLE;
2497 // falls through legacy drawing solution
2499 int x1 = static_cast<int>(rectangle.x);
2500 int y1 = static_cast<int>(rectangle.y);
2501 int x2 = x1 + static_cast<int>(rectangle.w) - 1;
2502 int y2 = y1 + static_cast<int>(rectangle.h) - 1;
2504 if (this->__lineWidth.asInteger == 1)
2506 if (!this->__isClipBoundsSet)
2508 __pScratchPad->RegisterFillRect(_RasterOp::FnFillRectAlpha32Bit);
2510 if (x2 > x1 && y2 > y1)
2512 __pScratchPad->FillRect(x1, y1, x2 - x1, 1, composedColor);
2513 __pScratchPad->FillRect(x2, y1, 1, y2 - y1, composedColor);
2515 __pScratchPad->FillRect(x1 + 1, y2, x2 - x1, 1, composedColor);
2516 __pScratchPad->FillRect(x1, y1 + 1, 1, y2 - y1, composedColor);
2520 __pScratchPad->FillRect(x1, y1, static_cast<int>(rectangle.w), static_cast<int>(rectangle.h), composedColor);
2523 __pScratchPad->RegisterFillRect(null);
2527 _Util::Rectangle<int> clip = { this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height };
2529 if (x2 > x1 && y2 > y1)
2531 _Util::Rectangle<int> rect1 = { x1, y1, x2 - x1, 1 };
2532 _Util::Rectangle<int> rect2 = { x2, y1, 1, y2 - y1 };
2533 _Util::Rectangle<int> rect3 = { x1 + 1, y2, x2 - x1, 1 };
2534 _Util::Rectangle<int> rect4 = { x1, y1 + 1, 1, y2 - y1 };
2536 _FillRectangleWithClip(__pScratchPad, composedColor, rect1, clip);
2537 _FillRectangleWithClip(__pScratchPad, composedColor, rect2, clip);
2538 _FillRectangleWithClip(__pScratchPad, composedColor, rect3, clip);
2539 _FillRectangleWithClip(__pScratchPad, composedColor, rect4, clip);
2543 _Util::Rectangle<int> rect1 = { x1, y1, static_cast<int>(rectangle.w), static_cast<int>(rectangle.h) };
2545 _FillRectangleWithClip(__pScratchPad, composedColor, rect1, clip);
2551 else if (this->__lineWidth.asInteger > 1)
2553 _GpPoint tempPoints[4] =
2564 memset(&info, 0, sizeof(info));
2566 SystemPixel* pBufferAddr = null;
2567 int bufferPitch = 0;
2569 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2571 info.width = __pScratchPad->GetWidth();
2572 info.height = __pScratchPad->GetHeight();
2573 info.bitsPerPixel = 32;
2574 info.pixelPerLine = bufferPitch;
2575 info.pPixels = (void*) pBufferAddr;
2576 info.color32 = composedColor;
2577 info.isClipBoundsSet = this->__isClipBoundsSet;
2578 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2580 line.SetLineWidth(this->__lineWidth.asInteger);
2582 result r = line.DrawPolygon(4, tempPoints, info);
2587 // this->__lineWidth is always greater than 0
2592 _Canvas::DrawRoundRectangle(const _Util::Rectangle<int>& rect, const _Util::Dimension<int>& arcDim)
2594 _Util::Rectangle<double> doubleRect =
2602 _Util::Dimension<double> doubleArcDim =
2608 return this->DrawRoundRectangle(doubleRect, doubleArcDim);
2612 _Canvas::DrawRoundRectangle(const _Util::Rectangle<double>& rect, const _Util::Dimension<double>& arcDim)
2614 if ((rect.w <= 0.0) || (rect.h <= 0))
2619 if ((int(arcDim.w) == 0) || (int(arcDim.h) == 0))
2621 return this->DrawRectangle(rect);
2624 _Util::Dimension<double> revisedArcDim =
2626 (arcDim.w <= rect.w / 2.0) ? arcDim.w : rect.w / 2.0,
2627 (arcDim.h <= rect.h / 2.0) ? arcDim.h : rect.h / 2.0
2630 // this->__lineWidth is always greater than 0
2632 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2634 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2636 if (pCairo && pCairo->pCairo)
2638 SET_CAIRO_DASH_STYLE;
2641 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2643 _Cairo::DrawRoundRectangle(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, rect, revisedArcDim);
2647 _Cairo::DrawRoundRectangle(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, rect, revisedArcDim);
2650 RESET_CAIRO_CLIPPING;
2651 RESET_CAIRO_DASH_STYLE;
2657 _CanvasRoundRect roundRect;
2660 memset(&info, 0, sizeof(info));
2662 SystemPixel* pBufferAddr = null;
2663 int bufferPitch = 0;
2665 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2667 info.width = __pScratchPad->GetWidth();
2668 info.height = __pScratchPad->GetHeight();
2669 info.bitsPerPixel = 32;
2670 info.pixelPerLine = bufferPitch;
2671 info.pPixels = (void*) pBufferAddr;
2672 info.color32 = composedColor;
2673 info.isClipBoundsSet = this->__isClipBoundsSet;
2674 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2676 roundRect.SetLineWidth(this->__lineWidth.asInteger);
2678 return roundRect.DrawRoundRect(int(rect.x), int(rect.y), int(rect.w), int(rect.h), int(revisedArcDim.w), int(revisedArcDim.h), info);
2683 _Canvas::DrawTriangle(const _Util::Point<double>& point1, const _Util::Point<double>& point2, const _Util::Point<double>& point3)
2685 // this->__lineWidth is always greater than 0
2687 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2689 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2691 if (pCairo && pCairo->pCairo)
2693 _Util::Point<double> point[] =
2695 { point1.x, point1.y },
2696 { point2.x, point2.y },
2697 { point3.x, point3.y }
2700 SET_CAIRO_DASH_STYLE;
2703 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2705 _Cairo::DrawPolygon(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, point, 3);
2709 _Cairo::DrawPolygon(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, point, 3);
2712 RESET_CAIRO_CLIPPING;
2713 RESET_CAIRO_DASH_STYLE;
2719 _CanvasTriangle triangle;
2722 memset(&info, 0, sizeof(info));
2724 SystemPixel* pBufferAddr = null;
2725 int bufferPitch = 0;
2727 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2729 info.width = __pScratchPad->GetWidth();
2730 info.height = __pScratchPad->GetHeight();
2731 info.bitsPerPixel = 32;
2732 info.pixelPerLine = bufferPitch;
2733 info.pPixels = (void*) pBufferAddr;
2734 info.color32 = composedColor;
2735 info.isClipBoundsSet = this->__isClipBoundsSet;
2736 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2738 triangle.SetLineWidth(this->__lineWidth.asInteger);
2740 _GpPoint p1 = { int(point1.x), int(point1.y) };
2741 _GpPoint p2 = { int(point2.x), int(point2.y) };
2742 _GpPoint p3 = { int(point3.x), int(point3.y) };
2744 return triangle.DrawTriangle(p1, p2, p3, info);
2749 _Canvas::FillTriangle(const Color& color, const _Util::Point<int>& point1, const _Util::Point<int>& point2, const _Util::Point<int>& point3)
2751 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
2753 _Util::Point<double> doublePoint1 =
2759 _Util::Point<double> doublePoint2 =
2765 _Util::Point<double> doublePoint3 =
2771 return this->__FillTriangle(composedColor, doublePoint1, doublePoint2, doublePoint3);
2775 _Canvas::FillTriangle(const Color& color, const _Util::Point<double>& point1, const _Util::Point<double>& point2, const _Util::Point<double>& point3)
2777 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
2779 return this->__FillTriangle(composedColor, point1, point2, point3);
2783 _Canvas::__FillTriangle(unsigned long composedColor, const _Util::Point<double>& point1, const _Util::Point<double>& point2, const _Util::Point<double>& point3)
2785 // this->__lineWidth is always greater than 0
2787 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2789 if (pCairo && pCairo->pCairo)
2791 _Util::Point<double> point[] =
2793 { point1.x, point1.y },
2794 { point2.x, point2.y },
2795 { point3.x, point3.y }
2800 _Cairo::FillPolygon(pCairo->pCairo, composedColor, point, 3);
2802 RESET_CAIRO_CLIPPING;
2808 _CanvasTriangle triangle;
2811 memset(&info, 0, sizeof(info));
2813 SystemPixel* pBufferAddr = null;
2814 int bufferPitch = 0;
2816 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2818 info.width = __pScratchPad->GetWidth();
2819 info.height = __pScratchPad->GetHeight();
2820 info.bitsPerPixel = 32;
2821 info.pixelPerLine = bufferPitch;
2822 info.pPixels = (void*) pBufferAddr;
2823 info.color32 = composedColor;
2824 info.isClipBoundsSet = this->__isClipBoundsSet;
2825 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2827 triangle.SetLineWidth(this->__lineWidth.asInteger);
2829 return triangle.FillTriangle(int(point1.x), int(point1.y), int(point2.x), int(point2.y), int(point3.x), int(point3.y), info);
2834 _Canvas::__FillEllipse(unsigned long composedColor, const _Util::Rectangle<double>& bounds)
2836 if ((bounds.w <= 0.0) || (bounds.h <= 0.0))
2841 // this->__lineWidth is always greater than 0
2843 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2845 if (pCairo && pCairo->pCairo)
2849 _Cairo::FillEllipse(pCairo->pCairo, composedColor, bounds);
2851 RESET_CAIRO_CLIPPING;
2857 _CanvasEllipse ellipse;
2860 memset(&info, 0, sizeof(info));
2862 SystemPixel* pBufferAddr = null;
2863 int bufferPitch = 0;
2865 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2867 info.width = __pScratchPad->GetWidth();
2868 info.height = __pScratchPad->GetHeight();
2869 info.bitsPerPixel = 32;
2870 info.pixelPerLine = bufferPitch;
2871 info.pPixels = (void*) pBufferAddr;
2872 info.color32 = composedColor;
2873 info.isClipBoundsSet = this->__isClipBoundsSet;
2874 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2876 ellipse.SetLineWidth(this->__lineWidth.asInteger);
2878 return ellipse.FillElliepse(int(bounds.x), int(bounds.y), int(bounds.w), int(bounds.h), info);
2883 _Canvas::FillEllipse(const Color& color, const _Util::Rectangle<int>& bounds)
2885 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
2887 _Util::Rectangle<double> doubleBounds =
2895 return this->__FillEllipse(composedColor, doubleBounds);
2899 _Canvas::FillEllipse(const Color& color, const _Util::Rectangle<double>& bounds)
2901 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
2903 return this->__FillEllipse(composedColor, bounds);
2907 _Canvas::FillPolygon(const Color& color, const _Util::Point<double>* pPoints, unsigned int pointCount)
2910 // Implementation of this method in API versions prior to 2.0 has the following issue:
2912 // -# If there are 4 input points and conditions below is satisfied, the drawing result does not match the expected behavior. @n
2914 // "point[0].x == point[3].x && point[1].x == point[2].x && point[0].y == point[1].y && point[2].y == point[3].y"
2916 // there are 4 cases can be occurred.
2918 // [case1] (p[0]->x > p[1]->x && p[0]->y > p[3]->y)
2923 // | | <--- expected result
2925 // p1--------p0_________
2928 // | | <--- wrong result
2932 // [case2] (p[0]->x < p[1]->x && p[0]->y > p[3]->y)
2937 // | | <--- expected result
2942 // | | <--- wrong result
2946 // [case3] (p[0]->x < p[1]->x && p[0]->y < p[3]->y)
2951 // | | <--- no problem.
2956 // [case4] (p[0]->x > p[1]->x && p[0]->y < p[3]->y)
2958 // p1________p0________
2961 // | | | <--- wrong result
2963 // p2--------p3--------
2966 // -- expected result
2968 // The issue mentioned above is resolved in API version 2.0, So, check the SDK version and emulate problem before step forward furthermore.
2970 // CR approved, no. EP-47D6817268074396919211307C39CA55
2973 // this->__lineWidth is always greater than 0
2975 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
2977 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2979 if (pCairo && pCairo->pCairo)
2983 _Cairo::FillPolygon(pCairo->pCairo, composedColor, pPoints, pointCount);
2985 RESET_CAIRO_CLIPPING;
2991 _CanvasFillPolygon polygon;
2994 memset(&info, 0, sizeof(info));
2996 SystemPixel* pBufferAddr = null;
2997 int bufferPitch = 0;
2999 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
3001 info.width = __pScratchPad->GetWidth();
3002 info.height = __pScratchPad->GetHeight();
3003 info.bitsPerPixel = 32;
3004 info.pixelPerLine = bufferPitch;
3005 info.pPixels = (void*) pBufferAddr;
3006 info.color32 = composedColor;
3007 info.isClipBoundsSet = this->__isClipBoundsSet;
3008 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
3010 polygon.SetLineWidth(this->__lineWidth.asInteger);
3012 std::unique_ptr<_GpPoint[]> tempPoints(new (std::nothrow) _GpPoint[pointCount]);
3014 _GpPoint* pTempPoints = tempPoints.get();
3016 if (pTempPoints == null)
3021 for (unsigned int i = 0; i < pointCount; i++)
3023 pTempPoints[i].x = int(pPoints[i].x);
3024 pTempPoints[i].y = int(pPoints[i].y);
3027 result r = polygon.FillPolygon(int(pointCount), pTempPoints, info);
3034 _Canvas::__FillRectangle(unsigned long composedColor, const _Util::Rectangle<double>& rectangle)
3036 if ((rectangle.w <= 0.0) || (rectangle.h <= 0.0))
3041 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3043 if (pCairo && pCairo->pCairo)
3047 _Cairo::FillRectangle(pCairo->pCairo, composedColor, rectangle);
3049 RESET_CAIRO_CLIPPING;
3055 _Util::Rectangle<int> rect =
3057 static_cast<int>(rectangle.x),
3058 static_cast<int>(rectangle.y),
3059 static_cast<int>(rectangle.w),
3060 static_cast<int>(rectangle.h)
3063 if (this->__isClipBoundsSet)
3067 int x2 = x1 + rect.w;
3068 int y2 = y1 + rect.h;
3070 x1 = (x1 >= this->__clipBounds.x) ? x1 : this->__clipBounds.x;
3071 y1 = (y1 >= this->__clipBounds.y) ? y1 : this->__clipBounds.y;
3073 x2 = (x2 <= this->__clipBounds.x + this->__clipBounds.width) ? x2 : this->__clipBounds.x + this->__clipBounds.width;
3074 y2 = (y2 <= this->__clipBounds.y + this->__clipBounds.height) ? y2 : this->__clipBounds.y + this->__clipBounds.height;
3082 if (rect.w > 0 && rect.h > 0)
3084 // alpha-fill-rect() applied
3085 __pScratchPad->RegisterFillRect(_RasterOp::FnFillRectAlpha32Bit);
3086 __pScratchPad->FillRect(rect.x, rect.y, rect.w, rect.h, composedColor);
3087 __pScratchPad->RegisterFillRect(null);
3095 _Canvas::FillRectangle(const Color& color, const Rectangle& rect)
3097 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3099 return this->__FillRectangle(composedColor, _Util::Convert<Rectangle, _Util::Rectangle<double> >(rect));
3103 _Canvas::FillRectangle(const Color& color, const _Util::Rectangle<int>& rect)
3105 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3107 _Util::Rectangle<double> doubleRect =
3115 return this->__FillRectangle(composedColor, doubleRect);
3119 _Canvas::FillRectangle(const Color& color, const _Util::Rectangle<double>& rect)
3121 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3123 return this->__FillRectangle(composedColor, rect);
3127 _Canvas::FillRoundRectangle(const Color& color, const _Util::Rectangle<int>& rect, const _Util::Dimension<int>& arcDim)
3129 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3131 _Util::Rectangle<double> doubleRect =
3139 _Util::Dimension<double> doubleArcDim =
3145 return this->__FillRoundRectangle(composedColor, doubleRect, doubleArcDim);
3149 _Canvas::FillRoundRectangle(const Color& color, const _Util::Rectangle<double>& rect, const _Util::Dimension<double>& arcDim)
3151 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3153 return this->__FillRoundRectangle(composedColor, rect, arcDim);
3157 _Canvas::__FillRoundRectangle(unsigned long composedColor, const _Util::Rectangle<double>& rect, const _Util::Dimension<double>& arcDim)
3159 if ((rect.w <= 0.0) || (rect.h <= 0.0))
3164 if ((int(arcDim.w) <= 0) || (int(arcDim.h) <= 0))
3166 return this->__FillRectangle(composedColor, rect);
3169 _Util::Dimension<double> revisedArcDim =
3171 (arcDim.w <= rect.w / 2.0) ? arcDim.w : rect.w / 2.0,
3172 (arcDim.h <= rect.h / 2.0) ? arcDim.h : rect.h / 2.0
3175 // this->__lineWidth is always greater than 0
3177 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3179 if (pCairo && pCairo->pCairo)
3183 _Cairo::FillRoundRectangle(pCairo->pCairo, composedColor, rect, revisedArcDim);
3185 RESET_CAIRO_CLIPPING;
3191 _CanvasRoundRect roundRect;
3194 memset(&info, 0, sizeof(info));
3196 SystemPixel* pBufferAddr = null;
3197 int bufferPitch = 0;
3199 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
3201 info.width = __pScratchPad->GetWidth();
3202 info.height = __pScratchPad->GetHeight();
3203 info.bitsPerPixel = 32;
3204 info.pixelPerLine = bufferPitch;
3205 info.pPixels = (void*) pBufferAddr;
3206 info.color32 = composedColor;
3207 info.isClipBoundsSet = this->__isClipBoundsSet;
3208 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
3210 roundRect.SetLineWidth(this->__lineWidth.asInteger);
3212 return roundRect.FillRoundRectangle(int(rect.x), int(rect.y), int(rect.w), int(rect.h), int(revisedArcDim.w), int(revisedArcDim.h), info);
3217 _Canvas::DrawText(const Point& point, const Tizen::Base::String& text)
3219 return _Font::DrawText(*this, point, text, 0, text.GetLength());
3223 _Canvas::DrawText(const Point& point, const Tizen::Base::String& text, int startIndex, int length)
3225 return _Font::DrawText(*this, point, text, startIndex, length);
3229 _Canvas::DrawText(const Point& point, const Tizen::Base::String& text, int startIndex, int length, const Color& outlineColor)
3231 return _Font::DrawText(*this, point, text, startIndex, length, outlineColor);
3235 _Canvas::GetBounds(void) const
3237 Rectangle rect(this->__xBufferPos, this->__yBufferPos, __pScratchPad->GetWidth(), __pScratchPad->GetHeight());
3239 if (this->__windowHandle != INVALID_HANDLE)
3249 _Canvas::GetLineStyle() const
3251 SysTryReturn(NID_GRP, this && this->__pSurface, LINE_STYLE_MAX, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3253 return this->__lineStyle;
3257 _Canvas::GetLineWidth() const
3259 SysTryReturn(NID_GRP, this && this->__pSurface, -1, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3261 return this->__lineWidth.asInteger;
3265 _Canvas::SetLineStyle(LineStyle style)
3267 this->__lineStyle = style;
3273 _Canvas::SetLineWidth(int width, float widthAsFloat)
3275 SysTryReturnResult(NID_GRP, width > 0, E_OUT_OF_RANGE, "The given line width(%d) is out of range.\n", width);
3277 this->__lineWidth = width;
3278 this->__lineWidth.asDouble = double(widthAsFloat);
3284 _Canvas::SetLineWidth(float width)
3286 SysTryReturnResult(NID_GRP, width > 0.0f, E_OUT_OF_RANGE, "The given line width(%f) is out of range.\n", width);
3288 this->__lineWidth = width;
3294 _Canvas::SetDashPattern(const Tizen::Graphics::_Util::AccumList<double>& dashValueList, double offset)
3296 SysTryReturn(NID_GRP, this && this->__pSurface, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3299 Tizen::Graphics::_Util::AccumList<double> listSwap;
3300 this->__dashData.pattern.Swap(listSwap);
3302 this->__dashData.offset = 0.0;
3306 Tizen::Graphics::_Util::AccumList<double>::ConstIterator dashIterator = dashValueList.Begin();
3308 for (; dashIterator != dashValueList.End(); dashIterator++)
3310 this->__dashData.pattern.Push(*dashIterator);
3313 this->__dashData.offset = offset;
3320 _Canvas::SetDrawingQuality(BitmapDrawingQuality quality)
3322 // 'quality' is verified in _CanvasImpl::SetDrawingQuality()
3323 this->__bitmapDrawingQuality = quality;
3326 BitmapDrawingQuality
3327 _Canvas::GetDrawingQuality(void) const
3329 return this->__bitmapDrawingQuality;
3333 _Canvas::SetBlendingMode(BlendingMode blendingMode)
3335 // 'blendingMode' is verified in _CanvasImpl::SetBlendingMode()
3336 this->__blendingMode = blendingMode;
3340 _Canvas::GetBlendingMode(void) const
3342 return this->__blendingMode;
3346 _Canvas::GetPixel(const Point& point, Color& color) const
3348 Point pos(point.x, point.y);
3350 // [ykahn 2011.06.27] revise the value of 'point' if it goes out-of-range
3352 Rectangle rtCanvas = _GetBoundsRel(*this);
3354 SysTryReturnResult(NID_GRP, !rtCanvas.IsEmpty(), E_OUT_OF_RANGE, "Cannot get the bounds of the canvas.\n");
3356 if (pos.x >= rtCanvas.width && rtCanvas.width >= 1)
3358 pos.x = rtCanvas.width - 1;
3361 if (pos.y >= rtCanvas.height && rtCanvas.height >= 1)
3363 pos.y = rtCanvas.height - 1;
3368 result r = E_OUT_OF_RANGE;
3370 Rectangle rect = this->GetBounds();
3375 if ((point.x >= rect.x && point.x < rect.x + rect.width) && (point.y >= rect.y && point.y < rect.y + rect.height))
3379 (const_cast<_Canvas*>(this))->Lock(info);
3381 if (info.bitsPerPixel == 32)
3383 unsigned long* pDest32 = (unsigned long*) info.pPixels;
3384 long pitch = info.pitch / 4;
3386 color.SetRGB32(pDest32[pitch * point.y + point.x], true);
3390 else if (info.bitsPerPixel == 16)
3392 unsigned short* pDest16 = (unsigned short*) info.pPixels;
3393 long pitch = info.pitch / 2;
3395 unsigned short color16 = pDest16[pitch * point.y + point.x];
3397 unsigned long r = (color16 & 0xF800) >> 8;
3398 unsigned long g = (color16 & 0x07E0) >> 3;
3399 unsigned long b = (color16 & 0x001F) << 3;
3405 unsigned long color32 = 0xFF000000 | (r << 16) | (g << 8) | (b);
3407 color.SetRGB32(color32, true);
3412 (const_cast<_Canvas*>(this))->Unlock();
3420 _Canvas::SetPixel(const _Util::Point<int>& point)
3422 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
3424 if (!this->__isClipBoundsSet)
3426 __pScratchPad->FillRect(point.x, point.y, 1, 1, composedColor);
3430 _Util::Rectangle<int> rect = { point.x, point.y, 1, 1 };
3431 _Util::Rectangle<int> clip = { this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height };
3433 _FillRectangleWithClip(__pScratchPad, composedColor, rect, clip);
3440 _Canvas::SetPixel(const _Util::Point<double>& point)
3442 _Util::Rectangle<double> doubleRect =
3450 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
3452 this->__FillRectangle(composedColor, doubleRect);
3460 int bufferWidth = __pSurface->GetWidth();
3461 int bufferHeight = __pSurface->GetHeight();
3462 int bufferPpl = __pSurface->GetPitch();
3464 // cannot use 'if (__pSurface->GetHandle())'
3465 if (this->__windowHandle != INVALID_HANDLE)
3468 evas_object_image_pixels_dirty_set((Evas_Object*) this->__windowHandle, true);
3470 Evas_Object* pSourceObject = _GetWindowSourceObject(this->__windowHandle);
3471 evas_object_image_data_set(pSourceObject, evas_object_image_data_get(pSourceObject, EINA_TRUE));
3472 evas_object_image_data_update_add(pSourceObject, 0, 0, bufferWidth, bufferHeight);
3475 evas_object_show((Evas_Object*) this->__windowHandle);
3481 SysTryReturnResult(NID_GRP, Tizen::App::_AppInfo::IsOspCompat(), E_UNSUPPORTED_OPERATION, "This method is unsupported in Tizen.");
3483 _CanvasShowFromMemory(this->__xBufferPos, this->__yBufferPos, 0, 0, bufferWidth, bufferHeight, __pBuffer, bufferWidth, bufferHeight, 32, bufferPpl * 4);
3490 _Canvas::Show(const Rectangle& rect)
3492 if ((rect.width == 0) || (rect.height == 0))
3497 if (this->__windowHandle != INVALID_HANDLE)
3500 int x2 = rect.x + rect.width;
3502 int y2 = rect.y + rect.height;
3525 evas_object_image_pixels_dirty_set((Evas_Object*) this->__windowHandle, true);
3526 // same as evas_object_image_data_update_add((Evas_Object*)this->__windowHandle, rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2), if (width >= 3) and (height >= 3)
3527 evas_object_image_data_update_add((Evas_Object*) this->__windowHandle, x1, y1, x2 - x1, y2 - y1);
3529 Evas_Object* pSourceObject = _GetWindowSourceObject(this->__windowHandle);
3530 evas_object_image_data_set(pSourceObject, evas_object_image_data_get(pSourceObject, EINA_TRUE));
3531 evas_object_image_data_update_add(pSourceObject, x1, y1, x2 - x1, y2 - y1);
3534 evas_object_show((Evas_Object*) this->__windowHandle);
3540 SysTryReturnResult(NID_GRP, Tizen::App::_AppInfo::IsOspCompat(), E_UNSUPPORTED_OPERATION, "This method is unsupported in Tizen.");
3542 int bufferWidth = __pSurface->GetWidth();
3543 int bufferHeight = __pSurface->GetHeight();
3544 int bufferPpl = __pSurface->GetPitch();
3546 _CanvasShowFromMemory(this->__xBufferPos + rect.x, this->__yBufferPos + rect.y, rect.x, rect.y, rect.width, rect.height, __pBuffer, bufferWidth, bufferHeight, 32, bufferPpl * 4);
3553 _Canvas::SetFont(const _Font& font)
3555 SysTryReturn(NID_GRP, this && this->__pSurface, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
3558 this->__pFont = const_cast<_Font*>(&font);
3564 _Canvas::SetPriorityFont(const _Font& font)
3566 SysTryReturn(NID_GRP, this && this->__pSurface, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
3569 this->__pPriorityFont = const_cast<_Font*>(&font);
3575 _Canvas::ResetPriorityFont(void)
3577 // nullify weak reference
3578 this->__pPriorityFont = null;
3582 _Canvas::SetClipBounds(const Rectangle& rect)
3584 if (__pScratchPad == null)
3591 int x2 = x1 + rect.width;
3592 int y2 = y1 + rect.height;
3594 x1 = (x1 > 0) ? x1 : 0;
3595 y1 = (y1 > 0) ? y1 : 0;
3596 x2 = (x2 < __pScratchPad->GetWidth()) ? x2 : __pScratchPad->GetWidth();
3597 y2 = (y2 < __pScratchPad->GetHeight()) ? y2 : __pScratchPad->GetHeight();
3599 x2 = (x1 > x2) ? x1 : x2;
3600 y2 = (y1 > y2) ? y1 : y2;
3602 if (x1 == 0 && y1 == 0 && x2 == __pScratchPad->GetWidth() && y2 == __pScratchPad->GetHeight())
3604 this->__isClipBoundsSet = false;
3608 this->__isClipBoundsSet = true;
3611 this->__clipBounds.SetBounds(x1, y1, x2 - x1, y2 - y1);
3617 _Canvas::GetClipBounds(void) const
3621 SysTryReturn(NID_GRP, this && this->__pSurface, rect, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3623 this->__GetClipBounds(rect);
3629 _Canvas::Lock(BufferInfo& info, long timeout)
3631 if (__pScratchPad == null)
3636 if (_BufferInfoImpl::GetInstance(info) != null)
3638 _BufferInfoImpl::GetInstance(info)->SetHandle(_BufferInfoImpl::HANDLE_TYPE_NONE, 0);
3641 SystemPixel* pBufferAddr = null;
3642 int bufferPitch = 0;
3644 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
3646 info.width = __pScratchPad->GetWidth();
3647 info.height = __pScratchPad->GetHeight();
3648 info.pitch = bufferPitch * sizeof(_SystemPixel);
3649 info.bitsPerPixel = sizeof(_SystemPixel) * 8;
3650 info.pixelFormat = PIXEL_FORMAT_ARGB8888;
3651 info.pPixels = (void*) pBufferAddr;
3652 //info.__handle = INVALID_HANDLE;
3664 _Canvas::SetForegroundColor(const Color& fgColor)
3666 this->__fgColorNative = fgColor;
3667 this->__ComposeFgColor();
3671 _Canvas::GetForegroundColor(void)
3673 return Color(this->__fgColor);
3677 _Canvas::SetBackgroundColor(const Color& bgColor)
3679 this->__bgColorNative = bgColor;
3680 this->__ComposeBgColor();
3684 _Canvas::GetBackgroundColor(void)
3686 return Color(this->__bgColor);
3690 _Canvas::SetForegroundOpacity(int level)
3692 SysTryReturnVoidResult(NID_GRP, this && this->__pSurface, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3704 this->__fgOpacity = level;
3705 this->__ComposeFgColor();
3709 _Canvas::GetForegroundOpacity(void)
3711 SysTryReturn(NID_GRP, this && this->__pSurface, 255, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3713 return this->__fgOpacity;
3717 _Canvas::SetBackgroundOpacity(int level)
3719 SysTryReturnVoidResult(NID_GRP, this && this->__pSurface, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3731 this->__bgOpacity = level;
3732 this->__ComposeBgColor();
3736 _Canvas::GetBackgroundOpacity(void)
3738 SysTryReturn(NID_GRP, this && this->__pSurface, 255, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3740 return this->__bgOpacity;
3744 _Canvas::SetPosition(int x, int y)
3746 SysTryReturnResult(NID_GRP, this->__windowHandle == INVALID_HANDLE, E_UNSUPPORTED_OPERATION, "Window canvas does not support moving the position.\n");
3755 _Canvas::GetInstance(_CanvasImpl& canvas)
3757 return (&canvas != null) ? canvas._pNativeCanvas : null;
3761 _Canvas::GetInstance(const _CanvasImpl& canvas)
3763 return (&canvas != null) ? canvas._pNativeCanvas : null;
3767 _Canvas::_IsWindowCanvas(void) const
3769 if (!(this && this->__pSurface))
3774 return (this->__windowHandle != INVALID_HANDLE);
3778 _Canvas::_SetPosition(int x, int y)
3780 if (!(this && this->__pSurface))
3782 return E_OPERATION_FAILED;
3785 if (this->__windowHandle != INVALID_HANDLE)
3787 return E_UNSUPPORTED_OPERATION;
3790 //?? what is this function ?
3798 _Canvas::_GetAlphaAttenuation(const _Bitmap& bitmap) const
3800 // 'bitmap' and 'this' are always valid.
3802 int alphaConstant = bitmap.GetAlphaConstant();
3804 alphaConstant = (alphaConstant > 255) ? 255 : alphaConstant;
3805 alphaConstant = (alphaConstant < 0) ? 0 : alphaConstant;
3807 int fgOpacity = this->__fgOpacity;
3809 if (fgOpacity > 0 && fgOpacity < 255)
3811 fgOpacity += (fgOpacity >> 7);
3812 alphaConstant = (alphaConstant * fgOpacity) >> 8;
3815 return alphaConstant;
3819 _Canvas::_SetBlendOption(_Canvas::BlendOption blendOption)
3821 if (!(this && this->__pSurface))
3826 if (blendOption < BLEND_MIN || blendOption >= BLEND_MAX)
3831 this->__blendOption = blendOption;
3834 _Canvas::BlendOption
3835 _Canvas::_GetBlendOption(void) const
3837 if (!(this && this->__pSurface))
3840 return BLEND_ALPHABLEND;
3843 return this->__blendOption;
3847 _Canvas::__InitFgBgColorFromTheme(void)
3849 __fgColorNative = (_GetDefaultForegroundColor) ? _GetDefaultForegroundColor() : Color(0xFF000000);
3850 __bgColorNative = (_GetDefaultBackgroundColor) ? _GetDefaultBackgroundColor() : Color(0xFFFFFFFF);
3852 this->__ComposeFgColor();
3853 this->__ComposeBgColor();
3857 _Canvas::__ComposeFgColor(void)
3859 this->__fgColor = _ComposeColor(this->__fgColorNative.GetRGB32(), this->__fgOpacity);
3863 _Canvas::__ComposeBgColor(void)
3865 this->__bgColor = _ComposeColor(this->__bgColorNative.GetRGB32(), this->__bgOpacity);
3869 _Canvas::__GetClipBounds(Rectangle& rect) const
3871 if (this->__isClipBoundsSet)
3873 rect = this->__clipBounds;
3877 rect = Rectangle(0, 0, __pScratchPad->GetWidth(), __pScratchPad->GetHeight());
3882 _Canvas::__Copy(const Point& destPoint, const _Canvas& srcCanvas, const Rectangle& srcRect)
3884 const _Canvas* pSrcCanvas = &srcCanvas;
3886 Rectangle clippedSrcRect(srcRect);
3888 if (_ClipRectangle(clippedSrcRect.x, clippedSrcRect.y, clippedSrcRect.width, clippedSrcRect.height, 0, 0, pSrcCanvas->__pScratchPad->GetWidth(), pSrcCanvas->__pScratchPad->GetHeight()) == CLIP_REJECT)
3893 __pScratchPad->BitBlt(destPoint.x, destPoint.y, pSrcCanvas->__pScratchPad, clippedSrcRect.x, clippedSrcRect.y, clippedSrcRect.width, clippedSrcRect.height);
3899 _Canvas::__Copy(const Rectangle& destRect, const _Canvas& srcCanvas, const Rectangle& srcRect)
3901 const _Canvas* pSrcCanvas = &srcCanvas;
3903 Rectangle clippedSrcRect(srcRect);
3905 if (_ClipRectangle(clippedSrcRect.x, clippedSrcRect.y, clippedSrcRect.width, clippedSrcRect.height, 0, 0, pSrcCanvas->__pScratchPad->GetWidth(), pSrcCanvas->__pScratchPad->GetHeight()) == CLIP_REJECT)
3911 SystemPixel* pSrcAddr = null;
3914 pSrcCanvas->__pScratchPad->GetBuffer(pSrcAddr, srcPitch);
3915 pSrcAddr += srcPitch * clippedSrcRect.y + clippedSrcRect.x;
3917 SystemPixel* pDstAddr = null;
3920 __pScratchPad->GetBuffer(pDstAddr, dstPitch);
3922 _Util::Pixmap srcImageEx(clippedSrcRect.width, clippedSrcRect.height, sizeof(SystemPixel) * 8, pSrcAddr, srcPitch * sizeof(SystemPixel));
3923 _Util::Pixmap dstImageEx(__pScratchPad->GetWidth(), __pScratchPad->GetHeight(), sizeof(SystemPixel) * 8, pDstAddr, dstPitch * sizeof(SystemPixel));
3925 Tizen::Graphics::_Effect::ScaleImage(dstImageEx, destRect.x, destRect.y, destRect.width, destRect.height, srcImageEx);
3931 }} // Tizen::Graphics