blob: 2aa8e8ce55b84091d4d8bb261073a51ddc665ee7 [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
egdaniel8dc7c3a2015-04-16 11:22:42 -070010#ifndef GrStencilAttachment_DEFINED
11#define GrStencilAttachment_DEFINED
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000012
joshualitt44701df2015-02-23 14:44:57 -080013#include "GrClip.h"
bsalomon6d3fe022014-07-25 08:35:45 -070014#include "GrGpuResource.h"
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000015
bsalomon@google.com558a75b2011-08-08 17:01:14 +000016class GrRenderTarget;
robertphillips@google.com46a86002012-08-08 10:42:44 +000017class GrResourceKey;
bsalomon@google.com558a75b2011-08-08 17:01:14 +000018
egdaniel8dc7c3a2015-04-16 11:22:42 -070019class GrStencilAttachment : public GrGpuResource {
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000020public:
mtklein2766c002015-06-26 11:45:03 -070021
robertphillips@google.com46a86002012-08-08 10:42:44 +000022
egdaniel8dc7c3a2015-04-16 11:22:42 -070023 virtual ~GrStencilAttachment() {
bsalomon@google.com558a75b2011-08-08 17:01:14 +000024 // TODO: allow SB to be purged and detach itself from rts
bsalomon@google.com558a75b2011-08-08 17:01:14 +000025 }
26
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000027 int width() const { return fWidth; }
28 int height() const { return fHeight; }
29 int bits() const { return fBits; }
bsalomon@google.com558a75b2011-08-08 17:01:14 +000030 int numSamples() const { return fSampleCnt; }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000031
32 // called to note the last clip drawn to this buffer.
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000033 void setLastClip(int32_t clipStackGenID,
34 const SkIRect& clipSpaceRect,
35 const SkIPoint clipSpaceToStencilOffset) {
36 fLastClipStackGenID = clipStackGenID;
37 fLastClipStackRect = clipSpaceRect;
38 fLastClipSpaceOffset = clipSpaceToStencilOffset;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000039 }
40
41 // called to determine if we have to render the clip into SB.
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000042 bool mustRenderClip(int32_t clipStackGenID,
43 const SkIRect& clipSpaceRect,
44 const SkIPoint clipSpaceToStencilOffset) const {
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +000045 return fLastClipStackGenID != clipStackGenID ||
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000046 fLastClipSpaceOffset != clipSpaceToStencilOffset ||
47 !fLastClipStackRect.contains(clipSpaceRect);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000048 }
49
bsalomon02a44a42015-02-19 09:09:00 -080050 // We create a unique stencil buffer at each width, height and sampleCnt and share it for
51 // all render targets that require a stencil with those params.
egdaniel8dc7c3a2015-04-16 11:22:42 -070052 static void ComputeSharedStencilAttachmentKey(int width, int height, int sampleCnt,
53 GrUniqueKey* key);
robertphillips@google.com46a86002012-08-08 10:42:44 +000054
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000055protected:
egdaniel8dc7c3a2015-04-16 11:22:42 -070056 GrStencilAttachment(GrGpu* gpu, LifeCycle lifeCycle, int width, int height, int bits,
57 int sampleCnt)
kkinnunen36c57df2015-01-27 00:30:18 -080058 : GrGpuResource(gpu, lifeCycle)
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
bsalomon6d3fe022014-07-25 08:35:45 -070078 typedef GrGpuResource INHERITED;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000079};
80
81#endif