blob: 7831a8d0f70476cf0235e7cda5d2ab312602af8e [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"
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +000016#include "GrDrawTarget.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000017
18class GrGpu;
19class GrRectanizer;
20class GrAtlasMgr;
21
22class GrAtlas {
23public:
reed@google.comac10a2d2010-12-22 21:39:39 +000024 int getPlotX() const { return fPlot.fX; }
25 int getPlotY() const { return fPlot.fY; }
reed@google.com98539c62011-03-15 15:40:16 +000026 GrMaskFormat getMaskFormat() const { return fMaskFormat; }
reed@google.comac10a2d2010-12-22 21:39:39 +000027
28 GrTexture* texture() const { return fTexture; }
29
30 bool addSubImage(int width, int height, const void*, GrIPoint16*);
31
32 static void FreeLList(GrAtlas* atlas) {
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000033 while (NULL != atlas) {
reed@google.comac10a2d2010-12-22 21:39:39 +000034 GrAtlas* next = atlas->fNext;
35 delete atlas;
36 atlas = next;
37 }
38 }
39
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000040 static bool RemoveUnusedAtlases(GrAtlasMgr* atlasMgr, GrAtlas** startAtlas);
41
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +000042 GrDrawTarget::DrawToken drawToken() const { return fDrawToken; }
43 void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; }
reed@google.comac10a2d2010-12-22 21:39:39 +000044
45private:
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000046 GrAtlas(GrAtlasMgr*, int plotX, int plotY, GrMaskFormat format);
reed@google.comac10a2d2010-12-22 21:39:39 +000047 ~GrAtlas(); // does not try to delete the fNext field
48
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000049 // for recycling
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +000050 GrDrawTarget::DrawToken fDrawToken;
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000051
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +000052 GrAtlas* fNext;
53
54 GrTexture* fTexture;
55 GrRectanizer* fRects;
56 GrAtlasMgr* fAtlasMgr;
57 GrIPoint16 fPlot;
58 GrMaskFormat fMaskFormat;
reed@google.comac10a2d2010-12-22 21:39:39 +000059
60 friend class GrAtlasMgr;
61};
62
63class GrPlotMgr;
64
65class GrAtlasMgr {
66public:
67 GrAtlasMgr(GrGpu*);
68 ~GrAtlasMgr();
69
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000070 GrAtlas* addToAtlas(GrAtlas**, int width, int height, const void*,
reed@google.com98539c62011-03-15 15:40:16 +000071 GrMaskFormat, GrIPoint16*);
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000072 void deleteAtlas(GrAtlas* atlas) { delete atlas; }
reed@google.comac10a2d2010-12-22 21:39:39 +000073
reed@google.com759c16e2011-03-15 19:15:15 +000074 GrTexture* getTexture(GrMaskFormat format) const {
75 GrAssert((unsigned)format < kCount_GrMaskFormats);
76 return fTexture[format];
77 }
reed@google.comac10a2d2010-12-22 21:39:39 +000078
79 // to be called by ~GrAtlas()
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000080 void freePlot(GrMaskFormat format, int x, int y);
reed@google.comac10a2d2010-12-22 21:39:39 +000081
reed@google.comac10a2d2010-12-22 21:39:39 +000082private:
83 GrGpu* fGpu;
reed@google.com759c16e2011-03-15 19:15:15 +000084 GrTexture* fTexture[kCount_GrMaskFormats];
reed@google.comac10a2d2010-12-22 21:39:39 +000085 GrPlotMgr* fPlotMgr;
86};
87
88#endif