1 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#include "GrStencilBuffer.h" 10 11#include "GrContext.h" 12#include "GrGpu.h" 13 14void GrStencilBuffer::wasDetachedFromRenderTarget(const GrRenderTarget* rt) { 15 GrAssert(fRTAttachmentCnt > 0); 16 if (0 == --fRTAttachmentCnt) { 17 this->unlockInCache(); 18 // At this point we could be deleted! 19 } 20} 21 22void GrStencilBuffer::transferToCacheAndLock() { 23 GrAssert(NULL == fCacheEntry); 24 fCacheEntry = 25 this->getGpu()->getContext()->addAndLockStencilBuffer(this); 26} 27 28void GrStencilBuffer::onRelease() { 29 // When the GrGpu rips through its list of resources and releases 30 // them it may release an SB before it releases its attached RTs. 31 // In that case when GrStencilBuffer sees its last detach it no 32 // long has a gpu ptr (gets nulled in GrResource::release()) and can't 33 // access the cache to unlock itself. So if we're being released and still 34 // have attachments go ahead and unlock now. 35 if (fRTAttachmentCnt) { 36 this->unlockInCache(); 37 // we shouldn't be deleted here because some RT still has a ref on us. 38 } 39 fCacheEntry = NULL; 40} 41 42void GrStencilBuffer::onAbandon() { 43 // we can use the same behavior as release. 44 this->onRelease(); 45} 46 47void GrStencilBuffer::unlockInCache() { 48 if (NULL != fCacheEntry) { 49 GrGpu* gpu = this->getGpu(); 50 if (NULL != gpu) { 51 GrAssert(NULL != gpu->getContext()); 52 gpu->getContext()->unlockStencilBuffer(fCacheEntry); 53 } 54 } 55} 56