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 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 13 | #include "GrPoint.h" |
| 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 | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 34 | int getOffsetX() const { return fOffset.fX; } |
| 35 | int getOffsetY() const { return fOffset.fY; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 36 | |
| 37 | GrTexture* texture() const { return fTexture; } |
| 38 | |
| 39 | bool addSubImage(int width, int height, const void*, GrIPoint16*); |
| 40 | |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 41 | GrDrawTarget::DrawToken drawToken() const { return fDrawToken; } |
| 42 | void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 43 | |
| 44 | private: |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 45 | GrPlot(); |
| 46 | ~GrPlot(); // does not try to delete the fNext field |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 47 | |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 48 | // for recycling |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 49 | GrDrawTarget::DrawToken fDrawToken; |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 50 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 51 | GrPlot* fNext; |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 52 | |
| 53 | GrTexture* fTexture; |
| 54 | GrRectanizer* fRects; |
| 55 | GrAtlasMgr* fAtlasMgr; |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 56 | GrIPoint16 fOffset; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame^] | 57 | size_t fBytesPerPixel; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 58 | |
| 59 | friend class GrAtlasMgr; |
| 60 | }; |
| 61 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 62 | class GrAtlasMgr { |
| 63 | public: |
commit-bot@chromium.org | 9529441 | 2013-09-26 15:28:40 +0000 | [diff] [blame] | 64 | GrAtlasMgr(GrGpu*, GrPixelConfig); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 65 | ~GrAtlasMgr(); |
| 66 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 67 | // add subimage of width, height dimensions to atlas |
| 68 | // returns the containing GrPlot and location relative to the backing texture |
| 69 | GrPlot* addToAtlas(GrAtlas*, int width, int height, const void*, GrIPoint16*); |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 70 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 71 | // free up any plots that are not waiting on a draw call |
| 72 | bool removeUnusedPlots(GrAtlas* atlas); |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 73 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 74 | // to be called by ~GrAtlas() |
| 75 | void deletePlotList(GrPlot* plot); |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 76 | |
commit-bot@chromium.org | 3fddf0e | 2013-09-26 12:57:19 +0000 | [diff] [blame] | 77 | GrTexture* getTexture() const { |
| 78 | return fTexture; |
reed@google.com | 759c16e | 2011-03-15 19:15:15 +0000 | [diff] [blame] | 79 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 80 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 81 | private: |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 82 | GrPlot* allocPlot(); |
| 83 | void freePlot(GrPlot* plot); |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 84 | |
commit-bot@chromium.org | 9529441 | 2013-09-26 15:28:40 +0000 | [diff] [blame] | 85 | GrGpu* fGpu; |
| 86 | GrPixelConfig fPixelConfig; |
| 87 | GrTexture* fTexture; |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 88 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 89 | // allocated array of GrPlots |
| 90 | GrPlot* fPlots; |
| 91 | // linked list of free GrPlots |
| 92 | GrPlot* fFreePlots; |
| 93 | }; |
| 94 | |
| 95 | class GrAtlas { |
| 96 | public: |
| 97 | GrAtlas(GrAtlasMgr* mgr) : fPlots(NULL), fAtlasMgr(mgr) { } |
| 98 | ~GrAtlas() { fAtlasMgr->deletePlotList(fPlots); } |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 99 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 100 | bool isEmpty() { return NULL == fPlots; } |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 101 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 102 | private: |
| 103 | GrPlot* fPlots; |
| 104 | GrAtlasMgr* fAtlasMgr; |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 105 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 106 | friend class GrAtlasMgr; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | #endif |