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