1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _CAIROCANVAS_CANVASBITMAP_HXX 29 #define _CAIROCANVAS_CANVASBITMAP_HXX 30 31 #include <cppuhelper/compbase4.hxx> 32 33 #include <com/sun/star/lang/XServiceInfo.hpp> 34 #include <com/sun/star/rendering/XBitmapCanvas.hpp> 35 #include <com/sun/star/rendering/XIntegerBitmap.hpp> 36 #include <com/sun/star/beans/XFastPropertySet.hpp> 37 #include <comphelper/uno3.hxx> 38 39 #include <basegfx/vector/b2isize.hxx> 40 41 #include <boost/shared_ptr.hpp> 42 43 #include <canvas/base/integerbitmapbase.hxx> 44 45 #include "cairo_cairo.hxx" 46 #include "cairo_canvashelper.hxx" 47 #include "cairo_repainttarget.hxx" 48 #include "cairo_spritecanvas.hxx" 49 50 51 /* Definition of CanvasBitmap class */ 52 53 namespace cairocanvas 54 { 55 typedef ::cppu::WeakComponentImplHelper4< ::com::sun::star::rendering::XBitmapCanvas, 56 ::com::sun::star::rendering::XIntegerBitmap, 57 ::com::sun::star::lang::XServiceInfo, 58 ::com::sun::star::beans::XFastPropertySet > CanvasBitmapBase_Base; 59 class CanvasBitmapSpriteSurface_Base : 60 public ::canvas::BaseMutexHelper<CanvasBitmapBase_Base>, 61 public SurfaceProvider 62 { 63 }; 64 65 typedef ::canvas::IntegerBitmapBase< 66 CanvasBitmapSpriteSurface_Base, 67 CanvasHelper, 68 ::osl::MutexGuard, 69 ::cppu::OWeakObject > CanvasBitmap_Base; 70 71 class CanvasBitmap : public CanvasBitmap_Base, 72 public RepaintTarget 73 { 74 public: 75 /** Create a canvas bitmap for the given surface 76 77 @param rSize 78 Size of the bitmap 79 80 @param rDevice 81 Reference device, with which bitmap should be compatible 82 */ 83 CanvasBitmap( const ::basegfx::B2ISize& rSize, 84 const SurfaceProviderRef& rDevice, 85 ::com::sun::star::rendering::XGraphicDevice* pDevice, 86 bool bHasAlpha ); 87 88 /// Dispose all internal references 89 virtual void SAL_CALL disposing(); 90 91 // Forwarding the XComponent implementation to the 92 // cppu::ImplHelper templated base 93 // Classname Base doing refcounting Base implementing the XComponent interface 94 // | | | 95 // V V V 96 DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS( CanvasBitmap, CanvasBitmapBase_Base, ::cppu::WeakComponentImplHelperBase ); 97 98 // XServiceInfo 99 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); 100 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); 101 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); 102 103 // SurfaceProvider 104 virtual SurfaceSharedPtr getSurface(); 105 virtual SurfaceSharedPtr createSurface( const ::basegfx::B2ISize& rSize, Content aContent = CAIRO_CONTENT_COLOR_ALPHA ); 106 virtual SurfaceSharedPtr createSurface( ::Bitmap& rBitmap ); 107 virtual SurfaceSharedPtr changeSurface( bool bHasAlpha, bool bCopyContent ); 108 virtual OutputDevice* getOutputDevice(); 109 110 // RepaintTarget 111 virtual bool repaint( const SurfaceSharedPtr& pSurface, 112 const ::com::sun::star::rendering::ViewState& viewState, 113 const ::com::sun::star::rendering::RenderState& renderState ); 114 115 // XFastPropertySet 116 // used to retrieve BitmapEx pointer or X Pixmap handles for this bitmap 117 // handle values have these meanings: 118 // 0 ... get pointer to BitmapEx 119 // 1 ... get X pixmap handle to rgb content 120 // 2 ... get X pitmap handle to alpha mask 121 // returned any contains either BitmapEx pointer or array of three Any value 122 // 1st a bool value: true - free the pixmap after used by XFreePixmap, false do nothing, the pixmap is used internally in the canvas 123 // 2nd the pixmap handle 124 // 3rd the pixmap depth 125 virtual ::com::sun::star::uno::Any SAL_CALL getFastPropertyValue(sal_Int32 nHandle) throw (::com::sun::star::uno::RuntimeException); 126 virtual void SAL_CALL setFastPropertyValue(sal_Int32, const ::com::sun::star::uno::Any&) throw (::com::sun::star::uno::RuntimeException) {} 127 128 private: 129 SurfaceProviderRef mpSurfaceProvider; 130 ::cairo::SurfaceSharedPtr mpBufferSurface; 131 ::cairo::CairoSharedPtr mpBufferCairo; 132 133 const ::basegfx::B2ISize maSize; 134 const bool mbHasAlpha; 135 }; 136 } 137 138 #endif /* _CAIROCANVAS_CANVASBITMAP_HXX */ 139