blob: b6f25c210ab7fdccfa7a98a9b6ff1f22dfbc9341 [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.comac10a2d2010-12-22 21:39:39 +000023 int getPlotX() const { return fPlot.fX; }
24 int getPlotY() const { return fPlot.fY; }
reed@google.com98539c62011-03-15 15:40:16 +000025 GrMaskFormat getMaskFormat() const { return fMaskFormat; }
reed@google.comac10a2d2010-12-22 21:39:39 +000026
27 GrTexture* texture() const { return fTexture; }
28
29 bool addSubImage(int width, int height, const void*, GrIPoint16*);
30
31 static void FreeLList(GrAtlas* atlas) {
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000032 while (NULL != atlas) {
reed@google.comac10a2d2010-12-22 21:39:39 +000033 GrAtlas* next = atlas->fNext;
34 delete atlas;
35 atlas = next;
36 }
37 }
38
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000039 static void MarkAllUnused(GrAtlas* atlas) {
40 while (NULL != atlas) {
41 atlas->fUsed = false;
42 atlas = atlas->fNext;
43 }
44 }
45
46 static bool RemoveUnusedAtlases(GrAtlasMgr* atlasMgr, GrAtlas** startAtlas);
47
48 bool used() const { return fUsed; }
49 void setUsed(bool used) { fUsed = used; }
reed@google.comac10a2d2010-12-22 21:39:39 +000050
51private:
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000052 GrAtlas(GrAtlasMgr*, int plotX, int plotY, GrMaskFormat format);
reed@google.comac10a2d2010-12-22 21:39:39 +000053 ~GrAtlas(); // does not try to delete the fNext field
54
55 GrAtlas* fNext;
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000056
57 // for recycling
58 bool fUsed;
59
reed@google.comac10a2d2010-12-22 21:39:39 +000060 GrTexture* fTexture;
61 GrRectanizer* fRects;
62 GrAtlasMgr* fAtlasMgr;
63 GrIPoint16 fPlot;
reed@google.com98539c62011-03-15 15:40:16 +000064 GrMaskFormat fMaskFormat;
reed@google.comac10a2d2010-12-22 21:39:39 +000065
66 friend class GrAtlasMgr;
67};
68
69class GrPlotMgr;
70
71class GrAtlasMgr {
72public:
73 GrAtlasMgr(GrGpu*);
74 ~GrAtlasMgr();
75
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000076 GrAtlas* addToAtlas(GrAtlas**, int width, int height, const void*,
reed@google.com98539c62011-03-15 15:40:16 +000077 GrMaskFormat, GrIPoint16*);
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000078 void deleteAtlas(GrAtlas* atlas) { delete atlas; }
reed@google.comac10a2d2010-12-22 21:39:39 +000079
reed@google.com759c16e2011-03-15 19:15:15 +000080 GrTexture* getTexture(GrMaskFormat format) const {
81 GrAssert((unsigned)format < kCount_GrMaskFormats);
82 return fTexture[format];
83 }
reed@google.comac10a2d2010-12-22 21:39:39 +000084
85 // to be called by ~GrAtlas()
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000086 void freePlot(GrMaskFormat format, int x, int y);
reed@google.comac10a2d2010-12-22 21:39:39 +000087
reed@google.comac10a2d2010-12-22 21:39:39 +000088private:
89 GrGpu* fGpu;
reed@google.com759c16e2011-03-15 19:15:15 +000090 GrTexture* fTexture[kCount_GrMaskFormats];
reed@google.comac10a2d2010-12-22 21:39:39 +000091 GrPlotMgr* fPlotMgr;
92};
93
94#endif