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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/gpu/GrPlotMgr.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +/*
     1.5 + * Copyright 2010 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef GrPlotMgr_DEFINED
    1.12 +#define GrPlotMgr_DEFINED
    1.13 +
    1.14 +#include "GrTypes.h"
    1.15 +#include "GrPoint.h"
    1.16 +#include "SkTypes.h"
    1.17 +
    1.18 +class GrPlotMgr : public SkNoncopyable {
    1.19 +public:
    1.20 +    GrPlotMgr(int width, int height) {
    1.21 +        fDim.set(width, height);
    1.22 +        size_t needed = width * height;
    1.23 +        if (needed <= sizeof(fStorage)) {
    1.24 +            fBusy = fStorage;
    1.25 +        } else {
    1.26 +            fBusy = SkNEW_ARRAY(char, needed);
    1.27 +        }
    1.28 +        this->reset();
    1.29 +    }
    1.30 +
    1.31 +    ~GrPlotMgr() {
    1.32 +        if (fBusy != fStorage) {
    1.33 +            delete[] fBusy;
    1.34 +        }
    1.35 +    }
    1.36 +
    1.37 +    void reset() {
    1.38 +        sk_bzero(fBusy, fDim.fX * fDim.fY);
    1.39 +    }
    1.40 +
    1.41 +    bool newPlot(GrIPoint16* loc) {
    1.42 +        char* busy = fBusy;
    1.43 +        for (int y = 0; y < fDim.fY; y++) {
    1.44 +            for (int x = 0; x < fDim.fX; x++) {
    1.45 +                if (!*busy) {
    1.46 +                    *busy = true;
    1.47 +                    loc->set(x, y);
    1.48 +                    return true;
    1.49 +                }
    1.50 +                busy++;
    1.51 +            }
    1.52 +        }
    1.53 +        return false;
    1.54 +    }
    1.55 +
    1.56 +    bool isBusy(int x, int y) const {
    1.57 +        SkASSERT((unsigned)x < (unsigned)fDim.fX);
    1.58 +        SkASSERT((unsigned)y < (unsigned)fDim.fY);
    1.59 +        return fBusy[y * fDim.fX + x] != 0;
    1.60 +    }
    1.61 +
    1.62 +    void freePlot(int x, int y) {
    1.63 +        SkASSERT((unsigned)x < (unsigned)fDim.fX);
    1.64 +        SkASSERT((unsigned)y < (unsigned)fDim.fY);
    1.65 +        fBusy[y * fDim.fX + x] = false;
    1.66 +    }
    1.67 +
    1.68 +private:
    1.69 +    enum {
    1.70 +        STORAGE = 64
    1.71 +    };
    1.72 +    char fStorage[STORAGE];
    1.73 +    char* fBusy;
    1.74 +    GrIPoint16  fDim;
    1.75 +};
    1.76 +
    1.77 +#endif

mercurial