xref: /aoo41x/main/canvas/source/vcl/cachedbitmap.cxx (revision 25ea7f45)
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 "cachedbitmap.hxx"
31 #include "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 ::com::sun::star;
41 
42 namespace vclcanvas
43 {
CachedBitmap(const GraphicObjectSharedPtr & rGraphicObject,const::Point & rPoint,const::Size & rSize,const GraphicAttr & rAttr,const rendering::ViewState & rUsedViewState,const rendering::RenderState & rUsedRenderState,const uno::Reference<rendering::XCanvas> & rTarget)44     CachedBitmap::CachedBitmap( const GraphicObjectSharedPtr& 				rGraphicObject,
45                                 const ::Point& 								rPoint,
46                                 const ::Size& 								rSize,
47                                 const GraphicAttr&							rAttr,
48                                 const rendering::ViewState&	  				rUsedViewState,
49                                 const rendering::RenderState&	  			rUsedRenderState,
50                                 const uno::Reference< rendering::XCanvas >& rTarget ) :
51         CachedPrimitiveBase( rUsedViewState, rTarget, true ),
52         mpGraphicObject( rGraphicObject ),
53         maRenderState(rUsedRenderState),
54         maPoint( rPoint ),
55         maSize( rSize ),
56         maAttributes( rAttr )
57     {
58     }
59 
disposing()60     void SAL_CALL CachedBitmap::disposing()
61     {
62         ::osl::MutexGuard aGuard( m_aMutex );
63 
64         mpGraphicObject.reset();
65 
66         CachedPrimitiveBase::disposing();
67     }
68 
doRedraw(const rendering::ViewState & rNewState,const rendering::ViewState & rOldState,const uno::Reference<rendering::XCanvas> & rTargetCanvas,bool bSameViewTransform)69     ::sal_Int8 CachedBitmap::doRedraw( const rendering::ViewState&					rNewState,
70                                        const rendering::ViewState&					rOldState,
71                                        const uno::Reference< rendering::XCanvas >& 	rTargetCanvas,
72                                        bool											bSameViewTransform )
73     {
74         ENSURE_OR_THROW( bSameViewTransform,
75                          "CachedBitmap::doRedraw(): base called with changed view transform "
76                          "(told otherwise during construction)" );
77 
78         // TODO(P1): Could adapt to modified clips as well
79         if( rNewState.Clip != rOldState.Clip )
80             return rendering::RepaintResult::FAILED;
81 
82         RepaintTarget* pTarget = dynamic_cast< RepaintTarget* >(rTargetCanvas.get());
83 
84         ENSURE_OR_THROW( pTarget,
85                           "CachedBitmap::redraw(): cannot cast target to RepaintTarget" );
86 
87         if( !pTarget->repaint( mpGraphicObject,
88                                rNewState,
89                                maRenderState,
90                                maPoint,
91                                maSize,
92                                maAttributes ) )
93         {
94             // target failed to repaint
95             return rendering::RepaintResult::FAILED;
96         }
97 
98         return rendering::RepaintResult::REDRAWN;
99     }
100 }
101