Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Side by Side Diff: src/core/SkCpu.cpp

Issue 1905683003: SkCpu w/o static initializer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: back to static-initializer on Windows Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkCpu.h ('k') | src/core/SkGraphics.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #define SkCpu_IMPL
8 #include "SkCpu.h" 9 #include "SkCpu.h"
9 #include "SkOncePtr.h" 10 #include "SkOnce.h"
10 11
11 #if defined(SK_CPU_X86) 12 #if defined(SK_CPU_X86)
12 #if defined(SK_BUILD_FOR_WIN32) 13 #if defined(SK_BUILD_FOR_WIN32)
13 #include <intrin.h> 14 #include <intrin.h>
14 static void cpuid (uint32_t abcd[4]) { __cpuid ((int*)abcd, 1); } 15 static void cpuid (uint32_t abcd[4]) { __cpuid ((int*)abcd, 1); }
15 static void cpuid7(uint32_t abcd[4]) { __cpuidex((int*)abcd, 7, 0); } 16 static void cpuid7(uint32_t abcd[4]) { __cpuidex((int*)abcd, 7, 0); }
16 static uint64_t xgetbv(uint32_t xcr) { return _xgetbv(xcr); } 17 static uint64_t xgetbv(uint32_t xcr) { return _xgetbv(xcr); }
17 #else 18 #else
18 #include <cpuid.h> 19 #include <cpuid.h>
19 #if !defined(__cpuid_count) // Old Mac Clang doesn't have this defined. 20 #if !defined(__cpuid_count) // Old Mac Clang doesn't have this defined.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 return features; 72 return features;
72 } 73 }
73 74
74 #else 75 #else
75 static uint32_t read_cpu_features() { 76 static uint32_t read_cpu_features() {
76 return 0; 77 return 0;
77 } 78 }
78 79
79 #endif 80 #endif
80 81
81 #if defined(__GNUC__) || defined(__clang__) 82 #if defined(_MSC_VER)
82 SK_DECLARE_STATIC_ONCE_PTR(uint32_t, gCachedCpuFeatures); 83 const uint32_t SkCpu::gCachedFeatures = read_cpu_features();
83 uint32_t SkCpu::RuntimeCpuFeatures() { 84
84 return *gCachedCpuFeatures.get([]{ return new uint32_t{read_cpu_features ()}; }); 85 void SkCpu::CacheRuntimeFeatures() {}
86
87 #else
88 uint32_t SkCpu::gCachedFeatures = 0;
89
90 void SkCpu::CacheRuntimeFeatures() {
91 static SkOnce once;
92 once([] { gCachedFeatures = read_cpu_features(); });
85 } 93 }
86 94
87 #else
88 const uint32_t SkCpu::gCachedCpuFeatures = read_cpu_features();
89
90 #endif 95 #endif
OLDNEW
« no previous file with comments | « src/core/SkCpu.h ('k') | src/core/SkGraphics.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698