annotate src/power/SDL_power.c @ 5053:b5b42be9333c

Fixed bug #1026 Vittorio Giovara 2010-07-16 19:09:28 PDT i was reading SDL_renderer_gles and i noticed that every time we there is some gl call the gl state is modified with a couple of glEnableClientState()/glDisableClientState. While this is completely fine for desktops systems, this is a major performace kill on mobile devices, right where opengles is implemented. Normal practice in this case is to update the glstate once, keep it always the same and disable/enable other states only in very special occasions. On the web there's plenty of documentation (on the top of my head http://developer.apple.com/iphone/library/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/Performance/Performance.html#//apple_ref/doc/uid/TP40008793-CH105-SW5 ) and i personally tried this. I modified my code and got a 10 fps boost, then modified SDL_render_gles and shifted from 40 fps to 50 fps alone -- considering that i started from ~30fps i got an 80% performance increase with this technique. I have attached a dif of my changes, hope that it will be included in mainstream.
author Sam Lantinga <slouken@libsdl.org>
date Wed, 19 Jan 2011 23:56:16 -0800
parents 42e1092225f9
children b530ef003506
rev   line source
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3272
diff changeset
3 Copyright (C) 1997-2010 Sam Lantinga
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 Lesser General Public License for more details.
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 Sam Lantinga
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 slouken@libsdl.org
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 */
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 #include "SDL_config.h"
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 #include "SDL_power.h"
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 /*
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 * Returns SDL_TRUE if we have a definitive answer.
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 * SDL_FALSE to try next implementation.
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 */
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 typedef SDL_bool
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3174
diff changeset
30 (*SDL_GetPowerInfo_Impl) (SDL_PowerState * state, int *seconds,
Sam Lantinga <slouken@libsdl.org>
parents: 3174
diff changeset
31 int *percent);
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3174
diff changeset
33 SDL_bool SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState *, int *, int *);
Sam Lantinga <slouken@libsdl.org>
parents: 3174
diff changeset
34 SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *, int *, int *);
Sam Lantinga <slouken@libsdl.org>
parents: 3174
diff changeset
35 SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState *, int *, int *);
Sam Lantinga <slouken@libsdl.org>
parents: 3174
diff changeset
36 SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *, int *, int *);
Sam Lantinga <slouken@libsdl.org>
parents: 3174
diff changeset
37 SDL_bool SDL_GetPowerInfo_BeOS(SDL_PowerState *, int *, int *);
Sam Lantinga <slouken@libsdl.org>
parents: 3174
diff changeset
38 SDL_bool SDL_GetPowerInfo_NintendoDS(SDL_PowerState *, int *, int *);
4444
42e1092225f9 Implemented SDL power APIs for iPhoneOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 3697
diff changeset
39 SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *);
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 #ifndef SDL_POWER_DISABLED
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 #ifdef SDL_POWER_HARDWIRED
3272
e8f63b28947d Removed outdated Dreamcast support
Sam Lantinga <slouken@libsdl.org>
parents: 3269
diff changeset
43 /* This is for things that _never_ have a battery */
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 static SDL_bool
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3174
diff changeset
45 SDL_GetPowerInfo_Hardwired(SDL_PowerState * state, int *seconds, int *percent)
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 {
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 *seconds = -1;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 *percent = -1;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 *state = SDL_POWERSTATE_NO_BATTERY;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 return SDL_TRUE;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 #endif
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 #endif
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
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 static SDL_GetPowerInfo_Impl implementations[] = {
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 #ifndef SDL_POWER_DISABLED
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3174
diff changeset
58 #ifdef SDL_POWER_LINUX /* in order of preference. More than could work. */
3174
c8b9c6d27476 Fixed some typos and added a couple of includes. All were need to get SDL_power to compile on Linux.
Bob Pendleton <bob@pendleton.com>
parents: 3173
diff changeset
59 SDL_GetPowerInfo_Linux_proc_acpi,
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 SDL_GetPowerInfo_Linux_proc_apm,
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 #endif
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3174
diff changeset
62 #ifdef SDL_POWER_WINDOWS /* handles Win32, Win64, PocketPC. */
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 SDL_GetPowerInfo_Windows,
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 #endif
4444
42e1092225f9 Implemented SDL power APIs for iPhoneOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 3697
diff changeset
65 #ifdef SDL_POWER_UIKIT /* handles iPhone/iPad/etc */
42e1092225f9 Implemented SDL power APIs for iPhoneOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 3697
diff changeset
66 SDL_GetPowerInfo_UIKit,
42e1092225f9 Implemented SDL power APIs for iPhoneOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 3697
diff changeset
67 #endif
42e1092225f9 Implemented SDL power APIs for iPhoneOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 3697
diff changeset
68 #ifdef SDL_POWER_MACOSX /* handles Mac OS X, Darwin. */
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 SDL_GetPowerInfo_MacOSX,
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 #endif
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3174
diff changeset
71 #ifdef SDL_POWER_NINTENDODS /* handles Nintendo DS. */
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 SDL_GetPowerInfo_NintendoDS,
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 #endif
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3174
diff changeset
74 #ifdef SDL_POWER_BEOS /* handles BeOS, Zeta, with euc.jp apm driver. */
3173
510e3f36c04a BeOS support for power subsystem.
Ryan C. Gordon <icculus@icculus.org>
parents: 3170
diff changeset
75 SDL_GetPowerInfo_BeOS,
510e3f36c04a BeOS support for power subsystem.
Ryan C. Gordon <icculus@icculus.org>
parents: 3170
diff changeset
76 #endif
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 #ifdef SDL_POWER_HARDWIRED
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 SDL_GetPowerInfo_Hardwired,
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 #endif
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 #endif
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 };
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 SDL_PowerState
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 SDL_GetPowerInfo(int *seconds, int *percent)
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 {
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3174
diff changeset
86 const int total = sizeof(implementations) / sizeof(implementations[0]);
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 int _seconds, _percent;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 SDL_PowerState retval;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89 int i;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 /* Make these never NULL for platform-specific implementations. */
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 if (seconds == NULL) {
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 seconds = &_seconds;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 if (percent == NULL) {
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 percent = &_percent;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 for (i = 0; i < total; i++) {
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3174
diff changeset
101 if (implementations[i] (&retval, seconds, percent)) {
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102 return retval;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 /* nothing was definitive. */
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 *seconds = -1;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108 *percent = -1;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 return SDL_POWERSTATE_UNKNOWN;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 /* vi: set ts=4 sw=4 expandtab: */