Refactor: BLF Use Vector for Glyph Cache List #118174
|
@ -131,24 +131,20 @@ static void blf_glyph_cache_free(GlyphCacheBLF *gc)
|
|||
/** \name Glyph Cache List
|
||||
* \{ */
|
||||
|
||||
GlyphCacheListBLF::GlyphCacheListBLF(FontBLF *font) : list{}, font(font)
|
||||
{
|
||||
BLI_mutex_init(&glyph_cache_mutex);
|
||||
}
|
||||
GlyphCacheListBLF::GlyphCacheListBLF(FontBLF *font) : list{}, font(font) {}
|
||||
|
||||
GlyphCacheListBLF ::~GlyphCacheListBLF()
|
||||
{
|
||||
clear();
|
||||
BLI_mutex_end(&glyph_cache_mutex);
|
||||
};
|
||||
|
||||
GlyphCacheBLF *GlyphCacheListBLF::acquire()
|
||||
{
|
||||
BLI_mutex_lock(&glyph_cache_mutex);
|
||||
glyph_cache_mutex.lock();
|
||||
|
||||
GlyphCacheBLF *gc = nullptr;
|
||||
|
||||
for (auto &entry : list) {
|
||||
for (GlyphCacheBLF *entry : list) {
|
||||
if (entry->size == font->size && (entry->bold == ((font->flags & BLF_BOLD) != 0)) &&
|
||||
(entry->italic == ((font->flags & BLF_ITALIC) != 0)) &&
|
||||
(entry->char_weight == font->char_weight) && (entry->char_slant == font->char_slant) &&
|
||||
|
@ -161,7 +157,7 @@ GlyphCacheBLF *GlyphCacheListBLF::acquire()
|
|||
|
||||
if (!gc) {
|
||||
gc = blf_glyph_cache_new(font);
|
||||
list.push_back(gc);
|
||||
list.append(gc);
|
||||
}
|
||||
|
||||
return gc;
|
||||
|
@ -169,17 +165,17 @@ GlyphCacheBLF *GlyphCacheListBLF::acquire()
|
|||
|
||||
void GlyphCacheListBLF::release()
|
||||
{
|
||||
BLI_mutex_unlock(&glyph_cache_mutex);
|
||||
this->glyph_cache_mutex.unlock();
|
||||
}
|
||||
|
||||
void GlyphCacheListBLF::clear()
|
||||
{
|
||||
BLI_mutex_lock(&glyph_cache_mutex);
|
||||
for (auto &entry : list) {
|
||||
glyph_cache_mutex.lock();
|
||||
for (GlyphCacheBLF *entry : list) {
|
||||
blf_glyph_cache_free(entry);
|
||||
}
|
||||
list.clear();
|
||||
BLI_mutex_unlock(&glyph_cache_mutex);
|
||||
glyph_cache_mutex.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
|
||||
#include "BLI_vector.hh"
|
||||
|
||||
#include "GPU_texture.h"
|
||||
#include "GPU_vertex_buffer.h"
|
||||
|
@ -109,13 +111,9 @@ typedef struct KerningCacheBLF {
|
|||
} KerningCacheBLF;
|
||||
|
||||
Harley marked this conversation as resolved
Outdated
|
||||
class GlyphCacheListBLF {
|
||||
Harley marked this conversation as resolved
Hans Goudey
commented
`blender::Vector` is generally preferable since it has methods to work better with other Blender containers, and it has an inline buffer to avoid allocations for small numbers of elements
|
||||
private:
|
||||
std::vector<GlyphCacheBLF *> list;
|
||||
|
||||
blender::Vector<GlyphCacheBLF *> list;
|
||||
FontBLF *font;
|
||||
Hans Goudey
commented
Sorry, I didn't realize this pointer here as the resolution to the need to pass "font" to the functions. I'll propose an alternative change to see what you think Sorry, I didn't realize this pointer here as the resolution to the need to pass "font" to the functions. I'll propose an alternative change to see what you think
|
||||
|
||||
/** Mutex lock for glyph cache. */
|
||||
ThreadMutex glyph_cache_mutex;
|
||||
std::mutex glyph_cache_mutex;
|
||||
|
||||
public:
|
||||
Harley marked this conversation as resolved
Hans Goudey
commented
It would probably be simpler/easy to switch to It would probably be simpler/easy to switch to `std::mutex` now too :)
|
||||
GlyphCacheListBLF(FontBLF *font);
|
||||
|
|
Loading…
Reference in New Issue
private
is redundant for classes which are private by default