michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #include "GrStencilBuffer.h" michael@0: michael@0: #include "GrContext.h" michael@0: #include "GrGpu.h" michael@0: #include "GrResourceCache.h" michael@0: michael@0: void GrStencilBuffer::transferToCache() { michael@0: SkASSERT(NULL == this->getCacheEntry()); michael@0: michael@0: this->getGpu()->getContext()->addStencilBuffer(this); michael@0: } michael@0: michael@0: namespace { michael@0: // we should never have more than one stencil buffer with same combo of (width,height,samplecount) michael@0: void gen_cache_id(int width, int height, int sampleCnt, GrCacheID* cacheID) { michael@0: static const GrCacheID::Domain gStencilBufferDomain = GrCacheID::GenerateDomain(); michael@0: GrCacheID::Key key; michael@0: uint32_t* keyData = key.fData32; michael@0: keyData[0] = width; michael@0: keyData[1] = height; michael@0: keyData[2] = sampleCnt; michael@0: memset(keyData + 3, 0, sizeof(key) - 3 * sizeof(uint32_t)); michael@0: GR_STATIC_ASSERT(sizeof(key) >= 3 * sizeof(uint32_t)); michael@0: cacheID->reset(gStencilBufferDomain, key); michael@0: } michael@0: } michael@0: michael@0: GrResourceKey GrStencilBuffer::ComputeKey(int width, michael@0: int height, michael@0: int sampleCnt) { michael@0: // All SBs are created internally to attach to RTs so they all use the same domain. michael@0: static const GrResourceKey::ResourceType gStencilBufferResourceType = michael@0: GrResourceKey::GenerateResourceType(); michael@0: GrCacheID id; michael@0: gen_cache_id(width, height, sampleCnt, &id); michael@0: michael@0: // we don't use any flags for SBs currently. michael@0: return GrResourceKey(id, gStencilBufferResourceType, 0); michael@0: }