xref: /AOO41X/main/canvas/source/null/null_spritecanvas.cxx (revision 25ea7f451e822ec0589487f23a9b6cc31f03fcc3)
1*25ea7f45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*25ea7f45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*25ea7f45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*25ea7f45SAndrew Rist  * distributed with this work for additional information
6*25ea7f45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*25ea7f45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*25ea7f45SAndrew Rist  * "License"); you may not use this file except in compliance
9*25ea7f45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*25ea7f45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*25ea7f45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*25ea7f45SAndrew Rist  * software distributed under the License is distributed on an
15*25ea7f45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*25ea7f45SAndrew Rist  * KIND, either express or implied.  See the License for the
17*25ea7f45SAndrew Rist  * specific language governing permissions and limitations
18*25ea7f45SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*25ea7f45SAndrew Rist  *************************************************************/
21*25ea7f45SAndrew Rist 
22*25ea7f45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_canvas.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <canvas/debug.hxx>
28cdf0e10cSrcweir #include <tools/diagnose_ex.h>
29cdf0e10cSrcweir #include <canvas/verbosetrace.hxx>
30cdf0e10cSrcweir #include <canvas/canvastools.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <osl/mutex.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp>
35cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
36cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
39cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx>
40cdf0e10cSrcweir #include <comphelper/servicedecl.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
43cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
44cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
45cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #include "null_spritecanvas.hxx"
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 
50cdf0e10cSrcweir using namespace ::com::sun::star;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.rendering.NullCanvas"
53cdf0e10cSrcweir 
54cdf0e10cSrcweir namespace nullcanvas
55cdf0e10cSrcweir {
SpriteCanvas(const uno::Sequence<uno::Any> & aArguments,const uno::Reference<uno::XComponentContext> & rxContext)56cdf0e10cSrcweir     SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >&                aArguments,
57cdf0e10cSrcweir                                 const uno::Reference< uno::XComponentContext >& rxContext ) :
58cdf0e10cSrcweir         maArguments(aArguments),
59cdf0e10cSrcweir         mxComponentContext( rxContext )
60cdf0e10cSrcweir     {
61cdf0e10cSrcweir     }
62cdf0e10cSrcweir 
initialize()63cdf0e10cSrcweir     void SpriteCanvas::initialize()
64cdf0e10cSrcweir     {
65cdf0e10cSrcweir         // #i64742# Only call initialize when not in probe mode
66cdf0e10cSrcweir         if( maArguments.getLength() == 0 )
67cdf0e10cSrcweir             return;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir         VERBOSE_TRACE( "SpriteCanvas::initialize called" );
70cdf0e10cSrcweir 
71cdf0e10cSrcweir         // At index 1, we expect a system window handle here,
72cdf0e10cSrcweir         // containing a pointer to a valid window, on which to output
73cdf0e10cSrcweir         // At index 2, we expect the current window bound rect
74cdf0e10cSrcweir         ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
75cdf0e10cSrcweir                              maArguments[1].getValueTypeClass() == uno::TypeClass_LONG,
76cdf0e10cSrcweir                              "SpriteCanvas::initialize: wrong number of arguments, or wrong types" );
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         awt::Rectangle aRect;
79cdf0e10cSrcweir         maArguments[2] >>= aRect;
80cdf0e10cSrcweir         const ::basegfx::B2ISize aSize(aRect.Width,
81cdf0e10cSrcweir                                        aRect.Height);
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         sal_Bool bIsFullscreen( sal_False );
84cdf0e10cSrcweir         maArguments[3] >>= bIsFullscreen;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir         // setup helper
87cdf0e10cSrcweir         maDeviceHelper.init( *this,
88cdf0e10cSrcweir                              aSize,
89cdf0e10cSrcweir                              bIsFullscreen );
90cdf0e10cSrcweir         maCanvasHelper.init( maRedrawManager,
91cdf0e10cSrcweir                              *this,
92cdf0e10cSrcweir                              aSize,
93cdf0e10cSrcweir                              false );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         maArguments.realloc(0);
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir 
disposing()98cdf0e10cSrcweir     void SAL_CALL SpriteCanvas::disposing()
99cdf0e10cSrcweir     {
100cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         mxComponentContext.clear();
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         // forward to parent
105cdf0e10cSrcweir         SpriteCanvasBaseT::disposing();
106cdf0e10cSrcweir     }
107cdf0e10cSrcweir 
showBuffer(::sal_Bool bUpdateAll)108cdf0e10cSrcweir     ::sal_Bool SAL_CALL SpriteCanvas::showBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
109cdf0e10cSrcweir     {
110cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir         // avoid repaints on hidden window (hidden: not mapped to
113cdf0e10cSrcweir         // screen). Return failure, since the screen really has _not_
114cdf0e10cSrcweir         // been updated (caller should try again later)
115cdf0e10cSrcweir         return !mbIsVisible ? false : SpriteCanvasBaseT::showBuffer( bUpdateAll );
116cdf0e10cSrcweir     }
117cdf0e10cSrcweir 
switchBuffer(::sal_Bool bUpdateAll)118cdf0e10cSrcweir     ::sal_Bool SAL_CALL SpriteCanvas::switchBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
119cdf0e10cSrcweir     {
120cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         // avoid repaints on hidden window (hidden: not mapped to
123cdf0e10cSrcweir         // screen). Return failure, since the screen really has _not_
124cdf0e10cSrcweir         // been updated (caller should try again later)
125cdf0e10cSrcweir         return !mbIsVisible ? false : SpriteCanvasBaseT::switchBuffer( bUpdateAll );
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir 
updateScreen(sal_Bool bUpdateAll)128cdf0e10cSrcweir     sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll ) throw (uno::RuntimeException)
129cdf0e10cSrcweir     {
130cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir         // avoid repaints on hidden window (hidden: not mapped to
133cdf0e10cSrcweir         // screen). Return failure, since the screen really has _not_
134cdf0e10cSrcweir         // been updated (caller should try again later)
135cdf0e10cSrcweir         return !mbIsVisible ? false : maCanvasHelper.updateScreen(
136cdf0e10cSrcweir             ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds),
137cdf0e10cSrcweir             bUpdateAll,
138cdf0e10cSrcweir             mbSurfaceDirty );
139cdf0e10cSrcweir     }
140cdf0e10cSrcweir 
getServiceName()141cdf0e10cSrcweir     ::rtl::OUString SAL_CALL SpriteCanvas::getServiceName(  ) throw (uno::RuntimeException)
142cdf0e10cSrcweir     {
143cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir 
initCanvas(SpriteCanvas * pCanvas)146cdf0e10cSrcweir     static uno::Reference<uno::XInterface> initCanvas( SpriteCanvas* pCanvas )
147cdf0e10cSrcweir     {
148cdf0e10cSrcweir         uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas));
149cdf0e10cSrcweir         pCanvas->initialize();
150cdf0e10cSrcweir         return xRet;
151cdf0e10cSrcweir     }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     namespace sdecl = comphelper::service_decl;
154cdf0e10cSrcweir     sdecl::class_<SpriteCanvas, sdecl::with_args<true> > serviceImpl(&initCanvas);
155cdf0e10cSrcweir     const sdecl::ServiceDecl nullCanvasDecl(
156cdf0e10cSrcweir         serviceImpl,
157cdf0e10cSrcweir         "com.sun.star.comp.rendering.NullCanvas",
158cdf0e10cSrcweir         SERVICE_NAME );
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir // The C shared lib entry points
162cdf0e10cSrcweir COMPHELPER_SERVICEDECL_EXPORTS1(nullcanvas::nullCanvasDecl)
163