fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / canvas / source / directx / dx_spritehelper.cxx
blob9e14f4c015c701bdaa62471b4d053000e8e5c296
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <ctype.h> // don't ask. msdev breaks otherwise...
22 #include <canvas/debug.hxx>
23 #include <canvas/verbosetrace.hxx>
24 #include <tools/diagnose_ex.h>
26 #include <rtl/logfile.hxx>
27 #include <rtl/math.hxx>
29 #include <canvas/canvastools.hxx>
31 #include <basegfx/matrix/b2dhommatrix.hxx>
32 #include <basegfx/point/b2dpoint.hxx>
33 #include <basegfx/tools/canvastools.hxx>
34 #include <basegfx/numeric/ftools.hxx>
35 #include <basegfx/polygon/b2dpolypolygontools.hxx>
36 #include <basegfx/polygon/b2dpolygontools.hxx>
37 #include <basegfx/polygon/b2dpolygontriangulator.hxx>
38 #include <basegfx/polygon/b2dpolygoncutandtouch.hxx>
40 #include "dx_canvascustomsprite.hxx"
41 #include "dx_spritehelper.hxx"
42 #include "dx_impltools.hxx"
44 #include <memory>
46 using namespace ::com::sun::star;
48 namespace dxcanvas
50 SpriteHelper::SpriteHelper() :
51 mpSpriteCanvas(),
52 mpBitmap(),
53 mbTextureDirty( true ),
54 mbShowSpriteBounds( false )
58 void SpriteHelper::init( const geometry::RealSize2D& rSpriteSize,
59 const SpriteCanvasRef& rSpriteCanvas,
60 const IDXRenderModuleSharedPtr& rRenderModule,
61 const DXSurfaceBitmapSharedPtr rBitmap,
62 bool bShowSpriteBounds )
64 ENSURE_OR_THROW( rSpriteCanvas.get() &&
65 rRenderModule &&
66 rBitmap,
67 "SpriteHelper::init(): Invalid device, sprite canvas or surface" );
69 mpSpriteCanvas = rSpriteCanvas;
70 mpBitmap = rBitmap;
71 mbTextureDirty = true;
72 mbShowSpriteBounds = bShowSpriteBounds;
74 // also init base class
75 CanvasCustomSpriteHelper::init( rSpriteSize,
76 rSpriteCanvas.get() );
79 void SpriteHelper::disposing()
81 mpBitmap.reset();
82 mpSpriteCanvas.clear();
84 // forward to parent
85 CanvasCustomSpriteHelper::disposing();
88 ::basegfx::B2DPolyPolygon SpriteHelper::polyPolygonFromXPolyPolygon2D( uno::Reference< rendering::XPolyPolygon2D >& xPoly ) const
90 return tools::polyPolygonFromXPolyPolygon2D( xPoly );
93 bool SpriteHelper::needRedraw() const
95 if( !mpBitmap ||
96 !mpSpriteCanvas.get() )
98 return false; // we're disposed, no redraw necessary
101 if( !isActive() ||
102 ::basegfx::fTools::equalZero( getAlpha() ) )
104 return false; // sprite is invisible
107 return true;
110 void SpriteHelper::redraw( bool& io_bSurfaceDirty ) const
112 if( !mpBitmap ||
113 !mpSpriteCanvas.get() )
115 return; // we're disposed
118 const ::basegfx::B2DPoint& rPos( getPosPixel() );
119 const double fAlpha( getAlpha() );
121 if( isActive() &&
122 !::basegfx::fTools::equalZero( fAlpha ) )
125 // TODO(Q2): For the time being, Device does not take a target
126 // surface, but always unconditionally renders to the
127 // background buffer.
129 // log output pos in device pixel
130 VERBOSE_TRACE( "SpriteHelper::redraw(): output pos is (%f, %f)",
131 rPos.getX(),
132 rPos.getY() );
134 const double fAlpha( getAlpha() );
135 const ::basegfx::B2DVector& rSize( getSizePixel() );
136 const ::basegfx::B2DHomMatrix& rTransform( getTransformation() );
137 const uno::Reference< rendering::XPolyPolygon2D >& xClip( getClip() );
139 mbTextureDirty = false;
140 io_bSurfaceDirty = false; // state taken, and processed.
142 ::basegfx::B2DPolyPolygon aClipPath; // empty for no clip
143 bool bIsClipRectangular( false ); // false, if no
144 // clip, or clip
145 // is complex
147 // setup and apply clip (if any)
148 // =================================
150 if( xClip.is() )
152 aClipPath = tools::polyPolygonFromXPolyPolygon2D( xClip );
154 const sal_Int32 nNumClipPolygons( aClipPath.count() );
155 if( nNumClipPolygons )
157 // TODO(P2): hold rectangle attribute directly
158 // at the XPolyPolygon2D
160 // check whether the clip is rectangular
161 if( nNumClipPolygons == 1 )
162 if( ::basegfx::tools::isRectangle( aClipPath.getB2DPolygon( 0 ) ) )
163 bIsClipRectangular = true;
167 const ::basegfx::B2DRectangle aSourceRect( 0.0,
168 0.0,
169 rSize.getX(),
170 rSize.getY() );
172 // draw simple rectangular area if no clip is set.
173 if( !aClipPath.count() )
175 mpBitmap->draw(fAlpha,rPos,rTransform);
177 else if( bIsClipRectangular )
179 // apply a simple rect clip
180 // ========================
182 ::basegfx::B2DRectangle aClipBounds(
183 ::basegfx::tools::getRange( aClipPath ) );
184 aClipBounds.intersect( aSourceRect );
186 mpBitmap->draw(fAlpha,rPos,aClipBounds,rTransform);
188 else
190 // apply clip the hard way
191 // =======================
193 mpBitmap->draw(fAlpha,rPos,aClipPath,rTransform);
196 if( mbShowSpriteBounds )
198 if( aClipPath.count() )
200 // TODO(F2): Re-enable debug output
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */