blob: 37d40f16ba73544e6371c4e6f23ed4dd040de343 [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
robertphillips@google.coma2d71482012-08-01 20:08:47 +000013#include "GrClipData.h"
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000014#include "GrResource.h"
15
bsalomon@google.com558a75b2011-08-08 17:01:14 +000016class GrRenderTarget;
17class GrResourceEntry;
robertphillips@google.com46a86002012-08-08 10:42:44 +000018class GrResourceKey;
bsalomon@google.com558a75b2011-08-08 17:01:14 +000019
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000020class GrStencilBuffer : public GrResource {
21public:
robertphillips@google.com7fa18762012-09-11 13:02:31 +000022 SK_DECLARE_INST_COUNT(GrStencilBuffer);
robertphillips@google.com46a86002012-08-08 10:42:44 +000023
bsalomon@google.com558a75b2011-08-08 17:01:14 +000024 virtual ~GrStencilBuffer() {
bsalomon@google.com558a75b2011-08-08 17:01:14 +000025 // TODO: allow SB to be purged and detach itself from rts
bsalomon@google.com558a75b2011-08-08 17:01:14 +000026 }
27
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000028 int width() const { return fWidth; }
29 int height() const { return fHeight; }
30 int bits() const { return fBits; }
bsalomon@google.com558a75b2011-08-08 17:01:14 +000031 int numSamples() const { return fSampleCnt; }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000032
33 // called to note the last clip drawn to this buffer.
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000034 void setLastClip(int32_t clipStackGenID,
35 const SkIRect& clipSpaceRect,
36 const SkIPoint clipSpaceToStencilOffset) {
37 fLastClipStackGenID = clipStackGenID;
38 fLastClipStackRect = clipSpaceRect;
39 fLastClipSpaceOffset = clipSpaceToStencilOffset;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000040 }
41
42 // called to determine if we have to render the clip into SB.
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000043 bool mustRenderClip(int32_t clipStackGenID,
44 const SkIRect& clipSpaceRect,
45 const SkIPoint clipSpaceToStencilOffset) const {
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +000046 return fLastClipStackGenID != clipStackGenID ||
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000047 fLastClipSpaceOffset != clipSpaceToStencilOffset ||
48 !fLastClipStackRect.contains(clipSpaceRect);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000049 }
50
robertphillips@google.com9fbcad02012-09-09 14:44:15 +000051 // Places the sb in the cache. The cache takes a ref of the stencil buffer.
52 void transferToCache();
bsalomon@google.com558a75b2011-08-08 17:01:14 +000053
robertphillips@google.com46a86002012-08-08 10:42:44 +000054 static GrResourceKey ComputeKey(int width, int height, int sampleCnt);
55
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000056protected:
bsalomon@google.com72830222013-01-23 20:25:22 +000057 GrStencilBuffer(GrGpu* gpu, bool isWrapped, int width, int height, int bits, int sampleCnt)
58 : GrResource(gpu, isWrapped)
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000059 , fWidth(width)
60 , fHeight(height)
61 , fBits(bits)
bsalomon@google.com558a75b2011-08-08 17:01:14 +000062 , fSampleCnt(sampleCnt)
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000063 , fLastClipStackGenID(SkClipStack::kInvalidGenID) {
64 fLastClipStackRect.setEmpty();
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000065 }
66
67private:
bsalomon@google.comeefe6f12011-08-09 17:57:12 +000068
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000069 int fWidth;
70 int fHeight;
71 int fBits;
bsalomon@google.com558a75b2011-08-08 17:01:14 +000072 int fSampleCnt;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000073
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000074 int32_t fLastClipStackGenID;
75 SkIRect fLastClipStackRect;
76 SkIPoint fLastClipSpaceOffset;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000077
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000078 typedef GrResource INHERITED;
79};
80
81#endif