| 1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 |
/*!******************************************************************** |
| 3 |
|
| 4 |
Audacity: A Digital Audio Editor |
| 5 |
|
| 6 |
WaveBitmapCache.h |
| 7 |
|
| 8 |
Dmitry Vedenko |
| 9 |
|
| 10 |
**********************************************************************/ |
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include <memory> |
| 14 |
|
| 15 |
#include "GraphicsDataCache.h" |
| 16 |
#include "Observer.h" |
| 17 |
#include "waveform/WavePaintParameters.h" |
| 18 |
|
| 19 |
class wxBitmap; |
| 20 |
class wxImage; |
| 21 |
class WaveDataCache; |
| 22 |
class Envelope; |
| 23 |
class WaveClip; |
| 24 |
|
| 25 |
//! An element, that contains a rasterized bitmap matching the WaveDataCacheElement |
| 26 |
class WAVE_TRACK_PAINT_API WaveBitmapCacheElement : |
| 27 |
public GraphicsDataCacheElementBase |
| 28 |
{ |
| 29 |
public: |
| 30 |
~WaveBitmapCacheElement() override; |
| 31 |
|
| 32 |
virtual uint8_t* Allocate(size_t width, size_t height) = 0; |
| 33 |
|
| 34 |
virtual size_t Width() const = 0; |
| 35 |
virtual size_t Height() const = 0; |
| 36 |
|
| 37 |
size_t AvailableColumns { 0 }; |
| 38 |
}; |
| 39 |
|
| 40 |
//! Cache containing rasterized bitmaps representing the waveform |
| 41 |
class WAVE_TRACK_PAINT_API WaveBitmapCache final : |
| 42 |
public GraphicsDataCache<WaveBitmapCacheElement> |
| 43 |
{ |
| 44 |
public: |
| 45 |
WaveBitmapCache(const WaveClip& waveClip, std::shared_ptr<WaveDataCache> dataCache, |
| 46 |
ElementFactory elementFactory); |
| 47 |
~WaveBitmapCache() override; |
| 48 |
|
| 49 |
WaveBitmapCache& SetPaintParameters(const WavePaintParameters& params); |
| 50 |
WaveBitmapCache& SetSelection(const ZoomInfo& zoomInfo, double t0, double t1, bool selected); |
| 51 |
|
| 52 |
private: |
| 53 |
bool InitializeElement( |
| 54 |
const GraphicsDataCacheKey& key, WaveBitmapCacheElement& element) override; |
| 55 |
|
| 56 |
void CheckCache(const ZoomInfo&, double, double) override; |
| 57 |
|
| 58 |
struct LookupHelper; |
| 59 |
|
| 60 |
WavePaintParameters mPaintParameters; |
| 61 |
|
| 62 |
struct |
| 63 |
{ |
| 64 |
int64_t FirstPixel { -1 }; |
| 65 |
int64_t LastPixel { -1 }; |
| 66 |
|
| 67 |
bool IsValid() const noexcept |
| 68 |
{ |
| 69 |
return FirstPixel < LastPixel; |
| 70 |
} |
| 71 |
} mSelection; |
| 72 |
|
| 73 |
std::unique_ptr<LookupHelper> mLookupHelper; |
| 74 |
|
| 75 |
const Envelope* mEnvelope { nullptr }; |
| 76 |
size_t mEnvelopeVersion { 0 }; |
| 77 |
|
| 78 |
const WaveClip& mWaveClip; |
| 79 |
Observer::Subscription mStretchChangedSubscription; |
| 80 |
}; |