Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/canvas/source/vcl/canvashelper.hxx
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
#pragma once
21
22
#include <com/sun/star/geometry/IntegerPoint2D.hpp>
23
#include <com/sun/star/geometry/IntegerRectangle2D.hpp>
24
#include <com/sun/star/rendering/IntegerBitmapLayout.hpp>
25
#include <com/sun/star/rendering/XCanvas.hpp>
26
27
#include "cachedbitmap.hxx"
28
#include "outdevprovider.hxx"
29
30
31
namespace vclcanvas
32
{
33
34
    /** Helper class for basic canvas functionality. Also offers
35
        optional backbuffer painting, when providing it with a second
36
        OutputDevice to render into.
37
     */
38
    class CanvasHelper
39
    {
40
    public:
41
        /** Create canvas helper
42
         */
43
        CanvasHelper();
44
45
        /// make noncopyable
46
        CanvasHelper(const CanvasHelper&) = delete;
47
        const CanvasHelper& operator=(const CanvasHelper&) = delete;
48
49
        /// Release all references
50
        void disposing();
51
52
        /** Initialize canvas helper
53
54
            This method late-initializes the canvas helper, providing
55
            it with the necessary device and output objects. Note that
56
            the CanvasHelper does <em>not</em> take ownership of the
57
            passed rDevice reference, nor does it perform any
58
            reference counting. Thus, to prevent the reference counted
59
            SpriteCanvas object from deletion, the user of this class
60
            is responsible for holding ref-counted references itself!
61
62
            @param rDevice
63
            Reference device this canvas is associated with
64
65
            @param rOutDev
66
            Set primary output device for this canvas. That's where
67
            all content is output to.
68
69
            @param bProtect
70
            When true, all output operations preserve outdev
71
            state. When false, outdev state might change at any time.
72
73
            @param bHaveAlpha
74
            When true, hasAlpha() will always return true, otherwise, false.
75
         */
76
        void init( css::rendering::XGraphicDevice&              rDevice,
77
                   const OutDevProviderSharedPtr&               rOutDev,
78
                   bool                                         bProtect,
79
                   bool                                         bHaveAlpha );
80
81
        /** Set primary output device
82
83
            This changes the primary output device, where rendering is
84
            sent to.
85
         */
86
        void setOutDev( const OutDevProviderSharedPtr&  rOutDev,
87
                        bool                            bProtect);
88
89
        /** Set secondary output device
90
91
            Used for sprites, to generate mask bitmap.
92
         */
93
        void setBackgroundOutDev( const OutDevProviderSharedPtr& rOutDev );
94
95
96
        // CanvasHelper functionality
97
        // ==========================
98
99
        // XCanvas (only providing, not implementing the
100
        // interface. Also note subtle method parameter differences)
101
        void clear();
102
        void drawLine( const css::rendering::XCanvas*      rCanvas,
103
                       const css::geometry::RealPoint2D&   aStartPoint,
104
                       const css::geometry::RealPoint2D&   aEndPoint,
105
                       const css::rendering::ViewState&    viewState,
106
                       const css::rendering::RenderState&  renderState );
107
        void drawBezier( const css::rendering::XCanvas*            rCanvas,
108
                         const css::geometry::RealBezierSegment2D& aBezierSegment,
109
                         const css::geometry::RealPoint2D&         aEndPoint,
110
                         const css::rendering::ViewState&          viewState,
111
                         const css::rendering::RenderState&        renderState );
112
        css::uno::Reference< css::rendering::XCachedPrimitive >
113
            drawPolyPolygon( const css::rendering::XCanvas*        rCanvas,
114
                             const css::uno::Reference<
115
                                 css::rendering::XPolyPolygon2D >&     xPolyPolygon,
116
                             const css::rendering::ViewState&      viewState,
117
                             const css::rendering::RenderState&    renderState );
118
        css::uno::Reference< css::rendering::XCachedPrimitive >
119
            strokePolyPolygon( const css::rendering::XCanvas*          rCanvas,
120
                               const css::uno::Reference<
121
                                       css::rendering::XPolyPolygon2D >&   xPolyPolygon,
122
                               const css::rendering::ViewState&        viewState,
123
                               const css::rendering::RenderState&      renderState,
124
                               const css::rendering::StrokeAttributes& strokeAttributes );
125
        css::uno::Reference< css::rendering::XCachedPrimitive >
126
            strokeTexturedPolyPolygon( const css::rendering::XCanvas*          rCanvas,
127
                                       const css::uno::Reference<
128
                                               css::rendering::XPolyPolygon2D >&   xPolyPolygon,
129
                                       const css::rendering::ViewState&        viewState,
130
                                       const css::rendering::RenderState&      renderState,
131
                                       const css::uno::Sequence<
132
                                               css::rendering::Texture >&      textures,
133
                                       const css::rendering::StrokeAttributes& strokeAttributes );
134
        css::uno::Reference< css::rendering::XCachedPrimitive >
135
            strokeTextureMappedPolyPolygon( const css::rendering::XCanvas*             rCanvas,
136
                                            const css::uno::Reference<
137
                                                    css::rendering::XPolyPolygon2D >&  xPolyPolygon,
138
                                            const css::rendering::ViewState&           viewState,
139
                                            const css::rendering::RenderState&         renderState,
140
                                            const css::uno::Sequence<
141
                                                    css::rendering::Texture >&         textures,
142
                                            const css::uno::Reference<
143
                                                    css::geometry::XMapping2D >&       xMapping,
144
                                            const css::rendering::StrokeAttributes&    strokeAttributes );
145
        css::uno::Reference< css::rendering::XPolyPolygon2D >
146
            queryStrokeShapes( const css::rendering::XCanvas*          rCanvas,
147
                               const css::uno::Reference<
148
                                       css::rendering::XPolyPolygon2D >&   xPolyPolygon,
149
                               const css::rendering::ViewState&        viewState,
150
                               const css::rendering::RenderState&      renderState,
151
                               const css::rendering::StrokeAttributes& strokeAttributes );
152
        css::uno::Reference< css::rendering::XCachedPrimitive >
153
            fillPolyPolygon( const css::rendering::XCanvas*            rCanvas,
154
                             const css::uno::Reference<
155
                                     css::rendering::XPolyPolygon2D >&     xPolyPolygon,
156
                             const css::rendering::ViewState&          viewState,
157
                             const css::rendering::RenderState&        renderState );
158
        css::uno::Reference< css::rendering::XCachedPrimitive >
159
            fillTexturedPolyPolygon( const css::rendering::XCanvas*            rCanvas,
160
                                     const css::uno::Reference<
161
                                             css::rendering::XPolyPolygon2D >& xPolyPolygon,
162
                                     const css::rendering::ViewState&          viewState,
163
                                     const css::rendering::RenderState&        renderState,
164
                                     const css::uno::Sequence<
165
                                             css::rendering::Texture >&        textures );
166
        css::uno::Reference< css::rendering::XCachedPrimitive >
167
            fillTextureMappedPolyPolygon( const css::rendering::XCanvas*           rCanvas,
168
                                          const css::uno::Reference<
169
                                                  css::rendering::XPolyPolygon2D >&    xPolyPolygon,
170
                                          const css::rendering::ViewState&         viewState,
171
                                          const css::rendering::RenderState&       renderState,
172
                                          const css::uno::Sequence<
173
                                                  css::rendering::Texture >&       textures,
174
                                          const css::uno::Reference<
175
                                                  css::geometry::XMapping2D >&         xMapping );
176
177
        css::uno::Reference< css::rendering::XCanvasFont >
178
            createFont( const css::rendering::XCanvas*         rCanvas,
179
                        const css::rendering::FontRequest&     fontRequest,
180
                        const css::uno::Sequence<
181
                            css::beans::PropertyValue >&       extraFontProperties,
182
                        const css::geometry::Matrix2D&         fontMatrix );
183
184
        css::uno::Sequence< css::rendering::FontInfo >
185
            queryAvailableFonts( const css::rendering::XCanvas*        rCanvas,
186
                                 const css::rendering::FontInfo&       aFilter,
187
                                 const css::uno::Sequence<
188
                                         css::beans::PropertyValue >&  aFontProperties );
189
190
        css::uno::Reference< css::rendering::XCachedPrimitive >
191
            drawText( const css::rendering::XCanvas*       rCanvas,
192
                      const css::rendering::StringContext& text,
193
                      const css::uno::Reference<
194
                              css::rendering::XCanvasFont >& xFont,
195
                      const css::rendering::ViewState&     viewState,
196
                      const css::rendering::RenderState&   renderState,
197
                      sal_Int8                                          textDirection );
198
199
        css::uno::Reference< css::rendering::XCachedPrimitive >
200
            drawTextLayout( const css::rendering::XCanvas*         rCanvas,
201
                            const css::uno::Reference<
202
                                    css::rendering::XTextLayout >& laidOutText,
203
                            const css::rendering::ViewState&       viewState,
204
                            const css::rendering::RenderState&     renderState );
205
206
        css::uno::Reference< css::rendering::XCachedPrimitive >
207
            drawBitmap( const css::rendering::XCanvas*     rCanvas,
208
                        const css::uno::Reference<
209
                                css::rendering::XBitmap >& xBitmap,
210
                        const css::rendering::ViewState&   viewState,
211
                        const css::rendering::RenderState& renderState );
212
        css::uno::Reference< css::rendering::XCachedPrimitive >
213
            drawBitmapModulated( const css::rendering::XCanvas*        rCanvas,
214
                                 const css::uno::Reference<
215
                                         css::rendering::XBitmap >&        xBitmap,
216
                                 const css::rendering::ViewState&      viewState,
217
                                 const css::rendering::RenderState&    renderState );
218
        // cast away const, need to change refcount (as this is
219
        // ~invisible to client code, still logically const)
220
        css::uno::Reference< css::rendering::XGraphicDevice >
221
0
            getDevice() { return css::uno::Reference< css::rendering::XGraphicDevice >(mpDevice); }
222
223
224
        // BitmapCanvasHelper functionality
225
        // ================================
226
227
        css::geometry::IntegerSize2D getSize();
228
229
        css::uno::Reference< css::rendering::XBitmap >
230
            getScaledBitmap( const css::geometry::RealSize2D&  newSize,
231
                             bool                              beFast );
232
233
        css::uno::Sequence< sal_Int8 >
234
            getData( css::rendering::IntegerBitmapLayout&      bitmapLayout,
235
                     const css::geometry::IntegerRectangle2D&  rect );
236
237
        css::uno::Sequence< sal_Int8 >
238
            getPixel( css::rendering::IntegerBitmapLayout& bitmapLayout,
239
                      const css::geometry::IntegerPoint2D& pos );
240
241
        css::rendering::IntegerBitmapLayout getMemoryLayout();
242
243
        /// Repaint a cached bitmap
244
        bool repaint( const GraphicObjectSharedPtr&                   rGrf,
245
                      const css::rendering::ViewState&                viewState,
246
                      const css::rendering::RenderState&              renderState,
247
                      const ::Point&                                  rPt,
248
                      const ::Size&                                   rSz,
249
                      const GraphicAttr&                              rAttr ) const;
250
251
        /** Flush drawing queue.
252
253
            This only works for Window canvases, and ensures that all
254
            pending render operations are flushed to the
255
            driver/hardware.
256
         */
257
        void flush() const;
258
259
        enum ColorType
260
        {
261
            LINE_COLOR, FILL_COLOR, TEXT_COLOR, IGNORE_COLOR
262
        };
263
264
        // returns alpha of color
265
        int setupOutDevState( const css::rendering::ViewState&     viewState,
266
                              const css::rendering::RenderState&   renderState,
267
                              ColorType                            eColorType ) const;
268
269
0
        bool hasAlpha() const { return mbHaveAlpha; }
270
271
    protected:
272
        /** Phyical output device
273
274
            Deliberately not a refcounted reference, because of
275
            potential circular references for spritecanvas.
276
         */
277
        css::rendering::XGraphicDevice*              mpDevice;
278
279
        /// Rendering to this outdev preserves its state
280
        OutDevProviderSharedPtr                      mpProtectedOutDevProvider;
281
282
        /// Rendering to this outdev does not preserve its state
283
        OutDevProviderSharedPtr                      mpOutDevProvider;
284
285
        /// Rendering to this outdev does not preserve its state
286
        OutDevProviderSharedPtr                      mp2ndOutDevProvider;
287
288
        /// When true, content is able to represent alpha
289
        bool                                         mbHaveAlpha;
290
291
    private:
292
        css::uno::Reference< css::rendering::XCachedPrimitive >
293
            implDrawBitmap( const css::rendering::XCanvas*     rCanvas,
294
                            const css::uno::Reference<
295
                                    css::rendering::XBitmap >&     xBitmap,
296
                            const css::rendering::ViewState&   viewState,
297
                            const css::rendering::RenderState& renderState,
298
                            bool                                            bModulateColors );
299
300
        bool setupTextOutput( ::Point&                                                                              o_rOutPos,
301
                              const css::rendering::ViewState&                                         viewState,
302
                              const css::rendering::RenderState&                                       renderState,
303
                              const css::uno::Reference< css::rendering::XCanvasFont >&   xFont ) const;
304
305
    };
306
}
307
308
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */