blob: 406b45c13802a491303f7b5b8d86d24e89a97e19 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
2 Copyright 2010 Google Inc.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17
18#ifndef GrAtlas_DEFINED
19#define GrAtlas_DEFINED
20
21#include "GrPoint.h"
22#include "GrTexture.h"
23#include "GrTDArray.h"
24
25class GrGpu;
26class GrRectanizer;
27class GrAtlasMgr;
28
29class GrAtlas {
30public:
reed@google.com98539c62011-03-15 15:40:16 +000031 GrAtlas(GrAtlasMgr*, int plotX, int plotY, GrMaskFormat);
reed@google.comac10a2d2010-12-22 21:39:39 +000032
33 int getPlotX() const { return fPlot.fX; }
34 int getPlotY() const { return fPlot.fY; }
reed@google.com98539c62011-03-15 15:40:16 +000035 GrMaskFormat getMaskFormat() const { return fMaskFormat; }
reed@google.comac10a2d2010-12-22 21:39:39 +000036
37 GrTexture* texture() const { return fTexture; }
38
39 bool addSubImage(int width, int height, const void*, GrIPoint16*);
40
41 static void FreeLList(GrAtlas* atlas) {
42 while (atlas) {
43 GrAtlas* next = atlas->fNext;
44 delete atlas;
45 atlas = next;
46 }
47 }
48
49 // testing
50 GrAtlas* nextAtlas() const { return fNext; }
51
52private:
53 ~GrAtlas(); // does not try to delete the fNext field
54
55 GrAtlas* fNext;
56 GrTexture* fTexture;
57 GrRectanizer* fRects;
58 GrAtlasMgr* fAtlasMgr;
59 GrIPoint16 fPlot;
reed@google.com98539c62011-03-15 15:40:16 +000060 GrMaskFormat fMaskFormat;
reed@google.comac10a2d2010-12-22 21:39:39 +000061
62 friend class GrAtlasMgr;
63};
64
65class GrPlotMgr;
66
67class GrAtlasMgr {
68public:
69 GrAtlasMgr(GrGpu*);
70 ~GrAtlasMgr();
71
72 GrAtlas* addToAtlas(GrAtlas*, int width, int height, const void*,
reed@google.com98539c62011-03-15 15:40:16 +000073 GrMaskFormat, GrIPoint16*);
reed@google.comac10a2d2010-12-22 21:39:39 +000074
reed@google.com759c16e2011-03-15 19:15:15 +000075 GrTexture* getTexture(GrMaskFormat format) const {
76 GrAssert((unsigned)format < kCount_GrMaskFormats);
77 return fTexture[format];
78 }
reed@google.comac10a2d2010-12-22 21:39:39 +000079
80 // to be called by ~GrAtlas()
81 void freePlot(int x, int y);
82
reed@google.comac10a2d2010-12-22 21:39:39 +000083private:
84 GrGpu* fGpu;
reed@google.com759c16e2011-03-15 19:15:15 +000085 GrTexture* fTexture[kCount_GrMaskFormats];
reed@google.comac10a2d2010-12-22 21:39:39 +000086 GrPlotMgr* fPlotMgr;
87};
88
89#endif
90
91