• 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 #include "GrTDArray.h"
17 
18 class GrGpu;
19 class GrRectanizer;
20 class GrAtlasMgr;
21 
22 class GrAtlas {
23 public:
24     GrAtlas(GrAtlasMgr*, int plotX, int plotY, GrMaskFormat);
25 
getPlotX()26     int getPlotX() const { return fPlot.fX; }
getPlotY()27     int getPlotY() const { return fPlot.fY; }
getMaskFormat()28     GrMaskFormat getMaskFormat() const { return fMaskFormat; }
29 
texture()30     GrTexture* texture() const { return fTexture; }
31 
32     bool addSubImage(int width, int height, const void*, GrIPoint16*);
33 
FreeLList(GrAtlas * atlas)34     static void FreeLList(GrAtlas* atlas) {
35         while (atlas) {
36             GrAtlas* next = atlas->fNext;
37             delete atlas;
38             atlas = next;
39         }
40     }
41 
42     // testing
nextAtlas()43     GrAtlas* nextAtlas() const { return fNext; }
44 
45 private:
46     ~GrAtlas(); // does not try to delete the fNext field
47 
48     GrAtlas*        fNext;
49     GrTexture*      fTexture;
50     GrRectanizer*   fRects;
51     GrAtlasMgr*     fAtlasMgr;
52     GrIPoint16      fPlot;
53     GrMaskFormat    fMaskFormat;
54 
55     friend class GrAtlasMgr;
56 };
57 
58 class GrPlotMgr;
59 
60 class GrAtlasMgr {
61 public:
62     GrAtlasMgr(GrGpu*);
63     ~GrAtlasMgr();
64 
65     GrAtlas* addToAtlas(GrAtlas*, int width, int height, const void*,
66                         GrMaskFormat, GrIPoint16*);
67 
getTexture(GrMaskFormat format)68     GrTexture* getTexture(GrMaskFormat format) const {
69         GrAssert((unsigned)format < kCount_GrMaskFormats);
70         return fTexture[format];
71     }
72 
73     // to be called by ~GrAtlas()
74     void freePlot(int x, int y);
75 
76 private:
77     GrGpu*      fGpu;
78     GrTexture*  fTexture[kCount_GrMaskFormats];
79     GrPlotMgr*  fPlotMgr;
80 };
81 
82 #endif
83 
84 
85