blob: 5aa56e07173c58a3bacabc3fa2a5ef475a70ed8a [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"
bsalomon453cf402014-11-11 14:15:57 -080013#include "GrResourceCache2.h"
robertphillips@google.com46a86002012-08-08 10:42:44 +000014
robertphillips@google.com46a86002012-08-08 10:42:44 +000015namespace {
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000016// we should never have more than one stencil buffer with same combo of (width,height,samplecount)
17void gen_cache_id(int width, int height, int sampleCnt, GrCacheID* cacheID) {
bsalomon10e23ca2014-11-25 05:52:06 -080018 static const GrCacheID::Domain gStencilBufferDomain = GrResourceKey::ScratchDomain();
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000019 GrCacheID::Key key;
20 uint32_t* keyData = key.fData32;
21 keyData[0] = width;
22 keyData[1] = height;
23 keyData[2] = sampleCnt;
bsalomon@google.com10a9fb82013-01-02 19:29:57 +000024 memset(keyData + 3, 0, sizeof(key) - 3 * sizeof(uint32_t));
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000025 GR_STATIC_ASSERT(sizeof(key) >= 3 * sizeof(uint32_t));
26 cacheID->reset(gStencilBufferDomain, key);
robertphillips@google.com46a86002012-08-08 10:42:44 +000027}
28}
29
rmistry@google.comd6176b02012-08-23 18:14:13 +000030GrResourceKey GrStencilBuffer::ComputeKey(int width,
31 int height,
robertphillips@google.com46a86002012-08-08 10:42:44 +000032 int sampleCnt) {
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000033 // 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.com46a86002012-08-08 10:42:44 +000038
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000039 // we don't use any flags for SBs currently.
40 return GrResourceKey(id, gStencilBufferResourceType, 0);
robertphillips@google.com46a86002012-08-08 10:42:44 +000041}