Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Unified Diff: src/gpu/GrAtlas.cpp

Issue 21594005: GPU Font Cache improvements: (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Remove some added spaces Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/gpu/GrAtlas.cpp
diff --git a/src/gpu/GrAtlas.cpp b/src/gpu/GrAtlas.cpp
index c1d6d3d693c4f332907a996874d1f72ed7231cae..0c8f9f392e6f550f0d7b574e32a16d042356c47e 100644
--- a/src/gpu/GrAtlas.cpp
+++ b/src/gpu/GrAtlas.cpp
@@ -47,6 +47,8 @@
GrAtlas::GrAtlas(GrAtlasMgr* mgr, int plotX, int plotY, GrMaskFormat format) {
fAtlasMgr = mgr; // just a pointer, not an owner
fNext = NULL;
+ fUsed = false;
+
fTexture = mgr->getTexture(format); // we're not an owner, just a pointer
fPlot.set(plotX, plotY);
@@ -62,7 +64,7 @@ GrAtlas::GrAtlas(GrAtlasMgr* mgr, int plotX, int plotY, GrMaskFormat format) {
}
GrAtlas::~GrAtlas() {
- fAtlasMgr->freePlot(fPlot.fX, fPlot.fY);
+ fAtlasMgr->freePlot(fMaskFormat, fPlot.fX, fPlot.fY);
delete fRects;
@@ -122,6 +124,7 @@ bool GrAtlas::addSubImage(int width, int height, const void* image,
// now tell the caller to skip the top/left BORDER
loc->fX += BORDER;
loc->fY += BORDER;
+
return true;
}
@@ -131,14 +134,19 @@ GrAtlasMgr::GrAtlasMgr(GrGpu* gpu) {
fGpu = gpu;
gpu->ref();
Gr_bzero(fTexture, sizeof(fTexture));
- fPlotMgr = SkNEW_ARGS(GrPlotMgr, (GR_PLOT_WIDTH, GR_PLOT_HEIGHT));
+ for (int i = 0; i < kCount_GrMaskFormats; ++i) {
+ fPlotMgr[i] = SkNEW_ARGS(GrPlotMgr, (GR_PLOT_WIDTH, GR_PLOT_HEIGHT));
+ }
}
GrAtlasMgr::~GrAtlasMgr() {
for (size_t i = 0; i < GR_ARRAY_COUNT(fTexture); i++) {
GrSafeUnref(fTexture[i]);
}
- delete fPlotMgr;
+ for (int i = 0; i < kCount_GrMaskFormats; ++i) {
+ delete fPlotMgr[i];
+ }
+
fGpu->unref();
}
@@ -156,21 +164,26 @@ static GrPixelConfig maskformat2pixelconfig(GrMaskFormat format) {
return kUnknown_GrPixelConfig;
}
-GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas* atlas,
+GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas** atlas,
int width, int height, const void* image,
GrMaskFormat format,
GrIPoint16* loc) {
- GrAssert(NULL == atlas || atlas->getMaskFormat() == format);
+ GrAssert(NULL == *atlas || (*atlas)->getMaskFormat() == format);
- if (atlas && atlas->addSubImage(width, height, image, loc)) {
- return atlas;
+ // iterate through entire atlas list, see if we can find a hole
+ GrAtlas* atlasIter = *atlas;
+ while (atlasIter) {
+ if (atlasIter->addSubImage(width, height, image, loc)) {
+ return atlasIter;
+ }
+ atlasIter = atlasIter->fNext;
}
// If the above fails, then either we have no starting atlas, or the current
- // one is full. Either way we need to allocate a new atlas
+ // atlas list is full. Either way we need to allocate a new atlas
GrIPoint16 plot;
- if (!fPlotMgr->newPlot(&plot)) {
+ if (!fPlotMgr[format]->newPlot(&plot)) {
return NULL;
}
@@ -196,11 +209,14 @@ GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas* atlas,
return NULL;
}
- newAtlas->fNext = atlas;
+ // new atlas, put at head
+ newAtlas->fNext = *atlas;
+ *atlas = newAtlas;
+
return newAtlas;
}
-void GrAtlasMgr::freePlot(int x, int y) {
- GrAssert(fPlotMgr->isBusy(x, y));
- fPlotMgr->freePlot(x, y);
+void GrAtlasMgr::freePlot(GrMaskFormat format, int x, int y) {
+ GrAssert(fPlotMgr[format]->isBusy(x, y));
+ fPlotMgr[format]->freePlot(x, y);
}

Powered by Google App Engine
This is Rietveld 408576698