blob: 180912e02d1879ee65f1cfcddc2f5e7d9a78bb91 [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.com0b6ad222012-12-20 14:23:26 +000016GR_DEFINE_RESOURCE_CACHE_TYPE(GrStencilBuffer)
bsalomon@google.com558a75b2011-08-08 17:01:14 +000017
robertphillips@google.com9fbcad02012-09-09 14:44:15 +000018void GrStencilBuffer::transferToCache() {
robertphillips@google.com1f47f4f2012-08-16 14:49:16 +000019 GrAssert(NULL == this->getCacheEntry());
robertphillips@google.com1f47f4f2012-08-16 14:49:16 +000020
robertphillips@google.com9fbcad02012-09-09 14:44:15 +000021 this->getGpu()->getContext()->addStencilBuffer(this);
bsalomon@google.comeefe6f12011-08-09 17:57:12 +000022}
robertphillips@google.com46a86002012-08-08 10:42:44 +000023
24namespace {
bsalomon@google.com0b6ad222012-12-20 14:23:26 +000025// we should never have more than one stencil buffer with same combo of
26// (width,height,samplecount)
27void gen_stencil_key_values(int width,
28 int height,
29 int sampleCnt,
30 GrCacheID* cacheID) {
31 cacheID->fPublicID = GrCacheID::kDefaultPublicCacheID;
32 cacheID->fResourceSpecific32 = width | (height << 16);
33 cacheID->fDomain = GrCacheData::kScratch_ResourceDomain;
34
35 GrAssert(sampleCnt >= 0 && sampleCnt < 256);
36 cacheID->fResourceSpecific16 = sampleCnt << 8;
37
38 // last 8 bits of 'fResourceSpecific16' is free for flags
robertphillips@google.com46a86002012-08-08 10:42:44 +000039}
40}
41
rmistry@google.comd6176b02012-08-23 18:14:13 +000042GrResourceKey GrStencilBuffer::ComputeKey(int width,
43 int height,
robertphillips@google.com46a86002012-08-08 10:42:44 +000044 int sampleCnt) {
bsalomon@google.com0b6ad222012-12-20 14:23:26 +000045 GrCacheID id(GrStencilBuffer::GetResourceType());
46 gen_stencil_key_values(width, height, sampleCnt, &id);
robertphillips@google.com46a86002012-08-08 10:42:44 +000047
bsalomon@google.com0b6ad222012-12-20 14:23:26 +000048 uint32_t v[4];
49 id.toRaw(v);
50 return GrResourceKey(v);
robertphillips@google.com46a86002012-08-08 10:42:44 +000051}