blob: 40a21545e15e6e7d1d089a3eba6db51c274eb441 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
reed@google.comac10a2d2010-12-22 21:39:39 +000011#ifndef GrAtlas_DEFINED
12#define GrAtlas_DEFINED
13
14#include "GrPoint.h"
15#include "GrTexture.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000016
17class GrGpu;
18class GrRectanizer;
19class GrAtlasMgr;
20
21class GrAtlas {
22public:
reed@google.com98539c62011-03-15 15:40:16 +000023 GrAtlas(GrAtlasMgr*, int plotX, int plotY, GrMaskFormat);
reed@google.comac10a2d2010-12-22 21:39:39 +000024
25 int getPlotX() const { return fPlot.fX; }
26 int getPlotY() const { return fPlot.fY; }
reed@google.com98539c62011-03-15 15:40:16 +000027 GrMaskFormat getMaskFormat() const { return fMaskFormat; }
reed@google.comac10a2d2010-12-22 21:39:39 +000028
29 GrTexture* texture() const { return fTexture; }
30
31 bool addSubImage(int width, int height, const void*, GrIPoint16*);
32
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
42 GrAtlas* nextAtlas() const { return fNext; }
43
44private:
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;
reed@google.com98539c62011-03-15 15:40:16 +000052 GrMaskFormat fMaskFormat;
reed@google.comac10a2d2010-12-22 21:39:39 +000053
54 friend class GrAtlasMgr;
55};
56
57class GrPlotMgr;
58
59class GrAtlasMgr {
60public:
61 GrAtlasMgr(GrGpu*);
62 ~GrAtlasMgr();
63
64 GrAtlas* addToAtlas(GrAtlas*, int width, int height, const void*,
reed@google.com98539c62011-03-15 15:40:16 +000065 GrMaskFormat, GrIPoint16*);
reed@google.comac10a2d2010-12-22 21:39:39 +000066
reed@google.com759c16e2011-03-15 19:15:15 +000067 GrTexture* getTexture(GrMaskFormat format) const {
68 GrAssert((unsigned)format < kCount_GrMaskFormats);
69 return fTexture[format];
70 }
reed@google.comac10a2d2010-12-22 21:39:39 +000071
72 // to be called by ~GrAtlas()
73 void freePlot(int x, int y);
74
reed@google.comac10a2d2010-12-22 21:39:39 +000075private:
76 GrGpu* fGpu;
reed@google.com759c16e2011-03-15 19:15:15 +000077 GrTexture* fTexture[kCount_GrMaskFormats];
reed@google.comac10a2d2010-12-22 21:39:39 +000078 GrPlotMgr* fPlotMgr;
79};
80
81#endif