-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] removed global mutable variable for tessellation allocation function pointers #46127
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ static void HeapFree(void* userData, void* ptr) { | |
| } | ||
|
|
||
| // Note: these units are "number of entities" for bucket size and not in KB. | ||
| static TESSalloc alloc = { | ||
| static const TESSalloc kAlloc = { | ||
| HeapAlloc, HeapRealloc, HeapFree, 0, /* =userData */ | ||
| 16, /* =meshEdgeBucketSize */ | ||
| 16, /* =meshVertexBucketSize */ | ||
|
|
@@ -32,7 +32,19 @@ static TESSalloc alloc = { | |
| }; | ||
|
|
||
| Tessellator::Tessellator() | ||
| : c_tessellator_(::tessNewTess(&alloc), &DestroyTessellator) {} | ||
| : c_tess_alloc_(nullptr, &DestroyTessAlloc), | ||
| c_tessellator_(nullptr, &DestroyTessellator) { | ||
| { | ||
| CTessAlloc tess_alloc(new TESSalloc(), &DestroyTessAlloc); | ||
| c_tess_alloc_ = std::move(tess_alloc); | ||
| } | ||
| memcpy(c_tess_alloc_.get(), &kAlloc, sizeof(TESSalloc)); | ||
| { | ||
| CTessellator tessellator(::tessNewTess(c_tess_alloc_.get()), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If you want to clarify the lifetime of this structure, then it should be sufficient to declare the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. The code as it was written is conforming to the api and docstrings since it takes a mutable pointer and has no mention of what it does to it. libTess2 will never be updated so it should be safe to pass a pointer to something on the stack. |
||
| &DestroyTessellator); | ||
| c_tessellator_ = std::move(tessellator); | ||
| } | ||
| } | ||
|
|
||
| Tessellator::~Tessellator() = default; | ||
|
|
||
|
|
@@ -128,4 +140,10 @@ void DestroyTessellator(TESStesselator* tessellator) { | |
| } | ||
| } | ||
|
|
||
| void DestroyTessAlloc(TESSalloc* alloc) { | ||
| if (alloc != nullptr) { | ||
| delete alloc; | ||
| } | ||
| } | ||
|
|
||
| } // namespace impeller | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This nested scope can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used those so someone doesn't accidentally use
tessellatorafter the move. That's not a compilation error, but is a clang tidy error.