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 <rtl/instance.hxx>
33 #include <cppuhelper/compbase1.hxx>
34 
35 #include <com/sun/star/lang/NoSupportException.hpp>
36 
37 #include <basegfx/tools/canvastools.hxx>
38 #include <basegfx/tools/unopolypolygon.hxx>
39 #include <vcl/canvastools.hxx>
40 
41 #include "null_spritecanvas.hxx"
42 #include "null_canvasbitmap.hxx"
43 #include "null_devicehelper.hxx"
44 
45 
46 using namespace ::com::sun::star;
47 
48 namespace nullcanvas
49 {
DeviceHelper()50     DeviceHelper::DeviceHelper() :
51         mpSpriteCanvas( NULL ),
52         maSize(),
53         mbFullScreen(false)
54     {
55     }
56 
init(SpriteCanvas & rSpriteCanvas,const::basegfx::B2ISize & rSize,bool bFullscreen)57     void DeviceHelper::init( SpriteCanvas&				rSpriteCanvas,
58                              const ::basegfx::B2ISize&	rSize,
59                              bool                       bFullscreen )
60     {
61         mpSpriteCanvas = &rSpriteCanvas;
62         maSize = rSize;
63         mbFullScreen = bFullscreen;
64     }
65 
disposing()66     void DeviceHelper::disposing()
67     {
68         // release all references
69         mpSpriteCanvas = NULL;
70     }
71 
getPhysicalResolution()72     geometry::RealSize2D DeviceHelper::getPhysicalResolution()
73     {
74         return geometry::RealSize2D( 75, 75 );
75     }
76 
getPhysicalSize()77     geometry::RealSize2D DeviceHelper::getPhysicalSize()
78     {
79         return geometry::RealSize2D( 210, 280 );
80     }
81 
createCompatibleLinePolyPolygon(const uno::Reference<rendering::XGraphicDevice> &,const uno::Sequence<uno::Sequence<geometry::RealPoint2D>> & points)82     uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
83         const uno::Reference< rendering::XGraphicDevice >& 				/*rDevice*/,
84         const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >&	points )
85     {
86         // disposed?
87         if( !mpSpriteCanvas )
88             return uno::Reference< rendering::XLinePolyPolygon2D >(); // we're disposed
89 
90         return uno::Reference< rendering::XLinePolyPolygon2D >(
91             new ::basegfx::unotools::UnoPolyPolygon(
92                 ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points )));
93     }
94 
createCompatibleBezierPolyPolygon(const uno::Reference<rendering::XGraphicDevice> &,const uno::Sequence<uno::Sequence<geometry::RealBezierSegment2D>> & points)95     uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
96         const uno::Reference< rendering::XGraphicDevice >& 						/*rDevice*/,
97         const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >&	points )
98     {
99         // disposed?
100         if( !mpSpriteCanvas )
101             return uno::Reference< rendering::XBezierPolyPolygon2D >(); // we're disposed
102 
103         return uno::Reference< rendering::XBezierPolyPolygon2D >(
104             new ::basegfx::unotools::UnoPolyPolygon(
105                 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) );
106     }
107 
createCompatibleBitmap(const uno::Reference<rendering::XGraphicDevice> &,const geometry::IntegerSize2D & size)108     uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
109         const uno::Reference< rendering::XGraphicDevice >& 	/*rDevice*/,
110         const geometry::IntegerSize2D& 						size )
111     {
112         // disposed?
113         if( !mpSpriteCanvas )
114             return uno::Reference< rendering::XBitmap >(); // we're disposed
115 
116         return uno::Reference< rendering::XBitmap >(
117             new CanvasBitmap(
118                 ::basegfx::unotools::b2ISizeFromIntegerSize2D( size ),
119                 mpSpriteCanvas,
120                 false ));
121     }
122 
createVolatileBitmap(const uno::Reference<rendering::XGraphicDevice> &,const geometry::IntegerSize2D &)123     uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
124         const uno::Reference< rendering::XGraphicDevice >& 	/*rDevice*/,
125         const geometry::IntegerSize2D& 						/*size*/ )
126     {
127         return uno::Reference< rendering::XVolatileBitmap >();
128     }
129 
createCompatibleAlphaBitmap(const uno::Reference<rendering::XGraphicDevice> &,const geometry::IntegerSize2D & size)130     uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
131         const uno::Reference< rendering::XGraphicDevice >& 	/*rDevice*/,
132         const geometry::IntegerSize2D& 						size )
133     {
134         // disposed?
135         if( !mpSpriteCanvas )
136             return uno::Reference< rendering::XBitmap >(); // we're disposed
137 
138         return uno::Reference< rendering::XBitmap >(
139             new CanvasBitmap(
140                 ::basegfx::unotools::b2ISizeFromIntegerSize2D( size ),
141                 mpSpriteCanvas,
142                 true ));
143     }
144 
createVolatileAlphaBitmap(const uno::Reference<rendering::XGraphicDevice> &,const geometry::IntegerSize2D &)145     uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
146         const uno::Reference< rendering::XGraphicDevice >& 	/*rDevice*/,
147         const geometry::IntegerSize2D& 						/*size*/ )
148     {
149         return uno::Reference< rendering::XVolatileBitmap >();
150     }
151 
hasFullScreenMode()152     sal_Bool DeviceHelper::hasFullScreenMode()
153     {
154         // TODO(F3): offer fullscreen mode the XCanvas way
155         return false;
156     }
157 
enterFullScreenMode(sal_Bool)158     sal_Bool DeviceHelper::enterFullScreenMode( sal_Bool /*bEnter*/ )
159     {
160         // TODO(F3): offer fullscreen mode the XCanvas way
161         return false;
162     }
163 
createBuffers(::sal_Int32)164     ::sal_Int32 DeviceHelper::createBuffers( ::sal_Int32 /*nBuffers*/ )
165     {
166         // TODO(F3): implement XBufferStrategy interface. For now, we
167         // _always_ will have exactly one backbuffer
168         return 1;
169     }
170 
destroyBuffers()171     void DeviceHelper::destroyBuffers()
172     {
173         // TODO(F3): implement XBufferStrategy interface. For now, we
174         // _always_ will have exactly one backbuffer
175     }
176 
showBuffer(bool bIsVisible,::sal_Bool bUpdateAll)177     ::sal_Bool DeviceHelper::showBuffer( bool bIsVisible, ::sal_Bool bUpdateAll )
178     {
179         // forward to sprite canvas helper
180         if( !bIsVisible || !mpSpriteCanvas )
181             return false;
182 
183         return mpSpriteCanvas->updateScreen( bUpdateAll );
184     }
185 
switchBuffer(bool bIsVisible,::sal_Bool bUpdateAll)186     ::sal_Bool DeviceHelper::switchBuffer( bool bIsVisible, ::sal_Bool bUpdateAll )
187     {
188         // no difference for VCL canvas
189         return showBuffer( bIsVisible, bUpdateAll );
190     }
191 
isAccelerated() const192     uno::Any DeviceHelper::isAccelerated() const
193     {
194         return ::com::sun::star::uno::makeAny(false);
195     }
196 
getDeviceHandle() const197     uno::Any DeviceHelper::getDeviceHandle() const
198     {
199         return uno::Any();
200     }
201 
getSurfaceHandle() const202     uno::Any DeviceHelper::getSurfaceHandle() const
203     {
204         return uno::Any();
205     }
206 
207     namespace
208     {
209         struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>,
210                                                             DeviceColorSpace>
211         {
operator ()nullcanvas::__anond20fd21f0111::DeviceColorSpace212             uno::Reference<rendering::XColorSpace> operator()()
213             {
214                 return vcl::unotools::createStandardColorSpace();
215             }
216         };
217     }
218 
getColorSpace() const219     uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const
220     {
221         // always the same
222         return DeviceColorSpace::get();
223     }
224 
notifySizeUpdate(const awt::Rectangle &)225     void DeviceHelper::notifySizeUpdate( const awt::Rectangle& /*rBounds*/ )
226     {
227         // TODO
228     }
229 
dumpScreenContent() const230     void DeviceHelper::dumpScreenContent() const
231     {
232         OSL_TRACE( "%s\n",
233                    BOOST_CURRENT_FUNCTION );
234     }
235 }
236