blob: e4e5190598128a8fac9eded87df2def35b012f79 [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"
robertphillips@google.com46a86002012-08-08 10:42:44 +000015#include "GrCacheID.h"
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000016
bsalomon@google.com558a75b2011-08-08 17:01:14 +000017class GrRenderTarget;
18class GrResourceEntry;
robertphillips@google.com46a86002012-08-08 10:42:44 +000019class GrResourceKey;
bsalomon@google.com558a75b2011-08-08 17:01:14 +000020
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000021class GrStencilBuffer : public GrResource {
22public:
robertphillips@google.com7fa18762012-09-11 13:02:31 +000023 SK_DECLARE_INST_COUNT(GrStencilBuffer);
robertphillips@google.com46a86002012-08-08 10:42:44 +000024 GR_DECLARE_RESOURCE_CACHE_TYPE()
25
bsalomon@google.com558a75b2011-08-08 17:01:14 +000026 virtual ~GrStencilBuffer() {
bsalomon@google.com558a75b2011-08-08 17:01:14 +000027 // TODO: allow SB to be purged and detach itself from rts
bsalomon@google.com558a75b2011-08-08 17:01:14 +000028 }
29
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000030 int width() const { return fWidth; }
31 int height() const { return fHeight; }
32 int bits() const { return fBits; }
bsalomon@google.com558a75b2011-08-08 17:01:14 +000033 int numSamples() const { return fSampleCnt; }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000034
35 // called to note the last clip drawn to this buffer.
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000036 void setLastClip(int32_t clipStackGenID,
37 const SkIRect& clipSpaceRect,
38 const SkIPoint clipSpaceToStencilOffset) {
39 fLastClipStackGenID = clipStackGenID;
40 fLastClipStackRect = clipSpaceRect;
41 fLastClipSpaceOffset = clipSpaceToStencilOffset;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000042 }
43
44 // called to determine if we have to render the clip into SB.
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000045 bool mustRenderClip(int32_t clipStackGenID,
46 const SkIRect& clipSpaceRect,
47 const SkIPoint clipSpaceToStencilOffset) const {
48 return SkClipStack::kInvalidGenID == clipStackGenID ||
49 fLastClipStackGenID != clipStackGenID ||
50 fLastClipSpaceOffset != clipSpaceToStencilOffset ||
51 !fLastClipStackRect.contains(clipSpaceRect);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000052 }
53
robertphillips@google.com9fbcad02012-09-09 14:44:15 +000054 // Places the sb in the cache. The cache takes a ref of the stencil buffer.
55 void transferToCache();
bsalomon@google.com558a75b2011-08-08 17:01:14 +000056
robertphillips@google.com46a86002012-08-08 10:42:44 +000057 static GrResourceKey ComputeKey(int width, int height, int sampleCnt);
58
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000059protected:
bsalomon@google.com558a75b2011-08-08 17:01:14 +000060 GrStencilBuffer(GrGpu* gpu, int width, int height, int bits, int sampleCnt)
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000061 : GrResource(gpu)
62 , fWidth(width)
63 , fHeight(height)
64 , fBits(bits)
bsalomon@google.com558a75b2011-08-08 17:01:14 +000065 , fSampleCnt(sampleCnt)
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000066 , fLastClipStackGenID(SkClipStack::kInvalidGenID) {
67 fLastClipStackRect.setEmpty();
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000068 }
69
70private:
bsalomon@google.comeefe6f12011-08-09 17:57:12 +000071
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000072 int fWidth;
73 int fHeight;
74 int fBits;
bsalomon@google.com558a75b2011-08-08 17:01:14 +000075 int fSampleCnt;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000076
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000077 int32_t fLastClipStackGenID;
78 SkIRect fLastClipStackRect;
79 SkIPoint fLastClipSpaceOffset;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000080
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000081 typedef GrResource INHERITED;
82};
83
84#endif