Home | History | Annotate | Download | only in gpu
      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"
     13 #include "GrResourceCache.h"
     14 
     15 void GrStencilBuffer::transferToCache() {
     16     SkASSERT(NULL == this->getCacheEntry());
     17 
     18     this->getGpu()->getContext()->addStencilBuffer(this);
     19 }
     20 
     21 namespace {
     22 // we should never have more than one stencil buffer with same combo of (width,height,samplecount)
     23 void gen_cache_id(int width, int height, int sampleCnt, GrCacheID* cacheID) {
     24     static const GrCacheID::Domain gStencilBufferDomain = GrCacheID::GenerateDomain();
     25     GrCacheID::Key key;
     26     uint32_t* keyData = key.fData32;
     27     keyData[0] = width;
     28     keyData[1] = height;
     29     keyData[2] = sampleCnt;
     30     memset(keyData + 3, 0, sizeof(key) - 3 * sizeof(uint32_t));
     31     GR_STATIC_ASSERT(sizeof(key) >= 3 * sizeof(uint32_t));
     32     cacheID->reset(gStencilBufferDomain, key);
     33 }
     34 }
     35 
     36 GrResourceKey GrStencilBuffer::ComputeKey(int width,
     37                                           int height,
     38                                           int sampleCnt) {
     39     // All SBs are created internally to attach to RTs so they all use the same domain.
     40     static const GrResourceKey::ResourceType gStencilBufferResourceType =
     41         GrResourceKey::GenerateResourceType();
     42     GrCacheID id;
     43     gen_cache_id(width, height, sampleCnt, &id);
     44 
     45     // we don't use any flags for SBs currently.
     46     return GrResourceKey(id, gStencilBufferResourceType, 0);
     47 }
     48