GrStencilAttachment.h revision 4c2443e36fdc6c095b17e90baa4a2f26a6f00b08
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" 1481c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com#include "GrResource.h" 1546a8600405e678718271f62c5994119b8d3241e9robertphillips@google.com#include "GrCacheID.h" 1681c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 17558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.comclass GrRenderTarget; 18558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.comclass GrResourceEntry; 1946a8600405e678718271f62c5994119b8d3241e9robertphillips@google.comclass GrResourceKey; 20558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com 2181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.comclass GrStencilBuffer : public GrResource { 2281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.compublic: 237fa18762e0ab64c3473df3aab0c2bfd6fabd8831robertphillips@google.com SK_DECLARE_INST_COUNT(GrStencilBuffer); 2446a8600405e678718271f62c5994119b8d3241e9robertphillips@google.com GR_DECLARE_RESOURCE_CACHE_TYPE() 2546a8600405e678718271f62c5994119b8d3241e9robertphillips@google.com 26558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com virtual ~GrStencilBuffer() { 27558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com // TODO: allow SB to be purged and detach itself from rts 28558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com } 29558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com 3081c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com int width() const { return fWidth; } 3181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com int height() const { return fHeight; } 3281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com int bits() const { return fBits; } 33558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com int numSamples() const { return fSampleCnt; } 3481c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 3581c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com // called to note the last clip drawn to this buffer. 364c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com void setLastClip(int32_t clipStackGenID, 374c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com const SkIRect& clipSpaceRect, 384c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com const SkIPoint clipSpaceToStencilOffset) { 394c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com fLastClipStackGenID = clipStackGenID; 404c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com fLastClipStackRect = clipSpaceRect; 414c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com fLastClipSpaceOffset = clipSpaceToStencilOffset; 4281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com } 4381c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 4481c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com // called to determine if we have to render the clip into SB. 454c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com bool mustRenderClip(int32_t clipStackGenID, 464c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com const SkIRect& clipSpaceRect, 474c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com const SkIPoint clipSpaceToStencilOffset) const { 484c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com return SkClipStack::kInvalidGenID == clipStackGenID || 494c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com fLastClipStackGenID != clipStackGenID || 504c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com fLastClipSpaceOffset != clipSpaceToStencilOffset || 514c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com !fLastClipStackRect.contains(clipSpaceRect); 5281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com } 5381c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 549fbcad0f00d7098574cf3394a812c9d845c9cc5brobertphillips@google.com // Places the sb in the cache. The cache takes a ref of the stencil buffer. 559fbcad0f00d7098574cf3394a812c9d845c9cc5brobertphillips@google.com void transferToCache(); 56558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com 5746a8600405e678718271f62c5994119b8d3241e9robertphillips@google.com static GrResourceKey ComputeKey(int width, int height, int sampleCnt); 5846a8600405e678718271f62c5994119b8d3241e9robertphillips@google.com 5981c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.comprotected: 60558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com GrStencilBuffer(GrGpu* gpu, int width, int height, int bits, int sampleCnt) 6181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com : GrResource(gpu) 6281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com , fWidth(width) 6381c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com , fHeight(height) 6481c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com , fBits(bits) 65558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com , fSampleCnt(sampleCnt) 664c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com , fLastClipStackGenID(SkClipStack::kInvalidGenID) { 674c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com fLastClipStackRect.setEmpty(); 6881c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com } 6981c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 7081c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.comprivate: 71eefe6f1eef1b5cd394853a3f31a92c3c8db62c45bsalomon@google.com 7281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com int fWidth; 7381c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com int fHeight; 7481c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com int fBits; 75558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com int fSampleCnt; 7681c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 774c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com int32_t fLastClipStackGenID; 784c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com SkIRect fLastClipStackRect; 794c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com SkIPoint fLastClipSpaceOffset; 8081c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 8181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com typedef GrResource INHERITED; 8281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com}; 8381c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 8481c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com#endif 85