Rename GrAtlasMgr to GrAtlas (and other cleanup)
This CL also renames the old GrAtlas to ClientPlotUsage and moves it into the new GrAtlas. R=jvanverth@google.com Author: robertphillips@google.com Review URL: https://codereview.chromium.org/355673002
This commit is contained in:
parent
20fa0c3238
commit
1d86ee8363
@ -23,7 +23,7 @@ static int g_UploadCount = 0;
|
||||
GrPlot::GrPlot() : fDrawToken(NULL, 0)
|
||||
, fTexture(NULL)
|
||||
, fRects(NULL)
|
||||
, fAtlasMgr(NULL)
|
||||
, fAtlas(NULL)
|
||||
, fBytesPerPixel(1)
|
||||
, fDirty(false)
|
||||
, fBatchUploads(false)
|
||||
@ -37,10 +37,10 @@ GrPlot::~GrPlot() {
|
||||
delete fRects;
|
||||
}
|
||||
|
||||
void GrPlot::init(GrAtlasMgr* mgr, int offX, int offY, int width, int height, size_t bpp,
|
||||
void GrPlot::init(GrAtlas* atlas, int offX, int offY, int width, int height, size_t bpp,
|
||||
bool batchUploads) {
|
||||
fRects = GrRectanizer::Factory(width, height);
|
||||
fAtlasMgr = mgr;
|
||||
fAtlas = atlas;
|
||||
fOffset.set(offX * width, offY * height);
|
||||
fBytesPerPixel = bpp;
|
||||
fPlotData = NULL;
|
||||
@ -146,9 +146,9 @@ void GrPlot::resetRects() {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GrAtlasMgr::GrAtlasMgr(GrGpu* gpu, GrPixelConfig config,
|
||||
const SkISize& backingTextureSize,
|
||||
int numPlotsX, int numPlotsY, bool batchUploads) {
|
||||
GrAtlas::GrAtlas(GrGpu* gpu, GrPixelConfig config,
|
||||
const SkISize& backingTextureSize,
|
||||
int numPlotsX, int numPlotsY, bool batchUploads) {
|
||||
fGpu = SkRef(gpu);
|
||||
fPixelConfig = config;
|
||||
fBackingTextureSize = backingTextureSize;
|
||||
@ -185,7 +185,7 @@ GrAtlasMgr::GrAtlasMgr(GrGpu* gpu, GrPixelConfig config,
|
||||
}
|
||||
}
|
||||
|
||||
GrAtlasMgr::~GrAtlasMgr() {
|
||||
GrAtlas::~GrAtlas() {
|
||||
SkSafeUnref(fTexture);
|
||||
SkDELETE_ARRAY(fPlotArray);
|
||||
|
||||
@ -195,7 +195,7 @@ GrAtlasMgr::~GrAtlasMgr() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void GrAtlasMgr::moveToHead(GrPlot* plot) {
|
||||
void GrAtlas::makeMRU(GrPlot* plot) {
|
||||
if (fPlotList.head() == plot) {
|
||||
return;
|
||||
}
|
||||
@ -204,15 +204,15 @@ void GrAtlasMgr::moveToHead(GrPlot* plot) {
|
||||
fPlotList.addToHead(plot);
|
||||
};
|
||||
|
||||
GrPlot* GrAtlasMgr::addToAtlas(GrAtlas* atlas,
|
||||
int width, int height, const void* image,
|
||||
SkIPoint16* loc) {
|
||||
GrPlot* GrAtlas::addToAtlas(ClientPlotUsage* usage,
|
||||
int width, int height, const void* image,
|
||||
SkIPoint16* loc) {
|
||||
// iterate through entire plot list for this atlas, see if we can find a hole
|
||||
// last one was most recently added and probably most empty
|
||||
for (int i = atlas->fPlots.count()-1; i >= 0; --i) {
|
||||
GrPlot* plot = atlas->fPlots[i];
|
||||
for (int i = usage->fPlots.count()-1; i >= 0; --i) {
|
||||
GrPlot* plot = usage->fPlots[i];
|
||||
if (plot->addSubImage(width, height, image, loc)) {
|
||||
this->moveToHead(plot);
|
||||
this->makeMRU(plot);
|
||||
return plot;
|
||||
}
|
||||
}
|
||||
@ -240,9 +240,10 @@ GrPlot* GrAtlasMgr::addToAtlas(GrAtlas* atlas,
|
||||
// make sure texture is set for quick lookup
|
||||
plot->fTexture = fTexture;
|
||||
if (plot->addSubImage(width, height, image, loc)) {
|
||||
this->moveToHead(plot);
|
||||
this->makeMRU(plot);
|
||||
// new plot for atlas, put at end of array
|
||||
*(atlas->fPlots.append()) = plot;
|
||||
SkASSERT(!usage->fPlots.contains(plot));
|
||||
*(usage->fPlots.append()) = plot;
|
||||
return plot;
|
||||
}
|
||||
plotIter.next();
|
||||
@ -252,21 +253,15 @@ GrPlot* GrAtlasMgr::addToAtlas(GrAtlas* atlas,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool GrAtlasMgr::removePlot(GrAtlas* atlas, const GrPlot* plot) {
|
||||
// iterate through plot list for this atlas
|
||||
int count = atlas->fPlots.count();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
if (plot == atlas->fPlots[i]) {
|
||||
atlas->fPlots.remove(i);
|
||||
return true;
|
||||
}
|
||||
void GrAtlas::removePlot(ClientPlotUsage* usage, const GrPlot* plot) {
|
||||
int index = usage->fPlots.find(const_cast<GrPlot*>(plot));
|
||||
if (index >= 0) {
|
||||
usage->fPlots.remove(index);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// get a plot that's not being used by the current draw
|
||||
GrPlot* GrAtlasMgr::getUnusedPlot() {
|
||||
GrPlot* GrAtlas::getUnusedPlot() {
|
||||
GrPlotList::Iter plotIter;
|
||||
plotIter.init(fPlotList, GrPlotList::Iter::kTail_IterStart);
|
||||
GrPlot* plot;
|
||||
@ -280,7 +275,7 @@ GrPlot* GrAtlasMgr::getUnusedPlot() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void GrAtlasMgr::uploadPlotsToTexture() {
|
||||
void GrAtlas::uploadPlotsToTexture() {
|
||||
if (fBatchUploads) {
|
||||
GrPlotList::Iter plotIter;
|
||||
plotIter.init(fPlotList, GrPlotList::Iter::kHead_IterStart);
|
||||
|
@ -16,18 +16,17 @@
|
||||
|
||||
class GrGpu;
|
||||
class GrRectanizer;
|
||||
class GrAtlasMgr;
|
||||
class GrAtlas;
|
||||
|
||||
// The backing GrTexture for a set of GrAtlases is broken into a spatial grid of GrPlots. When
|
||||
// a GrAtlas needs space on the texture, it requests a GrPlot. Each GrAtlas can claim one
|
||||
// or more GrPlots. The GrPlots keep track of subimage placement via their GrRectanizer. Once a
|
||||
// GrPlot is "full" (i.e. there is no room for the new subimage according to the GrRectanizer), the
|
||||
// GrAtlas can request a new GrPlot via GrAtlasMgr::addToAtlas().
|
||||
// GrAtlas can request a new GrPlot via GrAtlas::addToAtlas().
|
||||
//
|
||||
// If all GrPlots are allocated, the replacement strategy is up to the client. The drawToken is
|
||||
// available to ensure that all draw calls are finished for that particular GrPlot.
|
||||
// GrAtlasMgr::removeUnusedPlots() will free up any finished plots for a given GrAtlas.
|
||||
// GrAtlas::removeUnusedPlots() will free up any finished plots for a given GrAtlas.
|
||||
|
||||
class GrPlot {
|
||||
public:
|
||||
@ -47,7 +46,7 @@ public:
|
||||
private:
|
||||
GrPlot();
|
||||
~GrPlot(); // does not try to delete the fNext field
|
||||
void init(GrAtlasMgr* mgr, int offX, int offY, int width, int height, size_t bpp,
|
||||
void init(GrAtlas* atlas, int offX, int offY, int width, int height, size_t bpp,
|
||||
bool batchUploads);
|
||||
|
||||
// for recycling
|
||||
@ -56,30 +55,42 @@ private:
|
||||
unsigned char* fPlotData;
|
||||
GrTexture* fTexture;
|
||||
GrRectanizer* fRects;
|
||||
GrAtlasMgr* fAtlasMgr;
|
||||
GrAtlas* fAtlas;
|
||||
SkIPoint16 fOffset; // the offset of the plot in the backing texture
|
||||
size_t fBytesPerPixel;
|
||||
SkIRect fDirtyRect;
|
||||
bool fDirty;
|
||||
bool fBatchUploads;
|
||||
|
||||
friend class GrAtlasMgr;
|
||||
friend class GrAtlas;
|
||||
};
|
||||
|
||||
typedef SkTInternalLList<GrPlot> GrPlotList;
|
||||
|
||||
class GrAtlasMgr {
|
||||
class GrAtlas {
|
||||
public:
|
||||
GrAtlasMgr(GrGpu*, GrPixelConfig, const SkISize& backingTextureSize,
|
||||
int numPlotsX, int numPlotsY, bool batchUploads);
|
||||
~GrAtlasMgr();
|
||||
// This class allows each client to independently track the GrPlots in
|
||||
// which its data is stored.
|
||||
class ClientPlotUsage {
|
||||
public:
|
||||
bool isEmpty() const { return 0 == fPlots.count(); }
|
||||
|
||||
private:
|
||||
SkTDArray<GrPlot*> fPlots;
|
||||
|
||||
friend class GrAtlas;
|
||||
};
|
||||
|
||||
GrAtlas(GrGpu*, GrPixelConfig, const SkISize& backingTextureSize,
|
||||
int numPlotsX, int numPlotsY, bool batchUploads);
|
||||
~GrAtlas();
|
||||
|
||||
// add subimage of width, height dimensions to atlas
|
||||
// returns the containing GrPlot and location relative to the backing texture
|
||||
GrPlot* addToAtlas(GrAtlas*, int width, int height, const void*, SkIPoint16*);
|
||||
GrPlot* addToAtlas(ClientPlotUsage*, int width, int height, const void*, SkIPoint16*);
|
||||
|
||||
// remove reference to this plot
|
||||
bool removePlot(GrAtlas* atlas, const GrPlot* plot);
|
||||
void removePlot(ClientPlotUsage* usage, const GrPlot* plot);
|
||||
|
||||
// get a plot that's not being used by the current draw
|
||||
// this allows us to overwrite this plot without flushing
|
||||
@ -92,7 +103,7 @@ public:
|
||||
void uploadPlotsToTexture();
|
||||
|
||||
private:
|
||||
void moveToHead(GrPlot* plot);
|
||||
void makeMRU(GrPlot* plot);
|
||||
|
||||
GrGpu* fGpu;
|
||||
GrPixelConfig fPixelConfig;
|
||||
@ -104,21 +115,8 @@ private:
|
||||
|
||||
// allocated array of GrPlots
|
||||
GrPlot* fPlotArray;
|
||||
// LRU list of GrPlots
|
||||
// LRU list of GrPlots (MRU at head - LRU at tail)
|
||||
GrPlotList fPlotList;
|
||||
};
|
||||
|
||||
class GrAtlas {
|
||||
public:
|
||||
GrAtlas() { }
|
||||
~GrAtlas() { }
|
||||
|
||||
bool isEmpty() { return 0 == fPlots.count(); }
|
||||
|
||||
private:
|
||||
SkTDArray<GrPlot*> fPlots;
|
||||
|
||||
friend class GrAtlasMgr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "GrTextContext.h"
|
||||
|
||||
class GrTextStrike;
|
||||
class GrAtlasMgr;
|
||||
|
||||
/*
|
||||
* This class implements GrTextContext using standard bitmap fonts
|
||||
|
@ -53,17 +53,17 @@ void GrLayerCache::init() {
|
||||
static const int kAtlasTextureWidth = 1024;
|
||||
static const int kAtlasTextureHeight = 1024;
|
||||
|
||||
SkASSERT(NULL == fAtlasMgr.get());
|
||||
SkASSERT(NULL == fAtlas.get());
|
||||
|
||||
// The layer cache only gets 1 plot
|
||||
SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight);
|
||||
fAtlasMgr.reset(SkNEW_ARGS(GrAtlasMgr, (fContext->getGpu(), kSkia8888_GrPixelConfig,
|
||||
textureSize, 1, 1, false)));
|
||||
fAtlas.reset(SkNEW_ARGS(GrAtlas, (fContext->getGpu(), kSkia8888_GrPixelConfig,
|
||||
textureSize, 1, 1, false)));
|
||||
}
|
||||
|
||||
void GrLayerCache::freeAll() {
|
||||
fLayerHash.deleteAll();
|
||||
fAtlasMgr.free();
|
||||
fAtlas.free();
|
||||
}
|
||||
|
||||
GrCachedLayer* GrLayerCache::createLayer(const SkPicture* picture, int layerID) {
|
||||
|
@ -90,7 +90,7 @@ private:
|
||||
// The GrLayerCache caches pre-computed saveLayers for later rendering.
|
||||
// Non-atlased layers are stored in their own GrTexture while the atlased
|
||||
// layers share a single GrTexture.
|
||||
// Unlike the GrFontCache, the GrTexture atlas only has one GrAtlasMgr (for 8888)
|
||||
// Unlike the GrFontCache, the GrTexture atlas only has one GrAtlas (for 8888)
|
||||
// and one GrPlot (for the entire atlas). As such, the GrLayerCache
|
||||
// roughly combines the functionality of the GrFontCache and GrTextStrike
|
||||
// classes.
|
||||
@ -117,8 +117,8 @@ public:
|
||||
|
||||
private:
|
||||
GrContext* fContext; // pointer back to owning context
|
||||
SkAutoTDelete<GrAtlasMgr> fAtlasMgr; // TODO: could lazily allocate
|
||||
GrAtlas fPlotUsage;
|
||||
SkAutoTDelete<GrAtlas> fAtlas; // TODO: could lazily allocate
|
||||
GrAtlas::ClientPlotUsage fPlotUsage;
|
||||
|
||||
class PictureLayerKey;
|
||||
GrTHashTable<GrCachedLayer, PictureLayerKey, 7> fLayerHash;
|
||||
|
@ -32,7 +32,7 @@ static int g_PurgeCount = 0;
|
||||
GrFontCache::GrFontCache(GrGpu* gpu) : fGpu(gpu) {
|
||||
gpu->ref();
|
||||
for (int i = 0; i < kAtlasCount; ++i) {
|
||||
fAtlasMgr[i] = NULL;
|
||||
fAtlases[i] = NULL;
|
||||
}
|
||||
|
||||
fHead = fTail = NULL;
|
||||
@ -41,7 +41,7 @@ GrFontCache::GrFontCache(GrGpu* gpu) : fGpu(gpu) {
|
||||
GrFontCache::~GrFontCache() {
|
||||
fCache.deleteAll();
|
||||
for (int i = 0; i < kAtlasCount; ++i) {
|
||||
delete fAtlasMgr[i];
|
||||
delete fAtlases[i];
|
||||
}
|
||||
fGpu->unref();
|
||||
#if FONT_CACHE_STATS
|
||||
@ -79,17 +79,17 @@ GrTextStrike* GrFontCache::generateStrike(GrFontScaler* scaler,
|
||||
GrMaskFormat format = scaler->getMaskFormat();
|
||||
GrPixelConfig config = mask_format_to_pixel_config(format);
|
||||
int atlasIndex = mask_format_to_atlas_index(format);
|
||||
if (NULL == fAtlasMgr[atlasIndex]) {
|
||||
if (NULL == fAtlases[atlasIndex]) {
|
||||
SkISize textureSize = SkISize::Make(GR_ATLAS_TEXTURE_WIDTH,
|
||||
GR_ATLAS_TEXTURE_HEIGHT);
|
||||
fAtlasMgr[atlasIndex] = SkNEW_ARGS(GrAtlasMgr, (fGpu, config,
|
||||
textureSize,
|
||||
GR_NUM_PLOTS_X,
|
||||
GR_NUM_PLOTS_Y,
|
||||
true));
|
||||
fAtlases[atlasIndex] = SkNEW_ARGS(GrAtlas, (fGpu, config,
|
||||
textureSize,
|
||||
GR_NUM_PLOTS_X,
|
||||
GR_NUM_PLOTS_Y,
|
||||
true));
|
||||
}
|
||||
GrTextStrike* strike = SkNEW_ARGS(GrTextStrike,
|
||||
(this, scaler->getKey(), format, fAtlasMgr[atlasIndex]));
|
||||
(this, scaler->getKey(), format, fAtlases[atlasIndex]));
|
||||
fCache.insert(key, strike);
|
||||
|
||||
if (fHead) {
|
||||
@ -108,8 +108,8 @@ GrTextStrike* GrFontCache::generateStrike(GrFontScaler* scaler,
|
||||
void GrFontCache::freeAll() {
|
||||
fCache.deleteAll();
|
||||
for (int i = 0; i < kAtlasCount; ++i) {
|
||||
delete fAtlasMgr[i];
|
||||
fAtlasMgr[i] = NULL;
|
||||
delete fAtlases[i];
|
||||
fAtlases[i] = NULL;
|
||||
}
|
||||
fHead = NULL;
|
||||
fTail = NULL;
|
||||
@ -125,8 +125,8 @@ void GrFontCache::purgeStrike(GrTextStrike* strike) {
|
||||
bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike) {
|
||||
SkASSERT(NULL != preserveStrike);
|
||||
|
||||
GrAtlasMgr* atlasMgr = preserveStrike->fAtlasMgr;
|
||||
GrPlot* plot = atlasMgr->getUnusedPlot();
|
||||
GrAtlas* atlas = preserveStrike->fAtlas;
|
||||
GrPlot* plot = atlas->getUnusedPlot();
|
||||
if (NULL == plot) {
|
||||
return false;
|
||||
}
|
||||
@ -145,7 +145,7 @@ bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike) {
|
||||
strikeToPurge->removePlot(plot);
|
||||
|
||||
// clear out any empty strikes (except this one)
|
||||
if (strikeToPurge != preserveStrike && strikeToPurge->fAtlas.isEmpty()) {
|
||||
if (strikeToPurge != preserveStrike && strikeToPurge->fPlotUsage.isEmpty()) {
|
||||
this->purgeStrike(strikeToPurge);
|
||||
}
|
||||
}
|
||||
@ -190,8 +190,8 @@ void GrFontCache::validate() const {
|
||||
void GrFontCache::dump() const {
|
||||
static int gDumpCount = 0;
|
||||
for (int i = 0; i < kAtlasCount; ++i) {
|
||||
if (NULL != fAtlasMgr[i]) {
|
||||
GrTexture* texture = fAtlasMgr[i]->getTexture();
|
||||
if (NULL != fAtlases[i]) {
|
||||
GrTexture* texture = fAtlases[i]->getTexture();
|
||||
if (NULL != texture) {
|
||||
SkString filename;
|
||||
#ifdef SK_BUILD_FOR_ANDROID
|
||||
@ -222,12 +222,12 @@ void GrFontCache::dump() const {
|
||||
|
||||
GrTextStrike::GrTextStrike(GrFontCache* cache, const GrKey* key,
|
||||
GrMaskFormat format,
|
||||
GrAtlasMgr* atlasMgr) : fPool(64) {
|
||||
GrAtlas* atlas) : fPool(64) {
|
||||
fFontScalerKey = key;
|
||||
fFontScalerKey->ref();
|
||||
|
||||
fFontCache = cache; // no need to ref, it won't go away before we do
|
||||
fAtlasMgr = atlasMgr; // no need to ref, it won't go away before we do
|
||||
fAtlas = atlas; // no need to ref, it won't go away before we do
|
||||
|
||||
fMaskFormat = format;
|
||||
|
||||
@ -278,7 +278,7 @@ void GrTextStrike::removePlot(const GrPlot* plot) {
|
||||
}
|
||||
}
|
||||
|
||||
fAtlasMgr->removePlot(&fAtlas, plot);
|
||||
fAtlas->removePlot(&fPlotUsage, plot);
|
||||
}
|
||||
|
||||
|
||||
@ -314,9 +314,9 @@ bool GrTextStrike::addGlyphToAtlas(GrGlyph* glyph, GrFontScaler* scaler) {
|
||||
}
|
||||
}
|
||||
|
||||
GrPlot* plot = fAtlasMgr->addToAtlas(&fAtlas, glyph->width(),
|
||||
glyph->height(), storage.get(),
|
||||
&glyph->fAtlasLocation);
|
||||
GrPlot* plot = fAtlas->addToAtlas(&fPlotUsage, glyph->width(),
|
||||
glyph->height(), storage.get(),
|
||||
&glyph->fAtlasLocation);
|
||||
|
||||
if (NULL == plot) {
|
||||
return false;
|
||||
|
@ -28,7 +28,7 @@ class GrFontPurgeListener;
|
||||
*/
|
||||
class GrTextStrike {
|
||||
public:
|
||||
GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat, GrAtlasMgr*);
|
||||
GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat, GrAtlas*);
|
||||
~GrTextStrike();
|
||||
|
||||
const GrKey* getFontScalerKey() const { return fFontScalerKey; }
|
||||
@ -59,11 +59,11 @@ private:
|
||||
GrTAllocPool<GrGlyph> fPool;
|
||||
|
||||
GrFontCache* fFontCache;
|
||||
GrAtlasMgr* fAtlasMgr;
|
||||
GrAtlas* fAtlas;
|
||||
GrMaskFormat fMaskFormat;
|
||||
bool fUseDistanceField;
|
||||
|
||||
GrAtlas fAtlas;
|
||||
GrAtlas::ClientPlotUsage fPlotUsage;
|
||||
|
||||
GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
|
||||
|
||||
@ -91,8 +91,8 @@ public:
|
||||
|
||||
void updateTextures() {
|
||||
for (int i = 0; i < kAtlasCount; ++i) {
|
||||
if (fAtlasMgr[i]) {
|
||||
fAtlasMgr[i]->uploadPlotsToTexture();
|
||||
if (fAtlases[i]) {
|
||||
fAtlases[i]->uploadPlotsToTexture();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,7 +124,7 @@ private:
|
||||
GrTextStrike* fTail;
|
||||
|
||||
GrGpu* fGpu;
|
||||
GrAtlasMgr* fAtlasMgr[kAtlasCount];
|
||||
GrAtlas* fAtlases[kAtlasCount];
|
||||
|
||||
GrTextStrike* generateStrike(GrFontScaler*, const Key&);
|
||||
inline void detachStrikeFromList(GrTextStrike*);
|
||||
|
Loading…
Reference in New Issue
Block a user