1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/gpu/GrStencilBuffer.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,47 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2011 Google Inc. 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 +#include "GrStencilBuffer.h" 1.13 + 1.14 +#include "GrContext.h" 1.15 +#include "GrGpu.h" 1.16 +#include "GrResourceCache.h" 1.17 + 1.18 +void GrStencilBuffer::transferToCache() { 1.19 + SkASSERT(NULL == this->getCacheEntry()); 1.20 + 1.21 + this->getGpu()->getContext()->addStencilBuffer(this); 1.22 +} 1.23 + 1.24 +namespace { 1.25 +// we should never have more than one stencil buffer with same combo of (width,height,samplecount) 1.26 +void gen_cache_id(int width, int height, int sampleCnt, GrCacheID* cacheID) { 1.27 + static const GrCacheID::Domain gStencilBufferDomain = GrCacheID::GenerateDomain(); 1.28 + GrCacheID::Key key; 1.29 + uint32_t* keyData = key.fData32; 1.30 + keyData[0] = width; 1.31 + keyData[1] = height; 1.32 + keyData[2] = sampleCnt; 1.33 + memset(keyData + 3, 0, sizeof(key) - 3 * sizeof(uint32_t)); 1.34 + GR_STATIC_ASSERT(sizeof(key) >= 3 * sizeof(uint32_t)); 1.35 + cacheID->reset(gStencilBufferDomain, key); 1.36 +} 1.37 +} 1.38 + 1.39 +GrResourceKey GrStencilBuffer::ComputeKey(int width, 1.40 + int height, 1.41 + int sampleCnt) { 1.42 + // All SBs are created internally to attach to RTs so they all use the same domain. 1.43 + static const GrResourceKey::ResourceType gStencilBufferResourceType = 1.44 + GrResourceKey::GenerateResourceType(); 1.45 + GrCacheID id; 1.46 + gen_cache_id(width, height, sampleCnt, &id); 1.47 + 1.48 + // we don't use any flags for SBs currently. 1.49 + return GrResourceKey(id, gStencilBufferResourceType, 0); 1.50 +}