GrStencilAttachment.h revision 36c57dfb4fe9bbaca436942d5eaa75b142ba251d
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 1081c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com#ifndef GrStencilBuffer_DEFINED 1181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com#define GrStencilBuffer_DEFINED 1281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 13a2d71482db8b6d752a51c96da74768d7dfc27932robertphillips@google.com#include "GrClipData.h" 146d3fe022d68fd6dd32c0fab30e24fa5a4f048946bsalomon#include "GrGpuResource.h" 1581c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 16558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.comclass GrRenderTarget; 1746a8600405e678718271f62c5994119b8d3241e9robertphillips@google.comclass GrResourceKey; 18558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com 196d3fe022d68fd6dd32c0fab30e24fa5a4f048946bsalomonclass GrStencilBuffer : public GrGpuResource { 2081c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.compublic: 217fa18762e0ab64c3473df3aab0c2bfd6fabd8831robertphillips@google.com SK_DECLARE_INST_COUNT(GrStencilBuffer); 2246a8600405e678718271f62c5994119b8d3241e9robertphillips@google.com 23558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com virtual ~GrStencilBuffer() { 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 507775c85611c734a2af709b3a9c127939a4296c48bsalomon static void ComputeKey(int width, int height, int sampleCnt, GrScratchKey* key); 5146a8600405e678718271f62c5994119b8d3241e9robertphillips@google.com 5281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.comprotected: 5336c57dfb4fe9bbaca436942d5eaa75b142ba251dkkinnunen GrStencilBuffer(GrGpu* gpu, LifeCycle lifeCycle, int width, int height, int bits, int sampleCnt) 5436c57dfb4fe9bbaca436942d5eaa75b142ba251dkkinnunen : GrGpuResource(gpu, lifeCycle) 5581c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com , fWidth(width) 5681c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com , fHeight(height) 5781c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com , fBits(bits) 58558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com , fSampleCnt(sampleCnt) 594c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com , fLastClipStackGenID(SkClipStack::kInvalidGenID) { 6036c57dfb4fe9bbaca436942d5eaa75b142ba251dkkinnunen if (kCached_LifeCycle == lifeCycle) { 6136c57dfb4fe9bbaca436942d5eaa75b142ba251dkkinnunen GrScratchKey key; 6236c57dfb4fe9bbaca436942d5eaa75b142ba251dkkinnunen ComputeKey(width, height, sampleCnt, &key); 6336c57dfb4fe9bbaca436942d5eaa75b142ba251dkkinnunen this->setScratchKey(key); 6436c57dfb4fe9bbaca436942d5eaa75b142ba251dkkinnunen } 654c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com fLastClipStackRect.setEmpty(); 6681c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com } 6781c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 6881c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.comprivate: 69eefe6f1eef1b5cd394853a3f31a92c3c8db62c45bsalomon@google.com 7081c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com int fWidth; 7181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com int fHeight; 7281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com int fBits; 73558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com int fSampleCnt; 7481c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 754c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com int32_t fLastClipStackGenID; 764c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com SkIRect fLastClipStackRect; 774c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com SkIPoint fLastClipSpaceOffset; 7881c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 796d3fe022d68fd6dd32c0fab30e24fa5a4f048946bsalomon typedef GrGpuResource INHERITED; 8081c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com}; 8181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 8281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com#endif 83