update dev300-m58
[ooovba.git] / canvas / source / cairo / cairo_spritedevicehelper.cxx
blob5d96e63ccabfbb11e7145847ad767fd6cd3bf2a6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cairo_spritedevicehelper.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include <canvas/debug.hxx>
35 #include <canvas/verbosetrace.hxx>
36 #include <canvas/canvastools.hxx>
38 #include <osl/mutex.hxx>
39 #include <cppuhelper/compbase1.hxx>
41 #include <com/sun/star/lang/NoSupportException.hpp>
43 #include <toolkit/helper/vclunohelper.hxx>
44 #include <basegfx/tools/canvastools.hxx>
45 #include <basegfx/tools/unopolypolygon.hxx>
47 #include <vcl/syschild.hxx>
48 #include <vcl/canvastools.hxx>
50 #include "cairo_spritecanvas.hxx"
51 #include "cairo_canvasbitmap.hxx"
52 #include "cairo_devicehelper.hxx"
53 #include "cairo_cairo.hxx"
55 using namespace ::cairo;
56 using namespace ::com::sun::star;
58 namespace cairocanvas
61 SpriteDeviceHelper::SpriteDeviceHelper() :
62 mpSpriteCanvas( NULL ),
63 mpBufferSurface(),
64 maSize(),
65 mbFullScreen( false )
68 void SpriteDeviceHelper::init( Window& rOutputWindow,
69 SpriteCanvas& rSpriteCanvas,
70 const ::basegfx::B2ISize& rSize,
71 bool bFullscreen )
73 DeviceHelper::init(rSpriteCanvas,
74 rOutputWindow);
76 mpSpriteCanvas = &rSpriteCanvas;
77 mbFullScreen = bFullscreen;
79 setSize( rSize );
82 void SpriteDeviceHelper::disposing()
84 // release all references
85 mpBufferSurface.reset();
86 mpSpriteCanvas = NULL;
89 ::sal_Int32 SpriteDeviceHelper::createBuffers( ::sal_Int32 /*nBuffers*/ )
91 // TODO(F3): implement XBufferStrategy interface. For now, we
92 // _always_ will have exactly one backbuffer
93 return 1;
96 void SpriteDeviceHelper::destroyBuffers()
98 // TODO(F3): implement XBufferStrategy interface. For now, we
99 // _always_ will have exactly one backbuffer
102 ::sal_Bool SpriteDeviceHelper::showBuffer( bool, ::sal_Bool )
104 OSL_ENSURE(false,"Not supposed to be called, handled by SpriteCanvas");
105 return sal_False;
108 ::sal_Bool SpriteDeviceHelper::switchBuffer( bool, ::sal_Bool )
110 OSL_ENSURE(false,"Not supposed to be called, handled by SpriteCanvas");
111 return sal_False;
114 uno::Any SpriteDeviceHelper::isAccelerated() const
116 return ::com::sun::star::uno::makeAny(true);
119 uno::Any SpriteDeviceHelper::getDeviceHandle() const
121 return DeviceHelper::getDeviceHandle();
124 uno::Any SpriteDeviceHelper::getSurfaceHandle() const
126 return DeviceHelper::getSurfaceHandle();
129 void SpriteDeviceHelper::setSize( const ::basegfx::B2ISize& rSize )
131 OSL_TRACE("SpriteDeviceHelper::setSize(): device size %d x %d", rSize.getX(), rSize.getY() );
133 if( !mpSpriteCanvas )
134 return; // disposed
136 DeviceHelper::setSize(rSize);
138 if( mpBufferSurface && maSize != rSize )
139 mpBufferSurface.reset();
140 if( !mpBufferSurface )
141 mpBufferSurface = getWindowSurface()->getSimilar(
142 CAIRO_CONTENT_COLOR,
143 rSize.getX(), rSize.getY() );
145 if( maSize != rSize )
146 maSize = rSize;
148 mpSpriteCanvas->setSizePixel( maSize );
151 const ::basegfx::B2ISize& SpriteDeviceHelper::getSizePixel()
153 return maSize;
156 void SpriteDeviceHelper::notifySizeUpdate( const awt::Rectangle& rBounds )
158 setSize( ::basegfx::B2ISize(rBounds.Width, rBounds.Height) );
161 SurfaceSharedPtr SpriteDeviceHelper::getSurface()
163 return mpBufferSurface;
166 SurfaceSharedPtr SpriteDeviceHelper::getBufferSurface()
168 return mpBufferSurface;
171 SurfaceSharedPtr SpriteDeviceHelper::getWindowSurface()
173 return DeviceHelper::getSurface();
176 SurfaceSharedPtr SpriteDeviceHelper::createSurface( const ::basegfx::B2ISize& rSize, Content aContent )
178 if( mpBufferSurface )
179 return mpBufferSurface->getSimilar( aContent, rSize.getX(), rSize.getY() );
181 return SurfaceSharedPtr();
184 SurfaceSharedPtr SpriteDeviceHelper::createSurface( BitmapSystemData& rData, const Size& rSize )
186 if( getOutputDevice() )
187 return createBitmapSurface( *getOutputDevice(), rData, rSize );
189 return SurfaceSharedPtr();
193 /** SpriteDeviceHelper::flush Flush the platform native window
195 * Flushes the window by using the internally stored mpSysData.
198 void SpriteDeviceHelper::flush()
200 SurfaceSharedPtr pWinSurface=getWindowSurface();
201 if( pWinSurface )
202 pWinSurface->flush();