diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-12 20:58:58 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-12 20:58:58 +0000 |
commit | 0141ba3ca96fe156474074493b277cf2fd352cc8 (patch) | |
tree | 164445cceedac7e91d4b19a0fca8c1c757197020 /ppapi | |
parent | a8d4909721756525e14b9429db9c61a63932005d (diff) | |
download | chromium_src-0141ba3ca96fe156474074493b277cf2fd352cc8.zip chromium_src-0141ba3ca96fe156474074493b277cf2fd352cc8.tar.gz chromium_src-0141ba3ca96fe156474074493b277cf2fd352cc8.tar.bz2 |
Move the time conversion code to the PPAPI shared_impl directory and use it in
the proxy for converting event times.
This also removes the unnecessary GetInterface function from Graphics2D and
has the module use the thunk directly.
Review URL: http://codereview.chromium.org/7344009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92229 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/ppapi_shared.gypi | 2 | ||||
-rw-r--r-- | ppapi/proxy/ppb_core_proxy.cc | 11 | ||||
-rw-r--r-- | ppapi/shared_impl/time_conversion.cc | 49 | ||||
-rw-r--r-- | ppapi/shared_impl/time_conversion.h | 27 |
4 files changed, 84 insertions, 5 deletions
diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index d3cea67..b86c77e 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -47,6 +47,8 @@ 'shared_impl/ppp_instance_combined.h', 'shared_impl/resource_object_base.cc', 'shared_impl/resource_object_base.h', + 'shared_impl/time_conversion.cc', + 'shared_impl/time_conversion.h', 'shared_impl/tracker_base.cc', 'shared_impl/tracker_base.h', 'shared_impl/url_util_impl.cc', diff --git a/ppapi/proxy/ppb_core_proxy.cc b/ppapi/proxy/ppb_core_proxy.cc index a67ce1d..e3b8ab6 100644 --- a/ppapi/proxy/ppb_core_proxy.cc +++ b/ppapi/proxy/ppb_core_proxy.cc @@ -16,6 +16,10 @@ #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/time_conversion.h" + +using ppapi::TimeToPPTime; +using ppapi::TimeTicksToPPTimeTicks; namespace pp { namespace proxy { @@ -45,14 +49,11 @@ void MemFree(void* ptr) { } double GetTime() { - return base::Time::Now().ToDoubleT(); + return TimeToPPTime(base::Time::Now()); } double GetTimeTicks() { - // TODO(brettw) http://code.google.com/p/chromium/issues/detail?id=57448 - // This should be a tick timer rather than wall clock time, but needs to - // match message times, which also currently use wall clock time. - return GetTime(); + return TimeTicksToPPTimeTicks(base::TimeTicks::Now()); } void CallOnMainThread(int delay_in_ms, diff --git a/ppapi/shared_impl/time_conversion.cc b/ppapi/shared_impl/time_conversion.cc new file mode 100644 index 0000000..53d7b99 --- /dev/null +++ b/ppapi/shared_impl/time_conversion.cc @@ -0,0 +1,49 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/shared_impl/time_conversion.h" + +namespace ppapi { + +namespace { + +// Since WebKit doesn't use ticks for event times, we have to compute what +// the time ticks would be assuming the wall clock time doesn't change. +// +// This should only be used for WebKit times which we can't change the +// definition of. +double GetTimeToTimeTicksDeltaInSeconds() { + static double time_to_ticks_delta_seconds = 0.0; + if (time_to_ticks_delta_seconds == 0.0) { + double wall_clock = TimeToPPTime(base::Time::Now()); + double ticks = TimeTicksToPPTimeTicks(base::TimeTicks::Now()); + time_to_ticks_delta_seconds = ticks - wall_clock; + } + return time_to_ticks_delta_seconds; +} + +} // namespace + +PP_Time TimeToPPTime(base::Time t) { + return t.ToDoubleT(); +} + +base::Time PPTimeToTime(PP_Time t) { + return base::Time::FromDoubleT(t); +} + +PP_TimeTicks TimeTicksToPPTimeTicks(base::TimeTicks t) { + return static_cast<double>(t.ToInternalValue()) / + base::Time::kMicrosecondsPerSecond; +} + +PP_TimeTicks EventTimeToPPTimeTicks(double event_time) { + return event_time + GetTimeToTimeTicksDeltaInSeconds(); +} + +double PPTimeTicksToEventTime(PP_TimeTicks t) { + return t - GetTimeToTimeTicksDeltaInSeconds(); +} + +} // namespace ppapi diff --git a/ppapi/shared_impl/time_conversion.h b/ppapi/shared_impl/time_conversion.h new file mode 100644 index 0000000..bf41987 --- /dev/null +++ b/ppapi/shared_impl/time_conversion.h @@ -0,0 +1,27 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_SHARED_IMPL_TIME_CONVERSION_H_ +#define PPAPI_SHARED_IMPL_TIME_CONVERSION_H_ + +#include "base/time.h" +#include "ppapi/c/pp_time.h" + +namespace ppapi { + +PP_Time TimeToPPTime(base::Time t); +base::Time PPTimeToTime(PP_Time t); + +PP_TimeTicks TimeTicksToPPTimeTicks(base::TimeTicks t); + +// Converts between WebKit event times and time ticks. WebKit event times are +// currently expressed in terms of wall clock time. This function does the +// proper mapping to time ticks, assuming the wall clock time doesn't change +// (which isn't necessarily the case). +PP_TimeTicks EventTimeToPPTimeTicks(double event_time); +double PPTimeTicksToEventTime(PP_TimeTicks t); + +} // namespace ppapi + +#endif // PPAPI_SHARED_IMPL_TIME_CONVERSION_H_ |