Add DrawBitmap with flip using Pixman
authorhoonik.lee <hoonik.lee@samsung.com>
Mon, 1 Apr 2013 05:11:59 +0000 (14:11 +0900)
committerhoonik.lee <hoonik.lee@samsung.com>
Mon, 1 Apr 2013 12:05:17 +0000 (21:05 +0900)
Change-Id: I2d3f59159364119006d11b907cdd6f7448265c29
Signed-off-by: hoonik.lee <hoonik.lee@samsung.com>
src/graphics/FGrp_Canvas.cpp
src/graphics/FGrp_CanvasPixman.cpp
src/graphics/FGrp_CanvasPixman.h

index e9f7bd2..7e9546f 100755 (executable)
@@ -1965,6 +1965,22 @@ _Canvas::DrawBitmap(const Point& point, const _Bitmap& bitmap, FlipDirection dir
                {
                        bool pass = false;
 
+                       if (!this->__useStableRenderer && alphaConstant >= 255 && !bitmap.__hasMaskingColor)
+                       {
+                               _Util::LockManager dstLock(*this);
+                               SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.");
+
+                               const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
+
+                               {
+                                       _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(!pass)
                        {
                                _Util::LockManager dstLock(*this);
                                SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
index 4f5fec8..ca2095d 100644 (file)
@@ -275,6 +275,75 @@ 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<pixman_image_t> 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<Tizen::Graphics::_Util::Pixmap> premultipliedSrcImage;
+               Tizen::Graphics::_Util::AutoDeletor<pixman_image_t> pPixmanSrc;
+               Tizen::Graphics::_Util::AutoDeletor<pixman_image_t> 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_SRC)
+                       {
+                               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)
+               {
+                       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)
@@ -332,6 +401,19 @@ 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
index cb4f141..d84163f 100644 (file)
@@ -49,6 +49,9 @@ 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, int xDest, int yDest, double degree, int xPivot, int 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