blob: 87917ac995eec69efb79cc0c882dfa10447e05d4 [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
bsalomon@google.com0797c2c2012-12-20 15:13:01 +00008#include "GrTypes.h"
robertphillips@google.com46a86002012-08-08 10:42:44 +00009#include "SkThread.h" // for sk_atomic_inc
10
bsalomon@google.com5c265d62013-02-05 20:09:41 +000011// Well, the dummy_ "fix" caused a warning on windows, so hiding all of it
12// until we can find a universal fix.
13#if 0
reed@google.com3ac5eb52013-02-05 16:18:20 +000014// This used to be a global scope, but we got a warning about unused variable
15// so we moved it into here. We just want it to compile, so we can test the
16// static asserts.
17static inline void dummy_function_to_avoid_unused_var_warning() {
bsalomon@google.com5c265d62013-02-05 20:09:41 +000018 GrCacheID::Key kAssertKey;
reed@google.com3ac5eb52013-02-05 16:18:20 +000019 GR_STATIC_ASSERT(sizeof(kAssertKey.fData8) == sizeof(kAssertKey.fData32));
20 GR_STATIC_ASSERT(sizeof(kAssertKey.fData8) == sizeof(kAssertKey.fData64));
21 GR_STATIC_ASSERT(sizeof(kAssertKey.fData8) == sizeof(kAssertKey));
22}
bsalomon@google.com5c265d62013-02-05 20:09:41 +000023#endif
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000024
25GrCacheID::Domain GrCacheID::GenerateDomain() {
26 static int32_t gNextDomain = kInvalid_Domain + 1;
robertphillips@google.com46a86002012-08-08 10:42:44 +000027
28 int32_t domain = sk_atomic_inc(&gNextDomain);
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000029 if (domain >= 1 << (8 * sizeof(Domain))) {
robertphillips@google.com46a86002012-08-08 10:42:44 +000030 GrCrash("Too many Cache Domains");
31 }
32
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000033 return static_cast<Domain>(domain);
robertphillips@google.com46a86002012-08-08 10:42:44 +000034}