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 
30 #include "cairo_cachedbitmap.hxx"
31 #include "cairo_repainttarget.hxx"
32 
33 #include <com/sun/star/rendering/RepaintResult.hpp>
34 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
35 
36 #include <basegfx/matrix/b2dhommatrix.hxx>
37 #include <basegfx/tools/canvastools.hxx>
38 
39 
40 using namespace ::cairo;
41 using namespace ::com::sun::star;
42 
43 namespace cairocanvas
44 {
CachedBitmap(const SurfaceSharedPtr & pSurface,const rendering::ViewState & rUsedViewState,const rendering::RenderState & rUsedRenderState,const uno::Reference<rendering::XCanvas> & rTarget)45     CachedBitmap::CachedBitmap( const SurfaceSharedPtr&                     pSurface,
46                                 const rendering::ViewState&	  				rUsedViewState,
47                                 const rendering::RenderState&	  			rUsedRenderState,
48                                 const uno::Reference< rendering::XCanvas >& rTarget ) :
49         CachedPrimitiveBase( rUsedViewState, rTarget, true ),
50         mpSurface( pSurface ),
51         maRenderState( rUsedRenderState )
52     {}
53 
disposing()54     void SAL_CALL CachedBitmap::disposing()
55     {
56         ::osl::MutexGuard aGuard( m_aMutex );
57 
58         mpSurface.reset();
59         CachedPrimitiveBase::disposing();
60     }
61 
doRedraw(const rendering::ViewState & rNewState,const rendering::ViewState &,const uno::Reference<rendering::XCanvas> & rTargetCanvas,bool bSameViewTransform)62     ::sal_Int8 CachedBitmap::doRedraw( const rendering::ViewState&					rNewState,
63                                        const rendering::ViewState&					/*rOldState*/,
64                                        const uno::Reference< rendering::XCanvas >& 	rTargetCanvas,
65                                        bool											bSameViewTransform )
66     {
67         ENSURE_OR_THROW( bSameViewTransform,
68                           "CachedBitmap::doRedraw(): base called with changed view transform "
69                           "(told otherwise during construction)" );
70 
71         RepaintTarget* pTarget = dynamic_cast< RepaintTarget* >(rTargetCanvas.get());
72 
73         ENSURE_OR_THROW( pTarget,
74                           "CachedBitmap::redraw(): cannot cast target to RepaintTarget" );
75 
76         if( !pTarget->repaint( mpSurface,
77                                rNewState,
78                                maRenderState ) )
79         {
80             // target failed to repaint
81             return rendering::RepaintResult::FAILED;
82         }
83 
84         return rendering::RepaintResult::REDRAWN;
85     }
86 }
87