| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #ifndef GrStencilBuffer_DEFINED | 10 #ifndef GrStencilAttachment_DEFINED |
| 11 #define GrStencilBuffer_DEFINED | 11 #define GrStencilAttachment_DEFINED |
| 12 | 12 |
| 13 #include "GrClip.h" | 13 #include "GrClip.h" |
| 14 #include "GrGpuResource.h" | 14 #include "GrGpuResource.h" |
| 15 | 15 |
| 16 class GrRenderTarget; | 16 class GrRenderTarget; |
| 17 class GrResourceKey; | 17 class GrResourceKey; |
| 18 | 18 |
| 19 class GrStencilBuffer : public GrGpuResource { | 19 class GrStencilAttachment : public GrGpuResource { |
| 20 public: | 20 public: |
| 21 SK_DECLARE_INST_COUNT(GrStencilBuffer); | 21 SK_DECLARE_INST_COUNT(GrStencilAttachment); |
| 22 | 22 |
| 23 virtual ~GrStencilBuffer() { | 23 virtual ~GrStencilAttachment() { |
| 24 // TODO: allow SB to be purged and detach itself from rts | 24 // TODO: allow SB to be purged and detach itself from rts |
| 25 } | 25 } |
| 26 | 26 |
| 27 int width() const { return fWidth; } | 27 int width() const { return fWidth; } |
| 28 int height() const { return fHeight; } | 28 int height() const { return fHeight; } |
| 29 int bits() const { return fBits; } | 29 int bits() const { return fBits; } |
| 30 int numSamples() const { return fSampleCnt; } | 30 int numSamples() const { return fSampleCnt; } |
| 31 | 31 |
| 32 // called to note the last clip drawn to this buffer. | 32 // called to note the last clip drawn to this buffer. |
| 33 void setLastClip(int32_t clipStackGenID, | 33 void setLastClip(int32_t clipStackGenID, |
| 34 const SkIRect& clipSpaceRect, | 34 const SkIRect& clipSpaceRect, |
| 35 const SkIPoint clipSpaceToStencilOffset) { | 35 const SkIPoint clipSpaceToStencilOffset) { |
| 36 fLastClipStackGenID = clipStackGenID; | 36 fLastClipStackGenID = clipStackGenID; |
| 37 fLastClipStackRect = clipSpaceRect; | 37 fLastClipStackRect = clipSpaceRect; |
| 38 fLastClipSpaceOffset = clipSpaceToStencilOffset; | 38 fLastClipSpaceOffset = clipSpaceToStencilOffset; |
| 39 } | 39 } |
| 40 | 40 |
| 41 // called to determine if we have to render the clip into SB. | 41 // called to determine if we have to render the clip into SB. |
| 42 bool mustRenderClip(int32_t clipStackGenID, | 42 bool mustRenderClip(int32_t clipStackGenID, |
| 43 const SkIRect& clipSpaceRect, | 43 const SkIRect& clipSpaceRect, |
| 44 const SkIPoint clipSpaceToStencilOffset) const { | 44 const SkIPoint clipSpaceToStencilOffset) const { |
| 45 return fLastClipStackGenID != clipStackGenID || | 45 return fLastClipStackGenID != clipStackGenID || |
| 46 fLastClipSpaceOffset != clipSpaceToStencilOffset || | 46 fLastClipSpaceOffset != clipSpaceToStencilOffset || |
| 47 !fLastClipStackRect.contains(clipSpaceRect); | 47 !fLastClipStackRect.contains(clipSpaceRect); |
| 48 } | 48 } |
| 49 | 49 |
| 50 // We create a unique stencil buffer at each width, height and sampleCnt and
share it for | 50 // 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. | 51 // all render targets that require a stencil with those params. |
| 52 static void ComputeSharedStencilBufferKey(int width, int height, int sampleC
nt, | 52 static void ComputeSharedStencilAttachmentKey(int width, int height, int sam
pleCnt, |
| 53 GrUniqueKey* key); | 53 GrUniqueKey* key); |
| 54 | 54 |
| 55 protected: | 55 protected: |
| 56 GrStencilBuffer(GrGpu* gpu, LifeCycle lifeCycle, int width, int height, int
bits, int sampleCnt) | 56 GrStencilAttachment(GrGpu* gpu, LifeCycle lifeCycle, int width, int height,
int bits, |
| 57 int sampleCnt) |
| 57 : GrGpuResource(gpu, lifeCycle) | 58 : GrGpuResource(gpu, lifeCycle) |
| 58 , fWidth(width) | 59 , fWidth(width) |
| 59 , fHeight(height) | 60 , fHeight(height) |
| 60 , fBits(bits) | 61 , fBits(bits) |
| 61 , fSampleCnt(sampleCnt) | 62 , fSampleCnt(sampleCnt) |
| 62 , fLastClipStackGenID(SkClipStack::kInvalidGenID) { | 63 , fLastClipStackGenID(SkClipStack::kInvalidGenID) { |
| 63 fLastClipStackRect.setEmpty(); | 64 fLastClipStackRect.setEmpty(); |
| 64 } | 65 } |
| 65 | 66 |
| 66 private: | 67 private: |
| 67 | 68 |
| 68 int fWidth; | 69 int fWidth; |
| 69 int fHeight; | 70 int fHeight; |
| 70 int fBits; | 71 int fBits; |
| 71 int fSampleCnt; | 72 int fSampleCnt; |
| 72 | 73 |
| 73 int32_t fLastClipStackGenID; | 74 int32_t fLastClipStackGenID; |
| 74 SkIRect fLastClipStackRect; | 75 SkIRect fLastClipStackRect; |
| 75 SkIPoint fLastClipSpaceOffset; | 76 SkIPoint fLastClipSpaceOffset; |
| 76 | 77 |
| 77 typedef GrGpuResource INHERITED; | 78 typedef GrGpuResource INHERITED; |
| 78 }; | 79 }; |
| 79 | 80 |
| 80 #endif | 81 #endif |
| OLD | NEW |