1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _CAIROCANVAS_CANVASBITMAP_HXX 25 #define _CAIROCANVAS_CANVASBITMAP_HXX 26 27 #include <cppuhelper/compbase4.hxx> 28 29 #include <com/sun/star/lang/XServiceInfo.hpp> 30 #include <com/sun/star/rendering/XBitmapCanvas.hpp> 31 #include <com/sun/star/rendering/XIntegerBitmap.hpp> 32 #include <com/sun/star/beans/XFastPropertySet.hpp> 33 #include <comphelper/uno3.hxx> 34 35 #include <basegfx/vector/b2isize.hxx> 36 37 #include <boost/shared_ptr.hpp> 38 39 #include <canvas/base/integerbitmapbase.hxx> 40 41 #include "cairo_cairo.hxx" 42 #include "cairo_canvashelper.hxx" 43 #include "cairo_repainttarget.hxx" 44 #include "cairo_spritecanvas.hxx" 45 46 47 /* Definition of CanvasBitmap class */ 48 49 namespace cairocanvas 50 { 51 typedef ::cppu::WeakComponentImplHelper4< ::com::sun::star::rendering::XBitmapCanvas, 52 ::com::sun::star::rendering::XIntegerBitmap, 53 ::com::sun::star::lang::XServiceInfo, 54 ::com::sun::star::beans::XFastPropertySet > CanvasBitmapBase_Base; 55 class CanvasBitmapSpriteSurface_Base : 56 public ::canvas::BaseMutexHelper<CanvasBitmapBase_Base>, 57 public SurfaceProvider 58 { 59 }; 60 61 typedef ::canvas::IntegerBitmapBase< 62 CanvasBitmapSpriteSurface_Base, 63 CanvasHelper, 64 ::osl::MutexGuard, 65 ::cppu::OWeakObject > CanvasBitmap_Base; 66 67 class CanvasBitmap : public CanvasBitmap_Base, 68 public RepaintTarget 69 { 70 public: 71 /** Create a canvas bitmap for the given surface 72 73 @param rSize 74 Size of the bitmap 75 76 @param rDevice 77 Reference device, with which bitmap should be compatible 78 */ 79 CanvasBitmap( const ::basegfx::B2ISize& rSize, 80 const SurfaceProviderRef& rDevice, 81 ::com::sun::star::rendering::XGraphicDevice* pDevice, 82 bool bHasAlpha ); 83 84 /// Dispose all internal references 85 virtual void SAL_CALL disposing(); 86 87 // Forwarding the XComponent implementation to the 88 // cppu::ImplHelper templated base 89 // Classname Base doing refcounting Base implementing the XComponent interface 90 // | | | 91 // V V V 92 DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS( CanvasBitmap, CanvasBitmapBase_Base, ::cppu::WeakComponentImplHelperBase ); 93 94 // XServiceInfo 95 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); 96 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); 97 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); 98 99 // SurfaceProvider 100 virtual SurfaceSharedPtr getSurface(); 101 virtual SurfaceSharedPtr createSurface( const ::basegfx::B2ISize& rSize, Content aContent = CAIRO_CONTENT_COLOR_ALPHA ); 102 virtual SurfaceSharedPtr createSurface( ::Bitmap& rBitmap ); 103 virtual SurfaceSharedPtr changeSurface( bool bHasAlpha, bool bCopyContent ); 104 virtual OutputDevice* getOutputDevice(); 105 106 // RepaintTarget 107 virtual bool repaint( const SurfaceSharedPtr& pSurface, 108 const ::com::sun::star::rendering::ViewState& viewState, 109 const ::com::sun::star::rendering::RenderState& renderState ); 110 111 // XFastPropertySet 112 // used to retrieve BitmapEx pointer or X Pixmap handles for this bitmap 113 // handle values have these meanings: 114 // 0 ... get pointer to BitmapEx 115 // 1 ... get X pixmap handle to rgb content 116 // 2 ... get X pitmap handle to alpha mask 117 // returned any contains either BitmapEx pointer or array of three Any value 118 // 1st a bool value: true - free the pixmap after used by XFreePixmap, false do nothing, the pixmap is used internally in the canvas 119 // 2nd the pixmap handle 120 // 3rd the pixmap depth 121 virtual ::com::sun::star::uno::Any SAL_CALL getFastPropertyValue(sal_Int32 nHandle) throw (::com::sun::star::uno::RuntimeException); setFastPropertyValue(sal_Int32,const::com::sun::star::uno::Any &)122 virtual void SAL_CALL setFastPropertyValue(sal_Int32, const ::com::sun::star::uno::Any&) throw (::com::sun::star::uno::RuntimeException) {} 123 124 private: 125 SurfaceProviderRef mpSurfaceProvider; 126 ::cairo::SurfaceSharedPtr mpBufferSurface; 127 ::cairo::CairoSharedPtr mpBufferCairo; 128 129 const ::basegfx::B2ISize maSize; 130 const bool mbHasAlpha; 131 }; 132 } 133 134 #endif /* _CAIROCANVAS_CANVASBITMAP_HXX */ 135