GrRectanizer.h revision f6de475e5cbd143f348ff7738919e397b7fe7f57
1/*
2 * Copyright 2010 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GrRectanizer_DEFINED
9#define GrRectanizer_DEFINED
10
11#include "GrPoint.h"
12
13class GrRectanizerPurgeListener {
14public:
15    virtual ~GrRectanizerPurgeListener() {}
16
17    virtual void notifyPurgeStrip(void*, int yCoord) = 0;
18};
19
20class GrRectanizer {
21public:
22    GrRectanizer(int width, int height) : fWidth(width), fHeight(height) {
23        SkASSERT(width >= 0);
24        SkASSERT(height >= 0);
25    }
26
27    virtual ~GrRectanizer() {}
28
29    int width() const { return fWidth; }
30    int height() const { return fHeight; }
31
32    virtual bool addRect(int width, int height, GrIPoint16* loc) = 0;
33    virtual float percentFull() const = 0;
34
35    // return the Y-coordinate of a strip that should be purged, given height
36    // i.e. return the oldest such strip, or some other criteria. Return -1
37    // if there is no candidate
38    virtual int stripToPurge(int height) const = 0;
39    virtual void purgeStripAtY(int yCoord) = 0;
40
41    /**
42     *  Our factory, which returns the subclass du jour
43     */
44    static GrRectanizer* Factory(int width, int height);
45
46private:
47    int fWidth;
48    int fHeight;
49};
50
51#endif
52