WIP: UI: Refactor blf_glyph for C++ Features #117794
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#117794
Loading…
Reference in New Issue
No description provided.
Delete Branch "Harley/blender:blf_glyph_cpp"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
GlyphBLF and GlyphCacheBLF become classes with constructors,
destructors, member functions, static functions. Simplified
names, default arguments, etc.
@HooglyBoogly I'm mostly hoping for a quick check to see if this is the sort of thing we are looking for, that this is done mostly correct, etc. If far off the mark or too many mistakes to count, then a simple "Yikes Harley, go read a book!" is also a valid comment.
Nice! Using objects with desctuctors etc. is definitely better. It does seem to improve on the C pattern of passing the "this" pointer as an argument. What I'm less convinced about is the static class methods in some cases. In some cases like acquiring the cache, that seems to more-so be the responsibility of the font or the caller, not the cache itself. Maybe free functions would be fine in some places. Generally those should be used when logic isn't "contained" completely in the class.
A next step (for a separate commit) would be replacing raw pointers and
new
withunique_ptr
to clarify ownership. Replacing linked lists withVector
might be necessary at the same time.@ -1232,3 +1265,3 @@
if (glyph_font->variations) {
FT_Fixed coords[BLF_VARIATIONS_MAX];
FT_Fixed coords[BLF_VARIATIONS_MAX] = {0};
Isn't this array initialized by
FT_Get_Var_Design_Coordinates
? If so, zero initializing it here seems redundant@ -1289,3 +1321,1 @@
GlyphCacheBLF *gc,
const uint charcode,
uint8_t subpixel)
GlyphBLF *GlyphBLF::get_glyph(FontBLF *font,
get
is a misleading name for a function that might create the glyph. I'd stick with the old "ensure" name@ -1321,3 +1351,2 @@
#ifdef BLF_SUBPIXEL_AA
GlyphBLF *blf_glyph_ensure_subpixel(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, int32_t pen_x)
GlyphBLF *GlyphBLF::glyph_refine_aa(FontBLF *font, GlyphCacheBLF *gc, int32_t pen_x)
It feels a bit for a class to return a pointer to itself or potentially create a new instance. Just that it's handling logic that isn't really "self contained". So maybe going with a free function would be clearer here too
@HooglyBoogly
I think this is an improvement, but again wanting your opinion...
For current code the cache list is a ListBase that holds GlyphCacheBLF structs.
But it is the container that I want member functions, so I made a class to be the cache list, so containing the listbase, ThreadMutex, and then moved acquire, release, and clear there. This seems to make more sense, and at least it and GlyphCacheBLF have no static class methods.
It does give me pretty things like
font->cache->release();
@HooglyBoogly
This "acquire" is always just getting (or making) the correct GlyphCacheBLF that matches the current settings and size of the font. So I just added a pointer to the font in GlyphCacheListBLF. It only has to be set once, during FontBLF creation and could later be just a passing of this during its constructor. But that means that we get a nicer
font->cache->acquire()
Closing. A simpler refactor was committed by Hans here: #118222
Pull request closed