diff options
author | Armin Le Grand <Armin.Le.Grand@cib.de> | 2018-09-15 13:48:12 +0200 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@cib.de> | 2018-09-20 20:01:07 +0200 |
commit | 66232248ff55639052ddb76918d555e21dc9c46b (patch) | |
tree | 57ab3314e473f12b1ba3f2594f13abeded3d4fed /canvas | |
parent | ad15354a7061b39d2ba22011a6d74b4ba2af4fae (diff) |
Support buffering SystemDependent GraphicData (III)
This change is for speedup of fat line drawing when using
X11. This is a long-term problem which never really progressed,
but is avoided using Cairo in the future. Still - if used,
speedup using current state and buffering possibilities.
Two speedup steps will be used:
(1) The tesselation is no longer done using trapezoids. That
works (but was done wrong leaving artifacts) but is not fast
and done every time. It is even not done with FatLines and
more than 1000 points.
New version will use triangulation. Dspite using the existing
triangulator (that works but is slow) extend the FatLine
geometry creator to directly create triangles.
This is also necessary since for buffering that data a
transformation-invariant version is needed (in device coordinates
the data changes all the time when scrolling). Trapezoids are
by definition *not* transformation-invariant (e.g. rotation)
(2) Buffer that triangulation - with the needed care and watch.
It is e.g. necessary to react on 'hairlines' since these change
their logical LineWidth view-dependent (zoom). In those cases, the
buffered data *has* to be removed due to the base for buffering is
the created FatLine geometry based on one stable logical LineWidth
Also took the time to adapt B2DPolygonTriangulator to use an
own data type (B2DTriangle) and a vector of these for better
understandability and security. Adapted all usages as needed.
Change-Id: Iedb2932b094a8786fd9c32d0d0ab1ca603a1a7b2
Reviewed-on: https://gerrit.libreoffice.org/60818
Tested-by: Jenkins
Reviewed-by: Armin Le Grand <Armin.Le.Grand@cib.de>
Diffstat (limited to 'canvas')
-rw-r--r-- | canvas/source/opengl/ogl_canvascustomsprite.cxx | 31 | ||||
-rw-r--r-- | canvas/source/opengl/ogl_canvastools.cxx | 29 | ||||
-rw-r--r-- | canvas/source/tools/surfaceproxy.cxx | 19 |
3 files changed, 63 insertions, 16 deletions
diff --git a/canvas/source/opengl/ogl_canvascustomsprite.cxx b/canvas/source/opengl/ogl_canvascustomsprite.cxx index 5f53ab4ece46..3cb5ec9fe217 100644 --- a/canvas/source/opengl/ogl_canvascustomsprite.cxx +++ b/canvas/source/opengl/ogl_canvascustomsprite.cxx @@ -191,18 +191,35 @@ namespace oglcanvas const double fHeight=maSize.Height; // TODO(P3): buffer triangulation - const ::basegfx::B2DPolygon& rTriangulatedPolygon( + const ::basegfx::triangulator::B2DTriangleVector rTriangulatedPolygon( ::basegfx::triangulator::triangulate( ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(mxClip))); glBegin(GL_TRIANGLES); - for( sal_uInt32 i=0; i<rTriangulatedPolygon.count(); i++ ) + for( size_t i=0; i<rTriangulatedPolygon.size(); i++ ) { - const ::basegfx::B2DPoint& rPt( rTriangulatedPolygon.getB2DPoint(i) ); - const double s(rPt.getX()/fWidth); - const double t(rPt.getY()/fHeight); - glTexCoord2f(s,t); glVertex2d(rPt.getX(), rPt.getY()); - } + const::basegfx::triangulator::B2DTriangle& rCandidate(rTriangulatedPolygon[i]); + glTexCoord2f( + rCandidate.getA().getX()/fWidth, + rCandidate.getA().getY()/fHeight); + glVertex2d( + rCandidate.getA().getX(), + rCandidate.getA().getY()); + + glTexCoord2f( + rCandidate.getB().getX()/fWidth, + rCandidate.getB().getY()/fHeight); + glVertex2d( + rCandidate.getB().getX(), + rCandidate.getB().getY()); + + glTexCoord2f( + rCandidate.getC().getX()/fWidth, + rCandidate.getC().getY()/fHeight); + glVertex2d( + rCandidate.getC().getX(), + rCandidate.getC().getY()); + } glEnd(); } else diff --git a/canvas/source/opengl/ogl_canvastools.cxx b/canvas/source/opengl/ogl_canvastools.cxx index cbf20db3a1e5..56fa47fbf303 100644 --- a/canvas/source/opengl/ogl_canvastools.cxx +++ b/canvas/source/opengl/ogl_canvastools.cxx @@ -35,15 +35,32 @@ namespace oglcanvas const ::basegfx::B2DRange& rBounds(aPolyPoly.getB2DRange()); const double nWidth=rBounds.getWidth(); const double nHeight=rBounds.getHeight(); - const ::basegfx::B2DPolygon& rTriangulatedPolygon( + const ::basegfx::triangulator::B2DTriangleVector rTriangulatedPolygon( ::basegfx::triangulator::triangulate(aPolyPoly)); - for( sal_uInt32 i=0; i<rTriangulatedPolygon.count(); i++ ) + for( size_t i=0; i<rTriangulatedPolygon.size(); i++ ) { - const ::basegfx::B2DPoint& rPt( rTriangulatedPolygon.getB2DPoint(i) ); - const double s(rPt.getX()/nWidth); - const double t(rPt.getY()/nHeight); - glTexCoord2f(s,t); glVertex2d(rPt.getX(), rPt.getY()); + const::basegfx::triangulator::B2DTriangle& rCandidate(rTriangulatedPolygon[i]); + glTexCoord2f( + rCandidate.getA().getX()/nWidth, + rCandidate.getA().getY()/nHeight); + glVertex2d( + rCandidate.getA().getX(), + rCandidate.getA().getY()); + + glTexCoord2f( + rCandidate.getB().getX()/nWidth, + rCandidate.getB().getY()/nHeight); + glVertex2d( + rCandidate.getB().getX(), + rCandidate.getB().getY()); + + glTexCoord2f( + rCandidate.getC().getX()/nWidth, + rCandidate.getC().getY()/nHeight); + glVertex2d( + rCandidate.getC().getX(), + rCandidate.getC().getY()); } } diff --git a/canvas/source/tools/surfaceproxy.cxx b/canvas/source/tools/surfaceproxy.cxx index 5c1bff2a5950..164fb781b4d9 100644 --- a/canvas/source/tools/surfaceproxy.cxx +++ b/canvas/source/tools/surfaceproxy.cxx @@ -111,15 +111,28 @@ namespace canvas const ::basegfx::B2DPolyPolygon& rClipPoly, const ::basegfx::B2DHomMatrix& rTransform ) { - const ::basegfx::B2DPolygon& rTriangulatedPolygon( + const ::basegfx::triangulator::B2DTriangleVector& rTriangulatedVector( ::basegfx::triangulator::triangulate(rClipPoly)); + // we have now an explicit ::B2DTriangle and ::B2DTriangleVector, + // but I do not know enough about 'drawWithClip' or 'clipTriangleListOnRange' + // to adapt to that. Convert back to old three-point-in-polygon convention + ::basegfx::B2DPolygon aTriangulatedPolygon; + aTriangulatedPolygon.reserve(rTriangulatedVector.size() * 3); + + for(const auto& rCandidate : rTriangulatedVector) + { + aTriangulatedPolygon.append(rCandidate.getA()); + aTriangulatedPolygon.append(rCandidate.getB()); + aTriangulatedPolygon.append(rCandidate.getC()); + } + // dump polygons SAL_INFO("canvas", "Original clip polygon: " << basegfx::utils::exportToSvgD( rClipPoly, true, true, false )); - SAL_INFO("canvas", "Triangulated polygon: " << basegfx::utils::exportToSvgD(basegfx::B2DPolyPolygon(rTriangulatedPolygon), true, true, false )); + SAL_INFO("canvas", "Triangulated polygon: " << basegfx::utils::exportToSvgD(basegfx::B2DPolyPolygon(aTriangulatedPolygon), true, true, false )); for( const auto& rSurfacePtr : maSurfaceList ) - rSurfacePtr->drawWithClip( fAlpha, rPos, rTriangulatedPolygon, rTransform ); + rSurfacePtr->drawWithClip( fAlpha, rPos, aTriangulatedPolygon, rTransform ); return true; } |