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 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 83*3850f4f7SArmin Le Grand // create mask backbuffer, with one bit color depth #122485# use full depth to avoid problem with 1bit depth, get AAed masks 84*3850f4f7SArmin Le Grand BackBufferSharedPtr pBackBufferMask( new BackBuffer( rOutDevProvider->getOutDev() ) ); // , true ) ); // #122485# 85cdf0e10cSrcweir pBackBufferMask->setSize( aSize ); 86cdf0e10cSrcweir 87cdf0e10cSrcweir // TODO(F1): Implement alpha vdev (could prolly enable 88cdf0e10cSrcweir // antialiasing again, then) 89cdf0e10cSrcweir 90cdf0e10cSrcweir // disable font antialiasing (causes ugly shadows otherwise) 91cdf0e10cSrcweir pBackBuffer->getOutDev().SetAntialiasing( ANTIALIASING_DISABLE_TEXT ); 92cdf0e10cSrcweir pBackBufferMask->getOutDev().SetAntialiasing( ANTIALIASING_DISABLE_TEXT ); 93cdf0e10cSrcweir 94cdf0e10cSrcweir // set mask vdev drawmode, such that everything is painted 95cdf0e10cSrcweir // black. That leaves us with a binary image, white for 96cdf0e10cSrcweir // background, black for painted content 97cdf0e10cSrcweir pBackBufferMask->getOutDev().SetDrawMode( DRAWMODE_BLACKLINE | DRAWMODE_BLACKFILL | DRAWMODE_BLACKTEXT | 98cdf0e10cSrcweir DRAWMODE_BLACKGRADIENT | DRAWMODE_BLACKBITMAP ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir 101cdf0e10cSrcweir // setup canvas helper 102cdf0e10cSrcweir // ------------------- 103cdf0e10cSrcweir 104cdf0e10cSrcweir // always render into back buffer, don't preserve state (it's 105cdf0e10cSrcweir // our private VDev, after all), have notion of alpha 106cdf0e10cSrcweir maCanvasHelper.init( rDevice, 107cdf0e10cSrcweir pBackBuffer, 108cdf0e10cSrcweir false, 109cdf0e10cSrcweir true ); 110cdf0e10cSrcweir maCanvasHelper.setBackgroundOutDev( pBackBufferMask ); 111cdf0e10cSrcweir 112cdf0e10cSrcweir 113cdf0e10cSrcweir // setup sprite helper 114cdf0e10cSrcweir // ------------------- 115cdf0e10cSrcweir 116cdf0e10cSrcweir maSpriteHelper.init( rSpriteSize, 117cdf0e10cSrcweir rOwningSpriteCanvas, 118cdf0e10cSrcweir pBackBuffer, 119cdf0e10cSrcweir pBackBufferMask, 120cdf0e10cSrcweir bShowSpriteBounds ); 121cdf0e10cSrcweir 122cdf0e10cSrcweir // clear sprite to 100% transparent 123cdf0e10cSrcweir maCanvasHelper.clear(); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir void SAL_CALL CanvasCustomSprite::disposing() 127cdf0e10cSrcweir { 128cdf0e10cSrcweir tools::LocalGuard aGuard; 129cdf0e10cSrcweir 130cdf0e10cSrcweir // forward to parent 131cdf0e10cSrcweir CanvasCustomSpriteBaseT::disposing(); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir #define IMPLEMENTATION_NAME "VCLCanvas.CanvasCustomSprite" 135cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.rendering.CanvasCustomSprite" 136cdf0e10cSrcweir 137cdf0e10cSrcweir ::rtl::OUString SAL_CALL CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException ) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames() throw( uno::RuntimeException ) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aRet(1); 150cdf0e10cSrcweir aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); 151cdf0e10cSrcweir 152cdf0e10cSrcweir return aRet; 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir // Sprite 156cdf0e10cSrcweir void CanvasCustomSprite::redraw( OutputDevice& rOutDev, 157cdf0e10cSrcweir bool bBufferedUpdate ) const 158cdf0e10cSrcweir { 159cdf0e10cSrcweir tools::LocalGuard aGuard; 160cdf0e10cSrcweir 161cdf0e10cSrcweir redraw( rOutDev, maSpriteHelper.getPosPixel(), bBufferedUpdate ); 162cdf0e10cSrcweir } 163cdf0e10cSrcweir 164cdf0e10cSrcweir void CanvasCustomSprite::redraw( OutputDevice& rOutDev, 165cdf0e10cSrcweir const ::basegfx::B2DPoint& rOrigOutputPos, 166cdf0e10cSrcweir bool bBufferedUpdate ) const 167cdf0e10cSrcweir { 168cdf0e10cSrcweir tools::LocalGuard aGuard; 169cdf0e10cSrcweir 170cdf0e10cSrcweir maSpriteHelper.redraw( rOutDev, 171cdf0e10cSrcweir rOrigOutputPos, 172cdf0e10cSrcweir mbSurfaceDirty, 173cdf0e10cSrcweir bBufferedUpdate ); 174cdf0e10cSrcweir 175cdf0e10cSrcweir mbSurfaceDirty = false; 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir bool CanvasCustomSprite::repaint( const GraphicObjectSharedPtr& rGrf, 179cdf0e10cSrcweir const rendering::ViewState& viewState, 180cdf0e10cSrcweir const rendering::RenderState& renderState, 181cdf0e10cSrcweir const ::Point& rPt, 182cdf0e10cSrcweir const ::Size& rSz, 183cdf0e10cSrcweir const GraphicAttr& rAttr ) const 184cdf0e10cSrcweir { 185cdf0e10cSrcweir tools::LocalGuard aGuard; 186cdf0e10cSrcweir 187cdf0e10cSrcweir mbSurfaceDirty = true; 188cdf0e10cSrcweir 189cdf0e10cSrcweir return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr ); 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir } 193