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 INCLUDED_CANVAS_INTEGERBITMAPBASE_HXX 25 #define INCLUDED_CANVAS_INTEGERBITMAPBASE_HXX 26 27 #include <com/sun/star/rendering/XIntegerBitmap.hpp> 28 #include <canvas/base/bitmapcanvasbase.hxx> 29 30 31 namespace canvas 32 { 33 /** Helper template to handle XIntegerBitmap method forwarding to 34 BitmapCanvasHelper 35 36 Use this helper to handle the XIntegerBitmap part of your 37 implementation. 38 39 @tpl Base 40 Base class to use, most probably one of the 41 WeakComponentImplHelperN templates with the appropriate 42 interfaces. At least XIntegerBitmap should be among them (why 43 else would you use this template, then?). Base class must have 44 an Base( const Mutex& ) constructor (like the 45 WeakComponentImplHelperN templates have). 46 47 @tpl CanvasHelper 48 Canvas helper implementation for the backend in question 49 50 @tpl Mutex 51 Lock strategy to use. Defaults to using the 52 OBaseMutex-provided lock. Everytime one of the methods is 53 entered, an object of type Mutex is created with m_aMutex as 54 the sole parameter, and destroyed again when the method scope 55 is left. 56 57 @tpl UnambiguousBase 58 Optional unambiguous base class for XInterface of Base. It's 59 sometimes necessary to specify this parameter, e.g. if Base 60 derives from multiple UNO interface (were each provides its 61 own version of XInterface, making the conversion ambiguous) 62 63 @see CanvasBase for further contractual requirements towards 64 the CanvasHelper type, and some examples. 65 */ 66 template< class Base, 67 class CanvasHelper, 68 class Mutex=::osl::MutexGuard, 69 class UnambiguousBase=::com::sun::star::uno::XInterface > class IntegerBitmapBase : 70 public BitmapCanvasBase< Base, CanvasHelper, Mutex, UnambiguousBase > 71 { 72 public: 73 typedef BitmapCanvasBase< Base, CanvasHelper, Mutex, UnambiguousBase > BaseType; 74 75 // XIntegerBitmap getData(::com::sun::star::rendering::IntegerBitmapLayout & bitmapLayout,const::com::sun::star::geometry::IntegerRectangle2D & rect)76 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getData( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout, 77 const ::com::sun::star::geometry::IntegerRectangle2D& rect ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::rendering::VolatileContentDestroyedException, ::com::sun::star::uno::RuntimeException) 78 { 79 tools::verifyArgs(rect, 80 BOOST_CURRENT_FUNCTION, 81 static_cast< typename BaseType::UnambiguousBaseType* >(this)); 82 tools::verifyIndexRange(rect, BaseType::getSize() ); 83 84 typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 85 86 return BaseType::maCanvasHelper.getData( bitmapLayout, 87 rect ); 88 } 89 setData(const::com::sun::star::uno::Sequence<sal_Int8> & data,const::com::sun::star::rendering::IntegerBitmapLayout & bitmapLayout,const::com::sun::star::geometry::IntegerRectangle2D & rect)90 virtual void SAL_CALL setData( const ::com::sun::star::uno::Sequence< sal_Int8 >& data, 91 const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout, 92 const ::com::sun::star::geometry::IntegerRectangle2D& rect ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) 93 { 94 tools::verifyArgs(bitmapLayout, rect, 95 BOOST_CURRENT_FUNCTION, 96 static_cast< typename BaseType::UnambiguousBaseType* >(this)); 97 tools::verifyIndexRange(rect, BaseType::getSize() ); 98 99 typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 100 101 BaseType::mbSurfaceDirty = true; 102 BaseType::maCanvasHelper.modifying(); 103 104 BaseType::maCanvasHelper.setData( data, bitmapLayout, rect ); 105 } 106 setPixel(const::com::sun::star::uno::Sequence<sal_Int8> & color,const::com::sun::star::rendering::IntegerBitmapLayout & bitmapLayout,const::com::sun::star::geometry::IntegerPoint2D & pos)107 virtual void SAL_CALL setPixel( const ::com::sun::star::uno::Sequence< sal_Int8 >& color, 108 const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout, 109 const ::com::sun::star::geometry::IntegerPoint2D& pos ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) 110 { 111 tools::verifyArgs(bitmapLayout, pos, 112 BOOST_CURRENT_FUNCTION, 113 static_cast< typename BaseType::UnambiguousBaseType* >(this)); 114 tools::verifyIndexRange(pos, BaseType::getSize() ); 115 116 typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 117 118 BaseType::mbSurfaceDirty = true; 119 BaseType::maCanvasHelper.modifying(); 120 121 BaseType::maCanvasHelper.setPixel( color, bitmapLayout, pos ); 122 } 123 getPixel(::com::sun::star::rendering::IntegerBitmapLayout & bitmapLayout,const::com::sun::star::geometry::IntegerPoint2D & pos)124 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getPixel( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout, 125 const ::com::sun::star::geometry::IntegerPoint2D& pos ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::rendering::VolatileContentDestroyedException, ::com::sun::star::uno::RuntimeException) 126 { 127 tools::verifyArgs(pos, 128 BOOST_CURRENT_FUNCTION, 129 static_cast< typename BaseType::UnambiguousBaseType* >(this)); 130 tools::verifyIndexRange(pos, BaseType::getSize() ); 131 132 typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 133 134 return BaseType::maCanvasHelper.getPixel( bitmapLayout, 135 pos ); 136 } 137 getMemoryLayout()138 virtual ::com::sun::star::rendering::IntegerBitmapLayout SAL_CALL getMemoryLayout( ) throw (::com::sun::star::uno::RuntimeException) 139 { 140 typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 141 142 return BaseType::maCanvasHelper.getMemoryLayout(); 143 } 144 }; 145 } 146 147 #endif /* INCLUDED_CANVAS_INTEGERBITMAPBASE_HXX */ 148