blob: f0114e399d0a127427a29278ff18996664c93d80 [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"
16#include "GrTDArray.h"
17
18class GrGpu;
19class GrRectanizer;
20class GrAtlasMgr;
21
22class GrAtlas {
23public:
reed@google.com98539c62011-03-15 15:40:16 +000024 GrAtlas(GrAtlasMgr*, int plotX, int plotY, GrMaskFormat);
reed@google.comac10a2d2010-12-22 21:39:39 +000025
26 int getPlotX() const { return fPlot.fX; }
27 int getPlotY() const { return fPlot.fY; }
reed@google.com98539c62011-03-15 15:40:16 +000028 GrMaskFormat getMaskFormat() const { return fMaskFormat; }
reed@google.comac10a2d2010-12-22 21:39:39 +000029
30 GrTexture* texture() const { return fTexture; }
31
32 bool addSubImage(int width, int height, const void*, GrIPoint16*);
33
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
43 GrAtlas* nextAtlas() const { return fNext; }
44
45private:
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;
reed@google.com98539c62011-03-15 15:40:16 +000053 GrMaskFormat fMaskFormat;
reed@google.comac10a2d2010-12-22 21:39:39 +000054
55 friend class GrAtlasMgr;
56};
57
58class GrPlotMgr;
59
60class GrAtlasMgr {
61public:
62 GrAtlasMgr(GrGpu*);
63 ~GrAtlasMgr();
64
65 GrAtlas* addToAtlas(GrAtlas*, int width, int height, const void*,
reed@google.com98539c62011-03-15 15:40:16 +000066 GrMaskFormat, GrIPoint16*);
reed@google.comac10a2d2010-12-22 21:39:39 +000067
reed@google.com759c16e2011-03-15 19:15:15 +000068 GrTexture* getTexture(GrMaskFormat format) const {
69 GrAssert((unsigned)format < kCount_GrMaskFormats);
70 return fTexture[format];
71 }
reed@google.comac10a2d2010-12-22 21:39:39 +000072
73 // to be called by ~GrAtlas()
74 void freePlot(int x, int y);
75
reed@google.comac10a2d2010-12-22 21:39:39 +000076private:
77 GrGpu* fGpu;
reed@google.com759c16e2011-03-15 19:15:15 +000078 GrTexture* fTexture[kCount_GrMaskFormats];
reed@google.comac10a2d2010-12-22 21:39:39 +000079 GrPlotMgr* fPlotMgr;
80};
81
82#endif
83
84