calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / inc / salbmp.hxx
blob2ffffb93fb4daaaaa0fe02a15c3a7fa4c7024992
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_INC_SALBMP_HXX
21 #define INCLUDED_VCL_INC_SALBMP_HXX
23 #include <tools/gen.hxx>
24 #include <tools/solar.h>
25 #include <vcl/checksum.hxx>
26 #include <vcl/BitmapAccessMode.hxx>
27 #include <vcl/BitmapBuffer.hxx>
28 #include <vcl/bitmap/BitmapTypes.hxx>
29 #include <com/sun/star/rendering/XBitmapCanvas.hpp>
30 #include <basegfx/utils/systemdependentdata.hxx>
32 #if defined MACOSX || defined IOS
33 #include <premac.h>
34 #include <CoreGraphics/CoreGraphics.h>
35 #include <postmac.h>
36 #endif
38 struct BitmapBuffer;
39 class Color;
40 class SalGraphics;
41 class BitmapPalette;
42 struct BitmapSystemData;
43 enum class BmpScaleFlag;
45 extern const sal_uLong nVCLRLut[ 6 ];
46 extern const sal_uLong nVCLGLut[ 6 ];
47 extern const sal_uLong nVCLBLut[ 6 ];
48 extern const sal_uLong nVCLDitherLut[ 256 ];
49 extern const sal_uLong nVCLLut[ 256 ];
51 class VCL_PLUGIN_PUBLIC SalBitmap
53 public:
55 SalBitmap()
56 : mnChecksum(0)
57 , mbChecksumValid(false)
61 virtual ~SalBitmap();
63 virtual bool Create( const Size& rSize,
64 vcl::PixelFormat ePixelFormat,
65 const BitmapPalette& rPal ) = 0;
66 virtual bool Create( const SalBitmap& rSalBmp ) = 0;
67 virtual bool Create( const SalBitmap& rSalBmp,
68 SalGraphics* pGraphics ) = 0;
69 virtual bool Create( const SalBitmap& rSalBmp,
70 vcl::PixelFormat eNewPixelFormat) = 0;
71 virtual bool Create( const css::uno::Reference< css::rendering::XBitmapCanvas >& rBitmapCanvas,
72 Size& rSize,
73 bool bMask = false ) = 0;
74 virtual void Destroy() = 0;
75 virtual Size GetSize() const = 0;
76 virtual sal_uInt16 GetBitCount() const = 0;
78 virtual BitmapBuffer* AcquireBuffer( BitmapAccessMode nMode ) = 0;
79 virtual void ReleaseBuffer( BitmapBuffer* pBuffer, BitmapAccessMode nMode ) = 0;
80 virtual bool GetSystemData( BitmapSystemData& rData ) = 0;
82 virtual bool ScalingSupported() const = 0;
83 virtual bool Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag ) = 0;
84 void DropScaledCache();
86 virtual bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uInt8 nTol ) = 0;
88 virtual bool ConvertToGreyscale()
90 return false;
92 virtual bool InterpretAs8Bit()
94 return false;
97 virtual bool Erase( const Color& /*color*/ )
99 return false;
101 // Optimized case for AlphaMask::BlendWith().
102 virtual bool AlphaBlendWith( const SalBitmap& /*rSalBmp*/ )
104 return false;
107 #if defined MACOSX || defined IOS
108 // Related: tdf#146842 Eliminate temporary copies of SkiaSalBitmap when
109 // printing
110 // Commit 9eb732a32023e74c44ac8c3b5af9f5424273bb6c fixed crashing when
111 // printing SkiaSalBitmaps to a non-Skia SalGraphics. However, the fix
112 // almost always makes two copies of the SkiaSalBitmap's bitmap data: the
113 // first copy is made in SkiaSalBitmap::AcquireBuffer() and then
114 // QuartzSalBitmap makes a copy of the first copy.
115 // By making QuartzSalBitmap's methods that return a CGImageRef virtual,
116 // a non-Skia SalGraphics can now create a CGImageRef directly from a
117 // SkiaSalBitmap's Skia bitmap data without copying to any intermediate
118 // buffers.
119 // Note: these methods are not pure virtual as the SvpSalBitmap class
120 // extends this class directly.
121 virtual CGImageRef CreateWithMask( const SalBitmap&, int, int, int, int ) const { return nullptr; }
122 virtual CGImageRef CreateColorMask( int, int, int, int, Color ) const { return nullptr; }
123 virtual CGImageRef CreateCroppedImage( int, int, int, int ) const { return nullptr; }
124 #endif
126 BitmapChecksum GetChecksum() const
128 updateChecksum();
129 if (!mbChecksumValid)
130 return 0; // back-compat
131 return mnChecksum;
134 void InvalidateChecksum()
136 mbChecksumValid = false;
139 protected:
140 void updateChecksum() const;
141 // helper function to convert data in 1,2,4 bpp formats to a 8/24/32bpp format
142 enum class BitConvert
145 RGBA,
146 BGRA,
147 LAST = BGRA
149 static std::unique_ptr< sal_uInt8[] > convertDataBitCount( const sal_uInt8* src,
150 int width, int height, int bitCount, int bytesPerRow, const BitmapPalette& palette,
151 BitConvert type );
153 public:
154 // access to SystemDependentDataHolder, to support overload in derived class(es)
155 virtual const basegfx::SystemDependentDataHolder* accessSystemDependentDataHolder() const;
157 // exclusive management op's for SystemDependentData at SalBitmap
158 template<class T>
159 std::shared_ptr<T> getSystemDependentData() const
161 const basegfx::SystemDependentDataHolder* pDataHolder(accessSystemDependentDataHolder());
162 if(pDataHolder)
163 return std::static_pointer_cast<T>(pDataHolder->getSystemDependentData(typeid(T).hash_code()));
164 return std::shared_ptr<T>();
167 template<class T, class... Args>
168 std::shared_ptr<T> addOrReplaceSystemDependentData(Args&&... args) const
170 const basegfx::SystemDependentDataHolder* pDataHolder(accessSystemDependentDataHolder());
171 if(!pDataHolder)
172 return std::shared_ptr<T>();
174 std::shared_ptr<T> r = std::make_shared<T>(std::forward<Args>(args)...);
176 // tdf#129845 only add to buffer if a relevant buffer time is estimated
177 if(r->calculateCombinedHoldCyclesInSeconds() > 0)
179 basegfx::SystemDependentData_SharedPtr r2(r);
180 const_cast< basegfx::SystemDependentDataHolder* >(pDataHolder)->addOrReplaceSystemDependentData(r2);
183 return r;
186 private:
187 BitmapChecksum mnChecksum;
188 bool mbChecksumValid;
192 #endif
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */