Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2010 Google Inc. |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | #ifndef GrAtlas_DEFINED |
michael@0 | 10 | #define GrAtlas_DEFINED |
michael@0 | 11 | |
michael@0 | 12 | |
michael@0 | 13 | #include "GrPoint.h" |
michael@0 | 14 | #include "GrTexture.h" |
michael@0 | 15 | #include "GrDrawTarget.h" |
michael@0 | 16 | |
michael@0 | 17 | class GrGpu; |
michael@0 | 18 | class GrRectanizer; |
michael@0 | 19 | class GrAtlasMgr; |
michael@0 | 20 | class GrAtlas; |
michael@0 | 21 | |
michael@0 | 22 | // The backing GrTexture for a set of GrAtlases is broken into a spatial grid of GrPlots. When |
michael@0 | 23 | // a GrAtlas needs space on the texture, it requests a GrPlot. Each GrAtlas can claim one |
michael@0 | 24 | // or more GrPlots. The GrPlots keep track of subimage placement via their GrRectanizer. Once a |
michael@0 | 25 | // GrPlot is "full" (i.e. there is no room for the new subimage according to the GrRectanizer), the |
michael@0 | 26 | // GrAtlas can request a new GrPlot via GrAtlasMgr::addToAtlas(). |
michael@0 | 27 | // |
michael@0 | 28 | // If all GrPlots are allocated, the replacement strategy is up to the client. The drawToken is |
michael@0 | 29 | // available to ensure that all draw calls are finished for that particular GrPlot. |
michael@0 | 30 | // GrAtlasMgr::removeUnusedPlots() will free up any finished plots for a given GrAtlas. |
michael@0 | 31 | |
michael@0 | 32 | class GrPlot { |
michael@0 | 33 | public: |
michael@0 | 34 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrPlot); |
michael@0 | 35 | |
michael@0 | 36 | int getOffsetX() const { return fOffset.fX; } |
michael@0 | 37 | int getOffsetY() const { return fOffset.fY; } |
michael@0 | 38 | |
michael@0 | 39 | GrTexture* texture() const { return fTexture; } |
michael@0 | 40 | |
michael@0 | 41 | bool addSubImage(int width, int height, const void*, GrIPoint16*); |
michael@0 | 42 | |
michael@0 | 43 | GrDrawTarget::DrawToken drawToken() const { return fDrawToken; } |
michael@0 | 44 | void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; } |
michael@0 | 45 | |
michael@0 | 46 | void resetRects(); |
michael@0 | 47 | |
michael@0 | 48 | private: |
michael@0 | 49 | GrPlot(); |
michael@0 | 50 | ~GrPlot(); // does not try to delete the fNext field |
michael@0 | 51 | |
michael@0 | 52 | // for recycling |
michael@0 | 53 | GrDrawTarget::DrawToken fDrawToken; |
michael@0 | 54 | |
michael@0 | 55 | GrTexture* fTexture; |
michael@0 | 56 | GrRectanizer* fRects; |
michael@0 | 57 | GrAtlasMgr* fAtlasMgr; |
michael@0 | 58 | GrIPoint16 fOffset; |
michael@0 | 59 | size_t fBytesPerPixel; |
michael@0 | 60 | |
michael@0 | 61 | friend class GrAtlasMgr; |
michael@0 | 62 | }; |
michael@0 | 63 | |
michael@0 | 64 | typedef SkTInternalLList<GrPlot> GrPlotList; |
michael@0 | 65 | |
michael@0 | 66 | class GrAtlasMgr { |
michael@0 | 67 | public: |
michael@0 | 68 | GrAtlasMgr(GrGpu*, GrPixelConfig); |
michael@0 | 69 | ~GrAtlasMgr(); |
michael@0 | 70 | |
michael@0 | 71 | // add subimage of width, height dimensions to atlas |
michael@0 | 72 | // returns the containing GrPlot and location relative to the backing texture |
michael@0 | 73 | GrPlot* addToAtlas(GrAtlas*, int width, int height, const void*, GrIPoint16*); |
michael@0 | 74 | |
michael@0 | 75 | // remove reference to this plot |
michael@0 | 76 | bool removePlot(GrAtlas* atlas, const GrPlot* plot); |
michael@0 | 77 | |
michael@0 | 78 | // get a plot that's not being used by the current draw |
michael@0 | 79 | // this allows us to overwrite this plot without flushing |
michael@0 | 80 | GrPlot* getUnusedPlot(); |
michael@0 | 81 | |
michael@0 | 82 | GrTexture* getTexture() const { |
michael@0 | 83 | return fTexture; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | private: |
michael@0 | 87 | void moveToHead(GrPlot* plot); |
michael@0 | 88 | |
michael@0 | 89 | GrGpu* fGpu; |
michael@0 | 90 | GrPixelConfig fPixelConfig; |
michael@0 | 91 | GrTexture* fTexture; |
michael@0 | 92 | |
michael@0 | 93 | // allocated array of GrPlots |
michael@0 | 94 | GrPlot* fPlotArray; |
michael@0 | 95 | // LRU list of GrPlots |
michael@0 | 96 | GrPlotList fPlotList; |
michael@0 | 97 | }; |
michael@0 | 98 | |
michael@0 | 99 | class GrAtlas { |
michael@0 | 100 | public: |
michael@0 | 101 | GrAtlas() { } |
michael@0 | 102 | ~GrAtlas() { } |
michael@0 | 103 | |
michael@0 | 104 | bool isEmpty() { return 0 == fPlots.count(); } |
michael@0 | 105 | |
michael@0 | 106 | SkISize getSize() const; |
michael@0 | 107 | |
michael@0 | 108 | private: |
michael@0 | 109 | SkTDArray<GrPlot*> fPlots; |
michael@0 | 110 | |
michael@0 | 111 | friend class GrAtlasMgr; |
michael@0 | 112 | }; |
michael@0 | 113 | |
michael@0 | 114 | #endif |