gfx/skia/trunk/src/gpu/GrAtlas.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/gpu/GrAtlas.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,114 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2010 Google Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +#ifndef GrAtlas_DEFINED
    1.13 +#define GrAtlas_DEFINED
    1.14 +
    1.15 +
    1.16 +#include "GrPoint.h"
    1.17 +#include "GrTexture.h"
    1.18 +#include "GrDrawTarget.h"
    1.19 +
    1.20 +class GrGpu;
    1.21 +class GrRectanizer;
    1.22 +class GrAtlasMgr;
    1.23 +class GrAtlas;
    1.24 +
    1.25 +// The backing GrTexture for a set of GrAtlases is broken into a spatial grid of GrPlots. When
    1.26 +// a GrAtlas needs space on the texture, it requests a GrPlot. Each GrAtlas can claim one
    1.27 +// or more GrPlots. The GrPlots keep track of subimage placement via their GrRectanizer. Once a
    1.28 +// GrPlot is "full" (i.e. there is no room for the new subimage according to the GrRectanizer), the
    1.29 +// GrAtlas can request a new GrPlot via GrAtlasMgr::addToAtlas().
    1.30 +//
    1.31 +// If all GrPlots are allocated, the replacement strategy is up to the client. The drawToken is
    1.32 +// available to ensure that all draw calls are finished for that particular GrPlot.
    1.33 +// GrAtlasMgr::removeUnusedPlots() will free up any finished plots for a given GrAtlas.
    1.34 +
    1.35 +class GrPlot {
    1.36 +public:
    1.37 +    SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrPlot);
    1.38 +
    1.39 +    int getOffsetX() const { return fOffset.fX; }
    1.40 +    int getOffsetY() const { return fOffset.fY; }
    1.41 +
    1.42 +    GrTexture* texture() const { return fTexture; }
    1.43 +
    1.44 +    bool addSubImage(int width, int height, const void*, GrIPoint16*);
    1.45 +
    1.46 +    GrDrawTarget::DrawToken drawToken() const { return fDrawToken; }
    1.47 +    void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; }
    1.48 +
    1.49 +    void resetRects();
    1.50 +
    1.51 +private:
    1.52 +    GrPlot();
    1.53 +    ~GrPlot(); // does not try to delete the fNext field
    1.54 +
    1.55 +    // for recycling
    1.56 +    GrDrawTarget::DrawToken fDrawToken;
    1.57 +
    1.58 +    GrTexture*              fTexture;
    1.59 +    GrRectanizer*           fRects;
    1.60 +    GrAtlasMgr*             fAtlasMgr;
    1.61 +    GrIPoint16              fOffset;
    1.62 +    size_t                  fBytesPerPixel;
    1.63 +
    1.64 +    friend class GrAtlasMgr;
    1.65 +};
    1.66 +
    1.67 +typedef SkTInternalLList<GrPlot> GrPlotList;
    1.68 +
    1.69 +class GrAtlasMgr {
    1.70 +public:
    1.71 +    GrAtlasMgr(GrGpu*, GrPixelConfig);
    1.72 +    ~GrAtlasMgr();
    1.73 +
    1.74 +    // add subimage of width, height dimensions to atlas
    1.75 +    // returns the containing GrPlot and location relative to the backing texture
    1.76 +    GrPlot* addToAtlas(GrAtlas*, int width, int height, const void*, GrIPoint16*);
    1.77 +
    1.78 +    // remove reference to this plot
    1.79 +    bool removePlot(GrAtlas* atlas, const GrPlot* plot);
    1.80 +
    1.81 +    // get a plot that's not being used by the current draw
    1.82 +    // this allows us to overwrite this plot without flushing
    1.83 +    GrPlot* getUnusedPlot();
    1.84 +
    1.85 +    GrTexture* getTexture() const {
    1.86 +        return fTexture;
    1.87 +    }
    1.88 +
    1.89 +private:
    1.90 +    void moveToHead(GrPlot* plot);
    1.91 +
    1.92 +    GrGpu*        fGpu;
    1.93 +    GrPixelConfig fPixelConfig;
    1.94 +    GrTexture*    fTexture;
    1.95 +
    1.96 +    // allocated array of GrPlots
    1.97 +    GrPlot*       fPlotArray;
    1.98 +    // LRU list of GrPlots
    1.99 +    GrPlotList    fPlotList;
   1.100 +};
   1.101 +
   1.102 +class GrAtlas {
   1.103 +public:
   1.104 +    GrAtlas() { }
   1.105 +    ~GrAtlas() { }
   1.106 +
   1.107 +    bool isEmpty() { return 0 == fPlots.count(); }
   1.108 +
   1.109 +    SkISize getSize() const;
   1.110 +
   1.111 +private:
   1.112 +    SkTDArray<GrPlot*> fPlots;
   1.113 +
   1.114 +    friend class GrAtlasMgr;
   1.115 +};
   1.116 +
   1.117 +#endif

mercurial