Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/canvas/source/vcl/devicehelper.cxx
Line
Count
Source
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
22
#include <basegfx/utils/canvastools.hxx>
23
#include <basegfx/utils/unopolypolygon.hxx>
24
#include <canvas/canvastools.hxx>
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
32
using namespace ::com::sun::star;
33
34
namespace vclcanvas
35
{
36
    DeviceHelper::DeviceHelper()
37
0
    {}
38
39
    void DeviceHelper::init( const OutDevProviderSharedPtr& rOutDev )
40
0
    {
41
0
        mpOutDev = rOutDev;
42
0
    }
43
44
    geometry::RealSize2D DeviceHelper::getPhysicalResolution()
45
0
    {
46
0
        if( !mpOutDev )
47
0
            return ::canvastools::createInfiniteSize2D(); // we're disposed
48
49
        // Map a one-by-one millimeter box to pixel
50
0
        OutputDevice& rOutDev = mpOutDev->getOutDev();
51
0
        const MapMode aOldMapMode( rOutDev.GetMapMode() );
52
0
        rOutDev.SetMapMode( MapMode(MapUnit::MapMM) );
53
0
        const Size aPixelSize( rOutDev.LogicToPixel(Size(1,1)) );
54
0
        rOutDev.SetMapMode( aOldMapMode );
55
56
0
        return vcl::unotools::size2DFromSize( aPixelSize );
57
0
    }
58
59
    geometry::RealSize2D DeviceHelper::getPhysicalSize()
60
0
    {
61
0
        if( !mpOutDev )
62
0
            return ::canvastools::createInfiniteSize2D(); // we're disposed
63
64
        // Map the pixel dimensions of the output window to millimeter
65
0
        OutputDevice& rOutDev = mpOutDev->getOutDev();
66
0
        const MapMode aOldMapMode( rOutDev.GetMapMode() );
67
0
        rOutDev.SetMapMode( MapMode(MapUnit::MapMM) );
68
0
        const Size aLogSize( rOutDev.PixelToLogic(rOutDev.GetOutputSizePixel()) );
69
0
        rOutDev.SetMapMode( aOldMapMode );
70
71
0
        return vcl::unotools::size2DFromSize( aLogSize );
72
0
    }
73
74
    uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
75
        const uno::Reference< rendering::XGraphicDevice >&              ,
76
        const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >&  points )
77
0
    {
78
0
        uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
79
0
        if( !mpOutDev )
80
0
            return xPoly; // we're disposed
81
82
0
        xPoly.set( new ::basegfx::unotools::UnoPolyPolygon(
83
0
                       ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) );
84
        // vcl only handles even_odd polygons
85
0
        xPoly->setFillRule(rendering::FillRule_EVEN_ODD);
86
87
0
        return xPoly;
88
0
    }
89
90
    uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
91
        const uno::Reference< rendering::XGraphicDevice >&                      ,
92
        const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >&  points )
93
0
    {
94
0
        uno::Reference< rendering::XBezierPolyPolygon2D > xPoly;
95
0
        if( !mpOutDev )
96
0
            return xPoly; // we're disposed
97
98
0
        xPoly.set( new ::basegfx::unotools::UnoPolyPolygon(
99
0
                       ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) );
100
        // vcl only handles even_odd polygons
101
0
        xPoly->setFillRule(rendering::FillRule_EVEN_ODD);
102
103
0
        return xPoly;
104
0
    }
105
106
    uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
107
        const uno::Reference< rendering::XGraphicDevice >& rDevice,
108
        const geometry::IntegerSize2D&                     size )
109
0
    {
110
0
        if( !mpOutDev )
111
0
            return uno::Reference< rendering::XBitmap >(); // we're disposed
112
113
0
        return uno::Reference< rendering::XBitmap >(
114
0
            new CanvasBitmap( vcl::unotools::sizeFromIntegerSize2D(size),
115
0
                              false,
116
0
                              *rDevice,
117
0
                              mpOutDev ) );
118
0
    }
119
120
    uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
121
        const uno::Reference< rendering::XGraphicDevice >&  ,
122
        const geometry::IntegerSize2D&                       )
123
0
    {
124
0
        return uno::Reference< rendering::XVolatileBitmap >();
125
0
    }
126
127
    uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
128
        const uno::Reference< rendering::XGraphicDevice >& rDevice,
129
        const geometry::IntegerSize2D&                     size )
130
0
    {
131
0
        if( !mpOutDev )
132
0
            return uno::Reference< rendering::XBitmap >(); // we're disposed
133
134
0
        return uno::Reference< rendering::XBitmap >(
135
0
            new CanvasBitmap( vcl::unotools::sizeFromIntegerSize2D(size),
136
0
                              true,
137
0
                              *rDevice,
138
0
                              mpOutDev ) );
139
0
    }
140
141
    uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
142
        const uno::Reference< rendering::XGraphicDevice >&  ,
143
        const geometry::IntegerSize2D&                       )
144
0
    {
145
0
        return uno::Reference< rendering::XVolatileBitmap >();
146
0
    }
147
148
    void DeviceHelper::disposing()
149
0
    {
150
        // release all references
151
0
        mpOutDev.reset();
152
0
    }
153
154
    uno::Any DeviceHelper::isAccelerated() const
155
0
    {
156
0
        return css::uno::Any(false);
157
0
    }
158
159
    uno::Any DeviceHelper::getDeviceHandle() const
160
0
    {
161
0
        if( !mpOutDev )
162
0
            return uno::Any();
163
164
0
        return uno::Any(
165
0
            reinterpret_cast< sal_Int64 >(&mpOutDev->getOutDev()) );
166
0
    }
167
168
    uno::Any DeviceHelper::getSurfaceHandle() const
169
0
    {
170
0
        return getDeviceHandle();
171
0
    }
172
173
    namespace
174
    {
175
        uno::Reference<rendering::XColorSpace>& GetDeviceColorSpace()
176
0
        {
177
0
            static uno::Reference<rendering::XColorSpace> xColorSpace =
178
0
            []()
179
0
            {
180
0
                auto xTmp = canvastools::getStdColorSpace();
181
0
                assert( xTmp.is() );
182
0
                return xTmp;
183
0
            }();
184
0
            return xColorSpace;
185
0
        };
186
    }
187
188
    uno::Reference<rendering::XColorSpace> const & DeviceHelper::getColorSpace() const
189
0
    {
190
        // always the same
191
0
        return GetDeviceColorSpace();
192
0
    }
193
194
    void DeviceHelper::dumpScreenContent() const
195
0
    {
196
0
        static sal_Int32 nFilePostfixCount(0);
197
198
0
        if( !mpOutDev )
199
0
            return;
200
201
0
        OUString aFilename = "dbg_frontbuffer" + OUString::number(nFilePostfixCount) + ".bmp";
202
203
0
        SvFileStream aStream( aFilename, StreamMode::STD_READWRITE );
204
205
0
        const ::Point aEmptyPoint;
206
0
        OutputDevice& rOutDev = mpOutDev->getOutDev();
207
0
        bool bOldMap( rOutDev.IsMapModeEnabled() );
208
0
        rOutDev.EnableMapMode( false );
209
0
        WriteDIB(rOutDev.GetBitmap(aEmptyPoint, rOutDev.GetOutputSizePixel()), aStream, false);
210
0
        rOutDev.EnableMapMode( bOldMap );
211
212
0
        ++nFilePostfixCount;
213
0
    }
214
215
}
216
217
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */