mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-03 19:30:09 +00:00
vector: keep a shared reference to cached color table
This commit is contained in:
parent
e00ca32669
commit
710a4fd208
@ -59,18 +59,16 @@
|
|||||||
|
|
||||||
class VGradientCache {
|
class VGradientCache {
|
||||||
public:
|
public:
|
||||||
struct CacheInfo : public VSpanData::Pinnable {
|
struct CacheInfo : public VColorTable {
|
||||||
inline CacheInfo(VGradientStops s) : stops(std::move(s)) {}
|
inline CacheInfo(VGradientStops s) : stops(std::move(s)) {}
|
||||||
uint32_t buffer32[VGradient::colorTableSize];
|
|
||||||
VGradientStops stops;
|
VGradientStops stops;
|
||||||
bool alpha{true};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::unordered_multimap<uint64_t, std::shared_ptr<const CacheInfo>>
|
using VGradientColorTableHash = std::unordered_multimap<uint64_t, std::shared_ptr<const CacheInfo>>;
|
||||||
VGradientColorTableHash;
|
|
||||||
bool generateGradientColorTable(const VGradientStops &stops, float alpha,
|
bool generateGradientColorTable(const VGradientStops &stops, float alpha,
|
||||||
uint32_t *colorTable, int size);
|
uint32_t *colorTable, int size);
|
||||||
inline const std::shared_ptr<const CacheInfo> getBuffer(
|
inline const std::shared_ptr<const VColorTable> getBuffer(
|
||||||
const VGradient &gradient)
|
const VGradient &gradient)
|
||||||
{
|
{
|
||||||
uint64_t hash_val = 0;
|
uint64_t hash_val = 0;
|
||||||
@ -748,9 +746,9 @@ void VSpanData::setup(const VBrush &brush, VPainter::CompositionMode /*mode*/,
|
|||||||
break;
|
break;
|
||||||
case VBrush::Type::LinearGradient: {
|
case VBrush::Type::LinearGradient: {
|
||||||
mType = VSpanData::Type::LinearGradient;
|
mType = VSpanData::Type::LinearGradient;
|
||||||
auto cacheInfo = VGradientCacheInstance.getBuffer(*brush.mGradient);
|
mColorTable = VGradientCacheInstance.getBuffer(*brush.mGradient);
|
||||||
mGradient.mColorTable = cacheInfo->buffer32;
|
mGradient.mColorTable = mColorTable->buffer32;
|
||||||
mGradient.mColorTableAlpha = cacheInfo->alpha;
|
mGradient.mColorTableAlpha = mColorTable->alpha;
|
||||||
mGradient.linear.x1 = brush.mGradient->linear.x1;
|
mGradient.linear.x1 = brush.mGradient->linear.x1;
|
||||||
mGradient.linear.y1 = brush.mGradient->linear.y1;
|
mGradient.linear.y1 = brush.mGradient->linear.y1;
|
||||||
mGradient.linear.x2 = brush.mGradient->linear.x2;
|
mGradient.linear.x2 = brush.mGradient->linear.x2;
|
||||||
@ -761,9 +759,9 @@ void VSpanData::setup(const VBrush &brush, VPainter::CompositionMode /*mode*/,
|
|||||||
}
|
}
|
||||||
case VBrush::Type::RadialGradient: {
|
case VBrush::Type::RadialGradient: {
|
||||||
mType = VSpanData::Type::RadialGradient;
|
mType = VSpanData::Type::RadialGradient;
|
||||||
auto cacheInfo = VGradientCacheInstance.getBuffer(*brush.mGradient);
|
mColorTable = VGradientCacheInstance.getBuffer(*brush.mGradient);
|
||||||
mGradient.mColorTable = cacheInfo->buffer32;
|
mGradient.mColorTable = mColorTable->buffer32;
|
||||||
mGradient.mColorTableAlpha = cacheInfo->alpha;
|
mGradient.mColorTableAlpha = mColorTable->alpha;
|
||||||
mGradient.radial.cx = brush.mGradient->radial.cx;
|
mGradient.radial.cx = brush.mGradient->radial.cx;
|
||||||
mGradient.radial.cy = brush.mGradient->radial.cy;
|
mGradient.radial.cy = brush.mGradient->radial.cy;
|
||||||
mGradient.radial.fx = brush.mGradient->radial.fx;
|
mGradient.radial.fx = brush.mGradient->radial.fx;
|
||||||
|
@ -138,11 +138,13 @@ struct VBitmapData
|
|||||||
int const_alpha;
|
int const_alpha;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct VColorTable
|
||||||
|
{
|
||||||
|
uint32_t buffer32[VGradient::colorTableSize];
|
||||||
|
bool alpha{true};
|
||||||
|
};
|
||||||
|
|
||||||
struct VSpanData {
|
struct VSpanData {
|
||||||
class Pinnable {
|
|
||||||
protected:
|
|
||||||
~Pinnable() = default;
|
|
||||||
};
|
|
||||||
enum class Type { None, Solid, LinearGradient, RadialGradient, Texture };
|
enum class Type { None, Solid, LinearGradient, RadialGradient, Texture };
|
||||||
|
|
||||||
void updateSpanFunc();
|
void updateSpanFunc();
|
||||||
@ -174,7 +176,7 @@ struct VSpanData {
|
|||||||
ProcessRleSpan mBlendFunc;
|
ProcessRleSpan mBlendFunc;
|
||||||
ProcessRleSpan mUnclippedBlendFunc;
|
ProcessRleSpan mUnclippedBlendFunc;
|
||||||
VSpanData::Type mType;
|
VSpanData::Type mType;
|
||||||
std::shared_ptr<VSpanData::Pinnable> mCachedGradient;
|
std::shared_ptr<const VColorTable> mColorTable{nullptr};
|
||||||
VPoint mOffset; // offset to the subsurface
|
VPoint mOffset; // offset to the subsurface
|
||||||
VSize mDrawableSize;// suburface size
|
VSize mDrawableSize;// suburface size
|
||||||
union {
|
union {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user