aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrCacheID.cpp
blob: 4c6dd492c3107fd9338ca2860d7fe2b05b73086d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "GrCacheID.h"
#include "SkThread.h"       // for sk_atomic_inc

uint8_t GrCacheID::GetNextDomain() {
    // 0 reserved for kUnrestricted_ResourceDomain
    static int32_t gNextDomain = 1;

    int32_t domain = sk_atomic_inc(&gNextDomain);
    if (domain >= 256) {
        GrCrash("Too many Cache Domains");
    }

    return (uint8_t) domain;
}

uint8_t GrCacheID::GetNextResourceType() {
    // 0 reserved for kInvalid_ResourceType
    static int32_t gNextResourceType = 1;

    int32_t type = sk_atomic_inc(&gNextResourceType);
    if (type >= 256) {
        GrCrash("Too many Cache Resource Types");
    }

    return (uint8_t) type;
}

void GrCacheID::toRaw(uint32_t v[4]) {
    GrAssert(4*sizeof(uint32_t) == sizeof(GrCacheID));

    v[0] = (uint32_t) (fPublicID & 0xffffffffUL);
    v[1] = (uint32_t) ((fPublicID >> 32) & 0xffffffffUL);
    v[2] = fResourceSpecific32;
    v[3] = fDomain << 24 |
           fResourceType << 16 |
           fResourceSpecific16;
}