LibreOffice Module canvas (master) 1
cairo_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#include <sal/log.hxx>
22
25#include <tools/stream.hxx>
26#include <vcl/bitmapex.hxx>
27#include <vcl/canvastools.hxx>
28#include <vcl/dibtools.hxx>
29
31
34
35using namespace ::cairo;
36using namespace ::com::sun::star;
37
38namespace cairocanvas
39{
41 mpSurfaceProvider( nullptr ),
42 mpRefDevice( nullptr )
43 {
44 }
45
46 void DeviceHelper::implInit( SurfaceProvider& rSurfaceProvider,
47 OutputDevice& rRefDevice )
48 {
49 mpSurfaceProvider = &rSurfaceProvider;
50 mpRefDevice = &rRefDevice;
51
52 // no own surface, this is handled by derived classes
53 }
54
55 void DeviceHelper::init( SurfaceProvider& rSurfaceProvider,
56 OutputDevice& rRefDevice )
57 {
58 implInit(rSurfaceProvider, rRefDevice);
59
60 OutputDevice* pOutDev = getOutputDevice();
61 mpSurface = pOutDev->CreateSurface(pOutDev->GetOutOffXPixel(),
62 pOutDev->GetOutOffYPixel(),
63 pOutDev->GetOutputWidthPixel(),
64 pOutDev->GetOutputHeightPixel());
65 }
66
68 {
69 // release all references
70 mpSurface.reset();
71 mpRefDevice = nullptr;
72 mpSurfaceProvider = nullptr;
73 }
74
75 void DeviceHelper::setSize( const ::basegfx::B2ISize& rSize )
76 {
78 "canvas.cairo",
79 "device size " << rSize.getX() << " x " << rSize.getY());
80
81 if( !mpRefDevice )
82 return; // disposed
83
84 OutputDevice* pOutDev = getOutputDevice();
85
86 // X11 only
87 bool bReuseSurface = mpSurface &&
88 mpSurface->Resize(rSize.getX() + pOutDev->GetOutOffXPixel(),
89 rSize.getY() + pOutDev->GetOutOffYPixel());
90
91 if (!bReuseSurface)
92 {
93 mpSurface = pOutDev->CreateSurface(
94 pOutDev->GetOutOffXPixel(),
95 pOutDev->GetOutOffYPixel(),
96 rSize.getX(), rSize.getY() );
97 }
98 }
99
101 {
102 // Map a one-by-one millimeter box to pixel
103 const MapMode aOldMapMode( mpRefDevice->GetMapMode() );
104 mpRefDevice->SetMapMode( MapMode(MapUnit::MapMM) );
105 const Size aPixelSize( mpRefDevice->LogicToPixel(Size(1,1)) );
106 mpRefDevice->SetMapMode( aOldMapMode );
107
108 return vcl::unotools::size2DFromSize( aPixelSize );
109 }
110
111 geometry::RealSize2D DeviceHelper::getPhysicalSize()
112 {
113 if( !mpRefDevice )
115
116 // Map the pixel dimensions of the output window to millimeter
117 const MapMode aOldMapMode( mpRefDevice->GetMapMode() );
118 mpRefDevice->SetMapMode( MapMode(MapUnit::MapMM) );
119 const Size aLogSize( mpRefDevice->PixelToLogic(mpRefDevice->GetOutputSizePixel()) );
120 mpRefDevice->SetMapMode( aOldMapMode );
121
122 return vcl::unotools::size2DFromSize( aLogSize );
123 }
124
125 uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
126 const uno::Reference< rendering::XGraphicDevice >& ,
127 const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
128 {
129 // disposed?
130 if( !mpSurfaceProvider )
131 return uno::Reference< rendering::XLinePolyPolygon2D >(); // we're disposed
132
133 return uno::Reference< rendering::XLinePolyPolygon2D >(
134 new ::basegfx::unotools::UnoPolyPolygon(
135 ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) );
136 }
137
138 uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
139 const uno::Reference< rendering::XGraphicDevice >& ,
140 const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points )
141 {
142 // disposed?
143 if( !mpSurfaceProvider )
144 return uno::Reference< rendering::XBezierPolyPolygon2D >(); // we're disposed
145
146 return uno::Reference< rendering::XBezierPolyPolygon2D >(
147 new ::basegfx::unotools::UnoPolyPolygon(
148 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) );
149 }
150
151 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
152 const uno::Reference< rendering::XGraphicDevice >& rDevice,
153 const geometry::IntegerSize2D& size )
154 {
155 // disposed?
156 if( !mpSurfaceProvider )
157 return uno::Reference< rendering::XBitmap >(); // we're disposed
158
159 return uno::Reference< rendering::XBitmap >(
160 new CanvasBitmap(
161 ::basegfx::unotools::b2ISizeFromIntegerSize2D( size ),
163 rDevice.get(),
164 false ));
165 }
166
167 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
168 const uno::Reference< rendering::XGraphicDevice >& ,
169 const geometry::IntegerSize2D& /*size*/ )
170 {
171 return uno::Reference< rendering::XVolatileBitmap >();
172 }
173
174 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
175 const uno::Reference< rendering::XGraphicDevice >& rDevice,
176 const geometry::IntegerSize2D& size )
177 {
178 // disposed?
179 if( !mpSurfaceProvider )
180 return uno::Reference< rendering::XBitmap >(); // we're disposed
181
182 return uno::Reference< rendering::XBitmap >(
183 new CanvasBitmap(
184 ::basegfx::unotools::b2ISizeFromIntegerSize2D( size ),
186 rDevice.get(),
187 true ));
188 }
189
190 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
191 const uno::Reference< rendering::XGraphicDevice >& ,
192 const geometry::IntegerSize2D& /*size*/ )
193 {
194 return uno::Reference< rendering::XVolatileBitmap >();
195 }
196
198 {
199 return css::uno::Any(false);
200 }
201
203 {
204 return uno::Any( reinterpret_cast< sal_Int64 >(mpRefDevice.get()) );
205 }
206
208 {
209 return uno::Any();
210 }
211
212 uno::Reference<rendering::XColorSpace> const & DeviceHelper::getColorSpace() const
213 {
214 static uno::Reference<rendering::XColorSpace> SPACE = vcl::unotools::createStandardColorSpace();
215 // always the same
216 return SPACE;
217 }
218
220 {
221 static sal_Int32 nFilePostfixCount(0);
222
223 if( !mpRefDevice )
224 return;
225
226 OUString aFilename = "dbg_frontbuffer" + OUString::number(nFilePostfixCount) + ".bmp";
227
228 SvFileStream aStream( aFilename, StreamMode::STD_READWRITE );
229
230 const ::Point aEmptyPoint;
231 bool bOldMap( mpRefDevice->IsMapModeEnabled() );
232 mpRefDevice->EnableMapMode( false );
233 const ::BitmapEx aTempBitmap(mpRefDevice->GetBitmapEx(aEmptyPoint, mpRefDevice->GetOutputSizePixel()));
234 WriteDIB(aTempBitmap, aStream, false);
235 mpRefDevice->EnableMapMode( bOldMap );
236
237 ++nFilePostfixCount;
238 }
239
240 SurfaceSharedPtr DeviceHelper::createSurface( const ::basegfx::B2ISize& rSize, int aContent )
241 {
242 if( mpSurface )
243 return mpSurface->getSimilar( aContent, rSize.getX(), rSize.getY() );
244
245 return SurfaceSharedPtr();
246 }
247
249 {
250 if (mpRefDevice)
251 return mpRefDevice->CreateBitmapSurface(rData, rSize);
252
253 return SurfaceSharedPtr();
254 }
255}
256
257/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tools::Long GetOutOffYPixel() const
tools::Long GetOutputWidthPixel() const
tools::Long GetOutputHeightPixel() const
cairo::SurfaceSharedPtr CreateSurface(const cairo::CairoSurfaceSharedPtr &rSurface) const
tools::Long GetOutOffXPixel() const
reference_type * get() const
void disposing()
Dispose all internal references.
void init(SurfaceProvider &rSurfaceProvider, OutputDevice &rRefDevice)
init helper
css::uno::Reference< css::rendering::XVolatileBitmap > createVolatileAlphaBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
void implInit(SurfaceProvider &rSurfaceProvider, OutputDevice &rRefDevice)
init helper
::cairo::SurfaceSharedPtr createSurface(const ::basegfx::B2ISize &rSize, int aContent)
css::geometry::RealSize2D getPhysicalSize()
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 setSize(const ::basegfx::B2ISize &rSize)
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::XBezierPolyPolygon2D > createCompatibleBezierPolyPolygon(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::uno::Sequence< css::uno::Sequence< css::geometry::RealBezierSegment2D > > &points)
::cairo::SurfaceSharedPtr mpSurface
css::uno::Reference< css::rendering::XColorSpace > const & getColorSpace() const
VclPtr< OutputDevice > mpRefDevice
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::geometry::RealSize2D getPhysicalResolution()
css::uno::Any getSurfaceHandle() const
OutputDevice * getOutputDevice() const
css::uno::Any getDeviceHandle() const
css::uno::Reference< css::rendering::XBitmap > createCompatibleAlphaBitmap(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::geometry::IntegerSize2D &size)
SurfaceProvider * mpSurfaceProvider
Surface provider.
css::uno::Any isAccelerated() const
Target interface for XCachedPrimitive implementations.
#define SPACE
bool VCL_DLLPUBLIC WriteDIB(const Bitmap &rSource, SvStream &rOStm, bool bCompressed, bool bFileHeader)
#define SAL_INFO(area, stream)
const ContentProperties & rData
std::shared_ptr< Surface > SurfaceSharedPtr
::rtl::Reference< SurfaceProvider > SurfaceProviderRef
geometry::RealSize2D createInfiniteSize2D()
Create a RealSize2D with both coordinate values set to +infinity.
Definition: canvastools.cxx:67
uno::Reference< rendering::XColorSpace > createStandardColorSpace()
geometry::RealSize2D size2DFromSize(const Size &rSize)