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 <tools/diagnose_ex.h>
29 #include <canvas/verbosetrace.hxx>
30 #include <canvas/canvastools.hxx>
31 
32 #include <osl/mutex.hxx>
33 
34 #include <com/sun/star/registry/XRegistryKey.hpp>
35 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
36 #include <com/sun/star/uno/XComponentContext.hpp>
37 
38 #include <cppuhelper/factory.hxx>
39 #include <cppuhelper/implementationentry.hxx>
40 #include <comphelper/servicedecl.hxx>
41 
42 #include <basegfx/matrix/b2dhommatrix.hxx>
43 #include <basegfx/point/b2dpoint.hxx>
44 #include <basegfx/tools/canvastools.hxx>
45 #include <basegfx/numeric/ftools.hxx>
46 
47 #include "null_spritecanvas.hxx"
48 
49 
50 using namespace ::com::sun::star;
51 
52 #define SERVICE_NAME "com.sun.star.rendering.NullCanvas"
53 
54 namespace nullcanvas
55 {
SpriteCanvas(const uno::Sequence<uno::Any> & aArguments,const uno::Reference<uno::XComponentContext> & rxContext)56     SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >&                aArguments,
57                                 const uno::Reference< uno::XComponentContext >& rxContext ) :
58         maArguments(aArguments),
59         mxComponentContext( rxContext )
60     {
61     }
62 
initialize()63     void SpriteCanvas::initialize()
64     {
65         // #i64742# Only call initialize when not in probe mode
66         if( maArguments.getLength() == 0 )
67             return;
68 
69         VERBOSE_TRACE( "SpriteCanvas::initialize called" );
70 
71         // At index 1, we expect a system window handle here,
72         // containing a pointer to a valid window, on which to output
73         // At index 2, we expect the current window bound rect
74         ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
75                              maArguments[1].getValueTypeClass() == uno::TypeClass_LONG,
76                              "SpriteCanvas::initialize: wrong number of arguments, or wrong types" );
77 
78         awt::Rectangle aRect;
79         maArguments[2] >>= aRect;
80         const ::basegfx::B2ISize aSize(aRect.Width,
81                                        aRect.Height);
82 
83         sal_Bool bIsFullscreen( sal_False );
84         maArguments[3] >>= bIsFullscreen;
85 
86         // setup helper
87         maDeviceHelper.init( *this,
88                              aSize,
89                              bIsFullscreen );
90         maCanvasHelper.init( maRedrawManager,
91                              *this,
92                              aSize,
93                              false );
94 
95         maArguments.realloc(0);
96     }
97 
disposing()98     void SAL_CALL SpriteCanvas::disposing()
99     {
100         ::osl::MutexGuard aGuard( m_aMutex );
101 
102         mxComponentContext.clear();
103 
104         // forward to parent
105         SpriteCanvasBaseT::disposing();
106     }
107 
showBuffer(::sal_Bool bUpdateAll)108     ::sal_Bool SAL_CALL SpriteCanvas::showBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
109     {
110         ::osl::MutexGuard aGuard( m_aMutex );
111 
112         // avoid repaints on hidden window (hidden: not mapped to
113         // screen). Return failure, since the screen really has _not_
114         // been updated (caller should try again later)
115         return !mbIsVisible ? false : SpriteCanvasBaseT::showBuffer( bUpdateAll );
116     }
117 
switchBuffer(::sal_Bool bUpdateAll)118     ::sal_Bool SAL_CALL SpriteCanvas::switchBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
119     {
120         ::osl::MutexGuard aGuard( m_aMutex );
121 
122         // avoid repaints on hidden window (hidden: not mapped to
123         // screen). Return failure, since the screen really has _not_
124         // been updated (caller should try again later)
125         return !mbIsVisible ? false : SpriteCanvasBaseT::switchBuffer( bUpdateAll );
126     }
127 
updateScreen(sal_Bool bUpdateAll)128     sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll ) throw (uno::RuntimeException)
129     {
130         ::osl::MutexGuard aGuard( m_aMutex );
131 
132         // avoid repaints on hidden window (hidden: not mapped to
133         // screen). Return failure, since the screen really has _not_
134         // been updated (caller should try again later)
135         return !mbIsVisible ? false : maCanvasHelper.updateScreen(
136             ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds),
137             bUpdateAll,
138             mbSurfaceDirty );
139     }
140 
getServiceName()141     ::rtl::OUString SAL_CALL SpriteCanvas::getServiceName(  ) throw (uno::RuntimeException)
142     {
143         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
144     }
145 
initCanvas(SpriteCanvas * pCanvas)146     static uno::Reference<uno::XInterface> initCanvas( SpriteCanvas* pCanvas )
147     {
148         uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas));
149         pCanvas->initialize();
150         return xRet;
151     }
152 
153     namespace sdecl = comphelper::service_decl;
154     sdecl::class_<SpriteCanvas, sdecl::with_args<true> > serviceImpl(&initCanvas);
155     const sdecl::ServiceDecl nullCanvasDecl(
156         serviceImpl,
157         "com.sun.star.comp.rendering.NullCanvas",
158         SERVICE_NAME );
159 }
160 
161 // The C shared lib entry points
162 COMPHELPER_SERVICEDECL_EXPORTS1(nullcanvas::nullCanvasDecl)
163