From: hoonik.lee Date: Tue, 9 Apr 2013 13:13:26 +0000 (+0900) Subject: Modify DrawBitmap with flip For AlphaConstant and CompositeMode X-Git-Tag: submit/tizen_2.1/20130514.054411~146^2^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fc57ab82f1a175b50be5bc18130f0c80f37ed16b;p=platform%2Fframework%2Fnative%2Fuifw.git Modify DrawBitmap with flip For AlphaConstant and CompositeMode Change-Id: Id15a2bd87187f99ba7c421bd3bfc5325d486a3fe Signed-off-by: hoonik.lee --- diff --git a/src/graphics/FGrp_Canvas.cpp b/src/graphics/FGrp_Canvas.cpp index 2bfebd8..3608461 100755 --- a/src/graphics/FGrp_Canvas.cpp +++ b/src/graphics/FGrp_Canvas.cpp @@ -1954,7 +1954,7 @@ _Canvas::DrawBitmapForNinePatchedBitmap(const Rectangle& destRect, const _Bitmap } result -_Canvas::DrawBitmap(const Point& point, const _Bitmap& bitmap, FlipDirection dir) +_Canvas::DrawBitmap(const _Util::Point& pointD, const _Bitmap& bitmap, FlipDirection dir) { SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n"); @@ -1965,6 +1965,12 @@ _Canvas::DrawBitmap(const Point& point, const _Bitmap& bitmap, FlipDirection dir this->__GetClipBounds(clipRect); { + _Util::Point point = + { + _DoubleToIntForPos(pointD.x), + _DoubleToIntForPos(pointD.y) + }; + _Util::Pixmap* pFlippedImage = 0; { @@ -1991,7 +1997,7 @@ _Canvas::DrawBitmap(const Point& point, const _Bitmap& bitmap, FlipDirection dir { bool pass = false; - if (!this->__useStableRenderer && alphaConstant >= 255 && !bitmap.__hasMaskingColor) + if (!this->__useStableRenderer && pFlippedImage->depth == 32) { _Util::LockManager dstLock(*this); SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked."); @@ -2002,7 +2008,20 @@ _Canvas::DrawBitmap(const Point& point, const _Bitmap& bitmap, FlipDirection dir _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 = _Pixman::FlipPixmap(dstImage, *pFlippedImage, GetDrawingQuality(), GetCompositeMode(), point.x - clipRect.x, point.y - clipRect.y); + if (alphaConstant < 255) + { + std::unique_ptr<_Util::Pixmap> modifiedSrcImage(pFlippedImage->GetAlphaAttenuatedPixmap(alphaConstant)); + + if (modifiedSrcImage != null) + { + pass = _Pixman::CopyPixmap(dstImage, *modifiedSrcImage, GetDrawingQuality(), GetCompositeMode(), pointD.x - clipRect.x, pointD.y - clipRect.y); + } + } + + if (!pass) + { + pass = _Pixman::CopyPixmap(dstImage, *pFlippedImage, GetDrawingQuality(), GetCompositeMode(), pointD.x - clipRect.x, pointD.y - clipRect.y); + } } } diff --git a/src/graphics/FGrp_Canvas.h b/src/graphics/FGrp_Canvas.h index b94c628..712ebc2 100644 --- a/src/graphics/FGrp_Canvas.h +++ b/src/graphics/FGrp_Canvas.h @@ -156,7 +156,7 @@ public: result DrawBitmap(const _Util::Rectangle& rect, const _Bitmap& bitmap); result DrawBitmap(const _Util::Rectangle& destRect, const _Bitmap& srcBitmap, const _Util::Rectangle& srcRect); result DrawBitmapForNinePatchedBitmap(const Rectangle& destRect, const _Bitmap& srcBitmap, const Rectangle& srcRect, bool copyOnly = false); - result DrawBitmap(const Point& point, const _Bitmap& bitmap, FlipDirection dir); + result DrawBitmap(const _Util::Point& point, const _Bitmap& bitmap, FlipDirection dir); result DrawBitmap(const _Util::Point& point, const _Bitmap& bitmap, const _Util::Point& pivot, double degree); result DrawNinePatchedBitmap(const Rectangle& rect, const _Bitmap& bitmap); result DrawNineTiledBitmap(const Rectangle& rect, const _Bitmap& bitmap); diff --git a/src/graphics/FGrp_CanvasImpl.cpp b/src/graphics/FGrp_CanvasImpl.cpp index 3fcef9a..e9420a2 100755 --- a/src/graphics/FGrp_CanvasImpl.cpp +++ b/src/graphics/FGrp_CanvasImpl.cpp @@ -1245,43 +1245,7 @@ _CanvasImpl::DrawBitmap(const Point& vcPoint, const _BitmapImpl& bitmap, FlipDir { SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet."); - SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid."); - - switch (dir) - { - case FLIP_DIRECTION_HORIZONTAL: - case FLIP_DIRECTION_VERTICAL: - break; - default: - SysTryReturnResult(NID_GRP, 0, E_INVALID_ARG, "FlipStyle(%d) is invalid.", dir); - break; - } - - EXTRACT_BITMAPEX(pBitmapEx, bitmap); - - if (_ResUtil::NeedToConvertCoord()) - { - Tizen::Graphics::Dimension virSize; - Tizen::Graphics::Dimension phySize; - bool lazyScaling = Tizen::Graphics::_IsLazyScalingBitmap(bitmap, virSize, phySize); - - Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint); - - if (lazyScaling) - { - EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap); - - return this->_pNativeCanvas->DrawBitmap(pcPoint, *pScaledBitmapEx, dir); - } - else - { - return this->_pNativeCanvas->DrawBitmap(pcPoint, *pBitmapEx, dir); - } - } - else - { - return this->_pNativeCanvas->DrawBitmap(vcPoint, *pBitmapEx, dir); - } + return this->DrawBitmap(FloatPoint(float(vcPoint.x), float(vcPoint.y)), bitmap, dir); } result @@ -1311,24 +1275,24 @@ _CanvasImpl::DrawBitmap(const FloatPoint& vcPointF, const _BitmapImpl& bitmap, F FloatPoint pcPointF = _ResUtil::ConvertToPhyCoord(vcPointF); - Point pcPoint(_FloatToIntForPos(pcPointF.x), _FloatToIntForPos(pcPointF.y)); + _Util::Point pcPointD = _Util::Convert >(pcPointF); if (lazyScaling) { EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap); - return this->_pNativeCanvas->DrawBitmap(pcPoint, *pScaledBitmapEx, dir); + return this->_pNativeCanvas->DrawBitmap(pcPointD, *pScaledBitmapEx, dir); } else { - return this->_pNativeCanvas->DrawBitmap(pcPoint, *pBitmapEx, dir); + return this->_pNativeCanvas->DrawBitmap(pcPointD, *pBitmapEx, dir); } } else { - Point vcPoint(_FloatToIntForPos(vcPointF.x), _FloatToIntForPos(vcPointF.y)); + _Util::Point vcPointD = _Util::Convert >(vcPointF); - return this->_pNativeCanvas->DrawBitmap(vcPoint, *pBitmapEx, dir); + return this->_pNativeCanvas->DrawBitmap(vcPointD, *pBitmapEx, dir); } } diff --git a/src/graphics/FGrp_CanvasPixman.cpp b/src/graphics/FGrp_CanvasPixman.cpp index c53f543..8612dca 100644 --- a/src/graphics/FGrp_CanvasPixman.cpp +++ b/src/graphics/FGrp_CanvasPixman.cpp @@ -308,80 +308,6 @@ bool CompositePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Grap return false; } -bool ClipPixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, pixman_op_t rop, pixman_filter_t filter, pixman_repeat_t repeatMethod, int xDest, int yDest) -{ - Tizen::Graphics::_Util::AutoDeletor pPixmanDst; - - switch (dstImage.depth) - { - case 16: - pPixmanDst.Bind(pixman_image_create_bits(PIXMAN_r5g6b5, dstImage.width, dstImage.height, (uint32_t*)dstImage.pBitmap, dstImage.bytesPerLine)); - break; - case 32: - pPixmanDst.Bind(pixman_image_create_bits(PIXMAN_a8r8g8b8, dstImage.width, dstImage.height, (uint32_t*)dstImage.pBitmap, dstImage.bytesPerLine)); - break; - default: - return false; - } - - if (pPixmanDst) - { - std::auto_ptr premultipliedSrcImage; - Tizen::Graphics::_Util::AutoDeletor pPixmanSrc; - Tizen::Graphics::_Util::AutoDeletor pPixmanMsk; - - switch (srcImage.depth) - { - case 16: - pPixmanSrc.Bind(pixman_image_create_bits(PIXMAN_r5g6b5, srcImage.width, srcImage.height, (uint32_t*)srcImage.pBitmap, srcImage.bytesPerLine)); - break; - case 32: - if (srcImage.isPremultiplied || rop == PIXMAN_OP_COPY) - { - pPixmanSrc.Bind(pixman_image_create_bits(PIXMAN_a8r8g8b8, srcImage.width, srcImage.height, (uint32_t*)srcImage.pBitmap, srcImage.bytesPerLine)); - } - else - { - premultipliedSrcImage.reset(srcImage.GetPremultipliedPixmap()); - - if (premultipliedSrcImage.get()) - { - pPixmanSrc.Bind(pixman_image_create_bits(PIXMAN_a8r8g8b8, premultipliedSrcImage->width, premultipliedSrcImage->height, (uint32_t*)premultipliedSrcImage->pBitmap, premultipliedSrcImage->bytesPerLine)); - } - else - { - // slow but it does not create additional buffer - pPixmanSrc.Bind(pixman_image_create_bits(PIXMAN_x8r8g8b8, srcImage.width, srcImage.height, (uint32_t*)srcImage.pBitmap, srcImage.bytesPerLine)); - pPixmanMsk.Bind(pixman_image_create_bits(PIXMAN_a8r8g8b8, srcImage.width, srcImage.height, (uint32_t*)srcImage.pBitmap, srcImage.bytesPerLine)); - - if (pPixmanMsk == null) - { - return false; - } - } - } - break; - default: - return false; - } - - if (pPixmanSrc) - { - if (rop == PIXMAN_OP_COPY) - { - rop = PIXMAN_OP_SRC; - } - - pixman_image_set_repeat(pPixmanSrc, PIXMAN_REPEAT_NORMAL); - pixman_image_composite32(rop, pPixmanSrc, pPixmanMsk, pPixmanDst, 0, 0, 0, 0, xDest, yDest, srcImage.width, srcImage.height); - - return true; - } - } - - return false; -} - bool ResizePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, Tizen::Graphics::BitmapScalingQuality scalingQuality) { if (dstImage.width <= 0 || dstImage.height <= 0) @@ -484,19 +410,6 @@ bool RotatePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphic return CompositePixmap(dstImage, srcImage, rop, filter, transform, PIXMAN_REPEAT_NONE); } -bool FlipPixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, Tizen::Graphics::BitmapDrawingQuality drawingQuality, Tizen::Graphics::CompositeMode compositeMode, int xDest, int yDest) -{ - if (dstImage.width <= 0 || dstImage.height <= 0) - { - return true; - } - - pixman_op_t rop = Tizen::Graphics::_Pixman::GetRop(compositeMode); - pixman_filter_t filter = Tizen::Graphics::_Pixman::GetFilter(drawingQuality); - - return ClipPixmap(dstImage, srcImage, rop, filter, PIXMAN_REPEAT_REFLECT, xDest, yDest); -} - } // _Pixman }} // Tizen::Graphics diff --git a/src/graphics/FGrp_CanvasPixman.h b/src/graphics/FGrp_CanvasPixman.h index 1bf1dbc..b1ab7a7 100644 --- a/src/graphics/FGrp_CanvasPixman.h +++ b/src/graphics/FGrp_CanvasPixman.h @@ -59,9 +59,6 @@ ResizePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_U bool RotatePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, Tizen::Graphics::BitmapDrawingQuality drawingQuality, Tizen::Graphics::CompositeMode compositeMode, double xDest, double yDest, double degree, double xPivot, double yPivot); -bool -FlipPixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, Tizen::Graphics::BitmapDrawingQuality drawingQuality, Tizen::Graphics::CompositeMode compositeMode, int xDest, int yDest); - } // Tizen::Graphics::_Pixman }} // Tizen::Graphics