1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_canvas.hxx"
30 
31 #include <canvas/debug.hxx>
32 #include <canvas/verbosetrace.hxx>
33 #include <canvas/canvastools.hxx>
34 
35 #include <osl/mutex.hxx>
36 #include <cppuhelper/compbase1.hxx>
37 
38 #include <com/sun/star/lang/NoSupportException.hpp>
39 
40 #include <toolkit/helper/vclunohelper.hxx>
41 #include <basegfx/tools/canvastools.hxx>
42 #include <basegfx/tools/unopolypolygon.hxx>
43 
44 #include <vcl/syschild.hxx>
45 #include <vcl/canvastools.hxx>
46 
47 #include "cairo_spritecanvas.hxx"
48 #include "cairo_canvasbitmap.hxx"
49 #include "cairo_devicehelper.hxx"
50 #include "cairo_cairo.hxx"
51 
52 using namespace ::cairo;
53 using namespace ::com::sun::star;
54 
55 namespace cairocanvas
56 {
57 
58     SpriteDeviceHelper::SpriteDeviceHelper() :
59         mpSpriteCanvas( NULL ),
60         mpBufferSurface(),
61         maSize(),
62         mbFullScreen( false )
63     {}
64 
65     void SpriteDeviceHelper::init( Window&                   rOutputWindow,
66                                    SpriteCanvas&			 rSpriteCanvas,
67                                    const ::basegfx::B2ISize& rSize,
68                                    bool                      bFullscreen )
69     {
70         DeviceHelper::init(rSpriteCanvas,
71                            rOutputWindow);
72 
73         mpSpriteCanvas = &rSpriteCanvas;
74         mbFullScreen = bFullscreen;
75 
76         setSize( rSize );
77     }
78 
79     void SpriteDeviceHelper::disposing()
80     {
81         // release all references
82         mpBufferSurface.reset();
83         mpSpriteCanvas = NULL;
84     }
85 
86     ::sal_Int32 SpriteDeviceHelper::createBuffers( ::sal_Int32 /*nBuffers*/ )
87     {
88         // TODO(F3): implement XBufferStrategy interface. For now, we
89         // _always_ will have exactly one backbuffer
90         return 1;
91     }
92 
93     void SpriteDeviceHelper::destroyBuffers()
94     {
95         // TODO(F3): implement XBufferStrategy interface. For now, we
96         // _always_ will have exactly one backbuffer
97     }
98 
99     ::sal_Bool SpriteDeviceHelper::showBuffer( bool, ::sal_Bool )
100     {
101         OSL_ENSURE(false,"Not supposed to be called, handled by SpriteCanvas");
102         return sal_False;
103     }
104 
105     ::sal_Bool SpriteDeviceHelper::switchBuffer( bool, ::sal_Bool )
106     {
107         OSL_ENSURE(false,"Not supposed to be called, handled by SpriteCanvas");
108         return sal_False;
109     }
110 
111     uno::Any SpriteDeviceHelper::isAccelerated() const
112     {
113         return ::com::sun::star::uno::makeAny(true);
114     }
115 
116     uno::Any SpriteDeviceHelper::getDeviceHandle() const
117     {
118         return DeviceHelper::getDeviceHandle();
119     }
120 
121     uno::Any SpriteDeviceHelper::getSurfaceHandle() const
122     {
123         return DeviceHelper::getSurfaceHandle();
124     }
125 
126     void SpriteDeviceHelper::setSize( const ::basegfx::B2ISize& rSize )
127     {
128 		OSL_TRACE("SpriteDeviceHelper::setSize(): device size %d x %d", rSize.getX(), rSize.getY() );
129 
130         if( !mpSpriteCanvas )
131             return; // disposed
132 
133         DeviceHelper::setSize(rSize);
134 
135 		if( mpBufferSurface && maSize != rSize )
136             mpBufferSurface.reset();
137 		if( !mpBufferSurface )
138 			mpBufferSurface = getWindowSurface()->getSimilar(
139                 CAIRO_CONTENT_COLOR,
140                 rSize.getX(), rSize.getY() );
141 
142 		if( maSize != rSize )
143 			maSize = rSize;
144 
145 		mpSpriteCanvas->setSizePixel( maSize );
146     }
147 
148     const ::basegfx::B2ISize& SpriteDeviceHelper::getSizePixel()
149     {
150         return maSize;
151     }
152 
153     void SpriteDeviceHelper::notifySizeUpdate( const awt::Rectangle& rBounds )
154     {
155         setSize( ::basegfx::B2ISize(rBounds.Width, rBounds.Height) );
156     }
157 
158     SurfaceSharedPtr SpriteDeviceHelper::getSurface()
159     {
160         return mpBufferSurface;
161     }
162 
163     SurfaceSharedPtr SpriteDeviceHelper::getBufferSurface()
164     {
165         return mpBufferSurface;
166     }
167 
168     SurfaceSharedPtr SpriteDeviceHelper::getWindowSurface()
169     {
170         return DeviceHelper::getSurface();
171     }
172 
173     SurfaceSharedPtr SpriteDeviceHelper::createSurface( const ::basegfx::B2ISize& rSize, Content aContent )
174     {
175 		if( mpBufferSurface )
176 			return mpBufferSurface->getSimilar( aContent, rSize.getX(), rSize.getY() );
177 
178 		return SurfaceSharedPtr();
179     }
180 
181     SurfaceSharedPtr SpriteDeviceHelper::createSurface( BitmapSystemData& rData, const Size& rSize )
182     {
183         if( getOutputDevice() )
184             return createBitmapSurface( *getOutputDevice(), rData, rSize );
185 
186 		return SurfaceSharedPtr();
187     }
188 
189 
190     /** SpriteDeviceHelper::flush  Flush the platform native window
191      *
192      * Flushes the window by using the internally stored mpSysData.
193      *
194      **/
195     void SpriteDeviceHelper::flush()
196     {
197         SurfaceSharedPtr pWinSurface=getWindowSurface();
198         if( pWinSurface )
199             pWinSurface->flush();
200     }
201 }
202