blob: da597626d368b91b337d4abc493b2d901a8de834 [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
15GR_DEFINE_RESOURCE_CACHE_TYPE(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 {
24// we should never have more than one stencil buffer with same combo of
25// (width,height,samplecount)
rmistry@google.comd6176b02012-08-23 18:14:13 +000026void gen_stencil_key_values(int width,
robertphillips@google.com46a86002012-08-08 10:42:44 +000027 int height,
28 int sampleCnt,
29 GrCacheID* cacheID) {
30 cacheID->fPublicID = GrCacheID::kDefaultPublicCacheID;
31 cacheID->fResourceSpecific32 = width | (height << 16);
robertphillips@google.com9c2ea842012-08-13 17:47:59 +000032 cacheID->fDomain = GrCacheData::kScratch_ResourceDomain;
robertphillips@google.com46a86002012-08-08 10:42:44 +000033
34 GrAssert(sampleCnt >= 0 && sampleCnt < 256);
35 cacheID->fResourceSpecific16 = sampleCnt << 8;
36
37 // last 8 bits of 'fResourceSpecific16' is free for flags
38}
39}
40
rmistry@google.comd6176b02012-08-23 18:14:13 +000041GrResourceKey GrStencilBuffer::ComputeKey(int width,
42 int height,
robertphillips@google.com46a86002012-08-08 10:42:44 +000043 int sampleCnt) {
44 GrCacheID id(GrStencilBuffer::GetResourceType());
45 gen_stencil_key_values(width, height, sampleCnt, &id);
46
47 uint32_t v[4];
48 id.toRaw(v);
49 return GrResourceKey(v);
50}