1*25ea7f45SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*25ea7f45SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*25ea7f45SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*25ea7f45SAndrew Rist * distributed with this work for additional information 6*25ea7f45SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*25ea7f45SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*25ea7f45SAndrew Rist * "License"); you may not use this file except in compliance 9*25ea7f45SAndrew Rist * with the License. You may obtain a copy of the License at 10*25ea7f45SAndrew Rist * 11*25ea7f45SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*25ea7f45SAndrew Rist * 13*25ea7f45SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*25ea7f45SAndrew Rist * software distributed under the License is distributed on an 15*25ea7f45SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*25ea7f45SAndrew Rist * KIND, either express or implied. See the License for the 17*25ea7f45SAndrew Rist * specific language governing permissions and limitations 18*25ea7f45SAndrew Rist * under the License. 19*25ea7f45SAndrew Rist * 20*25ea7f45SAndrew Rist *************************************************************/ 21*25ea7f45SAndrew Rist 22*25ea7f45SAndrew 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 <canvas/verbosetrace.hxx> 29cdf0e10cSrcweir #include <canvas/canvastools.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <osl/mutex.hxx> 32cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <com/sun/star/lang/NoSupportException.hpp> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 37cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 38cdf0e10cSrcweir #include <basegfx/tools/unopolypolygon.hxx> 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include <vcl/syschild.hxx> 41cdf0e10cSrcweir #include <vcl/canvastools.hxx> 42cdf0e10cSrcweir 43cdf0e10cSrcweir #include "cairo_spritecanvas.hxx" 44cdf0e10cSrcweir #include "cairo_canvasbitmap.hxx" 45cdf0e10cSrcweir #include "cairo_devicehelper.hxx" 46cdf0e10cSrcweir #include "cairo_cairo.hxx" 47cdf0e10cSrcweir 48cdf0e10cSrcweir using namespace ::cairo; 49cdf0e10cSrcweir using namespace ::com::sun::star; 50cdf0e10cSrcweir 51cdf0e10cSrcweir namespace cairocanvas 52cdf0e10cSrcweir { 53cdf0e10cSrcweir SpriteDeviceHelper()54cdf0e10cSrcweir SpriteDeviceHelper::SpriteDeviceHelper() : 55cdf0e10cSrcweir mpSpriteCanvas( NULL ), 56cdf0e10cSrcweir mpBufferSurface(), 57cdf0e10cSrcweir maSize(), 58cdf0e10cSrcweir mbFullScreen( false ) 59cdf0e10cSrcweir {} 60cdf0e10cSrcweir init(Window & rOutputWindow,SpriteCanvas & rSpriteCanvas,const::basegfx::B2ISize & rSize,bool bFullscreen)61cdf0e10cSrcweir void SpriteDeviceHelper::init( Window& rOutputWindow, 62cdf0e10cSrcweir SpriteCanvas& rSpriteCanvas, 63cdf0e10cSrcweir const ::basegfx::B2ISize& rSize, 64cdf0e10cSrcweir bool bFullscreen ) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir DeviceHelper::init(rSpriteCanvas, 67cdf0e10cSrcweir rOutputWindow); 68cdf0e10cSrcweir 69cdf0e10cSrcweir mpSpriteCanvas = &rSpriteCanvas; 70cdf0e10cSrcweir mbFullScreen = bFullscreen; 71cdf0e10cSrcweir 72cdf0e10cSrcweir setSize( rSize ); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir disposing()75cdf0e10cSrcweir void SpriteDeviceHelper::disposing() 76cdf0e10cSrcweir { 77cdf0e10cSrcweir // release all references 78cdf0e10cSrcweir mpBufferSurface.reset(); 79cdf0e10cSrcweir mpSpriteCanvas = NULL; 80cdf0e10cSrcweir } 81cdf0e10cSrcweir createBuffers(::sal_Int32)82cdf0e10cSrcweir ::sal_Int32 SpriteDeviceHelper::createBuffers( ::sal_Int32 /*nBuffers*/ ) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir // TODO(F3): implement XBufferStrategy interface. For now, we 85cdf0e10cSrcweir // _always_ will have exactly one backbuffer 86cdf0e10cSrcweir return 1; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir destroyBuffers()89cdf0e10cSrcweir void SpriteDeviceHelper::destroyBuffers() 90cdf0e10cSrcweir { 91cdf0e10cSrcweir // TODO(F3): implement XBufferStrategy interface. For now, we 92cdf0e10cSrcweir // _always_ will have exactly one backbuffer 93cdf0e10cSrcweir } 94cdf0e10cSrcweir showBuffer(bool,::sal_Bool)95cdf0e10cSrcweir ::sal_Bool SpriteDeviceHelper::showBuffer( bool, ::sal_Bool ) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir OSL_ENSURE(false,"Not supposed to be called, handled by SpriteCanvas"); 98cdf0e10cSrcweir return sal_False; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir switchBuffer(bool,::sal_Bool)101cdf0e10cSrcweir ::sal_Bool SpriteDeviceHelper::switchBuffer( bool, ::sal_Bool ) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir OSL_ENSURE(false,"Not supposed to be called, handled by SpriteCanvas"); 104cdf0e10cSrcweir return sal_False; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir isAccelerated() const107cdf0e10cSrcweir uno::Any SpriteDeviceHelper::isAccelerated() const 108cdf0e10cSrcweir { 109cdf0e10cSrcweir return ::com::sun::star::uno::makeAny(true); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir getDeviceHandle() const112cdf0e10cSrcweir uno::Any SpriteDeviceHelper::getDeviceHandle() const 113cdf0e10cSrcweir { 114cdf0e10cSrcweir return DeviceHelper::getDeviceHandle(); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir getSurfaceHandle() const117cdf0e10cSrcweir uno::Any SpriteDeviceHelper::getSurfaceHandle() const 118cdf0e10cSrcweir { 119cdf0e10cSrcweir return DeviceHelper::getSurfaceHandle(); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir setSize(const::basegfx::B2ISize & rSize)122cdf0e10cSrcweir void SpriteDeviceHelper::setSize( const ::basegfx::B2ISize& rSize ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir OSL_TRACE("SpriteDeviceHelper::setSize(): device size %d x %d", rSize.getX(), rSize.getY() ); 125cdf0e10cSrcweir 126cdf0e10cSrcweir if( !mpSpriteCanvas ) 127cdf0e10cSrcweir return; // disposed 128cdf0e10cSrcweir 129cdf0e10cSrcweir DeviceHelper::setSize(rSize); 130cdf0e10cSrcweir 131cdf0e10cSrcweir if( mpBufferSurface && maSize != rSize ) 132cdf0e10cSrcweir mpBufferSurface.reset(); 133cdf0e10cSrcweir if( !mpBufferSurface ) 134cdf0e10cSrcweir mpBufferSurface = getWindowSurface()->getSimilar( 135cdf0e10cSrcweir CAIRO_CONTENT_COLOR, 136cdf0e10cSrcweir rSize.getX(), rSize.getY() ); 137cdf0e10cSrcweir 138cdf0e10cSrcweir if( maSize != rSize ) 139cdf0e10cSrcweir maSize = rSize; 140cdf0e10cSrcweir 141cdf0e10cSrcweir mpSpriteCanvas->setSizePixel( maSize ); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir getSizePixel()144cdf0e10cSrcweir const ::basegfx::B2ISize& SpriteDeviceHelper::getSizePixel() 145cdf0e10cSrcweir { 146cdf0e10cSrcweir return maSize; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir notifySizeUpdate(const awt::Rectangle & rBounds)149cdf0e10cSrcweir void SpriteDeviceHelper::notifySizeUpdate( const awt::Rectangle& rBounds ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir setSize( ::basegfx::B2ISize(rBounds.Width, rBounds.Height) ); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir getSurface()154cdf0e10cSrcweir SurfaceSharedPtr SpriteDeviceHelper::getSurface() 155cdf0e10cSrcweir { 156cdf0e10cSrcweir return mpBufferSurface; 157cdf0e10cSrcweir } 158cdf0e10cSrcweir getBufferSurface()159cdf0e10cSrcweir SurfaceSharedPtr SpriteDeviceHelper::getBufferSurface() 160cdf0e10cSrcweir { 161cdf0e10cSrcweir return mpBufferSurface; 162cdf0e10cSrcweir } 163cdf0e10cSrcweir getWindowSurface()164cdf0e10cSrcweir SurfaceSharedPtr SpriteDeviceHelper::getWindowSurface() 165cdf0e10cSrcweir { 166cdf0e10cSrcweir return DeviceHelper::getSurface(); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir createSurface(const::basegfx::B2ISize & rSize,Content aContent)169cdf0e10cSrcweir SurfaceSharedPtr SpriteDeviceHelper::createSurface( const ::basegfx::B2ISize& rSize, Content aContent ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir if( mpBufferSurface ) 172cdf0e10cSrcweir return mpBufferSurface->getSimilar( aContent, rSize.getX(), rSize.getY() ); 173cdf0e10cSrcweir 174cdf0e10cSrcweir return SurfaceSharedPtr(); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir createSurface(BitmapSystemData & rData,const Size & rSize)177cdf0e10cSrcweir SurfaceSharedPtr SpriteDeviceHelper::createSurface( BitmapSystemData& rData, const Size& rSize ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir if( getOutputDevice() ) 180cdf0e10cSrcweir return createBitmapSurface( *getOutputDevice(), rData, rSize ); 181cdf0e10cSrcweir 182cdf0e10cSrcweir return SurfaceSharedPtr(); 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir 186cdf0e10cSrcweir /** SpriteDeviceHelper::flush Flush the platform native window 187cdf0e10cSrcweir * 188cdf0e10cSrcweir * Flushes the window by using the internally stored mpSysData. 189cdf0e10cSrcweir * 190cdf0e10cSrcweir **/ flush()191cdf0e10cSrcweir void SpriteDeviceHelper::flush() 192cdf0e10cSrcweir { 193cdf0e10cSrcweir SurfaceSharedPtr pWinSurface=getWindowSurface(); 194cdf0e10cSrcweir if( pWinSurface ) 195cdf0e10cSrcweir pWinSurface->flush(); 196cdf0e10cSrcweir } 197cdf0e10cSrcweir } 198