125ea7f45SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 325ea7f45SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 425ea7f45SAndrew Rist * or more contributor license agreements. See the NOTICE file 525ea7f45SAndrew Rist * distributed with this work for additional information 625ea7f45SAndrew Rist * regarding copyright ownership. The ASF licenses this file 725ea7f45SAndrew Rist * to you under the Apache License, Version 2.0 (the 825ea7f45SAndrew Rist * "License"); you may not use this file except in compliance 925ea7f45SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 1125ea7f45SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 1325ea7f45SAndrew Rist * Unless required by applicable law or agreed to in writing, 1425ea7f45SAndrew Rist * software distributed under the License is distributed on an 1525ea7f45SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1625ea7f45SAndrew Rist * KIND, either express or implied. See the License for the 1725ea7f45SAndrew Rist * specific language governing permissions and limitations 1825ea7f45SAndrew Rist * under the License. 19cdf0e10cSrcweir * 2025ea7f45SAndrew Rist *************************************************************/ 2125ea7f45SAndrew Rist 2225ea7f45SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_canvas.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <canvas/debug.hxx> 28cdf0e10cSrcweir #include <tools/diagnose_ex.h> 29cdf0e10cSrcweir #include <canvas/verbosetrace.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <rtl/math.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <vcl/outdev.hxx> 34cdf0e10cSrcweir #include <vcl/bitmap.hxx> 35cdf0e10cSrcweir #include <vcl/alpha.hxx> 36cdf0e10cSrcweir #include <vcl/bitmapex.hxx> 37cdf0e10cSrcweir #include <vcl/canvastools.hxx> 38cdf0e10cSrcweir 39cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 40cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx> 41cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 42cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx> 43cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 44cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx> 45cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx> 46cdf0e10cSrcweir 47cdf0e10cSrcweir #include <canvas/canvastools.hxx> 48cdf0e10cSrcweir 49cdf0e10cSrcweir #include "canvascustomsprite.hxx" 50cdf0e10cSrcweir 51cdf0e10cSrcweir 52cdf0e10cSrcweir using namespace ::com::sun::star; 53cdf0e10cSrcweir 54cdf0e10cSrcweir 55cdf0e10cSrcweir namespace vclcanvas 56cdf0e10cSrcweir { 57cdf0e10cSrcweir CanvasCustomSprite(const geometry::RealSize2D & rSpriteSize,rendering::XGraphicDevice & rDevice,const::canvas::SpriteSurface::Reference & rOwningSpriteCanvas,const OutDevProviderSharedPtr & rOutDevProvider,bool bShowSpriteBounds)58cdf0e10cSrcweir CanvasCustomSprite::CanvasCustomSprite( const geometry::RealSize2D& rSpriteSize, 59cdf0e10cSrcweir rendering::XGraphicDevice& rDevice, 60cdf0e10cSrcweir const ::canvas::SpriteSurface::Reference& rOwningSpriteCanvas, 61cdf0e10cSrcweir const OutDevProviderSharedPtr& rOutDevProvider, 62cdf0e10cSrcweir bool bShowSpriteBounds ) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir ENSURE_OR_THROW( rOwningSpriteCanvas.get() && 65cdf0e10cSrcweir rOutDevProvider, 66cdf0e10cSrcweir "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" ); 67cdf0e10cSrcweir 68cdf0e10cSrcweir // setup back buffer 69cdf0e10cSrcweir // ----------------- 70cdf0e10cSrcweir 71cdf0e10cSrcweir const ::Size aSize( 72cdf0e10cSrcweir static_cast<sal_Int32>( ::std::max( 1.0, 73cdf0e10cSrcweir ceil( rSpriteSize.Width ))), // round up to nearest int, 74cdf0e10cSrcweir // enforce sprite to have at 75cdf0e10cSrcweir // least (1,1) pixel size 76cdf0e10cSrcweir static_cast<sal_Int32>( ::std::max( 1.0, 77cdf0e10cSrcweir ceil( rSpriteSize.Height ))) ); 78cdf0e10cSrcweir 79cdf0e10cSrcweir // create content backbuffer in screen depth 80cdf0e10cSrcweir BackBufferSharedPtr pBackBuffer( new BackBuffer( rOutDevProvider->getOutDev() ) ); 81cdf0e10cSrcweir pBackBuffer->setSize( aSize ); 82cdf0e10cSrcweir 833850f4f7SArmin Le Grand // create mask backbuffer, with one bit color depth #122485# use full depth to avoid problem with 1bit depth, get AAed masks 84*76e9555fSArmin Le Grand BackBufferSharedPtr pBackBufferMask( 85*76e9555fSArmin Le Grand #if defined LINUX || defined FREEBSD || defined NETBSD 86*76e9555fSArmin Le Grand // #122485# no 1bit buffers on Linuxes, 1bit Vdev seems to work no longer 87*76e9555fSArmin Le Grand new BackBuffer( rOutDevProvider->getOutDev() ) ); 88*76e9555fSArmin Le Grand #else 89*76e9555fSArmin Le Grand // 1bit mask buffer for all others 90*76e9555fSArmin Le Grand new BackBuffer( rOutDevProvider->getOutDev(), true ) ); 91*76e9555fSArmin Le Grand #endif 92cdf0e10cSrcweir pBackBufferMask->setSize( aSize ); 93cdf0e10cSrcweir 94cdf0e10cSrcweir // TODO(F1): Implement alpha vdev (could prolly enable 95cdf0e10cSrcweir // antialiasing again, then) 96cdf0e10cSrcweir 97cdf0e10cSrcweir // disable font antialiasing (causes ugly shadows otherwise) 98cdf0e10cSrcweir pBackBuffer->getOutDev().SetAntialiasing( ANTIALIASING_DISABLE_TEXT ); 99cdf0e10cSrcweir pBackBufferMask->getOutDev().SetAntialiasing( ANTIALIASING_DISABLE_TEXT ); 100cdf0e10cSrcweir 101cdf0e10cSrcweir // set mask vdev drawmode, such that everything is painted 102cdf0e10cSrcweir // black. That leaves us with a binary image, white for 103cdf0e10cSrcweir // background, black for painted content 104cdf0e10cSrcweir pBackBufferMask->getOutDev().SetDrawMode( DRAWMODE_BLACKLINE | DRAWMODE_BLACKFILL | DRAWMODE_BLACKTEXT | 105cdf0e10cSrcweir DRAWMODE_BLACKGRADIENT | DRAWMODE_BLACKBITMAP ); 106cdf0e10cSrcweir 107cdf0e10cSrcweir 108cdf0e10cSrcweir // setup canvas helper 109cdf0e10cSrcweir // ------------------- 110cdf0e10cSrcweir 111cdf0e10cSrcweir // always render into back buffer, don't preserve state (it's 112cdf0e10cSrcweir // our private VDev, after all), have notion of alpha 113cdf0e10cSrcweir maCanvasHelper.init( rDevice, 114cdf0e10cSrcweir pBackBuffer, 115cdf0e10cSrcweir false, 116cdf0e10cSrcweir true ); 117cdf0e10cSrcweir maCanvasHelper.setBackgroundOutDev( pBackBufferMask ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir 120cdf0e10cSrcweir // setup sprite helper 121cdf0e10cSrcweir // ------------------- 122cdf0e10cSrcweir 123cdf0e10cSrcweir maSpriteHelper.init( rSpriteSize, 124cdf0e10cSrcweir rOwningSpriteCanvas, 125cdf0e10cSrcweir pBackBuffer, 126cdf0e10cSrcweir pBackBufferMask, 127cdf0e10cSrcweir bShowSpriteBounds ); 128cdf0e10cSrcweir 129cdf0e10cSrcweir // clear sprite to 100% transparent 130cdf0e10cSrcweir maCanvasHelper.clear(); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir disposing()133cdf0e10cSrcweir void SAL_CALL CanvasCustomSprite::disposing() 134cdf0e10cSrcweir { 135cdf0e10cSrcweir tools::LocalGuard aGuard; 136cdf0e10cSrcweir 137cdf0e10cSrcweir // forward to parent 138cdf0e10cSrcweir CanvasCustomSpriteBaseT::disposing(); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir #define IMPLEMENTATION_NAME "VCLCanvas.CanvasCustomSprite" 142cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.rendering.CanvasCustomSprite" 143cdf0e10cSrcweir getImplementationName()144cdf0e10cSrcweir ::rtl::OUString SAL_CALL CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException ) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ); 147cdf0e10cSrcweir } 148cdf0e10cSrcweir supportsService(const::rtl::OUString & ServiceName)149cdf0e10cSrcweir sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir getSupportedServiceNames()154cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames() throw( uno::RuntimeException ) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aRet(1); 157cdf0e10cSrcweir aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); 158cdf0e10cSrcweir 159cdf0e10cSrcweir return aRet; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir // Sprite redraw(OutputDevice & rOutDev,bool bBufferedUpdate) const163cdf0e10cSrcweir void CanvasCustomSprite::redraw( OutputDevice& rOutDev, 164cdf0e10cSrcweir bool bBufferedUpdate ) const 165cdf0e10cSrcweir { 166cdf0e10cSrcweir tools::LocalGuard aGuard; 167cdf0e10cSrcweir 168cdf0e10cSrcweir redraw( rOutDev, maSpriteHelper.getPosPixel(), bBufferedUpdate ); 169cdf0e10cSrcweir } 170cdf0e10cSrcweir redraw(OutputDevice & rOutDev,const::basegfx::B2DPoint & rOrigOutputPos,bool bBufferedUpdate) const171cdf0e10cSrcweir void CanvasCustomSprite::redraw( OutputDevice& rOutDev, 172cdf0e10cSrcweir const ::basegfx::B2DPoint& rOrigOutputPos, 173cdf0e10cSrcweir bool bBufferedUpdate ) const 174cdf0e10cSrcweir { 175cdf0e10cSrcweir tools::LocalGuard aGuard; 176cdf0e10cSrcweir 177cdf0e10cSrcweir maSpriteHelper.redraw( rOutDev, 178cdf0e10cSrcweir rOrigOutputPos, 179cdf0e10cSrcweir mbSurfaceDirty, 180cdf0e10cSrcweir bBufferedUpdate ); 181cdf0e10cSrcweir 182cdf0e10cSrcweir mbSurfaceDirty = false; 183cdf0e10cSrcweir } 184cdf0e10cSrcweir repaint(const GraphicObjectSharedPtr & rGrf,const rendering::ViewState & viewState,const rendering::RenderState & renderState,const::Point & rPt,const::Size & rSz,const GraphicAttr & rAttr) const185cdf0e10cSrcweir bool CanvasCustomSprite::repaint( const GraphicObjectSharedPtr& rGrf, 186cdf0e10cSrcweir const rendering::ViewState& viewState, 187cdf0e10cSrcweir const rendering::RenderState& renderState, 188cdf0e10cSrcweir const ::Point& rPt, 189cdf0e10cSrcweir const ::Size& rSz, 190cdf0e10cSrcweir const GraphicAttr& rAttr ) const 191cdf0e10cSrcweir { 192cdf0e10cSrcweir tools::LocalGuard aGuard; 193cdf0e10cSrcweir 194cdf0e10cSrcweir mbSurfaceDirty = true; 195cdf0e10cSrcweir 196cdf0e10cSrcweir return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr ); 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir } 200