3 * Copyright 2010 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
9 #ifndef GrAtlas_DEFINED
10 #define GrAtlas_DEFINED
14 #include "GrTexture.h"
15 #include "GrDrawTarget.h"
22 // The backing GrTexture for a set of GrAtlases is broken into a spatial grid of GrPlots. When
23 // a GrAtlas needs space on the texture, it requests a GrPlot. Each GrAtlas can claim one
24 // or more GrPlots. The GrPlots keep track of subimage placement via their GrRectanizer. Once a
25 // GrPlot is "full" (i.e. there is no room for the new subimage according to the GrRectanizer), the
26 // GrAtlas can request a new GrPlot via GrAtlasMgr::addToAtlas().
28 // If all GrPlots are allocated, the replacement strategy is up to the client. The drawToken is
29 // available to ensure that all draw calls are finished for that particular GrPlot.
30 // GrAtlasMgr::removeUnusedPlots() will free up any finished plots for a given GrAtlas.
34 int getOffsetX() const { return fOffset.fX; }
35 int getOffsetY() const { return fOffset.fY; }
37 GrTexture* texture() const { return fTexture; }
39 bool addSubImage(int width, int height, const void*, GrIPoint16*);
41 GrDrawTarget::DrawToken drawToken() const { return fDrawToken; }
42 void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; }
46 ~GrPlot(); // does not try to delete the fNext field
49 GrDrawTarget::DrawToken fDrawToken;
55 GrAtlasMgr* fAtlasMgr;
57 size_t fBytesPerPixel;
59 friend class GrAtlasMgr;
64 GrAtlasMgr(GrGpu*, GrPixelConfig);
67 // add subimage of width, height dimensions to atlas
68 // returns the containing GrPlot and location relative to the backing texture
69 GrPlot* addToAtlas(GrAtlas*, int width, int height, const void*, GrIPoint16*);
71 // free up any plots that are not waiting on a draw call
72 bool removeUnusedPlots(GrAtlas* atlas);
74 // to be called by ~GrAtlas()
75 void deletePlotList(GrPlot* plot);
77 GrTexture* getTexture() const {
83 void freePlot(GrPlot* plot);
86 GrPixelConfig fPixelConfig;
89 // allocated array of GrPlots
91 // linked list of free GrPlots
97 GrAtlas(GrAtlasMgr* mgr) : fPlots(NULL), fAtlasMgr(mgr) { }
98 ~GrAtlas() { fAtlasMgr->deletePlotList(fPlots); }
100 bool isEmpty() { return NULL == fPlots; }
104 GrAtlasMgr* fAtlasMgr;
106 friend class GrAtlasMgr;