epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 9 | #ifndef GrAtlas_DEFINED |
| 10 | #define GrAtlas_DEFINED |
| 11 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 12 | |
robertphillips | d537341 | 2014-06-02 10:20:14 -0700 | [diff] [blame] | 13 | #include "SkPoint.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 14 | #include "GrTexture.h" |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 15 | #include "GrDrawTarget.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 16 | |
| 17 | class GrGpu; |
| 18 | class GrRectanizer; |
| 19 | class GrAtlasMgr; |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 20 | class GrAtlas; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 21 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 22 | // The backing GrTexture for a set of GrAtlases is broken into a spatial grid of GrPlots. When |
| 23 | // a GrAtlas needs space on the texture, it requests a GrPlot. Each GrAtlas can claim one |
| 24 | // or more GrPlots. The GrPlots keep track of subimage placement via their GrRectanizer. 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 GrAtlasMgr::addToAtlas(). |
| 27 | // |
| 28 | // If all GrPlots are allocated, the replacement strategy is up to the client. The drawToken is |
| 29 | // available to ensure that all draw calls are finished for that particular GrPlot. |
| 30 | // GrAtlasMgr::removeUnusedPlots() will free up any finished plots for a given GrAtlas. |
| 31 | |
| 32 | class GrPlot { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 33 | public: |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 34 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrPlot); |
skia.committer@gmail.com | ade9a34 | 2014-03-04 03:02:32 +0000 | [diff] [blame] | 35 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 36 | GrTexture* texture() const { return fTexture; } |
| 37 | |
robertphillips | d537341 | 2014-06-02 10:20:14 -0700 | [diff] [blame] | 38 | bool addSubImage(int width, int height, const void*, SkIPoint16*); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 39 | |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 40 | GrDrawTarget::DrawToken drawToken() const { return fDrawToken; } |
| 41 | void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 42 | |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 43 | void uploadToTexture(); |
| 44 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 45 | void resetRects(); |
| 46 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 47 | private: |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 48 | GrPlot(); |
| 49 | ~GrPlot(); // does not try to delete the fNext field |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 50 | void init(GrAtlasMgr* mgr, int offX, int offY, int width, int height, size_t bpp, |
| 51 | bool batchUploads); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 52 | |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 53 | // for recycling |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 54 | GrDrawTarget::DrawToken fDrawToken; |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 55 | |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 56 | unsigned char* fPlotData; |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 57 | GrTexture* fTexture; |
| 58 | GrRectanizer* fRects; |
| 59 | GrAtlasMgr* fAtlasMgr; |
robertphillips | d537341 | 2014-06-02 10:20:14 -0700 | [diff] [blame] | 60 | SkIPoint16 fOffset; // the offset of the plot in the backing texture |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 61 | size_t fBytesPerPixel; |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 62 | SkIRect fDirtyRect; |
| 63 | bool fDirty; |
| 64 | bool fBatchUploads; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 65 | |
| 66 | friend class GrAtlasMgr; |
| 67 | }; |
| 68 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 69 | typedef SkTInternalLList<GrPlot> GrPlotList; |
| 70 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 71 | class GrAtlasMgr { |
| 72 | public: |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 73 | GrAtlasMgr(GrGpu*, GrPixelConfig, const SkISize& backingTextureSize, |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 74 | int numPlotsX, int numPlotsY, bool batchUploads); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 75 | ~GrAtlasMgr(); |
| 76 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 77 | // add subimage of width, height dimensions to atlas |
| 78 | // returns the containing GrPlot and location relative to the backing texture |
robertphillips | d537341 | 2014-06-02 10:20:14 -0700 | [diff] [blame] | 79 | GrPlot* addToAtlas(GrAtlas*, int width, int height, const void*, SkIPoint16*); |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 80 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 81 | // remove reference to this plot |
| 82 | bool removePlot(GrAtlas* atlas, const GrPlot* plot); |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 83 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 84 | // get a plot that's not being used by the current draw |
| 85 | // this allows us to overwrite this plot without flushing |
| 86 | GrPlot* getUnusedPlot(); |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 87 | |
commit-bot@chromium.org | 3fddf0e | 2013-09-26 12:57:19 +0000 | [diff] [blame] | 88 | GrTexture* getTexture() const { |
| 89 | return fTexture; |
reed@google.com | 759c16e | 2011-03-15 19:15:15 +0000 | [diff] [blame] | 90 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 91 | |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 92 | void uploadPlotsToTexture(); |
| 93 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 94 | private: |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 95 | void moveToHead(GrPlot* plot); |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 96 | |
commit-bot@chromium.org | 9529441 | 2013-09-26 15:28:40 +0000 | [diff] [blame] | 97 | GrGpu* fGpu; |
| 98 | GrPixelConfig fPixelConfig; |
| 99 | GrTexture* fTexture; |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 100 | SkISize fBackingTextureSize; |
| 101 | int fNumPlotsX; |
| 102 | int fNumPlotsY; |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 103 | bool fBatchUploads; |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 104 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 105 | // allocated array of GrPlots |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 106 | GrPlot* fPlotArray; |
| 107 | // LRU list of GrPlots |
| 108 | GrPlotList fPlotList; |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | class GrAtlas { |
| 112 | public: |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 113 | GrAtlas() { } |
| 114 | ~GrAtlas() { } |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 115 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 116 | bool isEmpty() { return 0 == fPlots.count(); } |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 117 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 118 | private: |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 119 | SkTDArray<GrPlot*> fPlots; |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 120 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 121 | friend class GrAtlasMgr; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | #endif |