annotate test/testpower.c @ 5172:ededa1ccf91c

Switched the SDL 1.2 compatibility to use the window surface, so it's fast even when there's no hardware acceleration available. This means that the YUV overlay now uses software, but that's okay since fast YUV code should be using the textures now anyway.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 03 Feb 2011 21:13:55 -0800
parents 51750b7a966f
children
rev   line source
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /* Simple test of power subsystem. */
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 #include <stdio.h>
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 #include "SDL.h"
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
6 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
7 report_power(void)
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 {
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 int seconds, percent;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 char *statestr = NULL;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 printf("SDL-reported power info...\n");
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
14 switch (state) {
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
15 case SDL_POWERSTATE_UNKNOWN:
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
16 statestr = "Unknown";
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
17 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
18 case SDL_POWERSTATE_ON_BATTERY:
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
19 statestr = "On battery";
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
20 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
21 case SDL_POWERSTATE_NO_BATTERY:
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
22 statestr = "No battery";
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
23 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
24 case SDL_POWERSTATE_CHARGING:
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
25 statestr = "Charging";
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
26 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
27 case SDL_POWERSTATE_CHARGED:
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
28 statestr = "Charged";
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
29 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
30 default:
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
31 statestr = "!!API ERROR!!";
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
32 break;
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 printf("State: %s\n", statestr);
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 if (percent == -1) {
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 printf("Percent left: unknown\n");
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 } else {
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 printf("Percent left: %d%%\n", percent);
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 if (seconds == -1) {
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 printf("Time left: unknown\n");
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 } else {
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
46 printf("Time left: %d minutes, %d seconds\n", (int) (seconds / 60),
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
47 (int) (seconds % 60));
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
52 int
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
53 main(int argc, char *argv[])
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 {
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 if (SDL_Init(SDL_INIT_VIDEO) == -1) {
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 return 1;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 report_power();
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 SDL_Quit();
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 return 0;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 /* end of testpower.c ... */