| 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" |
| bsalomon | 453cf40 | 2014-11-11 14:15:57 -0800 | [diff] [blame] | 13 | #include "GrResourceCache2.h" |
| robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 14 | |
| robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 15 | namespace { |
| bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 16 | // we should never have more than one stencil buffer with same combo of (width,height,samplecount) |
| 17 | void gen_cache_id(int width, int height, int sampleCnt, GrCacheID* cacheID) { |
| bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 18 | static const GrCacheID::Domain gStencilBufferDomain = GrResourceKey::ScratchDomain(); |
| bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 19 | GrCacheID::Key key; |
| 20 | uint32_t* keyData = key.fData32; |
| 21 | keyData[0] = width; |
| 22 | keyData[1] = height; |
| 23 | keyData[2] = sampleCnt; |
| bsalomon@google.com | 10a9fb8 | 2013-01-02 19:29:57 +0000 | [diff] [blame] | 24 | memset(keyData + 3, 0, sizeof(key) - 3 * sizeof(uint32_t)); |
| bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 25 | GR_STATIC_ASSERT(sizeof(key) >= 3 * sizeof(uint32_t)); |
| 26 | cacheID->reset(gStencilBufferDomain, key); |
| robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 27 | } |
| 28 | } |
| 29 | |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 30 | GrResourceKey GrStencilBuffer::ComputeKey(int width, |
| 31 | int height, |
| robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 32 | int sampleCnt) { |
| bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 33 | // All SBs are created internally to attach to RTs so they all use the same domain. |
| 34 | static const GrResourceKey::ResourceType gStencilBufferResourceType = |
| 35 | GrResourceKey::GenerateResourceType(); |
| 36 | GrCacheID id; |
| 37 | gen_cache_id(width, height, sampleCnt, &id); |
| robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 38 | |
| bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 39 | // we don't use any flags for SBs currently. |
| 40 | return GrResourceKey(id, gStencilBufferResourceType, 0); |
| robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 41 | } |