Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/canvas/inc/base/spritecanvasbase.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 <rtl/ref.hxx>
23
#include <com/sun/star/rendering/InterpolationMode.hpp>
24
#include <base/integerbitmapbase.hxx>
25
#include <base/bitmapcanvasbase.hxx>
26
#include <sal/log.hxx>
27
#include <spriteredrawmanager.hxx>
28
29
namespace com::sun::star::rendering { class XAnimation; }
30
namespace com::sun::star::rendering { class XAnimatedSprite; }
31
namespace com::sun::star::rendering { class XCustomSprite; }
32
namespace com::sun::star::rendering { class XSprite; }
33
34
35
namespace canvas
36
{
37
    /** Helper template to handle XIntegerBitmap method forwarding to
38
        BitmapCanvasHelper
39
40
        Use this helper to handle the XIntegerBitmap part of your
41
        implementation.
42
43
        @tpl Base
44
        Base class to use, most probably one of the
45
        WeakComponentImplHelperN templates with the appropriate
46
        interfaces. At least XSpriteCanvas and SpriteSurface should be
47
        among them (why else would you use this template, then?). Base
48
        class must have a Base( const Mutex& ) constructor (like the
49
        WeakComponentImplHelperN templates have).
50
51
        @tpl CanvasHelper
52
        Canvas helper implementation for the backend in question
53
54
        @tpl Mutex
55
        Lock strategy to use. Defaults to using the
56
        BaseMutex-provided lock.  Every time one of the methods is
57
        entered, an object of type Mutex is created with m_aMutex as
58
        the sole parameter, and destroyed again when the method scope
59
        is left.
60
61
        @tpl UnambiguousBase
62
        Optional unambiguous base class for XInterface of Base. It's
63
        sometimes necessary to specify this parameter, e.g. if Base
64
        derives from multiple UNO interface (were each provides its
65
        own version of XInterface, making the conversion ambiguous)
66
67
        @see CanvasBase for further contractual requirements towards
68
        the CanvasHelper type, and some examples.
69
     */
70
    template< class Base,
71
              class CanvasHelper,
72
              class Mutex=::osl::MutexGuard,
73
              class UnambiguousBase = css::uno::XInterface > class SpriteCanvasBase :
74
        public IntegerBitmapBase< BitmapCanvasBase<Base, CanvasHelper, Mutex, UnambiguousBase> >
75
    {
76
    public:
77
        typedef IntegerBitmapBase< BitmapCanvasBase<Base, CanvasHelper, Mutex, UnambiguousBase> > BaseType;
78
        typedef ::rtl::Reference< SpriteCanvasBase >                            Reference;
79
80
        SpriteCanvasBase() :
81
0
            maRedrawManager()
82
0
        {
83
0
        }
84
85
        virtual void disposeThis() override
86
0
        {
87
0
            typename BaseType::MutexType aGuard( BaseType::m_aMutex );
88
89
0
            maRedrawManager.disposing();
90
91
            // pass on to base class
92
0
            BaseType::disposeThis();
93
0
        }
94
95
        // XSpriteCanvas
96
        virtual css::uno::Reference< css::rendering::XAnimatedSprite > SAL_CALL createSpriteFromAnimation( const css::uno::Reference< css::rendering::XAnimation >& animation ) override
97
0
        {
98
0
            canvastools::verifyArgs(animation,
99
0
                              __func__,
100
0
                              static_cast< typename BaseType::UnambiguousBaseType* >(this));
101
102
0
            typename BaseType::MutexType aGuard( BaseType::m_aMutex );
103
104
0
            return BaseType::maCanvasHelper.createSpriteFromAnimation(animation);
105
0
        }
106
107
        virtual css::uno::Reference< css::rendering::XAnimatedSprite > SAL_CALL createSpriteFromBitmaps( const css::uno::Sequence< css::uno::Reference< css::rendering::XBitmap > >& animationBitmaps,
108
                                                                                                                                   sal_Int8                                                                                                           interpolationMode ) override
109
0
        {
110
0
            canvastools::verifyArgs(animationBitmaps,
111
0
                              __func__,
112
0
                              static_cast< typename BaseType::UnambiguousBaseType* >(this));
113
0
            canvastools::verifyRange( interpolationMode,
114
0
                                css::rendering::InterpolationMode::NEAREST_NEIGHBOR,
115
0
                                css::rendering::InterpolationMode::BEZIERSPLINE4 );
116
117
0
            typename BaseType::MutexType aGuard( BaseType::m_aMutex );
118
119
0
            return BaseType::maCanvasHelper.createSpriteFromBitmaps(animationBitmaps, interpolationMode);
120
0
        }
121
122
        virtual css::uno::Reference< css::rendering::XCustomSprite > SAL_CALL createCustomSprite( const css::geometry::RealSize2D& spriteSize ) override
123
0
        {
124
0
            canvastools::verifySpriteSize(spriteSize,
125
0
                                    __func__,
126
0
                                    static_cast< typename BaseType::UnambiguousBaseType* >(this));
127
128
0
            typename BaseType::MutexType aGuard( BaseType::m_aMutex );
129
130
0
            return BaseType::maCanvasHelper.createCustomSprite(spriteSize);
131
0
        }
132
133
        virtual css::uno::Reference< css::rendering::XSprite > SAL_CALL createClonedSprite( const css::uno::Reference< css::rendering::XSprite >& original ) override
134
0
        {
135
0
            canvastools::verifyArgs(original,
136
0
                              __func__,
137
0
                              static_cast< typename BaseType::UnambiguousBaseType* >(this));
138
139
0
            typename BaseType::MutexType aGuard( BaseType::m_aMutex );
140
141
0
            return BaseType::maCanvasHelper.createClonedSprite(original);
142
0
        }
143
144
        // SpriteSurface
145
        virtual void showSprite( const Sprite::Reference& rSprite ) override
146
0
        {
147
0
            SAL_WARN_IF( !rSprite.is(), "canvas", "rSprite is null in showSprite()" );
148
149
150
0
            typename BaseType::MutexType aGuard( BaseType::m_aMutex );
151
152
0
            maRedrawManager.showSprite( rSprite );
153
0
        }
154
155
        virtual void hideSprite( const Sprite::Reference& rSprite ) override
156
0
        {
157
0
            SAL_WARN_IF( !rSprite.is(), "canvas", "rSprite is null in hideSprite()" );
158
159
0
            typename BaseType::MutexType aGuard( BaseType::m_aMutex );
160
161
0
            maRedrawManager.hideSprite( rSprite );
162
0
        }
163
164
        virtual void moveSprite( const Sprite::Reference&       rSprite,
165
                                 const ::basegfx::B2DPoint&     rOldPos,
166
                                 const ::basegfx::B2DPoint&     rNewPos,
167
                                 const ::basegfx::B2DVector&    rSpriteSize ) override
168
0
        {
169
0
            SAL_WARN_IF( !rSprite.is(), "canvas", "rSprite is null in moveSprite()" );
170
171
0
            typename BaseType::MutexType aGuard( BaseType::m_aMutex );
172
173
0
            maRedrawManager.moveSprite( rSprite, rOldPos, rNewPos, rSpriteSize );
174
0
        }
175
176
        virtual void updateSprite( const Sprite::Reference&     rSprite,
177
                                   const ::basegfx::B2DPoint&   rPos,
178
                                   const ::basegfx::B2DRange&   rUpdateArea ) override
179
0
        {
180
0
            SAL_WARN_IF( !rSprite.is(), "canvas", "rSprite is null in updateSprite()" );
181
182
0
            typename BaseType::MutexType aGuard( BaseType::m_aMutex );
183
184
0
            maRedrawManager.updateSprite( rSprite, rPos, rUpdateArea );
185
0
        }
186
187
    protected:
188
        SpriteRedrawManager maRedrawManager;
189
    };
190
}
191
192
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */