/* * Copyright 2022 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef skgpu_graphite_DrawAtlas_DEFINED #define skgpu_graphite_DrawAtlas_DEFINED #include <cmath> #include <string> #include <string_view> #include <vector> #include "src/core/SkIPoint16.h" #include "src/core/SkTHash.h" #include "src/gpu/AtlasTypes.h" class SkAutoPixmapStorage; namespace skgpu::graphite { class DrawContext; class Recorder; class TextureProxy; /** * TODO: the process described here is tentative, and this comment revised once locked down. * * This class manages one or more atlas textures on behalf of primitive draws in Device. The * drawing processes that use the atlas add preceding UploadTasks when generating RenderPassTasks. * The class provides facilities for using DrawTokens to detect data hazards. Plots that need * uploads are tracked until it is impossible to add data without overwriting texels read by draws * that have not yet been snapped to a RenderPassTask. At that point, the atlas will attempt to * allocate a new atlas texture (or "page") of the same size, up to a maximum number of textures, * and upload to that texture. If that's not possible, then the atlas will fail to add a subimage. * This gives the Device the chance to end the current draw, snap a RenderpassTask, and begin a new * one. Additional uploads will then succeed. * * When the atlas has multiple pages, new uploads are prioritized to the lower index pages, i.e., * it will try to upload to page 0 before page 1 or 2. To keep the atlas from continually using * excess space, periodic garbage collection is needed to shift data from the higher index pages to * the lower ones, and then eventually remove any pages that are no longer in use. "In use" is * determined by using the AtlasToken system: After a DrawPass is snapped a subarea of the page, or * "plot" is checked to see whether it was used in that DrawPass. If less than a quarter of the * plots have been used recently (within kPlotRecentlyUsedCount iterations) and there are available * plots in lower index pages, the higher index page will be deactivated, and its glyphs will * gradually migrate to other pages via the usual upload system. * * Garbage collection is initiated by the DrawAtlas's client via the compact() method. */ class DrawAtlas { … }; // For text there are three atlases (A8, 565, ARGB) that are kept in relation with one another. In // general, because A8 is the most frequently used mask format its dimensions are 2x the 565 and // ARGB dimensions, with the constraint that an atlas size will always contain at least one plot. // Since the ARGB atlas takes the most space, its dimensions are used to size the other two atlases. class DrawAtlasConfig { … }; } // namespace skgpu::graphite #endif