10#include <unordered_map>
44 return GradientHandle((slotIndex1Based << 8) | uint32_t(generation));
120 inline size_t Width() const noexcept {
return m_width; }
123 inline uint32_t
PageCount() const noexcept {
return static_cast<uint32_t
>(m_pages.size()); }
160 uint64_t contentHash = 0;
161 uint16_t refcount = 0;
166 uint8_t generation = 0;
174 uint32_t rowsUsed = 0;
175 std::vector<color4b> data;
176 Image* image =
nullptr;
181 uint32_t dirtyFirst = UINT32_MAX;
182 uint32_t dirtyLast = 0;
183 void MarkRows(uint32_t first, uint32_t last)
noexcept
185 dirtyFirst = std::min(dirtyFirst, first);
186 dirtyLast = std::max(dirtyLast, last);
188 void MarkAll() noexcept {
if (height > 0) MarkRows(0, height - 1); }
189 bool HasDirtyRows() const noexcept {
return dirtyFirst <= dirtyLast; }
190 void ClearDirty() noexcept { dirtyFirst = UINT32_MAX; dirtyLast = 0; }
194 int32_t smallRow = -1;
195 int32_t smallCursor = 0;
201 GradientHandle AcquireSmall(uint16_t width, uint64_t contentHash,
202 const color4b* colors);
203 GradientHandle AcquireRow(uint64_t contentHash,
204 std::span<const color4b> rowPixels);
207 int32_t AllocateSmallSlot(uint16_t width);
208 int32_t AllocateRowSlot();
210 uint32_t AllocateSlotStorage();
211 void FreeSlotStorage(uint32_t slotIdx);
213 bool GrowOrAddPage(uint32_t& outPageIdx, uint32_t& outRow);
214 bool EnsureSmallRowAvailable(uint32_t& outPageIdx, uint16_t width);
216 Slot* GetSlot(GradientHandle handle);
217 const Slot* GetSlot(GradientHandle handle)
const;
219 void ReleaseSlot(uint32_t slotIdx);
221 static uint64_t HashGradient(
const Gradient& g);
222 static uint64_t HashSmall(uint16_t width,
const color4b* colors);
225 std::vector<Page> m_pages;
226 std::vector<Slot> m_slots;
227 std::vector<uint32_t> m_freeSlotStorage;
232 static constexpr uint32_t kFreeListCount = 6;
233 std::vector<uint32_t> m_freeLists[kFreeListCount];
236 std::unordered_map<uint64_t, uint32_t> m_contentDedup;
238 bool m_pageTableDirty =
true;
void MarkPageModified(uint32_t pageIndex) noexcept
Makes the next GetGradientImage upload the whole page.
void AddRef(GradientHandle handle)
Raises the refcount of a live handle; pair with one Release.
size_t Width() const noexcept
Page width in texels, the same for every page.
Definition gui_gradient_manager.h:120
void ClearAll() noexcept
Releases every slot; every outstanding GradientHandle becomes stale, so holders (StyleManager,...
static constexpr uint32_t kMaxPageHeight
Page height cap; a full page gets a new page instead of growing.
Definition gui_gradient_manager.h:69
int32_t GetPagePhysicalImageIndex(uint32_t pageIndex) const noexcept
GradientHandle AcquireColors(const color4f &c0, const color4f &c1, const color4f &c2)
A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
GradientHandle AcquireColors(const color4b &c0, const color4b &c1)
A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
GradientHandle AcquireSolidColor(const color4f &color)
A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
bool Release(GradientHandle handle)
Lowers the refcount; true when it reached zero and the slot was reclaimed.
GradientHandle AcquireColors(const color4b &c0, const color4b &c1, const color4b &c2, const color4b &c3)
A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
GradientManager(size_t width=256)
An empty atlas whose pages are width texels wide.
bool IsValid(GradientHandle handle) const
True if the handle is live (slot occupied and generation matches).
std::span< const color4b > PageTextureData(uint32_t pageIndex) const noexcept
CPU texels of a page, PageHeight x Width.
GradientHandle AcquireRowPixels(std::span< const color4b > pixels)
A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
void ClearPageTableChanged() noexcept
Definition gui_gradient_manager.h:145
GradientHandle AcquireColors(const color4f &c0, const color4f &c1)
A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
GradientHandle AcquireGradient(const Gradient &g)
A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
GradientHandle AcquireSolidColor(const color4b &color)
A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
void SetPagePhysicalImageIndex(uint32_t pageIndex, int32_t shaderSlotZeroBased) noexcept
tachyon::Image * GetGradientImage(GraphicsContext *graphicsContext, uint32_t pageIndex=0)
The GPU image of a page, made when it's new or has grown; otherwise the rows written since go up into...
void ReleaseAll(GraphicsContext *graphicsContext)
Destroys every GPU image of the atlas (deferred through graphicsContext).
bool HasPageTableChanged() const noexcept
Definition gui_gradient_manager.h:144
size_t PageHeight(uint32_t pageIndex) const noexcept
Allocated height of a page in rows; the rows in use are at most this.
uint16_t GetRefcount(GradientHandle handle) const
Refcount of a live handle; 0 for an invalid or stale handle.
uint32_t PageCount() const noexcept
Number of pages allocated.
Definition gui_gradient_manager.h:123
std::span< color4b > PageTextureData(uint32_t pageIndex) noexcept
Writable CPU texels of a page; call MarkPageModified after writing.
GradientHandle AcquireColors(const color4f &c0, const color4f &c1, const color4f &c2, const color4f &c3)
A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
AtlasLocation GetLocation(GradientHandle handle) const
The atlas position of a handle; all zero for an invalid or stale handle.
GradientHandle AcquireColors(const color4b &c0, const color4b &c1, const color4b &c2)
A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
static constexpr int32_t kUnregisteredPage
GetPagePhysicalImageIndex of a page the renderer hasn't registered.
Definition gui_gradient_manager.h:72
A graphics backend: the device, the window contexts that render the GUI's windows,...
Definition gui_graphics_context.h:53
An image made by GraphicsContext::CreateImage; the backend defines its contents.
Definition gui_image.h:102
Definition gui_logging.h:24
Where a handle's texels are in the atlas.
Definition gui_gradient_manager.h:50
uint8_t page
logical page index (0..PageCount()-1)
Definition gui_gradient_manager.h:54
uint16_t width
number of columns (1..page.width)
Definition gui_gradient_manager.h:53
uint16_t col
starting column within the row (0..page.width-1)
Definition gui_gradient_manager.h:51
uint16_t row
row index within the page (0..page.height-1)
Definition gui_gradient_manager.h:52
Handle to a reference-counted GradientManager atlas slot.
Definition gui_gradient_manager.h:27
constexpr uint8_t Generation() const
wraps around
Definition gui_gradient_manager.h:36
static constexpr GradientHandle Invalid()
the invalid handle
Definition gui_gradient_manager.h:40
constexpr uint32_t SlotIndex() const
1-based; 0 = invalid
Definition gui_gradient_manager.h:35
constexpr bool IsValid() const
Not the invalid handle; GradientManager::IsValid also checks it's still live.
Definition gui_gradient_manager.h:34
constexpr bool operator==(const GradientHandle &) const noexcept=default
constexpr GradientHandle(uint32_t v)
Definition gui_gradient_manager.h:31
uint32_t value
encoded slot index and generation
Definition gui_gradient_manager.h:28
static constexpr GradientHandle Make(uint32_t slotIndex1Based, uint8_t generation)
Encodes a slot index (1-based) and generation.
Definition gui_gradient_manager.h:42
constexpr GradientHandle()=default
Up to kMaxStops color stops plus an angle and interpolation color space.
Definition gui_style_gradient.h:93
Definition gui_base_types.h:383
Definition gui_base_types.h:394