Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <canvas/debug.hxx>
30 : : #include <canvas/verbosetrace.hxx>
31 : : #include <tools/diagnose_ex.h>
32 : :
33 : : #include <rtl/logfile.hxx>
34 : : #include <rtl/math.hxx>
35 : :
36 : : #include <canvas/canvastools.hxx>
37 : :
38 : : #include <basegfx/matrix/b2dhommatrix.hxx>
39 : : #include <basegfx/point/b2dpoint.hxx>
40 : :
41 : : #include "cairo_canvascustomsprite.hxx"
42 : : #include "cairo_spritecanvas.hxx"
43 : :
44 : :
45 : : using namespace ::cairo;
46 : : using namespace ::com::sun::star;
47 : :
48 : : namespace cairocanvas
49 : : {
50 : 0 : CanvasCustomSprite::CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D& rSpriteSize,
51 : : const SpriteCanvasRef& rRefDevice ) :
52 : : mpSpriteCanvas( rRefDevice ),
53 : : maSize( ::canvas::tools::roundUp( rSpriteSize.Width ),
54 : 0 : ::canvas::tools::roundUp( rSpriteSize.Height ) )
55 : : {
56 : 0 : ENSURE_OR_THROW( rRefDevice.get(),
57 : : "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
58 : :
59 : : OSL_TRACE("sprite size: %d, %d",
60 : : ::canvas::tools::roundUp( rSpriteSize.Width ),
61 : : ::canvas::tools::roundUp( rSpriteSize.Height ));
62 : :
63 : 0 : mpBufferSurface = mpSpriteCanvas->createSurface( maSize );
64 : :
65 : : maCanvasHelper.init( maSize,
66 : 0 : *rRefDevice,
67 : 0 : rRefDevice.get() );
68 : 0 : maCanvasHelper.setSurface( mpBufferSurface, true );
69 : :
70 : : maSpriteHelper.init( rSpriteSize,
71 : 0 : rRefDevice );
72 : 0 : maSpriteHelper.setSurface( mpBufferSurface );
73 : :
74 : : // clear sprite to 100% transparent
75 : 0 : maCanvasHelper.clear();
76 : 0 : }
77 : :
78 : 0 : void CanvasCustomSprite::disposeThis()
79 : : {
80 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
81 : :
82 : 0 : mpSpriteCanvas.clear();
83 : 0 : mpBufferSurface.reset();
84 : :
85 : : // forward to parent
86 : 0 : CanvasCustomSpriteBaseT::disposeThis();
87 : 0 : }
88 : :
89 : 0 : void CanvasCustomSprite::redraw( const CairoSharedPtr& pCairo,
90 : : bool bBufferedUpdate ) const
91 : : {
92 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
93 : :
94 : 0 : redraw( pCairo, maSpriteHelper.getPosPixel(), bBufferedUpdate );
95 : 0 : }
96 : :
97 : 0 : void CanvasCustomSprite::redraw( const CairoSharedPtr& pCairo,
98 : : const ::basegfx::B2DPoint& rOrigOutputPos,
99 : : bool bBufferedUpdate ) const
100 : : {
101 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
102 : :
103 : : maSpriteHelper.redraw( pCairo,
104 : : rOrigOutputPos,
105 : : mbSurfaceDirty,
106 : 0 : bBufferedUpdate );
107 : :
108 : 0 : mbSurfaceDirty = false;
109 : 0 : }
110 : :
111 : 0 : bool CanvasCustomSprite::repaint( const SurfaceSharedPtr& pSurface,
112 : : const rendering::ViewState& viewState,
113 : : const rendering::RenderState& renderState )
114 : : {
115 : 0 : return maCanvasHelper.repaint( pSurface, viewState, renderState );
116 : : }
117 : :
118 : 0 : SurfaceSharedPtr CanvasCustomSprite::getSurface()
119 : : {
120 : 0 : return mpBufferSurface;
121 : : }
122 : :
123 : 0 : SurfaceSharedPtr CanvasCustomSprite::createSurface( const ::basegfx::B2ISize& rSize, Content aContent )
124 : : {
125 : 0 : return mpSpriteCanvas->createSurface(rSize,aContent);
126 : : }
127 : :
128 : 0 : SurfaceSharedPtr CanvasCustomSprite::createSurface( ::Bitmap& rBitmap )
129 : : {
130 : 0 : return mpSpriteCanvas->createSurface(rBitmap);
131 : : }
132 : :
133 : 0 : SurfaceSharedPtr CanvasCustomSprite::changeSurface( bool bHasAlpha, bool bCopyContent )
134 : : {
135 : 0 : if( !bHasAlpha && !bCopyContent )
136 : : {
137 : : OSL_TRACE("replacing sprite background surface");
138 : :
139 : 0 : mpBufferSurface = mpSpriteCanvas->createSurface( maSize, CAIRO_CONTENT_COLOR );
140 : 0 : maSpriteHelper.setSurface( mpBufferSurface );
141 : :
142 : 0 : return mpBufferSurface;
143 : : }
144 : :
145 : 0 : return SurfaceSharedPtr();
146 : : }
147 : :
148 : 0 : OutputDevice* CanvasCustomSprite::getOutputDevice()
149 : : {
150 : 0 : return mpSpriteCanvas->getOutputDevice();
151 : : }
152 : :
153 : : #define IMPLEMENTATION_NAME "CairoCanvas.CanvasCustomSprite"
154 : : #define SERVICE_NAME "com.sun.star.rendering.CanvasCustomSprite"
155 : :
156 : 0 : ::rtl::OUString SAL_CALL CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException )
157 : : {
158 : 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
159 : : }
160 : :
161 : 0 : sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
162 : : {
163 : 0 : return ServiceName == SERVICE_NAME;
164 : : }
165 : :
166 : 0 : uno::Sequence< ::rtl::OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames() throw( uno::RuntimeException )
167 : : {
168 : 0 : uno::Sequence< ::rtl::OUString > aRet(1);
169 : 0 : aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
170 : :
171 : 0 : return aRet;
172 : : }
173 : 0 : }
174 : :
175 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|