xref: /trunk/main/canvas/source/vcl/cachedbitmap.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_canvas.hxx"
30 
31 #include <canvas/debug.hxx>
32 #include <tools/diagnose_ex.h>
33 
34 #include "cachedbitmap.hxx"
35 #include "repainttarget.hxx"
36 
37 #include <com/sun/star/rendering/RepaintResult.hpp>
38 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
39 
40 #include <basegfx/matrix/b2dhommatrix.hxx>
41 #include <basegfx/tools/canvastools.hxx>
42 
43 
44 using namespace ::com::sun::star;
45 
46 namespace vclcanvas
47 {
48     CachedBitmap::CachedBitmap( const GraphicObjectSharedPtr& 				rGraphicObject,
49                                 const ::Point& 								rPoint,
50                                 const ::Size& 								rSize,
51                                 const GraphicAttr&							rAttr,
52                                 const rendering::ViewState&	  				rUsedViewState,
53                                 const rendering::RenderState&	  			rUsedRenderState,
54                                 const uno::Reference< rendering::XCanvas >& rTarget ) :
55         CachedPrimitiveBase( rUsedViewState, rTarget, true ),
56         mpGraphicObject( rGraphicObject ),
57         maRenderState(rUsedRenderState),
58         maPoint( rPoint ),
59         maSize( rSize ),
60         maAttributes( rAttr )
61     {
62     }
63 
64     void SAL_CALL CachedBitmap::disposing()
65     {
66         ::osl::MutexGuard aGuard( m_aMutex );
67 
68         mpGraphicObject.reset();
69 
70         CachedPrimitiveBase::disposing();
71     }
72 
73     ::sal_Int8 CachedBitmap::doRedraw( const rendering::ViewState&					rNewState,
74                                        const rendering::ViewState&					rOldState,
75                                        const uno::Reference< rendering::XCanvas >& 	rTargetCanvas,
76                                        bool											bSameViewTransform )
77     {
78         ENSURE_OR_THROW( bSameViewTransform,
79                          "CachedBitmap::doRedraw(): base called with changed view transform "
80                          "(told otherwise during construction)" );
81 
82         // TODO(P1): Could adapt to modified clips as well
83         if( rNewState.Clip != rOldState.Clip )
84             return rendering::RepaintResult::FAILED;
85 
86         RepaintTarget* pTarget = dynamic_cast< RepaintTarget* >(rTargetCanvas.get());
87 
88         ENSURE_OR_THROW( pTarget,
89                           "CachedBitmap::redraw(): cannot cast target to RepaintTarget" );
90 
91         if( !pTarget->repaint( mpGraphicObject,
92                                rNewState,
93                                maRenderState,
94                                maPoint,
95                                maSize,
96                                maAttributes ) )
97         {
98             // target failed to repaint
99             return rendering::RepaintResult::FAILED;
100         }
101 
102         return rendering::RepaintResult::REDRAWN;
103     }
104 }
105