Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/drawinglayer/source/processor2d/processor2dtools.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
#include <drawinglayer/processor2d/processor2dtools.hxx>
20
#include <vcl/gdimtf.hxx>
21
#include "vclpixelprocessor2d.hxx"
22
#include "vclmetafileprocessor2d.hxx"
23
#include <config_vclplug.h>
24
25
#if USE_HEADLESS_CODE
26
#include <drawinglayer/processor2d/cairopixelprocessor2d.hxx>
27
#elif defined(_WIN32)
28
#include <drawinglayer/processor2d/d2dpixelprocessor2d.hxx>
29
#include <vcl/sysdata.hxx>
30
#endif
31
32
using namespace com::sun::star;
33
34
namespace drawinglayer::processor2d
35
{
36
std::unique_ptr<BaseProcessor2D> createPixelProcessor2DFromScratch(
37
    const drawinglayer::geometry::ViewInformation2D& rViewInformation2D,
38
    sal_uInt32 nPixelWidth,
39
    sal_uInt32 nPixelHeight,
40
    bool bUseRGBA)
41
115
{
42
115
    if (0 == nPixelWidth || 0 == nPixelHeight)
43
        // error: no size given
44
0
        return nullptr;
45
46
115
#if USE_HEADLESS_CODE
47
    // Linux/Cairo: now globally activated in master. Leave a
48
    // possibility to deactivate for easy test/request testing
49
115
    static bool bUsePrimitiveRenderer(nullptr == std::getenv("DISABLE_SYSTEM_DEPENDENT_PRIMITIVE_RENDERER"));
50
51
115
    if (bUsePrimitiveRenderer)
52
115
    {
53
        // create CairoPixelProcessor2D with given size
54
115
        std::unique_ptr<CairoPixelProcessor2D> aRetval(
55
115
            std::make_unique<CairoPixelProcessor2D>(
56
115
                rViewInformation2D,
57
115
                nPixelWidth,
58
115
                nPixelHeight,
59
115
                bUseRGBA));
60
61
115
        if (aRetval->valid())
62
115
            return aRetval;
63
115
    }
64
0
#endif
65
66
    // avoid unused parameter errors
67
0
    (void)rViewInformation2D;
68
0
    (void)nPixelWidth;
69
0
    (void)nPixelHeight;
70
0
    (void)bUseRGBA;
71
72
    // error: no result when no SDPR supported
73
0
    return nullptr;
74
115
}
75
76
std::unique_ptr<BaseProcessor2D> createPixelProcessor2DFromOutputDevice(
77
    OutputDevice& rTargetOutDev,
78
    const drawinglayer::geometry::ViewInformation2D& rViewInformation2D)
79
6
{
80
6
#if USE_HEADLESS_CODE
81
    // Linux/Cairo: now globally activated in master. Leave a
82
    // possibility to deactivate for easy test/request testing
83
6
    static bool bUsePrimitiveRenderer(nullptr == std::getenv("DISABLE_SYSTEM_DEPENDENT_PRIMITIVE_RENDERER"));
84
85
6
    if (bUsePrimitiveRenderer)
86
6
    {
87
        // tdf#165061 do not use SDPR when RTL is enabled, SDPR is designed
88
        // for rendering EditViews and does not support RTL (yet?)
89
        // tdf#165437 also need to check for HasMirroredGraphics to
90
        // get *all* mirrorings covered
91
6
        const bool bMirrored(rTargetOutDev.IsRTLEnabled() || rTargetOutDev.HasMirroredGraphics());
92
93
6
        if (!bMirrored)
94
6
        {
95
            // create CairoPixelProcessor2D associated with the given
96
            // OutputDevice
97
6
            std::unique_ptr<CairoPixelProcessor2D> aRetval(
98
6
                std::make_unique<CairoPixelProcessor2D>(
99
6
                    rTargetOutDev,
100
6
                    rViewInformation2D));
101
102
6
            if (aRetval->valid())
103
6
            {
104
6
                return aRetval;
105
6
            }
106
6
        }
107
6
    }
108
#elif defined(_WIN32)
109
    // Windows: make dependent on TEST_SYSTEM_PRIMITIVE_RENDERER
110
    static bool bUsePrimitiveRenderer(nullptr != std::getenv("TEST_SYSTEM_PRIMITIVE_RENDERER"));
111
112
    if (bUsePrimitiveRenderer)
113
    {
114
        drawinglayer::geometry::ViewInformation2D aViewInformation2D(rViewInformation2D);
115
116
        // if mnOutOffX/mnOutOffY is set (a 'hack' to get a cheap additional offset), apply it additionally
117
        // NOTE: This will also need to take extended size of target device into
118
        //       consideration, using D2DPixelProcessor2D *will* have to clip
119
        //       against that. Thus for now this is *not* sufficient (see tdf#163125)
120
        if(0 != rTargetOutDev.GetOutOffXPixel() || 0 != rTargetOutDev.GetOutOffYPixel())
121
        {
122
            basegfx::B2DHomMatrix aTransform(aViewInformation2D.getViewTransformation());
123
            aTransform.translate(rTargetOutDev.GetOutOffXPixel(), rTargetOutDev.GetOutOffYPixel());
124
            aViewInformation2D.setViewTransformation(aTransform);
125
        }
126
127
        SystemGraphicsData aData(rTargetOutDev.GetSystemGfxData());
128
        std::unique_ptr<D2DPixelProcessor2D> aRetval(
129
            std::make_unique<D2DPixelProcessor2D>(aViewInformation2D, aData.hDC));
130
        if (aRetval->valid())
131
            return aRetval;
132
    }
133
#endif
134
135
    // default: create VclPixelProcessor2D
136
    // NOTE: Since this uses VCL OutputDevice in the VclPixelProcessor2D
137
    //       taking care of virtual devices is not needed, OutputDevice
138
    //       and VclPixelProcessor2D will traditionally take care of it
139
0
    return std::make_unique<VclPixelProcessor2D>(rViewInformation2D, rTargetOutDev);
140
6
}
141
142
std::unique_ptr<BaseProcessor2D> createProcessor2DFromOutputDevice(
143
    OutputDevice& rTargetOutDev,
144
    const drawinglayer::geometry::ViewInformation2D& rViewInformation2D)
145
59.3k
{
146
59.3k
    const GDIMetaFile* pMetaFile = rTargetOutDev.GetConnectMetaFile();
147
59.3k
    const bool bOutputToRecordingMetaFile(pMetaFile && pMetaFile->IsRecord()
148
59.3k
                                          && !pMetaFile->IsPause());
149
150
59.3k
    if (bOutputToRecordingMetaFile)
151
59.3k
    {
152
        // create MetaFile Vcl-Processor and process
153
59.3k
        return std::make_unique<VclMetafileProcessor2D>(rViewInformation2D, rTargetOutDev);
154
59.3k
    }
155
6
    else
156
6
    {
157
        // create Pixel Vcl-Processor
158
6
        return createPixelProcessor2DFromOutputDevice(rTargetOutDev, rViewInformation2D);
159
6
    }
160
59.3k
}
161
162
Bitmap extractBitmapFromBaseProcessor2D(const std::unique_ptr<BaseProcessor2D>& rProcessor)
163
115
{
164
115
    Bitmap aRetval;
165
166
115
#if USE_HEADLESS_CODE
167
    // currently only defined for cairo
168
115
    CairoPixelProcessor2D* pSource(dynamic_cast<CairoPixelProcessor2D*>(rProcessor.get()));
169
170
115
    if (nullptr != pSource)
171
115
        aRetval = pSource->extractBitmap();
172
115
#endif
173
174
    // avoid unused parameter errors
175
115
    (void)rProcessor;
176
177
    // default: return empty Bitmap
178
115
    return aRetval;
179
115
}
180
181
} // end of namespace
182
183
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */