LibreOffice Module canvas (master) 1
devicehelper.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
25#include <tools/stream.hxx>
26#include <vcl/canvastools.hxx>
27#include <vcl/dibtools.hxx>
28
29#include "canvasbitmap.hxx"
30#include "devicehelper.hxx"
31
32using namespace ::com::sun::star;
33
34namespace vclcanvas
35{
37 {}
38
40 {
41 mpOutDev = rOutDev;
42 }
43
45 {
46 if( !mpOutDev )
48
49 // Map a one-by-one millimeter box to pixel
50 OutputDevice& rOutDev = mpOutDev->getOutDev();
51 const MapMode aOldMapMode( rOutDev.GetMapMode() );
52 rOutDev.SetMapMode( MapMode(MapUnit::MapMM) );
53 const Size aPixelSize( rOutDev.LogicToPixel(Size(1,1)) );
54 rOutDev.SetMapMode( aOldMapMode );
55
56 return vcl::unotools::size2DFromSize( aPixelSize );
57 }
58
59 geometry::RealSize2D DeviceHelper::getPhysicalSize()
60 {
61 if( !mpOutDev )
63
64 // Map the pixel dimensions of the output window to millimeter
65 OutputDevice& rOutDev = mpOutDev->getOutDev();
66 const MapMode aOldMapMode( rOutDev.GetMapMode() );
67 rOutDev.SetMapMode( MapMode(MapUnit::MapMM) );
68 const Size aLogSize( rOutDev.PixelToLogic(rOutDev.GetOutputSizePixel()) );
69 rOutDev.SetMapMode( aOldMapMode );
70
71 return vcl::unotools::size2DFromSize( aLogSize );
72 }
73
74 uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
75 const uno::Reference< rendering::XGraphicDevice >& ,
76 const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
77 {
78 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
79 if( !mpOutDev )
80 return xPoly; // we're disposed
81
82 xPoly.set( new ::basegfx::unotools::UnoPolyPolygon(
83 ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) );
84 // vcl only handles even_odd polygons
85 xPoly->setFillRule(rendering::FillRule_EVEN_ODD);
86
87 return xPoly;
88 }
89
90 uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
91 const uno::Reference< rendering::XGraphicDevice >& ,
92 const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points )
93 {
94 uno::Reference< rendering::XBezierPolyPolygon2D > xPoly;
95 if( !mpOutDev )
96 return xPoly; // we're disposed
97
98 xPoly.set( new ::basegfx::unotools::UnoPolyPolygon(
99 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) );
100 // vcl only handles even_odd polygons
101 xPoly->setFillRule(rendering::FillRule_EVEN_ODD);
102
103 return xPoly;
104 }
105
106 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
107 const uno::Reference< rendering::XGraphicDevice >& rDevice,
108 const geometry::IntegerSize2D& size )
109 {
110 if( !mpOutDev )
111 return uno::Reference< rendering::XBitmap >(); // we're disposed
112
113 return uno::Reference< rendering::XBitmap >(
114 new CanvasBitmap( vcl::unotools::sizeFromIntegerSize2D(size),
115 false,
116 *rDevice,
117 mpOutDev ) );
118 }
119
120 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
121 const uno::Reference< rendering::XGraphicDevice >& ,
122 const geometry::IntegerSize2D& )
123 {
124 return uno::Reference< rendering::XVolatileBitmap >();
125 }
126
127 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
128 const uno::Reference< rendering::XGraphicDevice >& rDevice,
129 const geometry::IntegerSize2D& size )
130 {
131 if( !mpOutDev )
132 return uno::Reference< rendering::XBitmap >(); // we're disposed
133
134 return uno::Reference< rendering::XBitmap >(
135 new CanvasBitmap( vcl::unotools::sizeFromIntegerSize2D(size),
136 true,
137 *rDevice,
138 mpOutDev ) );
139 }
140
141 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
142 const uno::Reference< rendering::XGraphicDevice >& ,
143 const geometry::IntegerSize2D& )
144 {
145 return uno::Reference< rendering::XVolatileBitmap >();
146 }
147
149 {
150 // release all references
151 mpOutDev.reset();
152 }
153
155 {
156 return css::uno::Any(false);
157 }
158
160 {
161 if( !mpOutDev )
162 return uno::Any();
163
164 return uno::Any(
165 reinterpret_cast< sal_Int64 >(&mpOutDev->getOutDev()) );
166 }
167
169 {
170 return getDeviceHandle();
171 }
172
173 namespace
174 {
175 uno::Reference<rendering::XColorSpace>& GetDeviceColorSpace()
176 {
177 static uno::Reference<rendering::XColorSpace> xColorSpace =
178 []()
179 {
181 assert( xTmp.is() );
182 return xTmp;
183 }();
184 return xColorSpace;
185 };
186 }
187
188 uno::Reference<rendering::XColorSpace> const & DeviceHelper::getColorSpace() const
189 {
190 // always the same
191 return GetDeviceColorSpace();
192 }
193
195 {
196 static sal_Int32 nFilePostfixCount(0);
197
198 if( !mpOutDev )
199 return;
200
201 OUString aFilename = "dbg_frontbuffer" + OUString::number(nFilePostfixCount) + ".bmp";
202
203 SvFileStream aStream( aFilename, StreamMode::STD_READWRITE );
204
205 const ::Point aEmptyPoint;
206 OutputDevice& rOutDev = mpOutDev->getOutDev();
207 bool bOldMap( rOutDev.IsMapModeEnabled() );
208 rOutDev.EnableMapMode( false );
209 WriteDIB(rOutDev.GetBitmapEx(aEmptyPoint, rOutDev.GetOutputSizePixel()), aStream, false);
210 rOutDev.EnableMapMode( bOldMap );
211
212 ++nFilePostfixCount;
213 }
214
215}
216
217/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void EnableMapMode(bool bEnable=true)
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
Size GetOutputSizePixel() const
void SetMapMode()
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
const MapMode & GetMapMode() const
bool IsMapModeEnabled() const
BitmapEx GetBitmapEx(const Point &rSrcPt, const Size &rSize) const
void disposing()
Dispose all internal references.
void dumpScreenContent() const
called when DumpScreenContent property is enabled on XGraphicDevice, and writes out bitmaps of curren...
css::uno::Reference< css::rendering::XBitmap > createCompatibleBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
css::uno::Reference< css::rendering::XLinePolyPolygon2D > createCompatibleLinePolyPolygon(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::uno::Sequence< css::uno::Sequence< css::geometry::RealPoint2D > > &points)
void init(const OutDevProviderSharedPtr &rOutDev)
OutDevProviderSharedPtr mpOutDev
For retrieving device info.
css::uno::Reference< css::rendering::XColorSpace > const & getColorSpace() const
css::uno::Any isAccelerated() const
css::uno::Reference< css::rendering::XBitmap > createCompatibleAlphaBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
css::uno::Any getDeviceHandle() const
css::uno::Reference< css::rendering::XVolatileBitmap > createVolatileBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
css::uno::Reference< css::rendering::XVolatileBitmap > createVolatileAlphaBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
css::uno::Any getSurfaceHandle() const
css::uno::Reference< css::rendering::XBezierPolyPolygon2D > createCompatibleBezierPolyPolygon(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::uno::Sequence< css::uno::Sequence< css::geometry::RealBezierSegment2D > > &points)
css::geometry::RealSize2D getPhysicalSize()
css::geometry::RealSize2D getPhysicalResolution()
bool VCL_DLLPUBLIC WriteDIB(const Bitmap &rSource, SvStream &rOStm, bool bCompressed, bool bFileHeader)
geometry::RealSize2D createInfiniteSize2D()
Create a RealSize2D with both coordinate values set to +infinity.
Definition: canvastools.cxx:67
uno::Reference< rendering::XIntegerBitmapColorSpace > const & getStdColorSpace()
Return a color space for a default RGBA integer format.
Size sizeFromIntegerSize2D(const geometry::IntegerSize2D &rSize)
geometry::RealSize2D size2DFromSize(const Size &rSize)
std::shared_ptr< OutDevProvider > OutDevProviderSharedPtr