[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / ui / gl / angle_platform_impl.cc
blob1f1085b5a45bec66b95254aa87cd02c1be59957c
1 // Copyright 2015 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.
5 #include "ui/gl/angle_platform_impl.h"
7 #include "base/metrics/histogram.h"
8 #include "base/metrics/sparse_histogram.h"
9 #include "base/trace_event/trace_event.h"
11 namespace gfx {
13 ANGLEPlatformImpl::ANGLEPlatformImpl() {
16 ANGLEPlatformImpl::~ANGLEPlatformImpl() {
19 double ANGLEPlatformImpl::currentTime() {
20 return base::Time::Now().ToDoubleT();
23 double ANGLEPlatformImpl::monotonicallyIncreasingTime() {
24 return (base::TraceTicks::Now() - base::TraceTicks()).InSecondsF();
27 const unsigned char* ANGLEPlatformImpl::getTraceCategoryEnabledFlag(
28 const char* category_group) {
29 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group);
32 void ANGLEPlatformImpl::logError(const char* errorMessage) {
33 LOG(ERROR) << errorMessage;
36 void ANGLEPlatformImpl::logWarning(const char* warningMessage) {
37 LOG(WARNING) << warningMessage;
40 void ANGLEPlatformImpl::logInfo(const char* infoMessage) {
41 LOG(INFO) << infoMessage;
44 angle::Platform::TraceEventHandle ANGLEPlatformImpl::addTraceEvent(
45 char phase,
46 const unsigned char* category_group_enabled,
47 const char* name,
48 unsigned long long id,
49 double timestamp,
50 int num_args,
51 const char** arg_names,
52 const unsigned char* arg_types,
53 const unsigned long long* arg_values,
54 unsigned char flags) {
55 base::TraceTicks timestamp_tt =
56 base::TraceTicks() + base::TimeDelta::FromSecondsD(timestamp);
57 base::trace_event::TraceEventHandle handle =
58 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
59 phase, category_group_enabled, name, id, trace_event_internal::kNoId,
60 base::PlatformThread::CurrentId(), timestamp_tt, num_args, arg_names,
61 arg_types, arg_values, nullptr, flags);
62 angle::Platform::TraceEventHandle result;
63 memcpy(&result, &handle, sizeof(result));
64 return result;
67 void ANGLEPlatformImpl::updateTraceEventDuration(
68 const unsigned char* category_group_enabled,
69 const char* name,
70 TraceEventHandle handle) {
71 base::trace_event::TraceEventHandle trace_event_handle;
72 memcpy(&trace_event_handle, &handle, sizeof(handle));
73 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled, name,
74 trace_event_handle);
77 void ANGLEPlatformImpl::histogramCustomCounts(const char* name,
78 int sample,
79 int min,
80 int max,
81 int bucket_count) {
82 // Copied from histogram macro, but without the static variable caching
83 // the histogram because name is dynamic.
84 base::HistogramBase* counter = base::Histogram::FactoryGet(
85 name, min, max, bucket_count,
86 base::HistogramBase::kUmaTargetedHistogramFlag);
87 DCHECK_EQ(name, counter->histogram_name());
88 counter->Add(sample);
91 void ANGLEPlatformImpl::histogramEnumeration(const char* name,
92 int sample,
93 int boundary_value) {
94 // Copied from histogram macro, but without the static variable caching
95 // the histogram because name is dynamic.
96 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
97 name, 1, boundary_value, boundary_value + 1,
98 base::HistogramBase::kUmaTargetedHistogramFlag);
99 DCHECK_EQ(name, counter->histogram_name());
100 counter->Add(sample);
103 void ANGLEPlatformImpl::histogramSparse(const char* name, int sample) {
104 // For sparse histograms, we can use the macro, as it does not incorporate a
105 // static.
106 UMA_HISTOGRAM_SPARSE_SLOWLY(name, sample);
109 void ANGLEPlatformImpl::histogramBoolean(const char* name, bool sample) {
110 histogramEnumeration(name, sample ? 1 : 0, 2);
113 } // namespace gfx