src/power/SDL_power.c
author David Ludwig <dludwig@pobox.com>
Wed, 25 Dec 2013 21:39:48 -0500
changeset 8563 c0e68f3b6bbb
parent 7981 6d538bc1b395
child 8093 b43765095a6f
permissions -rw-r--r--
WinRT: compiled the d3d11 renderer's shaders into SDL itself

Previously, the shaders would get compiled separately, the output of which would need to be packaged into the app. This change should make SDL's dll be the only binary needed to include SDL in a WinRT app.
icculus@3170
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6885
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
icculus@3170
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
icculus@3170
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
icculus@3170
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
icculus@3170
    20
*/
icculus@3170
    21
#include "SDL_config.h"
icculus@3170
    22
#include "SDL_power.h"
icculus@3170
    23
icculus@3170
    24
/*
icculus@3170
    25
 * Returns SDL_TRUE if we have a definitive answer.
icculus@3170
    26
 * SDL_FALSE to try next implementation.
icculus@3170
    27
 */
icculus@3170
    28
typedef SDL_bool
slouken@3186
    29
    (*SDL_GetPowerInfo_Impl) (SDL_PowerState * state, int *seconds,
slouken@3186
    30
                              int *percent);
icculus@3170
    31
slouken@3186
    32
SDL_bool SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState *, int *, int *);
slouken@3186
    33
SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *, int *, int *);
slouken@3186
    34
SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState *, int *, int *);
slouken@3186
    35
SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *, int *, int *);
icculus@7981
    36
SDL_bool SDL_GetPowerInfo_Haiku(SDL_PowerState *, int *, int *);
icculus@4444
    37
SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *);
slouken@6448
    38
SDL_bool SDL_GetPowerInfo_Android(SDL_PowerState *, int *, int *);
kimonline@7009
    39
SDL_bool SDL_GetPowerInfo_PSP(SDL_PowerState *, int *, int *);
icculus@3170
    40
icculus@3170
    41
#ifndef SDL_POWER_DISABLED
icculus@3170
    42
#ifdef SDL_POWER_HARDWIRED
slouken@3272
    43
/* This is for things that _never_ have a battery */
icculus@3170
    44
static SDL_bool
slouken@3186
    45
SDL_GetPowerInfo_Hardwired(SDL_PowerState * state, int *seconds, int *percent)
icculus@3170
    46
{
icculus@3170
    47
    *seconds = -1;
icculus@3170
    48
    *percent = -1;
icculus@3170
    49
    *state = SDL_POWERSTATE_NO_BATTERY;
icculus@3170
    50
    return SDL_TRUE;
icculus@3170
    51
}
icculus@3170
    52
#endif
icculus@3170
    53
#endif
icculus@3170
    54
icculus@3170
    55
icculus@3170
    56
static SDL_GetPowerInfo_Impl implementations[] = {
icculus@3170
    57
#ifndef SDL_POWER_DISABLED
slouken@3186
    58
#ifdef SDL_POWER_LINUX          /* in order of preference. More than could work. */
bob@3174
    59
    SDL_GetPowerInfo_Linux_proc_acpi,
icculus@3170
    60
    SDL_GetPowerInfo_Linux_proc_apm,
icculus@3170
    61
#endif
slouken@3186
    62
#ifdef SDL_POWER_WINDOWS        /* handles Win32, Win64, PocketPC. */
icculus@3170
    63
    SDL_GetPowerInfo_Windows,
icculus@3170
    64
#endif
icculus@4444
    65
#ifdef SDL_POWER_UIKIT          /* handles iPhone/iPad/etc */
icculus@4444
    66
    SDL_GetPowerInfo_UIKit,
icculus@4444
    67
#endif
icculus@4444
    68
#ifdef SDL_POWER_MACOSX         /* handles Mac OS X, Darwin. */
icculus@3170
    69
    SDL_GetPowerInfo_MacOSX,
icculus@3170
    70
#endif
icculus@7981
    71
#ifdef SDL_POWER_HAIKU          /* with BeOS euc.jp apm driver. Does this work on Haiku? */
icculus@7981
    72
    SDL_GetPowerInfo_Haiku,
icculus@3173
    73
#endif
slouken@6448
    74
#ifdef SDL_POWER_ANDROID        /* handles Android. */
slouken@6448
    75
    SDL_GetPowerInfo_Android,
slouken@6448
    76
#endif
kimonline@7009
    77
#ifdef SDL_POWER_PSP        /* handles PSP. */
kimonline@7009
    78
    SDL_GetPowerInfo_PSP,
kimonline@7009
    79
#endif
kimonline@7009
    80
icculus@3170
    81
#ifdef SDL_POWER_HARDWIRED
icculus@3170
    82
    SDL_GetPowerInfo_Hardwired,
icculus@3170
    83
#endif
icculus@3170
    84
#endif
icculus@3170
    85
};
icculus@3170
    86
icculus@3170
    87
SDL_PowerState
icculus@3170
    88
SDL_GetPowerInfo(int *seconds, int *percent)
icculus@3170
    89
{
slouken@3186
    90
    const int total = sizeof(implementations) / sizeof(implementations[0]);
icculus@3170
    91
    int _seconds, _percent;
icculus@3170
    92
    SDL_PowerState retval;
icculus@3170
    93
    int i;
icculus@3170
    94
icculus@3170
    95
    /* Make these never NULL for platform-specific implementations. */
icculus@3170
    96
    if (seconds == NULL) {
icculus@3170
    97
        seconds = &_seconds;
icculus@3170
    98
    }
icculus@3170
    99
icculus@3170
   100
    if (percent == NULL) {
icculus@3170
   101
        percent = &_percent;
icculus@3170
   102
    }
icculus@3170
   103
icculus@3170
   104
    for (i = 0; i < total; i++) {
slouken@3186
   105
        if (implementations[i] (&retval, seconds, percent)) {
icculus@3170
   106
            return retval;
icculus@3170
   107
        }
icculus@3170
   108
    }
icculus@3170
   109
icculus@3170
   110
    /* nothing was definitive. */
icculus@3170
   111
    *seconds = -1;
icculus@3170
   112
    *percent = -1;
icculus@3170
   113
    return SDL_POWERSTATE_UNKNOWN;
icculus@3170
   114
}
icculus@3170
   115
icculus@3170
   116
/* vi: set ts=4 sw=4 expandtab: */