1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cairo_spritedevicehelper.cxx,v $
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
;
61 SpriteDeviceHelper::SpriteDeviceHelper() :
62 mpSpriteCanvas( NULL
),
68 void SpriteDeviceHelper::init( Window
& rOutputWindow
,
69 SpriteCanvas
& rSpriteCanvas
,
70 const ::basegfx::B2ISize
& rSize
,
73 DeviceHelper::init(rSpriteCanvas
,
76 mpSpriteCanvas
= &rSpriteCanvas
;
77 mbFullScreen
= bFullscreen
;
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
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");
108 ::sal_Bool
SpriteDeviceHelper::switchBuffer( bool, ::sal_Bool
)
110 OSL_ENSURE(false,"Not supposed to be called, handled by SpriteCanvas");
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
)
136 DeviceHelper::setSize(rSize
);
138 if( mpBufferSurface
&& maSize
!= rSize
)
139 mpBufferSurface
.reset();
140 if( !mpBufferSurface
)
141 mpBufferSurface
= getWindowSurface()->getSimilar(
143 rSize
.getX(), rSize
.getY() );
145 if( maSize
!= rSize
)
148 mpSpriteCanvas
->setSizePixel( maSize
);
151 const ::basegfx::B2ISize
& SpriteDeviceHelper::getSizePixel()
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();
202 pWinSurface
->flush();