blob: 5f60d94e4be4984ed0fb3e8e33d38d47acb0fcd5 [file] [log] [blame]
robertphillips@google.com46a86002012-08-08 10:42:44 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "GrCacheID.h"
9#include "SkThread.h" // for sk_atomic_inc
10
11uint8_t GrCacheID::GetNextDomain() {
12 // 0 reserved for kUnrestricted_ResourceDomain
13 static int32_t gNextDomain = 1;
14
15 int32_t domain = sk_atomic_inc(&gNextDomain);
16 if (domain >= 256) {
17 GrCrash("Too many Cache Domains");
18 }
19
20 return (uint8_t) domain;
21}
22
23uint8_t GrCacheID::GetNextResourceType() {
24 // 0 reserved for kInvalid_ResourceType
25 static int32_t gNextResourceType = 1;
26
27 int32_t type = sk_atomic_inc(&gNextResourceType);
28 if (type >= 256) {
29 GrCrash("Too many Cache Resource Types");
30 }
31
32 return (uint8_t) type;
33}
34
35void GrCacheID::toRaw(uint32_t v[4]) {
36 GrAssert(4*sizeof(uint32_t) == sizeof(GrCacheID));
37
38 v[0] = (uint32_t) (fPublicID & 0xffffffffUL);
39 v[1] = (uint32_t) ((fPublicID >> 32) & 0xffffffffUL);
40 v[2] = fResourceSpecific32;
41 v[3] = fDomain << 24 |
42 fResourceType << 16 |
43 fResourceSpecific16;
44}