gfx/skia/trunk/src/animator/SkTime.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/animator/SkTime.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,70 @@
     1.4 +/*
     1.5 + * Copyright 2006 The Android Open Source Project
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#include "SkTime.h"
    1.12 +
    1.13 +#ifdef SK_BUILD_FOR_WIN
    1.14 +
    1.15 +#ifdef SK_DEBUG
    1.16 +SkMSec gForceTickCount = (SkMSec) -1;
    1.17 +#endif
    1.18 +
    1.19 +void SkTime::GetDateTime(DateTime* t) {
    1.20 +    if (t) {
    1.21 +        SYSTEMTIME  syst;
    1.22 +
    1.23 +        ::GetLocalTime(&syst);
    1.24 +        t->fYear        = SkToU16(syst.wYear);
    1.25 +        t->fMonth       = SkToU8(syst.wMonth);
    1.26 +        t->fDayOfWeek   = SkToU8(syst.wDayOfWeek);
    1.27 +        t->fDay         = SkToU8(syst.wDay);
    1.28 +        t->fHour        = SkToU8(syst.wHour);
    1.29 +        t->fMinute      = SkToU8(syst.wMinute);
    1.30 +        t->fSecond      = SkToU8(syst.wSecond);
    1.31 +    }
    1.32 +}
    1.33 +
    1.34 +SkMSec SkTime::GetMSecs() {
    1.35 +#ifdef SK_DEBUG
    1.36 +    if (gForceTickCount != (SkMSec) -1) {
    1.37 +        return gForceTickCount;
    1.38 +    }
    1.39 +#endif
    1.40 +    return ::GetTickCount();
    1.41 +}
    1.42 +
    1.43 +#elif defined(xSK_BUILD_FOR_MAC)
    1.44 +
    1.45 +#include <time.h>
    1.46 +
    1.47 +void SkTime::GetDateTime(DateTime* t) {
    1.48 +    if (t) {
    1.49 +        tm      syst;
    1.50 +        time_t  tm;
    1.51 +
    1.52 +        time(&tm);
    1.53 +        localtime_r(&tm, &syst);
    1.54 +        t->fYear        = SkToU16(syst.tm_year);
    1.55 +        t->fMonth       = SkToU8(syst.tm_mon + 1);
    1.56 +        t->fDayOfWeek   = SkToU8(syst.tm_wday);
    1.57 +        t->fDay         = SkToU8(syst.tm_mday);
    1.58 +        t->fHour        = SkToU8(syst.tm_hour);
    1.59 +        t->fMinute      = SkToU8(syst.tm_min);
    1.60 +        t->fSecond      = SkToU8(syst.tm_sec);
    1.61 +    }
    1.62 +}
    1.63 +
    1.64 +SkMSec SkTime::GetMSecs() {
    1.65 +    UnsignedWide    wide;
    1.66 +    ::Microseconds(&wide);
    1.67 +
    1.68 +    int64_t s = ((int64_t)wide.hi << 32) | wide.lo;
    1.69 +    s = (s + 500) / 1000;   // rounded divide
    1.70 +    return (SkMSec)s;
    1.71 +}
    1.72 +
    1.73 +#endif

mercurial