blob: 865961acdc7f9891618dc1d20b044a8932c54af3 [file] [log] [blame]
bsalomon@google.com558a75b2011-08-08 17:01:14 +00001
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.com46a86002012-08-08 10:42:44 +000013#include "GrResourceCache.h"
14
robertphillips@google.com7fa18762012-09-11 13:02:31 +000015SK_DEFINE_INST_COUNT(GrStencilBuffer)
bsalomon@google.com558a75b2011-08-08 17:01:14 +000016
robertphillips@google.com9fbcad02012-09-09 14:44:15 +000017void GrStencilBuffer::transferToCache() {
robertphillips@google.com1f47f4f2012-08-16 14:49:16 +000018 GrAssert(NULL == this->getCacheEntry());
robertphillips@google.com1f47f4f2012-08-16 14:49:16 +000019
robertphillips@google.com9fbcad02012-09-09 14:44:15 +000020 this->getGpu()->getContext()->addStencilBuffer(this);
bsalomon@google.comeefe6f12011-08-09 17:57:12 +000021}
robertphillips@google.com46a86002012-08-08 10:42:44 +000022
23namespace {
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000024// we should never have more than one stencil buffer with same combo of (width,height,samplecount)
25void 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.com10a9fb82013-01-02 19:29:57 +000032 memset(keyData + 3, 0, sizeof(key) - 3 * sizeof(uint32_t));
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000033 GR_STATIC_ASSERT(sizeof(key) >= 3 * sizeof(uint32_t));
34 cacheID->reset(gStencilBufferDomain, key);
robertphillips@google.com46a86002012-08-08 10:42:44 +000035}
36}
37
rmistry@google.comd6176b02012-08-23 18:14:13 +000038GrResourceKey GrStencilBuffer::ComputeKey(int width,
39 int height,
robertphillips@google.com46a86002012-08-08 10:42:44 +000040 int sampleCnt) {
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000041 // 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.com46a86002012-08-08 10:42:44 +000046
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000047 // we don't use any flags for SBs currently.
48 return GrResourceKey(id, gStencilBufferResourceType, 0);
robertphillips@google.com46a86002012-08-08 10:42:44 +000049}