blob: 3765a4c657074768142c0066da562350d77d5acd [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 {
46 return SkClipStack::kInvalidGenID == clipStackGenID ||
47 fLastClipStackGenID != clipStackGenID ||
48 fLastClipSpaceOffset != clipSpaceToStencilOffset ||
49 !fLastClipStackRect.contains(clipSpaceRect);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000050 }
51
robertphillips@google.com9fbcad02012-09-09 14:44:15 +000052 // Places the sb in the cache. The cache takes a ref of the stencil buffer.
53 void transferToCache();
bsalomon@google.com558a75b2011-08-08 17:01:14 +000054
robertphillips@google.com46a86002012-08-08 10:42:44 +000055 static GrResourceKey ComputeKey(int width, int height, int sampleCnt);
56
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000057protected:
bsalomon@google.com72830222013-01-23 20:25:22 +000058 GrStencilBuffer(GrGpu* gpu, bool isWrapped, int width, int height, int bits, int sampleCnt)
59 : GrResource(gpu, isWrapped)
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000060 , fWidth(width)
61 , fHeight(height)
62 , fBits(bits)
bsalomon@google.com558a75b2011-08-08 17:01:14 +000063 , fSampleCnt(sampleCnt)
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000064 , fLastClipStackGenID(SkClipStack::kInvalidGenID) {
65 fLastClipStackRect.setEmpty();
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000066 }
67
68private:
bsalomon@google.comeefe6f12011-08-09 17:57:12 +000069
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000070 int fWidth;
71 int fHeight;
72 int fBits;
bsalomon@google.com558a75b2011-08-08 17:01:14 +000073 int fSampleCnt;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000074
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000075 int32_t fLastClipStackGenID;
76 SkIRect fLastClipStackRect;
77 SkIPoint fLastClipSpaceOffset;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000078
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000079 typedef GrResource INHERITED;
80};
81
82#endif