blob: d1fe4dde2fed6c4bd7828b3a6ed3f88911bb42c6 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
2 Copyright 2010 Google Inc.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17
18#ifndef GrClipIterator_DEFINED
19#define GrClipIterator_DEFINED
20
21#include "GrRect.h"
22
23class GrClipIterator {
24public:
25 GrClipIterator() : fNeedBounds(true) {}
26 virtual ~GrClipIterator() {}
27
28 /**
29 * Returns true if there are no more rects to process
30 */
31 virtual bool isDone() = 0;
32
33 /**
34 * Rewind the iterate to replay the set of rects again
35 */
36 virtual void rewind() = 0;
37
38 /**
39 * Return the current rect. It is an error to call this when done() is true
40 */
41 virtual void getRect(GrIRect*) = 0;
42
43 /**
44 * Call to move to the next rect in the set
45 */
46 virtual void next() = 0;
47
48 /**
49 * Set bounds to be the bounds of the clip.
50 */
51 virtual void computeBounds(GrIRect* bounds) = 0;
52
53 /**
54 * Subclass should call this whenever their underlying bounds has changed.
55 */
56 void invalidateBoundsCache() { fNeedBounds = true; }
57
58 const GrIRect& getBounds() {
59 if (fNeedBounds) {
60 this->computeBounds(&fBounds);
61 fNeedBounds = false;
62 }
63 return fBounds;
64 }
65
66private:
67 GrIRect fBounds;
68 bool fNeedBounds;
69};
70
71/**
72 * Call to rewind iter, first checking to see if iter is NULL
73 */
74static inline void GrSafeRewind(GrClipIterator* iter) {
75 if (iter) {
76 iter->rewind();
77 }
78}
79
80#endif
81