add patch
[framework/osp/uifw.git] / src / graphics / FGrp_Canvas.cpp
index 251af9e..fd92850 100755 (executable)
@@ -1573,13 +1573,133 @@ _Canvas::DrawBitmap(const _Util::Point<int>& point, const _Bitmap& bitmap)
 {
        SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
 
-       _Util::Point<double> pointD =
+       int alphaConstant = this->_GetAlphaAttenuation(bitmap);
+
        {
-               double(point.x),
-               double(point.y)
-       };
+               Rectangle clipRect;
+               this->__GetClipBounds(clipRect);
+
+               bool pass = false;
+
+               {
+                       _Util::LockManagerFast srcLock(bitmap);
+                       _Util::LockManagerFast dstLock(*this);
+
+                       SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
+                       SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
+
+                       const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
+                       const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
+
+                       {
+                               _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
+                               _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
+
+                               _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
+                               _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x,clipRect.y, clipRect.width, clipRect.height);
+
+                               if (srcBufferInfo.pixelFormat == PIXEL_FORMAT_RGB565 && srcImage.enableColorKey == 0 && dstBufferInfo.pixelFormat == PIXEL_FORMAT_ARGB8888 && !this->__isClipBoundsSet)
+                               {
+                                       pixman_image_t* pPixmanSrc = pixman_image_create_bits(PIXMAN_r5g6b5, srcBufferInfo.width, srcBufferInfo.height, (uint32_t*)srcBufferInfo.pPixels, srcBufferInfo.pitch);
+                                       pixman_image_t* pPixmanDst = pixman_image_create_bits(PIXMAN_a8r8g8b8, dstBufferInfo.width, dstBufferInfo.height, (uint32_t*)dstBufferInfo.pPixels, dstBufferInfo.pitch);
+
+                                       if (pPixmanSrc && pPixmanDst)
+                                       {
+                                               pixman_image_composite32(PIXMAN_OP_SRC, pPixmanSrc,NULL, pPixmanDst, 0, 0, 0, 0, point.x, point.y, srcBufferInfo.width, srcBufferInfo.height);
+                                               pass = true;
+                                       }
+
+                                       if (pPixmanDst)
+                                       {
+                                               pixman_image_unref(pPixmanDst);
+                                       }
+
+                                       if (pPixmanSrc)
+                                       {
+                                               pixman_image_unref(pPixmanSrc);
+                                       }
+                               }
+                       }
+
+                       {
+                               Color color;
 
-       return this->DrawBitmap(pointD, bitmap);
+                               bool isPixmanSupported = !(bitmap.__isOpaqueAllOver && GetCompositeMode() == COMPOSITE_MODE_SRC_OVER) && (!this->__useStableRenderer || bitmap.__isPremultiplied);
+
+                               if (isPixmanSupported)
+                               {
+                                       Color color;
+
+                                       isPixmanSupported = !((bitmap.GetBitsPerPixel() == 16) && (bitmap.GetMaskingColor(color) == E_SUCCESS));
+                               }
+
+                               if (isPixmanSupported)
+                               {
+                                       _Util::Rectangle<int> outRect = { 0, 0, -1, -1 };
+                                       _Util::Rectangle<int> dstRect = { point.x, point.y, srcBufferInfo.width, srcBufferInfo.height };
+                                       _Util::Rectangle<int> tgtRect = { clipRect.x, clipRect.y, clipRect.width, clipRect.height };
+
+                                       if (_Util::IntersectRect(outRect, tgtRect, dstRect))
+                                       {
+                                               _Util::Bounds<int> outBounds = { outRect.x, outRect.y, outRect.x + outRect.w, outRect.y + outRect.h };
+                                               _Util::Bounds<int> dstBounds = { dstRect.x, dstRect.y, dstRect.x + dstRect.w, dstRect.y + dstRect.h };
+                                               _Util::Bounds<int> srcBounds =
+
+                                               {
+                                                       (outBounds.x1 - dstBounds.x1),
+                                                       (outBounds.y1 - dstBounds.y1),
+                                                       srcBufferInfo.width + (outBounds.x2 - dstBounds.x2),
+                                                       srcBufferInfo.height + (outBounds.y2 - dstBounds.y2),
+                                               };
+
+                                               srcBounds.x1 = (srcBounds.x1 >= 0) ? srcBounds.x1 :0;
+                                               srcBounds.y1 = (srcBounds.y1 >= 0) ? srcBounds.y1 :0;
+                                               srcBounds.x2 = (srcBounds.x2 <= srcBufferInfo.width) ? srcBounds.x2 : srcBufferInfo.width;
+                                               srcBounds.y2 = (srcBounds.y2 <= srcBufferInfo.height) ? srcBounds.y2 : srcBufferInfo.height;
+
+                                               _Util::Pixmap srcImageUnclipped(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
+                                               _Util::Pixmap srcImage = srcImageUnclipped.GetSubBitmap(srcBounds.x1, srcBounds.y1, srcBounds.x2 - srcBounds.x1, srcBounds.y2 - srcBounds.y1);
+                                               _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
+
+                                               _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
+                                               _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(outRect.x, outRect.y, outRect.w, outRect.h);
+
+                                               pixman_transform_t transform;
+                                               pixman_transform_init_identity(&transform);
+
+                                               if (alphaConstant < 255)
+                                               {
+                                                       std::unique_ptr<_Util::Pixmap> modifiedSrcImage(srcImage.GetAlphaAttenuatedPixmap(alphaConstant));
+
+                                                       if (modifiedSrcImage != null)
+                                                       {
+                                                               pass = _Pixman::CopyPixmap(dstImage, *modifiedSrcImage.get(), GetDrawingQuality(), GetCompositeMode());
+                                                       }
+                                               }
+
+                                               if (!pass)
+                                               {
+                                                       pass = _Pixman::CopyPixmap(dstImage, srcImage, GetDrawingQuality(), GetCompositeMode());
+                                               }
+                                       }
+                               }
+
+                               if (!pass)
+                               {
+                                       _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
+                                       _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
+
+                                       _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
+                                       _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
+                                       pass = Tizen::Graphics::_Effect::DrawImageWithAlpha(dstImage, point.x - clipRect.x, point.y - clipRect.y, srcImage, alphaConstant);
+                               }
+                       }
+               }
+
+               SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
+
+               return E_SUCCESS;
+       }
 }
 
 result
@@ -4288,7 +4408,7 @@ _Canvas::__Copy(const Rectangle& destRect, const _Canvas& srcCanvas, const Recta
                _Util::Pixmap srcImageEx(clippedSrcRect.width, clippedSrcRect.height, sizeof(SystemPixel) * 8, pSrcAddr, srcPitch * sizeof(SystemPixel));
                _Util::Pixmap dstImageEx(__pScratchPad->GetWidth(), __pScratchPad->GetHeight(), sizeof(SystemPixel) * 8, pDstAddr, dstPitch * sizeof(SystemPixel));
 
-               Tizen::Graphics::_Effect::ScaleImage(dstImageEx, destRect.x, destRect.y, destRect.width, destRect.height, srcImageEx);
+               Tizen::Graphics::_Effect::ScaleImage(dstImageEx, destRect.x, destRect.y, destRect.width, destRect.height, srcImageEx, _Effect::ROP_COPY);
        }
 
        return E_SUCCESS;