blob: b2acaee8e277d35e0146745c41a4f7849d249424 [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; }
26
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 bool RemoveUnusedAtlases(GrAtlasMgr* atlasMgr, GrAtlas** startAtlas);
40
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +000041 GrDrawTarget::DrawToken drawToken() const { return fDrawToken; }
42 void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; }
reed@google.comac10a2d2010-12-22 21:39:39 +000043
44private:
commit-bot@chromium.org95294412013-09-26 15:28:40 +000045 GrAtlas(GrAtlasMgr*, int plotX, int plotY, int bpp);
reed@google.comac10a2d2010-12-22 21:39:39 +000046 ~GrAtlas(); // does not try to delete the fNext field
47
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000048 // for recycling
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +000049 GrDrawTarget::DrawToken fDrawToken;
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000050
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +000051 GrAtlas* fNext;
52
53 GrTexture* fTexture;
54 GrRectanizer* fRects;
55 GrAtlasMgr* fAtlasMgr;
56 GrIPoint16 fPlot;
commit-bot@chromium.org95294412013-09-26 15:28:40 +000057 int fBytesPerPixel;
reed@google.comac10a2d2010-12-22 21:39:39 +000058
59 friend class GrAtlasMgr;
60};
61
62class GrPlotMgr;
63
64class GrAtlasMgr {
65public:
commit-bot@chromium.org95294412013-09-26 15:28:40 +000066 GrAtlasMgr(GrGpu*, GrPixelConfig);
reed@google.comac10a2d2010-12-22 21:39:39 +000067 ~GrAtlasMgr();
68
commit-bot@chromium.org3fddf0e2013-09-26 12:57:19 +000069 GrAtlas* addToAtlas(GrAtlas**, int width, int height, const void*, GrIPoint16*);
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000070 void deleteAtlas(GrAtlas* atlas) { delete atlas; }
reed@google.comac10a2d2010-12-22 21:39:39 +000071
commit-bot@chromium.org3fddf0e2013-09-26 12:57:19 +000072 GrTexture* getTexture() const {
73 return fTexture;
reed@google.com759c16e2011-03-15 19:15:15 +000074 }
reed@google.comac10a2d2010-12-22 21:39:39 +000075
76 // to be called by ~GrAtlas()
commit-bot@chromium.org3fddf0e2013-09-26 12:57:19 +000077 void freePlot(int x, int y);
reed@google.comac10a2d2010-12-22 21:39:39 +000078
reed@google.comac10a2d2010-12-22 21:39:39 +000079private:
commit-bot@chromium.org95294412013-09-26 15:28:40 +000080 GrGpu* fGpu;
81 GrPixelConfig fPixelConfig;
82 GrTexture* fTexture;
83 GrPlotMgr* fPlotMgr;
reed@google.comac10a2d2010-12-22 21:39:39 +000084};
85
86#endif