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

Unified Diff: src/gpu/GrAtlas.h

Issue 24981004: GrAtlas cleanup: Split out GrPlot and GrAtlas (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Tweaked comment Created 7 years, 3 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
« no previous file with comments | « include/gpu/GrGlyph.h ('k') | src/gpu/GrAtlas.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrAtlas.h
diff --git a/src/gpu/GrAtlas.h b/src/gpu/GrAtlas.h
index b2acaee8e277d35e0146745c41a4f7849d249424..d06bba1435156978f1bea1d90b0c8927139859a1 100644
--- a/src/gpu/GrAtlas.h
+++ b/src/gpu/GrAtlas.h
@@ -6,11 +6,10 @@
* found in the LICENSE file.
*/
-
-
#ifndef GrAtlas_DEFINED
#define GrAtlas_DEFINED
+
#include "GrPoint.h"
#include "GrTexture.h"
#include "GrDrawTarget.h"
@@ -18,69 +17,93 @@
class GrGpu;
class GrRectanizer;
class GrAtlasMgr;
-
-class GrAtlas {
+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().
+//
+// 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.
+
+class GrPlot {
public:
- int getPlotX() const { return fPlot.fX; }
- int getPlotY() const { return fPlot.fY; }
+ int getOffsetX() const { return fOffset.fX; }
+ int getOffsetY() const { return fOffset.fY; }
GrTexture* texture() const { return fTexture; }
bool addSubImage(int width, int height, const void*, GrIPoint16*);
- static void FreeLList(GrAtlas* atlas) {
- while (NULL != atlas) {
- GrAtlas* next = atlas->fNext;
- delete atlas;
- atlas = next;
- }
- }
-
- static bool RemoveUnusedAtlases(GrAtlasMgr* atlasMgr, GrAtlas** startAtlas);
-
GrDrawTarget::DrawToken drawToken() const { return fDrawToken; }
void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; }
private:
- GrAtlas(GrAtlasMgr*, int plotX, int plotY, int bpp);
- ~GrAtlas(); // does not try to delete the fNext field
+ GrPlot();
+ ~GrPlot(); // does not try to delete the fNext field
// for recycling
GrDrawTarget::DrawToken fDrawToken;
- GrAtlas* fNext;
+ GrPlot* fNext;
GrTexture* fTexture;
GrRectanizer* fRects;
GrAtlasMgr* fAtlasMgr;
- GrIPoint16 fPlot;
+ GrIPoint16 fOffset;
int fBytesPerPixel;
friend class GrAtlasMgr;
};
-class GrPlotMgr;
-
class GrAtlasMgr {
public:
GrAtlasMgr(GrGpu*, GrPixelConfig);
~GrAtlasMgr();
- GrAtlas* addToAtlas(GrAtlas**, int width, int height, const void*, GrIPoint16*);
- void deleteAtlas(GrAtlas* atlas) { delete atlas; }
-
+ // 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*, GrIPoint16*);
+
+ // free up any plots that are not waiting on a draw call
+ bool removeUnusedPlots(GrAtlas* atlas);
+
+ // to be called by ~GrAtlas()
+ void deletePlotList(GrPlot* plot);
+
GrTexture* getTexture() const {
return fTexture;
}
- // to be called by ~GrAtlas()
- void freePlot(int x, int y);
-
private:
+ GrPlot* allocPlot();
+ void freePlot(GrPlot* plot);
+
GrGpu* fGpu;
GrPixelConfig fPixelConfig;
GrTexture* fTexture;
- GrPlotMgr* fPlotMgr;
+
+ // allocated array of GrPlots
+ GrPlot* fPlots;
+ // linked list of free GrPlots
+ GrPlot* fFreePlots;
+};
+
+class GrAtlas {
+public:
+ GrAtlas(GrAtlasMgr* mgr) : fPlots(NULL), fAtlasMgr(mgr) { }
+ ~GrAtlas() { fAtlasMgr->deletePlotList(fPlots); }
+
+ bool isEmpty() { return NULL == fPlots; }
+
+private:
+ GrPlot* fPlots;
+ GrAtlasMgr* fAtlasMgr;
+
+ friend class GrAtlasMgr;
};
#endif
« no previous file with comments | « include/gpu/GrGlyph.h ('k') | src/gpu/GrAtlas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698