1 // Copyright 2016 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef SKIA_EXT_SKIA_HISTOGRAM_H_ 6 #define SKIA_EXT_SKIA_HISTOGRAM_H_ 7 8 #include <stdint.h> 9 10 #include <atomic> 11 #include <memory> 12 13 // This file exposes Chrome's histogram functionality to Skia, without bringing 14 // in any Chrome specific headers. To achieve the same level of optimization as 15 // is present in Chrome, we need to use an inlined atomic pointer. This macro 16 // defines a placeholder atomic which will be inlined into the call-site. This 17 // placeholder is passed to the actual histogram logic in Chrome. 18 #define SK_HISTOGRAM_POINTER_HELPER(function, ...) \ 19 do { \ 20 static std::atomic_uintptr_t atomic_histogram_pointer; \ 21 function(std::addressof(atomic_histogram_pointer), __VA_ARGS__); \ 22 } while (0) 23 24 #define SK_HISTOGRAM_BOOLEAN(name, sample) \ 25 SK_HISTOGRAM_POINTER_HELPER(skia::HistogramBoolean, "Skia." name, sample) 26 27 #define SK_HISTOGRAM_ENUMERATION(name, sample, boundary_value) \ 28 SK_HISTOGRAM_POINTER_HELPER(skia::HistogramEnumeration, "Skia." name, \ 29 sample, boundary_value) 30 31 namespace skia { 32 33 void HistogramBoolean(std::atomic_uintptr_t* atomic_histogram_pointer, 34 const char* name, 35 bool sample); 36 void HistogramEnumeration(std::atomic_uintptr_t* atomic_histogram_pointer, 37 const char* name, 38 int sample, 39 int boundary_value); 40 41 } // namespace skia 42 43 #endif // SKIA_EXT_SKIA_HISTOGRAM_H_ 44