robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 1 | /* |
| 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.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 8 | #include "GrTypes.h" |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 9 | #include "SkThread.h" // for sk_atomic_inc |
| 10 | |
reed@google.com | 3ac5eb5 | 2013-02-05 16:18:20 +0000 | [diff] [blame^] | 11 | // This used to be a global scope, but we got a warning about unused variable |
| 12 | // so we moved it into here. We just want it to compile, so we can test the |
| 13 | // static asserts. |
| 14 | static inline void dummy_function_to_avoid_unused_var_warning() { |
| 15 | GrCacheID::Key kAssertKey; |
| 16 | GR_STATIC_ASSERT(sizeof(kAssertKey.fData8) == sizeof(kAssertKey.fData32)); |
| 17 | GR_STATIC_ASSERT(sizeof(kAssertKey.fData8) == sizeof(kAssertKey.fData64)); |
| 18 | GR_STATIC_ASSERT(sizeof(kAssertKey.fData8) == sizeof(kAssertKey)); |
| 19 | } |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 20 | |
| 21 | GrCacheID::Domain GrCacheID::GenerateDomain() { |
| 22 | static int32_t gNextDomain = kInvalid_Domain + 1; |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 23 | |
| 24 | int32_t domain = sk_atomic_inc(&gNextDomain); |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 25 | if (domain >= 1 << (8 * sizeof(Domain))) { |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 26 | GrCrash("Too many Cache Domains"); |
| 27 | } |
| 28 | |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 29 | return static_cast<Domain>(domain); |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 30 | } |