OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #ifndef GrBatchAtlas_DEFINED |
| 9 #define GrBatchAtlas_DEFINED |
| 10 |
| 11 #include "GrDrawTarget.h" |
| 12 #include "GrTexture.h" |
| 13 #include "SkPoint.h" |
| 14 #include "SkTInternalLList.h" |
| 15 |
| 16 class GrBatchAtlas; |
| 17 class GrBatchPlot; |
| 18 class GrBatchTarget; |
| 19 class GrRectanizer; |
| 20 class GrTextureUploader; |
| 21 |
| 22 typedef SkTInternalLList<GrBatchPlot> GrBatchPlotList; |
| 23 |
| 24 class GrBatchAtlas { |
| 25 public: |
| 26 typedef GrDrawTarget::BatchToken BatchToken; |
| 27 // An AtlasID is an opaque handle which callers can use to determine if the
atlas contains |
| 28 // a specific piece of data |
| 29 typedef uint32_t AtlasID; |
| 30 |
| 31 GrBatchAtlas(GrTexture*, int numPlotsX, int numPlotsY); |
| 32 ~GrBatchAtlas(); |
| 33 |
| 34 // Adds a width x height subimage to the atlas. Upon success it returns |
| 35 // the containing GrPlot and absolute location in the backing texture. |
| 36 // NULL is returned if the subimage cannot fit in the atlas. |
| 37 // If provided, the image data will be written to the CPU-side backing bitma
p. |
| 38 bool addToAtlas(AtlasID*, GrBatchTarget*, int width, int height, const void*
image, |
| 39 SkIPoint16* loc); |
| 40 |
| 41 GrTexture* getTexture() const { return fTexture; } |
| 42 |
| 43 bool hasID(AtlasID id); |
| 44 void setLastRefToken(AtlasID id, BatchToken batchToken); |
| 45 |
| 46 SkDEBUGCODE(void uploadPlotsToTexture(GrTextureUploader);) |
| 47 |
| 48 private: |
| 49 int getIndexFromID(AtlasID id) { |
| 50 return id & 0xffff; |
| 51 } |
| 52 |
| 53 int getGenerationFromID(AtlasID id) { |
| 54 return (id >> 16) & 0xffff; |
| 55 } |
| 56 |
| 57 inline void updatePlot(GrBatchTarget*, AtlasID*, GrBatchPlot*); |
| 58 |
| 59 void makeMRU(GrBatchPlot* plot); |
| 60 |
| 61 GrTexture* fTexture; |
| 62 int fNumPlotsX; |
| 63 int fNumPlotsY; |
| 64 int fPlotWidth; |
| 65 int fPlotHeight; |
| 66 size_t fBPP; |
| 67 |
| 68 // allocated array of GrBatchPlots |
| 69 SkAutoTUnref<GrBatchPlot>* fPlotArray; |
| 70 // LRU list of GrPlots (MRU at head - LRU at tail) |
| 71 GrBatchPlotList fPlotList; |
| 72 |
| 73 }; |
| 74 |
| 75 #endif |
OLD | NEW |