LibreOffice Module canvas (master) 1
surfaceproxy.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21#include <sal/log.hxx>
22
26#include <utility>
27
28#include "surfaceproxy.hxx"
29
30namespace canvas
31{
32 SurfaceProxy::SurfaceProxy( std::shared_ptr<canvas::IColorBuffer> xBuffer,
33 PageManagerSharedPtr xPageManager ) :
34 mpPageManager(std::move( xPageManager )),
35 mpBuffer(std::move( xBuffer ))
36 {
37 const ::basegfx::B2ISize aImageSize(mpBuffer->getWidth(),mpBuffer->getHeight());
38 const ::basegfx::B2ISize aPageSize(mpPageManager->getPageSize());
39 const sal_Int32 aPageSizeX(aPageSize.getWidth());
40 const sal_Int32 aPageSizeY(aPageSize.getHeight());
41 const sal_Int32 aImageSizeX(aImageSize.getWidth());
42 const sal_Int32 aImageSizeY(aImageSize.getHeight());
43
44 // see if the size of the colorbuffer is larger than the size
45 // of a single page. if this is the case we divide the
46 // colorbuffer into as many surfaces as we need to get the
47 // whole area distributed. otherwise (the colorbuffer is
48 // smaller than the size of a single page) we search for free
49 // pages or create a new one.
50 // the incoming image is too large to fit into a single
51 // page. strategy: we split the image into rectangular
52 // areas that are as large as the maximum page size
53 // dictates and follow the strategy for fitting images.
54 size_t dwNumSurfaces(0);
55 for(sal_Int32 y=0; y<aImageSizeY; y+=aPageSizeY)
56 for(sal_Int32 x=0; x<aImageSizeX; x+=aPageSizeX)
57 ++dwNumSurfaces;
58 maSurfaceList.reserve(dwNumSurfaces);
59
60 for(sal_Int32 y=0; y<aImageSizeY; y+=aPageSizeY)
61 {
62 for(sal_Int32 x=0; x<aImageSizeX; x+=aPageSizeX)
63 {
64 // the current surface is located at the position [x,y]
65 // and has the size [min(restx,pagesizex),min(resty,pagesizey)
66 ::basegfx::B2IPoint aOffset(x,y);
67 ::basegfx::B2ISize aSize( std::min( aImageSize.getWidth()-x,
68 aPageSize.getWidth() ),
69 std::min( aImageSize.getHeight()-y,
70 aPageSize.getHeight() ) );
71
72 maSurfaceList.push_back(
73 std::make_shared<Surface>(
76 aOffset,
77 aSize));
78 }
79 }
80 }
81
83 {
84 for( const auto& rSurfacePtr : maSurfaceList )
85 rSurfacePtr->setColorBufferDirty();
86 }
87
88 bool SurfaceProxy::draw( double fAlpha,
89 const ::basegfx::B2DPoint& rPos,
90 const ::basegfx::B2DHomMatrix& rTransform )
91 {
92 for( const auto& rSurfacePtr : maSurfaceList )
93 rSurfacePtr->draw( fAlpha, rPos, rTransform );
94
95 return true;
96 }
97
98 bool SurfaceProxy::draw( double fAlpha,
99 const ::basegfx::B2DPoint& rPos,
100 const ::basegfx::B2DRange& rArea,
101 const ::basegfx::B2DHomMatrix& rTransform )
102 {
103 for( const auto& rSurfacePtr : maSurfaceList )
104 rSurfacePtr->drawRectangularArea( fAlpha, rPos, rArea, rTransform );
105
106 return true;
107 }
108
109 bool SurfaceProxy::draw( double fAlpha,
110 const ::basegfx::B2DPoint& rPos,
111 const ::basegfx::B2DPolyPolygon& rClipPoly,
112 const ::basegfx::B2DHomMatrix& rTransform )
113 {
114 const ::basegfx::triangulator::B2DTriangleVector& rTriangulatedVector(
115 ::basegfx::triangulator::triangulate(rClipPoly));
116
117 // we have now an explicit ::B2DTriangle and ::B2DTriangleVector,
118 // but I do not know enough about 'drawWithClip' or 'clipTriangleListOnRange'
119 // to adapt to that. Convert back to old three-point-in-polygon convention
120 ::basegfx::B2DPolygon aTriangulatedPolygon;
121 aTriangulatedPolygon.reserve(rTriangulatedVector.size() * 3);
122
123 for(const auto& rCandidate : rTriangulatedVector)
124 {
125 aTriangulatedPolygon.append(rCandidate.getA());
126 aTriangulatedPolygon.append(rCandidate.getB());
127 aTriangulatedPolygon.append(rCandidate.getC());
128 }
129
130 // dump polygons
131 SAL_INFO("canvas", "Original clip polygon: " << basegfx::utils::exportToSvgD( rClipPoly, true, true, false ));
132 SAL_INFO("canvas", "Triangulated polygon: " << basegfx::utils::exportToSvgD(basegfx::B2DPolyPolygon(aTriangulatedPolygon), true, true, false ));
133
134 for( const auto& rSurfacePtr : maSurfaceList )
135 rSurfacePtr->drawWithClip( fAlpha, rPos, aTriangulatedPolygon, rTransform );
136
137 return true;
138 }
139}
140
141/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
void reserve(sal_uInt32 nCount)
SurfaceProxy(std::shared_ptr< canvas::IColorBuffer > xBuffer, PageManagerSharedPtr xPageManager)
virtual void setColorBufferDirty() override
Notify the proxy that the color buffer has changed.
std::shared_ptr< canvas::IColorBuffer > mpBuffer
virtual bool draw(double fAlpha, const ::basegfx::B2DPoint &rPos, const ::basegfx::B2DHomMatrix &rTransform) override
Render the surface content to screen.
PageManagerSharedPtr mpPageManager
std::vector< SurfaceSharedPtr > maSurfaceList
float y
Definition: dx_9rm.cxx:190
float x
Definition: dx_9rm.cxx:190
#define SAL_INFO(area, stream)
OUString exportToSvgD(const B2DPolyPolygon &rPolyPoly, bool bUseRelativeCoordinates, bool bDetectQuadraticBeziers, bool bHandleRelativeNextPointCompatible, bool bOOXMLMotionPath=false)
std::shared_ptr< PageManager > PageManagerSharedPtr
Definition: pagemanager.hxx:73
PageManagerSharedPtr mpPageManager