• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2010 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 
11 #ifndef GrAtlas_DEFINED
12 #define GrAtlas_DEFINED
13 
14 #include "GrPoint.h"
15 #include "GrTexture.h"
16 
17 class GrGpu;
18 class GrRectanizer;
19 class GrAtlasMgr;
20 
21 class GrAtlas {
22 public:
23     GrAtlas(GrAtlasMgr*, int plotX, int plotY, GrMaskFormat);
24 
getPlotX()25     int getPlotX() const { return fPlot.fX; }
getPlotY()26     int getPlotY() const { return fPlot.fY; }
getMaskFormat()27     GrMaskFormat getMaskFormat() const { return fMaskFormat; }
28 
texture()29     GrTexture* texture() const { return fTexture; }
30 
31     bool addSubImage(int width, int height, const void*, GrIPoint16*);
32 
FreeLList(GrAtlas * atlas)33     static void FreeLList(GrAtlas* atlas) {
34         while (atlas) {
35             GrAtlas* next = atlas->fNext;
36             delete atlas;
37             atlas = next;
38         }
39     }
40 
41     // testing
nextAtlas()42     GrAtlas* nextAtlas() const { return fNext; }
43 
44 private:
45     ~GrAtlas(); // does not try to delete the fNext field
46 
47     GrAtlas*        fNext;
48     GrTexture*      fTexture;
49     GrRectanizer*   fRects;
50     GrAtlasMgr*     fAtlasMgr;
51     GrIPoint16      fPlot;
52     GrMaskFormat    fMaskFormat;
53 
54     friend class GrAtlasMgr;
55 };
56 
57 class GrPlotMgr;
58 
59 class GrAtlasMgr {
60 public:
61     GrAtlasMgr(GrGpu*);
62     ~GrAtlasMgr();
63 
64     GrAtlas* addToAtlas(GrAtlas*, int width, int height, const void*,
65                         GrMaskFormat, GrIPoint16*);
66 
getTexture(GrMaskFormat format)67     GrTexture* getTexture(GrMaskFormat format) const {
68         GrAssert((unsigned)format < kCount_GrMaskFormats);
69         return fTexture[format];
70     }
71 
72     // to be called by ~GrAtlas()
73     void freePlot(int x, int y);
74 
75 private:
76     GrGpu*      fGpu;
77     GrTexture*  fTexture[kCount_GrMaskFormats];
78     GrPlotMgr*  fPlotMgr;
79 };
80 
81 #endif
82