Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: src/gpu/GrBatchAtlas.h

Issue 975303005: Creation of GrBatchAtlas and Distancefieldpathrenderer batch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more tidying Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2010 Google Inc.
bsalomon 2015/03/05 22:11:08 copyrights on new files are all 2010
joshualitt 2015/03/09 19:45:15 Acknowledged.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9 #ifndef GrBatchAtlas_DEFINED
10 #define GrBatchAtlas_DEFINED
11
12 #include "GrDrawTarget.h"
13 #include "GrTexture.h"
14 #include "SkPoint.h"
15 #include "SkTInternalLList.h"
16
17 class GrBatchAtlas;
18 class GrBatchTarget;
19 class GrGpu;
20 class GrRectanizer;
21
22 // The backing GrTexture for a set of GrAtlases is broken into a spatial grid of GrPlots. When
bsalomon 2015/03/05 22:20:49 for a GrAtlas, not a set of atlases, right?
Jvsquare 2015/03/06 15:45:36 This comment block is from GrAtlas.h, so any chang
23 // a GrAtlas needs space on the texture, it requests a GrPlot. Each GrAtlas can claim one
bsalomon 2015/03/05 22:20:49 atlases claim plots or have plots?
24 // or more GrPlots. The GrPlots keep track of subimage placement via their GrRec tanizer. Once a
25 // GrPlot is "full" (i.e. there is no room for the new subimage according to the GrRectanizer), the
26 // GrAtlas can request a new GrPlot via GrAtlas::addToAtlas().
bsalomon 2015/03/05 22:20:49 Maybe in here state somewhere that plots accumulat
27 //
28 // If all GrPlots are allocated, the replacement strategy is up to the client. T he drawToken is
bsalomon 2015/03/05 22:20:49 Document that the unit of replacement is the plot?
joshualitt 2015/03/09 19:45:15 I rewrote this entire comment in the cpp file
29 // available to ensure that all draw calls are finished for that particular GrPl ot.
30 // GrAtlas::removeUnusedPlots() will free up any finished plots for a given GrAt las.
31
32 class GrBatchPlot : public SkRefCnt {
bsalomon 2015/03/05 22:20:49 Do plots need to be exposed to client of GrBatchAt
joshualitt 2015/03/09 19:45:15 Acknowledged.
33 public:
34 typedef GrDrawTarget::BatchToken BatchToken;
35 SK_DECLARE_INST_COUNT(GrBatchPlot);
36 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrBatchPlot);
37
38 // This returns a plot ID unique to each plot in a given GrAtlas. They are
bsalomon 2015/03/05 22:20:49 we usually use genID to mean an ID that changes wh
joshualitt 2015/03/09 19:45:15 Acknowledged.
39 // consecutive and start at 0.
40 int id() const { return fID; }
41 int generation() const { return fGeneration; }
bsalomon 2015/03/05 22:20:49 comment about how this changes when content of the
joshualitt 2015/03/09 19:45:15 Acknowledged.
42
43 GrTexture* texture() const { return fTexture; }
44
45 bool addSubImage(int width, int height, const void*, SkIPoint16*);
46
47 BatchToken lastUploadToken() const { return fLastUpload; }
bsalomon 2015/03/05 22:20:49 These should be documented, esp lastRefToken
joshualitt 2015/03/09 19:45:15 Acknowledged.
48 BatchToken lastRefToken() const { return fLastRef; }
49 void setLastUploadToken(BatchToken batchToken) { fLastUpload = batchToken; }
50 void setLastRefToken(BatchToken batchToken) { fLastRef = batchToken; }
51
52 void uploadToTexture();
53
54 void resetRects();
55
56 int x() const { return fX; }
57 int y() const { return fY; }
58
59 private:
60 GrBatchPlot();
61 ~GrBatchPlot(); // does not try to delete the fNext field
62 void init(GrGpu*, GrBatchAtlas*, GrTexture*, int id, uint32_t generation, in t offX, int offY,
63 int width, int height, size_t bpp);
64
65 BatchToken fLastUpload;
66 BatchToken fLastRef;
67
68 uint32_t fID;
69 uint32_t fGeneration;
70 unsigned char* fPlotData;
71 int fPlotWidth;
bsalomon 2015/03/06 16:34:59 Do these really need plot in the name? The object
joshualitt 2015/03/09 19:45:15 Acknowledged.
72 int fPlotHeight;
73 int fX;
74 int fY;
75 GrGpu* fGpu;
bsalomon 2015/03/06 16:34:59 Does this really need the gpu object, should it be
joshualitt 2015/03/09 19:45:15 Acknowledged.
76 GrTexture* fTexture;
77 GrRectanizer* fRects;
78 GrBatchAtlas* fAtlas;
79 SkIPoint16 fOffset; // the offset of the plot in the backing texture
80 size_t fBytesPerPixel;
81 SkIRect fDirtyRect;
82 SkDEBUGCODE(bool fDirty;)
83
84 friend class GrBatchAtlas;
85
86 typedef SkRefCnt INHERITED;
87 };
88
89 class GrPlotUpdater {
bsalomon 2015/03/05 22:11:08 It really seems like this should be a generic uplo
joshualitt 2015/03/09 19:45:15 Acknowledged.
90 public:
91 GrPlotUpdater() : fPlot(NULL) {}
92 GrPlotUpdater(GrBatchPlot* plot) : fPlot(SkRef(plot)) { SkASSERT(plot); }
93 GrPlotUpdater(const GrPlotUpdater& other)
94 : fPlot(SkRef(other.fPlot.get())) {
95 SkASSERT(other.fPlot);
96 }
97 GrDrawTarget::BatchToken lastUploadToken() const { return fPlot->lastUploadT oken(); }
98 void update() { fPlot->uploadToTexture(); }
99
100 private:
101 SkAutoTUnref<GrBatchPlot> fPlot;
102 };
103
104 typedef SkTInternalLList<GrBatchPlot> GrBatchPlotList;
105
106 class GrBatchAtlas {
107 public:
108 typedef GrDrawTarget::BatchToken BatchToken;
109 // An AtlasID is an opaque handle which callers can use to determine if the atlas contains
110 // a specific piece of data
111 typedef uint32_t AtlasID;
112
113 GrBatchAtlas(GrGpu*, GrTexture*, int numPlotsX, int numPlotsY);
114 ~GrBatchAtlas();
115
116 // Adds a width x height subimage to the atlas. Upon success it returns
117 // the containing GrPlot and absolute location in the backing texture.
118 // NULL is returned if the subimage cannot fit in the atlas.
119 // If provided, the image data will either be immediately uploaded or
120 // written to the CPU-side backing bitmap.
121 bool addToAtlas(AtlasID*, GrBatchTarget*, int width, int height, const void* image,
122 SkIPoint16* loc);
123
124 GrTexture* getTexture() const { return fTexture; }
125
126 // A debug function to upload all plot data to the texture
127 void uploadPlotsToTexture();
bsalomon 2015/03/05 22:11:08 SkDEBUGCODE()?
joshualitt 2015/03/09 19:45:15 Acknowledged.
128
129 bool hasID(AtlasID id) {
130 int index = this->getIndexFromID(id);
131 SkASSERT(index < fNumPlotsX * fNumPlotsY);
132 return fPlotArray[index]->generation() == this->getGenerationFromID(id);
bsalomon 2015/03/05 22:20:49 is this right? I would think that we'd be using id
joshualitt 2015/03/09 19:45:15 this is correct, I have renamed id to index to mak
133 }
134
135 void setLastRefToken(AtlasID id, BatchToken batchToken) {
136 SkASSERT(this->hasID(id));
137 int index = this->getIndexFromID(id);
138 fPlotArray[index]->setLastRefToken(batchToken);
139 }
140
141 private:
142 int getIndexFromID(AtlasID id) {
143 return (id >> 16) & 0xffff;
144 }
145
146 int getGenerationFromID(AtlasID id) {
147 return id & 0xffff;
148 }
149
150 inline void updatePlot(GrBatchTarget*, AtlasID*, GrBatchPlot*);
151
152 void makeMRU(GrBatchPlot* plot);
153
154 GrGpu* fGpu;
155 GrTexture* fTexture;
156 int fNumPlotsX;
157 int fNumPlotsY;
158 int fPlotWidth;
159 int fPlotHeight;
160 size_t fBPP;
161
162 // allocated array of GrBatchPlots
163 SkAutoTUnref<GrBatchPlot>* fPlotArray;
164 // LRU list of GrPlots (MRU at head - LRU at tail)
165 GrBatchPlotList fPlotList;
166
167 };
168
169 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698