WIP: UI: Refactor blf_glyph for C++ Features #117794

Closed
Harley Acheson wants to merge 6 commits from Harley/blender:blf_glyph_cpp into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

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.

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.
Harley Acheson added 1 commit 2024-02-04 03:38:25 +01:00
d125b73299 WIP: UI: Refactor blf_glyph for C++ Features
GlyphBLF and GlyphCacheBLF become classes with constructors,
destructors, member functions, static functions. Simplified
names, default arguments, etc.
Harley Acheson added this to the User Interface project 2024-02-04 03:38:48 +01:00
Harley Acheson requested review from Hans Goudey 2024-02-04 03:38:55 +01:00
Hans Goudey reviewed 2024-02-05 14:51:09 +01:00
Hans Goudey left a comment
Member

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 with unique_ptr to clarify ownership. Replacing linked lists with Vector might be necessary at the same time.

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` with `unique_ptr` to clarify ownership. Replacing linked lists with `Vector` 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};
Member

Isn't this array initialized by FT_Get_Var_Design_Coordinates? If so, zero initializing it here seems redundant

Isn't this array initialized by `FT_Get_Var_Design_Coordinates`? If so, zero initializing it here seems redundant
Harley marked this conversation as resolved
@ -1289,3 +1321,1 @@
GlyphCacheBLF *gc,
const uint charcode,
uint8_t subpixel)
GlyphBLF *GlyphBLF::get_glyph(FontBLF *font,
Member

get is a misleading name for a function that might create the glyph. I'd stick with the old "ensure" name

`get` is a misleading name for a function that might create the glyph. I'd stick with the old "ensure" name
Harley marked this conversation as resolved
@ -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)
Member

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

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
Harley Acheson added 2 commits 2024-02-06 02:08:50 +01:00
Author
Member

@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 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();`
Harley Acheson added 2 commits 2024-02-06 21:17:54 +01:00
Author
Member

@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()

@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()`
Harley Acheson added 1 commit 2024-02-06 22:02:17 +01:00
Author
Member

Closing. A simpler refactor was committed by Hans here: #118222

Closing. A simpler refactor was committed by Hans here: #118222
Harley Acheson closed this pull request 2024-02-20 01:43:40 +01:00

Pull request closed

Sign in to join this conversation.
No reviewers
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
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#117794
No description provided.