skia_histogram.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #ifndef SKIA_EXT_SKIA_HISTOGRAM_H_
  5. #define SKIA_EXT_SKIA_HISTOGRAM_H_
  6. #include <stdint.h>
  7. #include <atomic>
  8. #include <memory>
  9. // This file exposes Chrome's histogram functionality to Skia, without bringing
  10. // in any Chrome specific headers. To achieve the same level of optimization as
  11. // is present in Chrome, we need to use an inlined atomic pointer. This macro
  12. // defines a placeholder atomic which will be inlined into the call-site. This
  13. // placeholder is passed to the actual histogram logic in Chrome.
  14. #define SK_HISTOGRAM_POINTER_HELPER(function, ...) \
  15. do { \
  16. static std::atomic_uintptr_t atomic_histogram_pointer; \
  17. function(std::addressof(atomic_histogram_pointer), __VA_ARGS__); \
  18. } while (0)
  19. #define SK_HISTOGRAM_BOOLEAN(name, sample) \
  20. SK_HISTOGRAM_POINTER_HELPER(skia::HistogramBoolean, "Skia." name, sample)
  21. #define SK_HISTOGRAM_EXACT_LINEAR(name, sample, value_max) \
  22. SK_HISTOGRAM_POINTER_HELPER(skia::HistogramExactLinear, "Skia." name, \
  23. sample, value_max)
  24. #define SK_HISTOGRAM_MEMORY_KB(name, sample) \
  25. SK_HISTOGRAM_POINTER_HELPER(skia::HistogramMemoryKB, "Skia." name, sample)
  26. namespace skia {
  27. void HistogramBoolean(std::atomic_uintptr_t* atomic_histogram_pointer,
  28. const char* name,
  29. bool sample);
  30. void HistogramExactLinear(std::atomic_uintptr_t* atomic_histogram_pointer,
  31. const char* name,
  32. int sample,
  33. int value_max);
  34. void HistogramMemoryKB(std::atomic_uintptr_t* atomic_histogram_pointer,
  35. const char* name,
  36. int sample);
  37. } // namespace skia
  38. #endif // SKIA_EXT_SKIA_HISTOGRAM_H_