blob: 34fbe1116c6e53213739aa650a0085b606acafdd [file] [log] [blame]
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#ifndef GrStencilBuffer_DEFINED
11#define GrStencilBuffer_DEFINED
12
13#include "GrClip.h"
14#include "GrResource.h"
15
16class GrStencilBuffer : public GrResource {
17public:
18 int width() const { return fWidth; }
19 int height() const { return fHeight; }
20 int bits() const { return fBits; }
21
22 // called to note the last clip drawn to this buffer.
23 void setLastClip(const GrClip& clip, int width, int height) {
24 fLastClip = clip;
25 fLastClipWidth = width;
26 fLastClipHeight = height;
27 GrAssert(width <= fWidth);
28 GrAssert(height <= fHeight);
29 }
30
31 // called to determine if we have to render the clip into SB.
32 bool mustRenderClip(const GrClip& clip, int width, int height) const {
33 // The clip is in device space. That is it doesn't scale to fit a
34 // smaller RT. It is just truncated on the right / bottom edges.
35 // Note that this assumes that the viewport origin never moves within
36 // the stencil buffer. This is valid today.
37 return width > fLastClipWidth ||
38 height > fLastClipHeight ||
39 clip != fLastClip;
40 }
41
42 const GrClip& getLastClip() const {
43 return fLastClip;
44 }
45
46protected:
47 GrStencilBuffer(GrGpu* gpu, int width, int height, int bits)
48 : GrResource(gpu)
49 , fWidth(width)
50 , fHeight(height)
51 , fBits(bits)
52 , fLastClip()
53 , fLastClipWidth(-1)
54 , fLastClipHeight(-1) {
55 }
56
57private:
58 int fWidth;
59 int fHeight;
60 int fBits;
61
62 GrClip fLastClip;
63 int fLastClipWidth;
64 int fLastClipHeight;
65
66 typedef GrResource INHERITED;
67};
68
69#endif