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 : : #include <basegfx/tools/canvastools.hxx>
41 : : #include <basegfx/numeric/ftools.hxx>
42 : : #include <basegfx/polygon/b2dpolypolygontools.hxx>
43 : : #include <basegfx/polygon/b2dpolygontools.hxx>
44 : : #include <basegfx/polygon/b2dpolygontriangulator.hxx>
45 : : #include <basegfx/polygon/b2dpolygoncutandtouch.hxx>
46 : :
47 : : #include "cairo_canvascustomsprite.hxx"
48 : : #include "cairo_spritehelper.hxx"
49 : :
50 : : #include <memory>
51 : :
52 : :
53 : : using namespace ::cairo;
54 : : using namespace ::com::sun::star;
55 : :
56 : : namespace cairocanvas
57 : : {
58 : 0 : SpriteHelper::SpriteHelper() :
59 : : mpSpriteCanvas(),
60 : : mpBufferSurface(),
61 : 0 : mbTextureDirty(true)
62 : 0 : {}
63 : :
64 : 0 : void SpriteHelper::init( const geometry::RealSize2D& rSpriteSize,
65 : : const SpriteCanvasRef& rSpriteCanvas )
66 : : {
67 : 0 : ENSURE_OR_THROW( rSpriteCanvas.get(),
68 : : "SpriteHelper::init(): Invalid device, sprite canvas or surface" );
69 : :
70 : 0 : mpSpriteCanvas = rSpriteCanvas;
71 : 0 : mbTextureDirty = true;
72 : :
73 : : // also init base class
74 : : CanvasCustomSpriteHelper::init( rSpriteSize,
75 : 0 : rSpriteCanvas.get() );
76 : 0 : }
77 : :
78 : 0 : void SpriteHelper::setSurface( const SurfaceSharedPtr& pBufferSurface )
79 : : {
80 : 0 : mpBufferSurface = pBufferSurface;
81 : 0 : }
82 : :
83 : 0 : void SpriteHelper::disposing()
84 : : {
85 : 0 : mpBufferSurface.reset();
86 : 0 : mpSpriteCanvas.clear();
87 : :
88 : : // forward to parent
89 : 0 : CanvasCustomSpriteHelper::disposing();
90 : 0 : }
91 : :
92 : 0 : void SpriteHelper::redraw( const CairoSharedPtr& pCairo,
93 : : const ::basegfx::B2DPoint& rPos,
94 : : bool& /*io_bSurfacesDirty*/,
95 : : bool /*bBufferedUpdate*/ ) const
96 : : {
97 : : #ifdef CAIRO_CANVAS_PERF_TRACE
98 : : struct timespec aTimer;
99 : : mxDevice->startPerfTrace( &aTimer );
100 : : #endif
101 : :
102 : 0 : const double fAlpha( getAlpha() );
103 : 0 : const ::basegfx::B2DHomMatrix aTransform( getTransformation() );
104 : :
105 : 0 : if( isActive() && !::basegfx::fTools::equalZero( fAlpha ) )
106 : : {
107 : : OSL_TRACE ("CanvasCustomSprite::redraw called");
108 : 0 : if( pCairo )
109 : : {
110 : 0 : basegfx::B2DVector aSize = getSizePixel();
111 : 0 : cairo_save( pCairo.get() );
112 : :
113 : : double fX, fY;
114 : :
115 : 0 : fX = rPos.getX();
116 : 0 : fY = rPos.getY();
117 : :
118 : 0 : if( !aTransform.isIdentity() )
119 : : {
120 : : cairo_matrix_t aMatrix, aInverseMatrix;
121 : : cairo_matrix_init( &aMatrix,
122 : : aTransform.get( 0, 0 ), aTransform.get( 1, 0 ), aTransform.get( 0, 1 ),
123 : 0 : aTransform.get( 1, 1 ), aTransform.get( 0, 2 ), aTransform.get( 1, 2 ) );
124 : :
125 : 0 : aMatrix.x0 = basegfx::fround( aMatrix.x0 );
126 : 0 : aMatrix.y0 = basegfx::fround( aMatrix.y0 );
127 : :
128 : 0 : cairo_matrix_init( &aInverseMatrix, aMatrix.xx, aMatrix.yx, aMatrix.xy, aMatrix.yy, aMatrix.x0, aMatrix.y0 );
129 : 0 : cairo_matrix_invert( &aInverseMatrix );
130 : 0 : cairo_matrix_transform_distance( &aInverseMatrix, &fX, &fY );
131 : :
132 : 0 : cairo_set_matrix( pCairo.get(), &aMatrix );
133 : : }
134 : :
135 : 0 : fX = basegfx::fround( fX );
136 : 0 : fY = basegfx::fround( fY );
137 : :
138 : : cairo_matrix_t aOrigMatrix;
139 : 0 : cairo_get_matrix( pCairo.get(), &aOrigMatrix );
140 : 0 : cairo_translate( pCairo.get(), fX, fY );
141 : :
142 : 0 : if( getClip().is() )
143 : : {
144 : 0 : const uno::Reference<rendering::XPolyPolygon2D>& rClip( getClip() );
145 : :
146 : : ::basegfx::B2DPolyPolygon aClipPoly(
147 : : ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(
148 : 0 : rClip ));
149 : :
150 : : doPolyPolygonImplementation( aClipPoly, Clip, pCairo.get(),
151 : 0 : NULL, SurfaceProviderRef(mpSpriteCanvas.get()),
152 : 0 : rClip->getFillRule() );
153 : : }
154 : :
155 : : OSL_TRACE ("aSize %f x %f position: %f,%f", aSize.getX(), aSize.getY(), fX, fY );
156 : 0 : cairo_rectangle( pCairo.get(), 0, 0, floor( aSize.getX() ), floor( aSize.getY() ) );
157 : 0 : cairo_clip( pCairo.get() );
158 : 0 : cairo_set_matrix( pCairo.get(), &aOrigMatrix );
159 : :
160 : 0 : if( isContentFullyOpaque() )
161 : 0 : cairo_set_operator( pCairo.get(), CAIRO_OPERATOR_SOURCE );
162 : : cairo_set_source_surface( pCairo.get(),
163 : 0 : mpBufferSurface->getCairoSurface().get(),
164 : 0 : fX, fY );
165 : 0 : if( ::rtl::math::approxEqual( fAlpha, 1.0 ) )
166 : 0 : cairo_paint( pCairo.get() );
167 : : else
168 : 0 : cairo_paint_with_alpha( pCairo.get(), fAlpha );
169 : :
170 : 0 : cairo_restore( pCairo.get() );
171 : : }
172 : 0 : }
173 : :
174 : : #ifdef CAIRO_CANVAS_PERF_TRACE
175 : : mxDevice->stopPerfTrace( &aTimer, "sprite redraw" );
176 : : #endif
177 : 0 : }
178 : :
179 : 0 : ::basegfx::B2DPolyPolygon SpriteHelper::polyPolygonFromXPolyPolygon2D( uno::Reference< rendering::XPolyPolygon2D >& xPoly ) const
180 : : {
181 : 0 : return ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(xPoly);
182 : : }
183 : 0 : }
184 : :
185 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|