MCPcopy Create free account
hub / github.com/Snapchat/Valdi / allocateBitmap

Method allocateBitmap

snap_drawing/src/snap_drawing/cpp/Utils/ImageQueue.cpp:93–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91}
92
93Valdi::Result<Ref<Valdi::IBitmap>> ImageQueue::allocateBitmap(int width, int height, Valdi::ColorType colorType) {
94 auto bitmapInfo = Valdi::BitmapInfo(width, height, colorType, Valdi::AlphaType::AlphaTypePremul, 0);
95
96 {
97 std::lock_guard<Valdi::Mutex> lock(_mutex);
98 if (!isCacheCompatibleWithBitmapInfo(bitmapInfo)) {
99 _cacheBitmapInfo = {bitmapInfo};
100 _cachedBitmaps.clear();
101 }
102
103 if (!_cachedBitmaps.empty()) {
104 auto cachedBitmap = std::move(_cachedBitmaps.back());
105 _cachedBitmaps.pop_back();
106
107 Ref<Valdi::IBitmap> pooledBitmap = Valdi::makeShared<PooledBitmap>(this, std::move(cachedBitmap));
108 return pooledBitmap;
109 }
110 }
111
112 // Cache is empty, allocating the bitmap
113
114 auto bitmap = Bitmap::make(bitmapInfo);
115 if (!bitmap) {
116 return bitmap.moveError();
117 }
118
119 Ref<Valdi::IBitmap> pooledBitmap = Valdi::makeShared<PooledBitmap>(this, bitmap.moveValue());
120 return pooledBitmap;
121}
122
123void ImageQueue::enqueueCachedBitmap(const Ref<Valdi::IBitmap>& sourceBitmap) {
124 std::lock_guard<Valdi::Mutex> lock(_mutex);

Callers 1

allocateAndEnqueueMethod · 0.45

Calls 4

clearMethod · 0.65
BitmapInfoClass · 0.50
emptyMethod · 0.45
backMethod · 0.45

Tested by 1

allocateAndEnqueueMethod · 0.36