| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gl/angle_platform_impl.h" | 5 #include "ui/gl/angle_platform_impl.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "third_party/angle/include/platform/Platform.h" |
| 11 #include "ui/gl/gl_bindings.h" |
| 10 | 12 |
| 11 namespace gl { | 13 namespace gl { |
| 12 | 14 |
| 13 ANGLEPlatformImpl::ANGLEPlatformImpl() { | 15 namespace { |
| 14 } | |
| 15 | 16 |
| 16 ANGLEPlatformImpl::~ANGLEPlatformImpl() { | 17 angle::ResetDisplayPlatformFunc g_angle_reset_platform = nullptr; |
| 17 } | |
| 18 | 18 |
| 19 double ANGLEPlatformImpl::currentTime() { | 19 double ANGLEPlatformImpl_currentTime(angle::PlatformMethods* platform) { |
| 20 return base::Time::Now().ToDoubleT(); | 20 return base::Time::Now().ToDoubleT(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 double ANGLEPlatformImpl::monotonicallyIncreasingTime() { | 23 double ANGLEPlatformImpl_monotonicallyIncreasingTime( |
| 24 angle::PlatformMethods* platform) { |
| 24 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); | 25 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); |
| 25 } | 26 } |
| 26 | 27 |
| 27 const unsigned char* ANGLEPlatformImpl::getTraceCategoryEnabledFlag( | 28 const unsigned char* ANGLEPlatformImpl_getTraceCategoryEnabledFlag( |
| 29 angle::PlatformMethods* platform, |
| 28 const char* category_group) { | 30 const char* category_group) { |
| 29 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); | 31 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); |
| 30 } | 32 } |
| 31 | 33 |
| 32 void ANGLEPlatformImpl::logError(const char* errorMessage) { | 34 void ANGLEPlatformImpl_logError(angle::PlatformMethods* platform, |
| 35 const char* errorMessage) { |
| 33 LOG(ERROR) << errorMessage; | 36 LOG(ERROR) << errorMessage; |
| 34 } | 37 } |
| 35 | 38 |
| 36 void ANGLEPlatformImpl::logWarning(const char* warningMessage) { | 39 void ANGLEPlatformImpl_logWarning(angle::PlatformMethods* platform, |
| 40 const char* warningMessage) { |
| 37 LOG(WARNING) << warningMessage; | 41 LOG(WARNING) << warningMessage; |
| 38 } | 42 } |
| 39 | 43 |
| 40 angle::Platform::TraceEventHandle ANGLEPlatformImpl::addTraceEvent( | 44 angle::TraceEventHandle ANGLEPlatformImpl_addTraceEvent( |
| 45 angle::PlatformMethods* platform, |
| 41 char phase, | 46 char phase, |
| 42 const unsigned char* category_group_enabled, | 47 const unsigned char* category_group_enabled, |
| 43 const char* name, | 48 const char* name, |
| 44 unsigned long long id, | 49 unsigned long long id, |
| 45 double timestamp, | 50 double timestamp, |
| 46 int num_args, | 51 int num_args, |
| 47 const char** arg_names, | 52 const char** arg_names, |
| 48 const unsigned char* arg_types, | 53 const unsigned char* arg_types, |
| 49 const unsigned long long* arg_values, | 54 const unsigned long long* arg_values, |
| 50 unsigned char flags) { | 55 unsigned char flags) { |
| 51 base::TimeTicks timestamp_tt = | 56 base::TimeTicks timestamp_tt = |
| 52 base::TimeTicks() + base::TimeDelta::FromSecondsD(timestamp); | 57 base::TimeTicks() + base::TimeDelta::FromSecondsD(timestamp); |
| 53 base::trace_event::TraceEventHandle handle = | 58 base::trace_event::TraceEventHandle handle = |
| 54 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( | 59 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( |
| 55 phase, category_group_enabled, name, | 60 phase, category_group_enabled, name, |
| 56 trace_event_internal::kGlobalScope, id, trace_event_internal::kNoId, | 61 trace_event_internal::kGlobalScope, id, trace_event_internal::kNoId, |
| 57 base::PlatformThread::CurrentId(), timestamp_tt, num_args, arg_names, | 62 base::PlatformThread::CurrentId(), timestamp_tt, num_args, arg_names, |
| 58 arg_types, arg_values, nullptr, flags); | 63 arg_types, arg_values, nullptr, flags); |
| 59 angle::Platform::TraceEventHandle result; | 64 angle::TraceEventHandle result; |
| 60 memcpy(&result, &handle, sizeof(result)); | 65 memcpy(&result, &handle, sizeof(result)); |
| 61 return result; | 66 return result; |
| 62 } | 67 } |
| 63 | 68 |
| 64 void ANGLEPlatformImpl::updateTraceEventDuration( | 69 void ANGLEPlatformImpl_updateTraceEventDuration( |
| 70 angle::PlatformMethods* platform, |
| 65 const unsigned char* category_group_enabled, | 71 const unsigned char* category_group_enabled, |
| 66 const char* name, | 72 const char* name, |
| 67 TraceEventHandle handle) { | 73 angle::TraceEventHandle handle) { |
| 68 base::trace_event::TraceEventHandle trace_event_handle; | 74 base::trace_event::TraceEventHandle trace_event_handle; |
| 69 memcpy(&trace_event_handle, &handle, sizeof(handle)); | 75 memcpy(&trace_event_handle, &handle, sizeof(handle)); |
| 70 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled, name, | 76 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled, name, |
| 71 trace_event_handle); | 77 trace_event_handle); |
| 72 } | 78 } |
| 73 | 79 |
| 74 void ANGLEPlatformImpl::histogramCustomCounts(const char* name, | 80 void ANGLEPlatformImpl_histogramCustomCounts(angle::PlatformMethods* platform, |
| 75 int sample, | 81 const char* name, |
| 76 int min, | 82 int sample, |
| 77 int max, | 83 int min, |
| 78 int bucket_count) { | 84 int max, |
| 85 int bucket_count) { |
| 79 // Copied from histogram macro, but without the static variable caching | 86 // Copied from histogram macro, but without the static variable caching |
| 80 // the histogram because name is dynamic. | 87 // the histogram because name is dynamic. |
| 81 base::HistogramBase* counter = base::Histogram::FactoryGet( | 88 base::HistogramBase* counter = base::Histogram::FactoryGet( |
| 82 name, min, max, bucket_count, | 89 name, min, max, bucket_count, |
| 83 base::HistogramBase::kUmaTargetedHistogramFlag); | 90 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 84 DCHECK_EQ(name, counter->histogram_name()); | 91 DCHECK_EQ(name, counter->histogram_name()); |
| 85 counter->Add(sample); | 92 counter->Add(sample); |
| 86 } | 93 } |
| 87 | 94 |
| 88 void ANGLEPlatformImpl::histogramEnumeration(const char* name, | 95 void ANGLEPlatformImpl_histogramEnumeration(angle::PlatformMethods* platform, |
| 89 int sample, | 96 const char* name, |
| 90 int boundary_value) { | 97 int sample, |
| 98 int boundary_value) { |
| 91 // Copied from histogram macro, but without the static variable caching | 99 // Copied from histogram macro, but without the static variable caching |
| 92 // the histogram because name is dynamic. | 100 // the histogram because name is dynamic. |
| 93 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( | 101 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
| 94 name, 1, boundary_value, boundary_value + 1, | 102 name, 1, boundary_value, boundary_value + 1, |
| 95 base::HistogramBase::kUmaTargetedHistogramFlag); | 103 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 96 DCHECK_EQ(name, counter->histogram_name()); | 104 DCHECK_EQ(name, counter->histogram_name()); |
| 97 counter->Add(sample); | 105 counter->Add(sample); |
| 98 } | 106 } |
| 99 | 107 |
| 100 void ANGLEPlatformImpl::histogramSparse(const char* name, int sample) { | 108 void ANGLEPlatformImpl_histogramSparse(angle::PlatformMethods* platform, |
| 109 const char* name, |
| 110 int sample) { |
| 101 // For sparse histograms, we can use the macro, as it does not incorporate a | 111 // For sparse histograms, we can use the macro, as it does not incorporate a |
| 102 // static. | 112 // static. |
| 103 UMA_HISTOGRAM_SPARSE_SLOWLY(name, sample); | 113 UMA_HISTOGRAM_SPARSE_SLOWLY(name, sample); |
| 104 } | 114 } |
| 105 | 115 |
| 106 void ANGLEPlatformImpl::histogramBoolean(const char* name, bool sample) { | 116 void ANGLEPlatformImpl_histogramBoolean(angle::PlatformMethods* platform, |
| 107 histogramEnumeration(name, sample ? 1 : 0, 2); | 117 const char* name, |
| 118 bool sample) { |
| 119 ANGLEPlatformImpl_histogramEnumeration(platform, name, sample ? 1 : 0, 2); |
| 120 } |
| 121 |
| 122 } // anonymous namespace |
| 123 |
| 124 bool InitializeANGLEPlatform(EGLDisplay display) { |
| 125 angle::GetDisplayPlatformFunc angle_get_platform = |
| 126 reinterpret_cast<angle::GetDisplayPlatformFunc>( |
| 127 eglGetProcAddress("ANGLEGetDisplayPlatform")); |
| 128 if (!angle_get_platform) |
| 129 return false; |
| 130 |
| 131 // Save the pointer to the destroy function here to avoid crash. |
| 132 g_angle_reset_platform = reinterpret_cast<angle::ResetDisplayPlatformFunc>( |
| 133 eglGetProcAddress("ANGLEResetDisplayPlatform")); |
| 134 |
| 135 angle::PlatformMethods* platformMethods = nullptr; |
| 136 if (!angle_get_platform(static_cast<angle::EGLDisplayType>(display), |
| 137 angle::g_PlatformMethodNames, |
| 138 angle::g_NumPlatformMethods, nullptr, |
| 139 &platformMethods)) |
| 140 return false; |
| 141 platformMethods->currentTime = ANGLEPlatformImpl_currentTime; |
| 142 platformMethods->addTraceEvent = ANGLEPlatformImpl_addTraceEvent; |
| 143 platformMethods->currentTime = ANGLEPlatformImpl_currentTime; |
| 144 platformMethods->getTraceCategoryEnabledFlag = |
| 145 ANGLEPlatformImpl_getTraceCategoryEnabledFlag; |
| 146 platformMethods->histogramBoolean = ANGLEPlatformImpl_histogramBoolean; |
| 147 platformMethods->histogramCustomCounts = |
| 148 ANGLEPlatformImpl_histogramCustomCounts; |
| 149 platformMethods->histogramEnumeration = |
| 150 ANGLEPlatformImpl_histogramEnumeration; |
| 151 platformMethods->histogramSparse = ANGLEPlatformImpl_histogramSparse; |
| 152 platformMethods->logError = ANGLEPlatformImpl_logError; |
| 153 platformMethods->logWarning = ANGLEPlatformImpl_logWarning; |
| 154 platformMethods->monotonicallyIncreasingTime = |
| 155 ANGLEPlatformImpl_monotonicallyIncreasingTime; |
| 156 platformMethods->updateTraceEventDuration = |
| 157 ANGLEPlatformImpl_updateTraceEventDuration; |
| 158 return true; |
| 159 } |
| 160 |
| 161 void ResetANGLEPlatform(EGLDisplay display) { |
| 162 if (!g_angle_reset_platform) |
| 163 return; |
| 164 g_angle_reset_platform(static_cast<angle::EGLDisplayType>(display)); |
| 108 } | 165 } |
| 109 | 166 |
| 110 } // namespace gl | 167 } // namespace gl |
| OLD | NEW |