First pass at font cache refactor: Create an atlas manager per texture
This changes the AtlasMgr from a singleton class to one that is
created per-texture. This is the first step in allowing us to create
Atlases of other types (e.g., combine small icons into one big texture).
R=bsalomon@google.com
Author: jvanverth@google.com
Review URL: https://chromiumcodereview.appspot.com/24608002
git-svn-id: http://skia.googlecode.com/svn/trunk@11468 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrAtlas.cpp b/src/gpu/GrAtlas.cpp
index 9cdde22..b3f2e34 100644
--- a/src/gpu/GrAtlas.cpp
+++ b/src/gpu/GrAtlas.cpp
@@ -55,7 +55,7 @@
fAtlasMgr = mgr; // just a pointer, not an owner
fNext = NULL;
- fTexture = mgr->getTexture(format); // we're not an owner, just a pointer
+ fTexture = mgr->getTexture(); // we're not an owner, just a pointer
fPlot.set(plotX, plotY);
fRects = GrRectanizer::Factory(GR_ATLAS_WIDTH - BORDER,
@@ -70,7 +70,7 @@
}
GrAtlas::~GrAtlas() {
- fAtlasMgr->freePlot(fMaskFormat, fPlot.fX, fPlot.fY);
+ fAtlasMgr->freePlot(fPlot.fX, fPlot.fY);
delete fRects;
@@ -161,22 +161,17 @@
///////////////////////////////////////////////////////////////////////////////
-GrAtlasMgr::GrAtlasMgr(GrGpu* gpu) {
+GrAtlasMgr::GrAtlasMgr(GrGpu* gpu, GrMaskFormat format) {
fGpu = gpu;
+ fMaskFormat = format;
gpu->ref();
- Gr_bzero(fTexture, sizeof(fTexture));
- for (int i = 0; i < kCount_GrMaskFormats; ++i) {
- fPlotMgr[i] = SkNEW_ARGS(GrPlotMgr, (GR_PLOT_WIDTH, GR_PLOT_HEIGHT));
- }
+ fTexture = NULL;
+ fPlotMgr = SkNEW_ARGS(GrPlotMgr, (GR_PLOT_WIDTH, GR_PLOT_HEIGHT));
}
GrAtlasMgr::~GrAtlasMgr() {
- for (size_t i = 0; i < GR_ARRAY_COUNT(fTexture); i++) {
- SkSafeUnref(fTexture[i]);
- }
- for (int i = 0; i < kCount_GrMaskFormats; ++i) {
- delete fPlotMgr[i];
- }
+ SkSafeUnref(fTexture);
+ delete fPlotMgr;
fGpu->unref();
#if FONT_CACHE_STATS
@@ -200,10 +195,7 @@
GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas** atlas,
int width, int height, const void* image,
- GrMaskFormat format,
GrIPoint16* loc) {
- SkASSERT(NULL == *atlas || (*atlas)->getMaskFormat() == format);
-
// iterate through entire atlas list, see if we can find a hole
GrAtlas* atlasIter = *atlas;
while (atlasIter) {
@@ -217,27 +209,25 @@
// atlas list is full. Either way we need to allocate a new atlas
GrIPoint16 plot;
- if (!fPlotMgr[format]->newPlot(&plot)) {
+ if (!fPlotMgr->newPlot(&plot)) {
return NULL;
}
- SkASSERT(0 == kA8_GrMaskFormat);
- SkASSERT(1 == kA565_GrMaskFormat);
- if (NULL == fTexture[format]) {
+ if (NULL == fTexture) {
// TODO: Update this to use the cache rather than directly creating a texture.
GrTextureDesc desc;
desc.fFlags = kDynamicUpdate_GrTextureFlagBit;
desc.fWidth = GR_ATLAS_TEXTURE_WIDTH;
desc.fHeight = GR_ATLAS_TEXTURE_HEIGHT;
- desc.fConfig = maskformat2pixelconfig(format);
+ desc.fConfig = maskformat2pixelconfig(fMaskFormat);
- fTexture[format] = fGpu->createTexture(desc, NULL, 0);
- if (NULL == fTexture[format]) {
+ fTexture = fGpu->createTexture(desc, NULL, 0);
+ if (NULL == fTexture) {
return NULL;
}
}
- GrAtlas* newAtlas = SkNEW_ARGS(GrAtlas, (this, plot.fX, plot.fY, format));
+ GrAtlas* newAtlas = SkNEW_ARGS(GrAtlas, (this, plot.fX, plot.fY, fMaskFormat));
if (!newAtlas->addSubImage(width, height, image, loc)) {
delete newAtlas;
return NULL;
@@ -250,7 +240,7 @@
return newAtlas;
}
-void GrAtlasMgr::freePlot(GrMaskFormat format, int x, int y) {
- SkASSERT(fPlotMgr[format]->isBusy(x, y));
- fPlotMgr[format]->freePlot(x, y);
+void GrAtlasMgr::freePlot(int x, int y) {
+ SkASSERT(fPlotMgr->isBusy(x, y));
+ fPlotMgr->freePlot(x, y);
}