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) |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 16 | |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 17 | void GrStencilBuffer::transferToCache() { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 18 | SkASSERT(NULL == this->getCacheEntry()); |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 19 | |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 20 | this->getGpu()->getContext()->addStencilBuffer(this); |
bsalomon@google.com | eefe6f1 | 2011-08-09 17:57:12 +0000 | [diff] [blame] | 21 | } |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 22 | |
| 23 | namespace { |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 24 | // we should never have more than one stencil buffer with same combo of (width,height,samplecount) |
| 25 | void gen_cache_id(int width, int height, int sampleCnt, GrCacheID* cacheID) { |
| 26 | static const GrCacheID::Domain gStencilBufferDomain = GrCacheID::GenerateDomain(); |
| 27 | GrCacheID::Key key; |
| 28 | uint32_t* keyData = key.fData32; |
| 29 | keyData[0] = width; |
| 30 | keyData[1] = height; |
| 31 | keyData[2] = sampleCnt; |
bsalomon@google.com | 10a9fb8 | 2013-01-02 19:29:57 +0000 | [diff] [blame] | 32 | memset(keyData + 3, 0, sizeof(key) - 3 * sizeof(uint32_t)); |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 33 | GR_STATIC_ASSERT(sizeof(key) >= 3 * sizeof(uint32_t)); |
| 34 | cacheID->reset(gStencilBufferDomain, key); |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 38 | GrResourceKey GrStencilBuffer::ComputeKey(int width, |
| 39 | int height, |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 40 | int sampleCnt) { |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 41 | // All SBs are created internally to attach to RTs so they all use the same domain. |
| 42 | static const GrResourceKey::ResourceType gStencilBufferResourceType = |
| 43 | GrResourceKey::GenerateResourceType(); |
| 44 | GrCacheID id; |
| 45 | gen_cache_id(width, height, sampleCnt, &id); |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 46 | |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 47 | // we don't use any flags for SBs currently. |
| 48 | return GrResourceKey(id, gStencilBufferResourceType, 0); |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 49 | } |