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