bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 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" |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 13 | #include "GrResourceCache.h" |
| 14 | |
robertphillips@google.com | 7fa1876 | 2012-09-11 13:02:31 +0000 | [diff] [blame^] | 15 | SK_DEFINE_INST_COUNT(GrStencilBuffer) |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 16 | GR_DEFINE_RESOURCE_CACHE_TYPE(GrStencilBuffer) |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 17 | |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 18 | void GrStencilBuffer::transferToCache() { |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 19 | GrAssert(NULL == this->getCacheEntry()); |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 20 | |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 21 | this->getGpu()->getContext()->addStencilBuffer(this); |
bsalomon@google.com | eefe6f1 | 2011-08-09 17:57:12 +0000 | [diff] [blame] | 22 | } |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 23 | |
| 24 | namespace { |
| 25 | // we should never have more than one stencil buffer with same combo of |
| 26 | // (width,height,samplecount) |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 27 | void gen_stencil_key_values(int width, |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 28 | int height, |
| 29 | int sampleCnt, |
| 30 | GrCacheID* cacheID) { |
| 31 | cacheID->fPublicID = GrCacheID::kDefaultPublicCacheID; |
| 32 | cacheID->fResourceSpecific32 = width | (height << 16); |
robertphillips@google.com | 9c2ea84 | 2012-08-13 17:47:59 +0000 | [diff] [blame] | 33 | cacheID->fDomain = GrCacheData::kScratch_ResourceDomain; |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 34 | |
| 35 | GrAssert(sampleCnt >= 0 && sampleCnt < 256); |
| 36 | cacheID->fResourceSpecific16 = sampleCnt << 8; |
| 37 | |
| 38 | // last 8 bits of 'fResourceSpecific16' is free for flags |
| 39 | } |
| 40 | } |
| 41 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 42 | GrResourceKey GrStencilBuffer::ComputeKey(int width, |
| 43 | int height, |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 44 | int sampleCnt) { |
| 45 | GrCacheID id(GrStencilBuffer::GetResourceType()); |
| 46 | gen_stencil_key_values(width, height, sampleCnt, &id); |
| 47 | |
| 48 | uint32_t v[4]; |
| 49 | id.toRaw(v); |
| 50 | return GrResourceKey(v); |
| 51 | } |