Line data Source code
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 :
21 : #include <boost/bind.hpp>
22 : #include <basegfx/polygon/b2dpolygoncutandtouch.hxx>
23 : #include <basegfx/polygon/b2dpolygontriangulator.hxx>
24 : #include <basegfx/polygon/b2dpolypolygontools.hxx>
25 : #include "surfaceproxy.hxx"
26 :
27 : namespace canvas
28 : {
29 :
30 : // SurfaceProxy::SurfaceProxy
31 :
32 :
33 0 : SurfaceProxy::SurfaceProxy( const canvas::IColorBufferSharedPtr& pBuffer,
34 : const PageManagerSharedPtr& pPageManager ) :
35 : mpPageManager( pPageManager ),
36 : maSurfaceList(),
37 0 : mpBuffer( pBuffer )
38 : {
39 0 : const ::basegfx::B2ISize aImageSize(mpBuffer->getWidth(),mpBuffer->getHeight());
40 0 : const ::basegfx::B2ISize aPageSize(mpPageManager->getPageSize());
41 0 : const sal_Int32 aPageSizeX(aPageSize.getX());
42 0 : const sal_Int32 aPageSizeY(aPageSize.getY());
43 0 : const sal_Int32 aImageSizeX(aImageSize.getX());
44 0 : const sal_Int32 aImageSizeY(aImageSize.getY());
45 :
46 : // see if the size of the colorbuffer is larger than the size
47 : // of a single page. if this is the case we divide the
48 : // colorbuffer into as many surfaces as we need to get the
49 : // whole area distributed. otherwise (the colorbuffer is
50 : // smaller than the size of a single page) we search for free
51 : // pages or create a new one.
52 : // the incoming image is too large to fit into a single
53 : // page. strategy: we split the image into rectangular
54 : // areas that are as large as the maximum page size
55 : // dictates and follow the strategy for fitting images.
56 0 : size_t dwNumSurfaces(0);
57 0 : for(sal_Int32 y=0; y<aImageSizeY; y+=aPageSizeY)
58 0 : for(sal_Int32 x=0; x<aImageSizeX; x+=aPageSizeX)
59 0 : ++dwNumSurfaces;
60 0 : maSurfaceList.reserve(dwNumSurfaces);
61 :
62 0 : for(sal_Int32 y=0; y<aImageSizeY; y+=aPageSizeY)
63 : {
64 0 : for(sal_Int32 x=0; x<aImageSizeX; x+=aPageSizeX)
65 : {
66 : // the current surface is located at the position [x,y]
67 : // and has the size [min(restx,pagesizex),min(resty,pagesizey)
68 0 : ::basegfx::B2IPoint aOffset(x,y);
69 0 : ::basegfx::B2ISize aSize( ::std::min( aImageSize.getX()-x,
70 0 : aPageSize.getX() ),
71 0 : ::std::min( aImageSize.getY()-y,
72 0 : aPageSize.getY() ) );
73 :
74 : maSurfaceList.push_back(
75 : SurfaceSharedPtr(
76 : new Surface(
77 : mpPageManager,
78 : mpBuffer,
79 : aOffset,
80 0 : aSize)));
81 0 : }
82 0 : }
83 0 : }
84 :
85 :
86 : // SurfaceProxy::setColorBufferDirty
87 :
88 :
89 0 : void SurfaceProxy::setColorBufferDirty()
90 : {
91 : ::std::for_each( maSurfaceList.begin(),
92 : maSurfaceList.end(),
93 0 : ::boost::mem_fn(&Surface::setColorBufferDirty));
94 0 : }
95 :
96 :
97 : // SurfaceProxy::draw
98 :
99 :
100 0 : bool SurfaceProxy::draw( double fAlpha,
101 : const ::basegfx::B2DPoint& rPos,
102 : const ::basegfx::B2DHomMatrix& rTransform )
103 : {
104 : ::std::for_each( maSurfaceList.begin(),
105 : maSurfaceList.end(),
106 : ::boost::bind( &Surface::draw,
107 : _1,
108 : fAlpha,
109 : ::boost::cref(rPos),
110 0 : ::boost::cref(rTransform)));
111 :
112 0 : return true;
113 : }
114 :
115 :
116 : // SurfaceProxy::draw
117 :
118 :
119 0 : bool SurfaceProxy::draw( double fAlpha,
120 : const ::basegfx::B2DPoint& rPos,
121 : const ::basegfx::B2DRange& rArea,
122 : const ::basegfx::B2DHomMatrix& rTransform )
123 : {
124 : ::std::for_each( maSurfaceList.begin(),
125 : maSurfaceList.end(),
126 : ::boost::bind(&Surface::drawRectangularArea,
127 : _1,
128 : fAlpha,
129 : ::boost::cref(rPos),
130 : ::boost::cref(rArea),
131 0 : ::boost::cref(rTransform)));
132 :
133 0 : return true;
134 : }
135 :
136 :
137 : // SurfaceProxy::draw
138 :
139 :
140 0 : bool SurfaceProxy::draw( double fAlpha,
141 : const ::basegfx::B2DPoint& rPos,
142 : const ::basegfx::B2DPolyPolygon& rClipPoly,
143 : const ::basegfx::B2DHomMatrix& rTransform )
144 : {
145 : const ::basegfx::B2DPolygon& rTriangulatedPolygon(
146 0 : ::basegfx::triangulator::triangulate(rClipPoly));
147 :
148 : #if OSL_DEBUG_LEVEL > 2
149 : // dump polygons
150 : OSL_TRACE( "Original clip polygon: %s\n"
151 : "Triangulated polygon: %s\n",
152 : OUStringToOString(
153 : basegfx::tools::exportToSvgD( rClipPoly, true, true, false ),
154 : RTL_TEXTENCODING_ASCII_US).getStr(),
155 : OUStringToOString(
156 : basegfx::tools::exportToSvgD(
157 : basegfx::B2DPolyPolygon(rTriangulatedPolygon), true, true, false ),
158 : RTL_TEXTENCODING_ASCII_US).getStr() );
159 : #endif
160 :
161 : ::std::for_each( maSurfaceList.begin(),
162 : maSurfaceList.end(),
163 : ::boost::bind(&Surface::drawWithClip,
164 : _1,
165 : fAlpha,
166 : ::boost::cref(rPos),
167 : ::boost::cref(rTriangulatedPolygon),
168 0 : ::boost::cref(rTransform)));
169 :
170 0 : return true;
171 : }
172 3 : }
173 :
174 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|