michael@0: /* michael@0: * Copyright 2010 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef GrPlotMgr_DEFINED michael@0: #define GrPlotMgr_DEFINED michael@0: michael@0: #include "GrTypes.h" michael@0: #include "GrPoint.h" michael@0: #include "SkTypes.h" michael@0: michael@0: class GrPlotMgr : public SkNoncopyable { michael@0: public: michael@0: GrPlotMgr(int width, int height) { michael@0: fDim.set(width, height); michael@0: size_t needed = width * height; michael@0: if (needed <= sizeof(fStorage)) { michael@0: fBusy = fStorage; michael@0: } else { michael@0: fBusy = SkNEW_ARRAY(char, needed); michael@0: } michael@0: this->reset(); michael@0: } michael@0: michael@0: ~GrPlotMgr() { michael@0: if (fBusy != fStorage) { michael@0: delete[] fBusy; michael@0: } michael@0: } michael@0: michael@0: void reset() { michael@0: sk_bzero(fBusy, fDim.fX * fDim.fY); michael@0: } michael@0: michael@0: bool newPlot(GrIPoint16* loc) { michael@0: char* busy = fBusy; michael@0: for (int y = 0; y < fDim.fY; y++) { michael@0: for (int x = 0; x < fDim.fX; x++) { michael@0: if (!*busy) { michael@0: *busy = true; michael@0: loc->set(x, y); michael@0: return true; michael@0: } michael@0: busy++; michael@0: } michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: bool isBusy(int x, int y) const { michael@0: SkASSERT((unsigned)x < (unsigned)fDim.fX); michael@0: SkASSERT((unsigned)y < (unsigned)fDim.fY); michael@0: return fBusy[y * fDim.fX + x] != 0; michael@0: } michael@0: michael@0: void freePlot(int x, int y) { michael@0: SkASSERT((unsigned)x < (unsigned)fDim.fX); michael@0: SkASSERT((unsigned)y < (unsigned)fDim.fY); michael@0: fBusy[y * fDim.fX + x] = false; michael@0: } michael@0: michael@0: private: michael@0: enum { michael@0: STORAGE = 64 michael@0: }; michael@0: char fStorage[STORAGE]; michael@0: char* fBusy; michael@0: GrIPoint16 fDim; michael@0: }; michael@0: michael@0: #endif