1044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/* 2044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * Copyright (C) 2011 The Android Open Source Project 3044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * 4044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * Licensed under the Apache License, Version 2.0 (the "License"); 5044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * you may not use this file except in compliance with the License. 6044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * You may obtain a copy of the License at 7044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * 8044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * http://www.apache.org/licenses/LICENSE-2.0 9044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * 10044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * Unless required by applicable law or agreed to in writing, software 11044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * distributed under the License is distributed on an "AS IS" BASIS, 12044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * See the License for the specific language governing permissions and 14044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * limitations under the License. 15044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */ 16044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams 17044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams/** @file rs_time.rsh 18e227f9a1a3f2475002e0ca40342ddb979ba36752Stephen Hines * \brief RenderScript time routines 19044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams * 20e227f9a1a3f2475002e0ca40342ddb979ba36752Stephen Hines * This file contains RenderScript functions relating to time and date 21d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * manipulation. 22044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams */ 23044e2ee36ffe6520570a7f0207d75a8fce8b8e91Jason Sams 24ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines#ifndef __RS_TIME_RSH__ 25ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines#define __RS_TIME_RSH__ 26ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines 27d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines/** 28d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * Calendar time interpreted as seconds elapsed since the Epoch (00:00:00 on 29d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * January 1, 1970, Coordinated Universal Time (UTC)). 30d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines */ 3164147ebf4f0b1c23d2caf2cf7c1675d27de97d99Tim Murray#ifndef __LP64__ 32ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hinestypedef int rs_time_t; 3364147ebf4f0b1c23d2caf2cf7c1675d27de97d99Tim Murray#else 3464147ebf4f0b1c23d2caf2cf7c1675d27de97d99Tim Murraytypedef long rs_time_t; 3564147ebf4f0b1c23d2caf2cf7c1675d27de97d99Tim Murray#endif 36ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines 37d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines/** 38d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * Data structure for broken-down time components. 39d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * 40d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_sec - Seconds after the minute. This ranges from 0 to 59, but possibly 41d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * up to 60 for leap seconds. 42d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_min - Minutes after the hour. This ranges from 0 to 59. 43d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_hour - Hours past midnight. This ranges from 0 to 23. 44d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_mday - Day of the month. This ranges from 1 to 31. 45d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_mon - Months since January. This ranges from 0 to 11. 46d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_year - Years since 1900. 47d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_wday - Days since Sunday. This ranges from 0 to 6. 48d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_yday - Days since January 1. This ranges from 0 to 365. 49d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * tm_isdst - Flag to indicate whether daylight saving time is in effect. The 50d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * value is positive if it is in effect, zero if it is not, and 51d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * negative if the information is not available. 52d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines */ 53ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hinestypedef struct { 54d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines int tm_sec; ///< seconds 55d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines int tm_min; ///< minutes 56d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines int tm_hour; ///< hours 57d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines int tm_mday; ///< day of the month 58d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines int tm_mon; ///< month 59d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines int tm_year; ///< year 60d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines int tm_wday; ///< day of the week 61d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines int tm_yday; ///< day of the year 62d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines int tm_isdst; ///< daylight savings time 63ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines} rs_tm; 64ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines 65d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines/** 66d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * Returns the number of seconds since the Epoch (00:00:00 UTC, January 1, 67d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * 1970). If @p timer is non-NULL, the result is also stored in the memory 68d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * pointed to by this variable. If an error occurs, a value of -1 is returned. 69d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * 70d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * @param timer Location to also store the returned calendar time. 71d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * 72d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * @return Seconds since the Epoch. 73d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines */ 74ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hinesextern rs_time_t __attribute__((overloadable)) 75ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines rsTime(rs_time_t *timer); 76ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines 77d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines/** 78d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * Converts the time specified by @p timer into broken-down time and stores it 79d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * in @p local. This function also returns a pointer to @p local. If @p local 80d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * is NULL, this function does nothing and returns NULL. 81d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * 82d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * @param local Broken-down time. 83d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * @param timer Input time as calendar time. 84d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * 85d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * @return Pointer to broken-down time (same as input @p local). 86d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines */ 87ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hinesextern rs_tm * __attribute__((overloadable)) 88ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines rsLocaltime(rs_tm *local, const rs_time_t *timer); 89ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines 90d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines/** 91d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * Returns the current system clock (uptime) in milliseconds. 92d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * 93d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * @return Uptime in milliseconds. 94d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines */ 95ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hinesextern int64_t __attribute__((overloadable)) 96ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines rsUptimeMillis(void); 97ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines 98d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines/** 99d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * Returns the current system clock (uptime) in nanoseconds. 100d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * 101d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * @return Uptime in nanoseconds. 102d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines */ 103ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hinesextern int64_t __attribute__((overloadable)) 104ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines rsUptimeNanos(void); 105ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines 106d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines/** 107d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * Returns the time in seconds since this function was last called in this 108d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * script. 109d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * 110d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines * @return Time in seconds. 111d5dccb8c49d8da069f2630c4ac9c0e2d14958a88Stephen Hines */ 112ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hinesextern float __attribute__((overloadable)) 113ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines rsGetDt(void); 114ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines 115ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines#endif 116