181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com/* 381c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com * Copyright 2011 Google Inc. 481c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com * 581c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com * Use of this source code is governed by a BSD-style license that can be 681c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com * found in the LICENSE file. 781c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com */ 881c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 981c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 108dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel#ifndef GrStencilAttachment_DEFINED 118dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel#define GrStencilAttachment_DEFINED 1281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 1344701df5ce572ac3cccec785cf52103d3d5d14a5joshualitt#include "GrClip.h" 146d3fe022d68fd6dd32c0fab30e24fa5a4f048946bsalomon#include "GrGpuResource.h" 1581c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 16558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.comclass GrRenderTarget; 1746a8600405e678718271f62c5994119b8d3241e9robertphillips@google.comclass GrResourceKey; 18558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com 198dc7c3a839b38b73af34cc2674a06f49eb1ce527egdanielclass GrStencilAttachment : public GrGpuResource { 2081c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.compublic: 212766c00fc0b6a07d46e5f74cdad45da2ef625237mtklein 2246a8600405e678718271f62c5994119b8d3241e9robertphillips@google.com 238dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel virtual ~GrStencilAttachment() { 24558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com // TODO: allow SB to be purged and detach itself from rts 25558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com } 26558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com 2781c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com int width() const { return fWidth; } 2881c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com int height() const { return fHeight; } 2981c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com int bits() const { return fBits; } 30558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com int numSamples() const { return fSampleCnt; } 3181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 3281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com // called to note the last clip drawn to this buffer. 334c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com void setLastClip(int32_t clipStackGenID, 344c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com const SkIRect& clipSpaceRect, 354c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com const SkIPoint clipSpaceToStencilOffset) { 364c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com fLastClipStackGenID = clipStackGenID; 374c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com fLastClipStackRect = clipSpaceRect; 384c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com fLastClipSpaceOffset = clipSpaceToStencilOffset; 3981c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com } 4081c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 4181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com // called to determine if we have to render the clip into SB. 424c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com bool mustRenderClip(int32_t clipStackGenID, 434c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com const SkIRect& clipSpaceRect, 444c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com const SkIPoint clipSpaceToStencilOffset) const { 45d3e5842db0cb169e10d6da1e62c94ba5cf182bb4commit-bot@chromium.org return fLastClipStackGenID != clipStackGenID || 464c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com fLastClipSpaceOffset != clipSpaceToStencilOffset || 474c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com !fLastClipStackRect.contains(clipSpaceRect); 4881c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com } 4981c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 5002a44a488605112aa6683c9d919e13b188112ce1bsalomon // We create a unique stencil buffer at each width, height and sampleCnt and share it for 5102a44a488605112aa6683c9d919e13b188112ce1bsalomon // all render targets that require a stencil with those params. 528dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel static void ComputeSharedStencilAttachmentKey(int width, int height, int sampleCnt, 538dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel GrUniqueKey* key); 5446a8600405e678718271f62c5994119b8d3241e9robertphillips@google.com 5581c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.comprotected: 568dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel GrStencilAttachment(GrGpu* gpu, LifeCycle lifeCycle, int width, int height, int bits, 578dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel int sampleCnt) 5836c57dfb4fe9bbaca436942d5eaa75b142ba251dkkinnunen : GrGpuResource(gpu, lifeCycle) 5981c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com , fWidth(width) 6081c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com , fHeight(height) 6181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com , fBits(bits) 62558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com , fSampleCnt(sampleCnt) 634c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com , fLastClipStackGenID(SkClipStack::kInvalidGenID) { 644c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com fLastClipStackRect.setEmpty(); 6581c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com } 6681c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 6781c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.comprivate: 68eefe6f1eef1b5cd394853a3f31a92c3c8db62c45bsalomon@google.com 6981c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com int fWidth; 7081c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com int fHeight; 7181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com int fBits; 72558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com int fSampleCnt; 7381c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 744c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com int32_t fLastClipStackGenID; 754c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com SkIRect fLastClipStackRect; 764c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com SkIPoint fLastClipSpaceOffset; 7781c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 786d3fe022d68fd6dd32c0fab30e24fa5a4f048946bsalomon typedef GrGpuResource INHERITED; 7981c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com}; 8081c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 8181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com#endif 82