Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
d03a7700
Commit
d03a7700
authored
Jun 10, 2009
by
Sam Lantinga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
indent
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403645
parent
e74bc6f8
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
617 additions
and
705 deletions
+617
-705
SDL_atomic.h
include/SDL_atomic.h
+303
-393
SDL_mouse.c
src/events/SDL_mouse.c
+1
-0
SDL_power.c
src/power/SDL_power.c
+20
-20
SDL_syspower.c
src/power/beos/SDL_syspower.c
+14
-15
SDL_syspower.c
src/power/linux/SDL_syspower.c
+30
-31
SDL_syspower.c
src/power/macosx/SDL_syspower.c
+13
-13
SDL_syspower.c
src/power/nds/SDL_syspower.c
+3
-3
SDL_syspower.c
src/power/os2/SDL_syspower.c
+18
-18
SDL_syspower.c
src/power/windows/SDL_syspower.c
+10
-11
SDL_video.c
src/video/SDL_video.c
+52
-56
SDL_photon.c
src/video/photon/SDL_photon.c
+11
-11
SDL_qnxgf.c
src/video/qnxgf/SDL_qnxgf.c
+6
-6
SDL_win32modes.c
src/video/win32/SDL_win32modes.c
+4
-4
SDL_x11events.c
src/video/x11/SDL_x11events.c
+2
-0
common.c
test/common.c
+48
-45
testatomic.c
test/testatomic.c
+53
-53
testpower.c
test/testpower.c
+25
-24
testsprite2.c
test/testsprite2.c
+4
-2
No files found.
include/SDL_atomic.h
View file @
d03a7700
...
@@ -44,58 +44,44 @@ extern "C" {
...
@@ -44,58 +44,44 @@ extern "C" {
#if defined(__GNUC__) && (defined(i386) || defined(__i386__) || defined(__x86_64__))
#if defined(__GNUC__) && (defined(i386) || defined(__i386__) || defined(__x86_64__))
static
__inline__
void
static
__inline__
void
SDL_atomic_int_add
(
volatile
int
*
atomic
,
int
value
)
SDL_atomic_int_add
(
volatile
int
*
atomic
,
int
value
)
{
{
__asm__
__volatile__
(
"lock;"
__asm__
__volatile__
(
"lock;"
"addl %1, %0"
:
"=m"
(
*
atomic
)
"addl %1, %0"
:
"ir"
(
value
),
"m"
(
*
atomic
));
:
"=m"
(
*
atomic
)
:
"ir"
(
value
),
"m"
(
*
atomic
));
}
}
static
__inline__
int
static
__inline__
int
SDL_atomic_int_xchg_add
(
volatile
int
*
atomic
,
int
value
)
SDL_atomic_int_xchg_add
(
volatile
int
*
atomic
,
int
value
)
{
{
int
rv
;
int
rv
;
__asm__
__volatile__
(
"lock;"
__asm__
__volatile__
(
"lock;"
"xaddl %0, %1"
:
"=r"
(
rv
),
"=m"
(
*
atomic
)
"xaddl %0, %1"
:
"0"
(
value
),
"m"
(
*
atomic
));
:
"=r"
(
rv
),
return
rv
;
"=m"
(
*
atomic
)
:
"0"
(
value
),
"m"
(
*
atomic
));
return
rv
;
}
}
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
SDL_atomic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
{
{
int
rv
;
int
rv
;
__asm__
__volatile__
(
"lock;"
__asm__
__volatile__
(
"lock;"
"cmpxchgl %2, %1"
:
"=a"
(
rv
),
"=m"
(
*
atomic
)
"cmpxchgl %2, %1"
:
"r"
(
newvalue
),
"m"
(
*
atomic
),
"0"
(
oldvalue
));
:
"=a"
(
rv
),
return
(
SDL_bool
)
(
rv
==
oldvalue
);
"=m"
(
*
atomic
)
:
"r"
(
newvalue
),
"m"
(
*
atomic
),
"0"
(
oldvalue
));
return
(
SDL_bool
)(
rv
==
oldvalue
);
}
}
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
void
*
newvalue
)
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
void
*
newvalue
)
{
{
void
*
rv
;
void
*
rv
;
__asm__
__volatile__
(
"lock;"
__asm__
__volatile__
(
"lock;"
# if defined(__x86_64__)
# if defined(__x86_64__)
"cmpxchgq %q2, %1"
"cmpxchgq %q2, %1"
# else
# else
"cmpxchgl %2, %1"
"cmpxchgl %2, %1"
# endif
# endif
:
"=a"
(
rv
),
:
"=a"
(
rv
),
"=m"
(
*
atomic
)
"=m"
(
*
atomic
)
:
"r"
(
newvalue
),
"m"
(
*
atomic
),
"0"
(
oldvalue
));
:
"r"
(
newvalue
),
return
(
SDL_bool
)
(
rv
==
oldvalue
);
"m"
(
*
atomic
),
"0"
(
oldvalue
));
return
(
SDL_bool
)(
rv
==
oldvalue
);
}
}
#elif defined(__GNUC__) && defined(__alpha__)
#elif defined(__GNUC__) && defined(__alpha__)
# define ATOMIC_MEMORY_BARRIER (__asm__ __volatile__ ("mb" : : : "memory"))
# define ATOMIC_MEMORY_BARRIER (__asm__ __volatile__ ("mb" : : : "memory"))
...
@@ -122,53 +108,45 @@ SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
...
@@ -122,53 +108,45 @@ SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
# if (SIZEOF_VOIDP == 4)
# if (SIZEOF_VOIDP == 4)
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
void
*
newvalue
)
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
{
void
*
newvalue
)
int
rv
;
{
void
*
prev
;
int
rv
;
__asm__
__volatile__
(
" mb
\n
"
void
*
prev
;
"1: ldl_l %0,%2
\n
"
__asm__
__volatile__
(
" mb
\n
"
" cmpeq %0,%3,%1
\n
"
"1: ldl_l %0,%2
\n
"
" beq $1,2f
\n
"
" cmpeq %0,%3,%1
\n
"
" mov %4,%1
\n
"
" beq $1,2f
\n
"
" stl_c %1,%2
\n
"
" mov %4,%1
\n
"
" beq %1,1b
\n
"
" stl_c %1,%2
\n
"
" mb
\n
"
" beq %1,1b
\n
"
"2:"
" mb
\n
"
"2:"
:
"=&r"
(
prev
),
"=&r"
(
rv
)
:
"=&r"
(
prev
),
:
"m"
(
*
atomic
),
"Ir"
(
oldvalue
),
"Ir"
(
newvalue
)
"=&r"
(
rv
)
:
"memory"
);
:
"m"
(
*
atomic
),
return
(
SDL_bool
)
(
rv
!=
0
);
"Ir"
(
oldvalue
),
"Ir"
(
newvalue
)
:
"memory"
);
return
(
SDL_bool
)(
rv
!=
0
);
}
}
# elif (SIZEOF_VOIDP == 8)
# elif (SIZEOF_VOIDP == 8)
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
void
*
newvalue
)
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
{
void
*
newvalue
)
int
rv
;
{
void
*
prev
;
int
rv
;
__asm__
__volatile__
(
" mb
\n
"
void
*
prev
;
"1: ldq_l %0,%2
\n
"
__asm__
__volatile__
(
" mb
\n
"
" cmpeq %0,%3,%1
\n
"
"1: ldq_l %0,%2
\n
"
" beq %1,2f
\n
"
" cmpeq %0,%3,%1
\n
"
" mov %4,%1
\n
"
" beq %1,2f
\n
"
" stq_c %1,%2
\n
"
" mov %4,%1
\n
"
" beq %1,1b
\n
"
" stq_c %1,%2
\n
"
" mb
\n
"
" beq %1,1b
\n
"
"2:"
" mb
\n
"
"2:"
:
"=&r"
(
prev
),
"=&r"
(
rv
)
:
"=&r"
(
prev
),
:
"m"
(
*
atomic
),
"Ir"
(
oldvalue
),
"Ir"
(
newvalue
)
"=&r"
(
rv
)
:
"memory"
);
:
"m"
(
*
atomic
),
return
(
SDL_bool
)
(
rv
!=
0
);
"Ir"
(
oldvalue
),
"Ir"
(
newvalue
)
:
"memory"
);
return
(
SDL_bool
)(
rv
!=
0
);
}
}
# else
# else
# error "Your system has an unsupported pointer size"
# error "Your system has an unsupported pointer size"
# endif
/* SIZEOF_VOIDP */
# endif
/* SIZEOF_VOIDP */
#elif defined(__GNUC__) && defined(__sparc__)
#elif defined(__GNUC__) && defined(__sparc__)
# define ATOMIC_MEMORY_BARRIER \
# define ATOMIC_MEMORY_BARRIER \
(__asm__ __volatile__("membar #LoadLoad | #LoadStore" \
(__asm__ __volatile__("membar #LoadLoad | #LoadStore" \
...
@@ -185,32 +163,25 @@ SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
...
@@ -185,32 +163,25 @@ SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
# if (SIZEOF_VOIDP == 4)
# if (SIZEOF_VOIDP == 4)
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
void
*
newvalue
)
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
{
void
*
newvalue
)
void
*
rv
;
{
__asm__
__volatile__
(
"cas [%4], %2, %0"
void
*
rv
;
:
"=r"
(
rv
),
__asm__
__volatile__
(
"cas [%4], %2, %0"
:
"=r"
(
rv
),
"=m"
(
*
atomic
)
"=m"
(
*
atomic
)
:
"r"
(
oldvalue
),
:
"r"
(
oldvalue
),
"m"
(
*
atomic
),
"r"
(
atomic
),
"0"
(
newvalue
));
"m"
(
*
atomic
),
return
(
SDL_bool
)
(
rv
==
oldvalue
);
"r"
(
atomic
),
"0"
(
newvalue
));
return
(
SDL_bool
)(
rv
==
oldvalue
);
}
}
# elif (SIZEOF_VOIDP == 8)
# elif (SIZEOF_VOIDP == 8)
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
void
*
newvalue
)
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
{
void
*
newvalue
)
void
*
rv
;
{
void
**
a
=
atomic
;
void
*
rv
;
__asm__
__volatile__
(
"casx [%4], %2, %0"
void
**
a
=
atomic
;
:
"=r"
(
rv
),
__asm__
__volatile__
(
"casx [%4], %2, %0"
:
"=r"
(
rv
),
"=m"
(
*
a
)
"=m"
(
*
a
)
:
"r"
(
oldvalue
),
"m"
(
*
a
),
"r"
(
a
),
"0"
(
newvalue
));
:
"r"
(
oldvalue
),
return
(
SDL_bool
)
(
rv
==
oldvalue
);
"m"
(
*
a
),
"r"
(
a
),
"0"
(
newvalue
));
return
(
SDL_bool
)(
rv
==
oldvalue
);
}
}
# else
# else
# error "Your system has an unsupported pointer size"
# error "Your system has an unsupported pointer size"
...
@@ -219,122 +190,90 @@ SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
...
@@ -219,122 +190,90 @@ SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
# define ATOMIC_MEMORY_BARRIER \
# define ATOMIC_MEMORY_BARRIER \
(__asm__ __volatile__ ("sync" : : : "memory"))
(__asm__ __volatile__ ("sync" : : : "memory"))
static
__inline__
void
static
__inline__
void
SDL_atomic_int_add
(
volatile
int
*
atomic
,
int
value
)
SDL_atomic_int_add
(
volatile
int
*
atomic
,
int
value
)
{
{
int
rv
,
tmp
;
int
rv
,
tmp
;
__asm__
__volatile__
(
"1: lwarx %0, 0, %3
\n
"
__asm__
__volatile__
(
"1: lwarx %0, 0, %3
\n
"
" add %1, %0, %4
\n
"
" add %1, %0, %4
\n
"
" stwcx. %1, 0, %3
\n
"
" stwcx. %1, 0, %3
\n
"
" bne- 1b"
" bne- 1b"
:
"=&b"
(
rv
),
"=&r"
(
tmp
),
"=m"
(
*
atomic
)
:
"=&b"
(
rv
),
:
"b"
(
atomic
),
"r"
(
value
),
"m"
(
*
atomic
)
"=&r"
(
tmp
),
:
"cr0"
,
"memory"
);
"=m"
(
*
atomic
)
:
"b"
(
atomic
),
"r"
(
value
),
"m"
(
*
atomic
)
:
"cr0"
,
"memory"
);
}
}
static
__inline__
int
static
__inline__
int
SDL_atomic_int_xchg_add
(
volatile
int
*
atomic
,
int
value
)
SDL_atomic_int_xchg_add
(
volatile
int
*
atomic
,
int
value
)
{
{
int
rv
,
tmp
;
int
rv
,
tmp
;
__asm__
__volatile__
(
"1: lwarx %0, 0, %3
\n
"
__asm__
__volatile__
(
"1: lwarx %0, 0, %3
\n
"
" add %1, %0, %4
\n
"
" add %1, %0, %4
\n
"
" stwcx. %1, 0, %3
\n
"
" stwcx. %1, 0, %3
\n
"
" bne- 1b"
" bne- 1b"
:
"=&b"
(
rv
),
"=&r"
(
tmp
),
"=m"
(
*
atomic
)
:
"=&b"
(
rv
),
:
"b"
(
atomic
),
"r"
(
value
),
"m"
(
*
atomic
)
"=&r"
(
tmp
),
:
"cr0"
,
"memory"
);
"=m"
(
*
atomic
)
return
rv
;
:
"b"
(
atomic
),
"r"
(
value
),
"m"
(
*
atomic
)
:
"cr0"
,
"memory"
);
return
rv
;
}
}
# if (SIZEOF_VOIDP == 4)
# if (SIZEOF_VOIDP == 4)
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
SDL_atomic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
{
{
int
rv
;
int
rv
;
__asm__
__volatile__
(
" sync
\n
"
__asm__
__volatile__
(
" sync
\n
"
"1: lwarx %0, 0, %1
\n
"
"1: lwarx %0, 0, %1
\n
"
" subf. %0, %2, %0
\n
"
" subf. %0, %2, %0
\n
"
" bne 2f
\n
"
" bne 2f
\n
"
" stwcx. %3, 0, %1
\n
"
" stwcx. %3, 0, %1
\n
"
" bne- 1b
\n
"
" bne- 1b
\n
"
"2: isync"
:
"=&r"
(
rv
)
"2: isync"
:
"b"
(
atomic
),
"r"
(
oldvalue
),
"r"
:
"cr0"
,
"memory"
);
:
"=&r"
(
rv
)
return
(
SDL_bool
)
(
rv
==
0
);
:
"b"
(
atomic
),
"r"
(
oldvalue
),
"r"
:
"cr0"
,
"memory"
);
return
(
SDL_bool
)(
rv
==
0
);
}
}
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
void
*
newvalue
)
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
{
void
*
newvalue
)
void
*
rv
;
{
__asm__
__volatile__
(
"sync
\n
"
void
*
rv
;
"1: lwarx %0, 0, %1
\n
"
__asm__
__volatile__
(
"sync
\n
"
" subf. %0, %2, %0
\n
"
"1: lwarx %0, 0, %1
\n
"
" bne 2f
\n
"
" subf. %0, %2, %0
\n
"
" stwcx. %3, 0, %1
\n
"
" bne 2f
\n
"
" bne- 1b
\n
"
" stwcx. %3, 0, %1
\n
"
"2: isync"
" bne- 1b
\n
"
"2: isync"
:
"=&r"
(
rv
)
:
"=&r"
(
rv
)
:
"b"
(
atomic
),
"r"
(
oldvalue
),
"r"
(
newvalue
)
:
"b"
(
atomic
),
:
"cr0"
,
"memory"
);
"r"
(
oldvalue
),
return
(
SDL_bool
)
(
rv
==
0
);
"r"
(
newvalue
)
:
"cr0"
,
"memory"
);
return
(
SDL_bool
)(
rv
==
0
);
}
}
# elif (SIZEOF_VOIDP == 8)
# elif (SIZEOF_VOIDP == 8)
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
SDL_atomic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
{
{
int
rv
;
int
rv
;
__asm__
__volatile__
(
" sync
\n
"
__asm__
__volatile__
(
" sync
\n
"
"1: lwarx %0, 0, %1
\n
"
"1: lwarx %0, 0, %1
\n
"
" extsw %0, %0
\n
"
" extsw %0, %0
\n
"
" subf. %0, %2, %0
\n
"
" subf. %0, %2, %0
\n
"
" bne 2f
\n
"
" bne 2f
\n
"
" stwcx. %3, 0, %1
\n
"
" stwcx. %3, 0, %1
\n
"
" bne- 1b
\n
"
" bne- 1b
\n
"
"2: isync"
:
"=&r"
(
rv
)
"2: isync"
:
"b"
(
atomic
),
"r"
(
oldvalue
),
"r"
:
"cr0"
,
"memory"
);
:
"=&r"
(
rv
)
return
(
SDL_bool
)
(
rv
==
0
);
:
"b"
(
atomic
),
"r"
(
oldvalue
),
"r"
:
"cr0"
,
"memory"
);
return
(
SDL_bool
)(
rv
==
0
);
}
}
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
void
*
newvalue
)
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
{
void
*
newvalue
)
void
*
rv
;
{
__asm__
__volatile__
(
"sync
\n
"
void
*
rv
;
"1: ldarx %0, 0, %1
\n
"
__asm__
__volatile__
(
"sync
\n
"
" subf. %0, %2, %0
\n
"
"1: ldarx %0, 0, %1
\n
"
" bne 2f
\n
"
" subf. %0, %2, %0
\n
"
" stdcx. %3, 0, %1
\n
"
" bne 2f
\n
"
" bne- 1b
\n
"
" stdcx. %3, 0, %1
\n
"
"2: isync"
" bne- 1b
\n
"
"2: isync"
:
"=&r"
(
rv
)
:
"=&r"
(
rv
)
:
"b"
(
atomic
),
"r"
(
oldvalue
),
"r"
(
newvalue
)
:
"b"
(
atomic
),
:
"cr0"
,
"memory"
);
"r"
(
oldvalue
),
return
(
SDL_bool
)
(
rv
==
0
);
"r"
(
newvalue
)
:
"cr0"
,
"memory"
);
return
(
SDL_bool
)(
rv
==
0
);
}
}
# else
# else
# error "Your system has an unsupported pointer size"
# error "Your system has an unsupported pointer size"
...
@@ -351,161 +290,130 @@ SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
...
@@ -351,161 +290,130 @@ SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
(__sync_bool_compare_and_swap((long*)(atomic),(long)(oldvalue),(long)(newvalue)))
(__sync_bool_compare_and_swap((long*)(atomic),(long)(oldvalue),(long)(newvalue)))
#elif defined(__GNUC__) && defined(__LINUX__) && (defined(__mips__) || defined(__MIPS__))
#elif defined(__GNUC__) && defined(__LINUX__) && (defined(__mips__) || defined(__MIPS__))
static
__inline__
int
static
__inline__
int
SDL_atomic_int_xchg_add
(
volatile
int
*
atomic
,
int
value
)
SDL_atomic_int_xchg_add
(
volatile
int
*
atomic
,
int
value
)
{
{
int
rv
,
tmp
;
int
rv
,
tmp
;
__asm__
__volatile__
(
"1:
\n
"
__asm__
__volatile__
(
"1:
\n
"
".set push
\n
"
".set push
\n
"
".set mips2
\n
"
".set mips2
\n
"
"ll %0,%3
\n
"
"ll %0,%3
\n
"
"addu %1,%4,%0
\n
"
"addu %1,%4,%0
\n
"
"sc %1,%2
\n
"
"sc %1,%2
\n
"
".set pop
\n
"
".set pop
\n
"
"beqz %1,1b
\n
"
"beqz %1,1b
\n
"
:
"=&r"
(
rv
),
:
"=&r"
(
rv
),
"=&r"
(
tmp
),
"=m"
(
*
atomic
)
"=&r"
(
tmp
),
:
"m"
(
*
atomic
),
"r"
(
value
)
"=m"
(
*
atomic
)
:
"memory"
);
:
"m"
(
*
atomic
),
return
rv
;
"r"
(
value
)
:
"memory"
);
return
rv
;
}
}
static
__inline__
void
static
__inline__
void
SDL_atomic_int_add
(
volatile
int
*
atomic
,
int
value
)
SDL_atomic_int_add
(
volatile
int
*
atomic
,
int
value
)
{
{
int
rv
;
int
rv
;
__asm__
__volatile__
(
"1:
\n
"
__asm__
__volatile__
(
"1:
\n
"
".set push
\n
"
".set push
\n
"
".set mips2
\n
"
".set mips2
\n
"
"ll %0,%2
\n
"
"ll %0,%2
\n
"
"addu %0,%3,%0
\n
"
"addu %0,%3,%0
\n
"
"sc %0,%1
\n
"
"sc %0,%1
\n
"
".set pop
\n
"
".set pop
\n
"
"beqz %0,1b
\n
"
"beqz %0,1b
\n
"
:
"=&r"
(
rv
),
"=m"
(
*
atomic
)
:
"=&r"
(
rv
),
:
"m"
(
*
atomic
),
"r"
(
value
)
"=m"
(
*
atomic
)
:
"memory"
);
:
"m"
(
*
atomic
),
"r"
(
value
)
:
"memory"
);
}
}
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
SDL_atomic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
{
{
int
rv
;
int
rv
;
__asm__
__volatile__
(
" .set push
\n
"
__asm__
__volatile__
(
" .set push
\n
"
" .set noat
\n
"
" .set noat
\n
"
" .set mips3
\n
"
" .set mips3
\n
"
"1: ll %0, %2
\n
"
"1: ll %0, %2
\n
"
" bne %0, %z3, 2f
\n
"
" bne %0, %z3, 2f
\n
"
" .set mips0
\n
"
" .set mips0
\n
"
" move $1, %z4
\n
"
" move $1, %z4
\n
"
" .set mips3
\n
"
" .set mips3
\n
"
" sc $1, %1
\n
"
" sc $1, %1
\n
"
" beqz $1, 1b
\n
"
" beqz $1, 1b
\n
"
" sync
\n
"
" sync
\n
"
"2:
\n
"
"2:
\n
"
" .set pop
\n
"
" .set pop
\n
"
:
"=&r"
(
rv
),
"=R"
(
*
atomic
)
:
"=&r"
(
rv
),
:
"R"
(
*
atomic
),
"Jr"
(
oldvalue
),
"Jr"
(
newvalue
)
"=R"
(
*
atomic
)
:
"memory"
);
:
"R"
(
*
atomic
),
return
(
SDL_bool
)
rv
;
"Jr"
(
oldvalue
),
"Jr"
(
newvalue
)
:
"memory"
);
return
(
SDL_bool
)
rv
;
}
}
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
void
*
newvalue
)
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
{
void
*
newvalue
)
int
rv
;
{
__asm__
__volatile__
(
" .set push
\n
"
int
rv
;
" .set noat
\n
"
__asm__
__volatile__
(
" .set push
\n
"
" .set mips3
\n
"
" .set noat
\n
"
" .set mips3
\n
"
# if defined(__mips64)
# if defined(__mips64)
"1: lld %0, %2
\n
"
"1: lld %0, %2
\n
"
# else
# else
"1: ll %0, %2
\n
"
"1: ll %0, %2
\n
"
# endif
# endif
" bne %0, %z3, 2f
\n
"
" bne %0, %z3, 2f
\n
"
" move $1, %z4
\n
"
" move $1, %z4
\n
"
# if defined(__mips64)
# if defined(__mips64)
" sc $1, %1
\n
"
" sc $1, %1
\n
"
# else
# else
" scd $1, %1
\n
"
" scd $1, %1
\n
"
# endif
# endif
" beqz $1, 1b
\n
"
" beqz $1, 1b
\n
"
" sync
\n
"
" sync
\n
"
"2:
\n
"
"2:
\n
"
" .set pop
\n
"
" .set pop
\n
"
:
"=&r"
(
rv
),
"=R"
(
*
atomic
)
:
"=&r"
(
rv
),
:
"R"
(
*
atomic
),
"Jr"
(
oldvalue
),
"Jr"
(
newvalue
)
"=R"
(
*
atomic
)
:
"memory"
);
:
"R"
(
*
atomic
),
return
(
SDL_bool
)
rv
;
"Jr"
(
oldvalue
),
"Jr"
(
newvalue
)
:
"memory"
);
return
(
SDL_bool
)
rv
;
}
}
#elif defined(__GNUC__) && defined(__m68k__)
#elif defined(__GNUC__) && defined(__m68k__)
static
__inline__
int
static
__inline__
int
SDL_atomic_int_xchg_add
(
volatile
int
*
atomic
,
int
value
)
SDL_atomic_int_xchg_add
(
volatile
int
*
atomic
,
int
value
)
{
{
int
rv
=
*
atomic
;
int
rv
=
*
atomic
;
int
tmp
;
int
tmp
;
__asm__
__volatile__
(
"1: move%.l %0,%1
\n
"
__asm__
__volatile__
(
"1: move%.l %0,%1
\n
"
" add%.l %2,%1
\n
"
" add%.l %2,%1
\n
"
" cas%.l %0,%1,%3
\n
"
" cas%.l %0,%1,%3
\n
"
" jbne 1b
\n
"
" jbne 1b
\n
"
:
"=d"
(
rv
),
"=&d"
(
tmp
)
:
"=d"
(
rv
),
:
"d"
(
value
),
"m"
(
*
atomic
),
"0"
(
rv
)
"=&d"
(
tmp
)
:
"memory"
);
:
"d"
(
value
),
return
(
SDL_bool
)
rv
;
"m"
(
*
atomic
),
"0"
(
rv
)
:
"memory"
);
return
(
SDL_bool
)
rv
;
}
}
static
__inline__
void
static
__inline__
void
SDL_atomic_int_add
(
volatile
int
*
atomic
,
int
value
)
SDL_atomic_int_add
(
volatile
int
*
atomic
,
int
value
)
{
{
__asm__
__volatile__
(
"add%.l %0,%1"
__asm__
__volatile__
(
"add%.l %0,%1"
::
"id"
(
value
),
"m"
(
*
atomic
)
:
:
"memory"
);
:
"id"
(
value
),
"m"
(
*
atomic
)
:
"memory"
);
}
}
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
SDL_atomic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
{
{
char
rv
;
char
rv
;
int
readvalue
;
int
readvalue
;
__asm__
__volatile__
(
"cas%.l %2,%3,%1
\n
"
__asm__
__volatile__
(
"cas%.l %2,%3,%1
\n
"
"seq %0"
"seq %0"
:
"=dm"
(
rv
),
"=m"
(
*
atomic
),
"=d"
(
readvalue
)
:
"=dm"
(
rv
),
:
"d"
(
newvalue
),
"m"
(
*
atomic
),
"2"
(
oldvalue
));
"=m"
(
*
atomic
),
return
(
SDL_bool
)
rv
;
"=d"
(
readvalue
)
:
"d"
(
newvalue
),
"m"
(
*
atomic
),
"2"
(
oldvalue
));
return
(
SDL_bool
)
rv
;
}
}
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
void
*
newvalue
)
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
{
void
*
newvalue
)
char
rv
;
{
int
readvalue
;
char
rv
;
__asm__
__volatile__
(
"cas%.l %2,%3,%1
\n
"
int
readvalue
;
"seq %0"
__asm__
__volatile__
(
"cas%.l %2,%3,%1
\n
"
:
"=dm"
(
rv
),
"seq %0"
:
"=dm"
(
rv
),
"=m"
(
*
atomic
),
"=d"
(
readvalue
)
"=m"
(
*
atomic
),
:
"d"
(
newvalue
),
"m"
(
*
atomic
),
"2"
(
oldvalue
));
"=d"
(
readvalue
)
return
(
SDL_bool
)
rv
;
:
"d"
(
newvalue
),
"m"
(
*
atomic
),
"2"
(
oldvalue
));
return
(
SDL_bool
)
rv
;
}
}
#elif defined(__GNUC__) && defined(__s390__)
#elif defined(__GNUC__) && defined(__s390__)
# define ATOMIC_INT_CMP_XCHG(atomic,oldvalue,newvalue) \
# define ATOMIC_INT_CMP_XCHG(atomic,oldvalue,newvalue) \
...
@@ -521,30 +429,26 @@ SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
...
@@ -521,30 +429,26 @@ SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
})
})
# if (SIZEOF_VOIDP == 4)
# if (SIZEOF_VOIDP == 4)
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
void
*
newvalue
)
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
void
*
newvalue
)
{
{
void
*
rv
=
oldvalue
;
void
*
rv
=
oldvalue
;
__asm__
__volatile__
(
"cs %0, %2, %1"
__asm__
__volatile__
(
"cs %0, %2, %1"
:
"+d"
(
rv
),
"=Q"
(
*
atomic
)
:
"+d"
(
rv
),
:
"d"
(
newvalue
),
"m"
(
*
atomic
)
"=Q"
(
*
atomic
)
:
"cc"
);
:
"d"
(
newvalue
),
return
(
SDL_bool
)
(
rv
==
oldvalue
);
"m"
(
*
atomic
)
:
"cc"
);
return
(
SDL_bool
)(
rv
==
oldvalue
);
}
}
# elif (SIZEOF_VOIDP == 8)
# elif (SIZEOF_VOIDP == 8)
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
void
*
newvalue
)
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
{
void
*
newvalue
)
void
*
rv
=
oldvalue
;
{
void
**
a
=
atomic
;
void
*
rv
=
oldvalue
;
__asm__
__volatile__
(
"csg %0, %2, %1"
void
**
a
=
atomic
;
:
"+d"
(
rv
),
__asm__
__volatile__
(
"csg %0, %2, %1"
:
"+d"
(
rv
),
"=Q"
(
*
a
)
"=Q"
(
*
a
)
:
"d"
((
long
)
(
newvalue
)),
"m"
(
*
a
)
:
"d"
((
long
)(
newvalue
)),
:
"cc"
);
"m"
(
*
a
)
return
(
SDL_bool
)
(
rv
==
oldvalue
);
:
"cc"
);
return
(
SDL_bool
)(
rv
==
oldvalue
);
}
}
# else
# else
# error "Your system has an unsupported pointer size"
# error "Your system has an unsupported pointer size"
...
@@ -552,31 +456,34 @@ SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
...
@@ -552,31 +456,34 @@ SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
#elif defined(__WIN32__)
#elif defined(__WIN32__)
# include <windows.h>
# include <windows.h>
static
__inline__
int
static
__inline__
int
SDL_atomic_int_xchg_add
(
volatile
int
*
atomic
,
int
value
)
SDL_atomic_int_xchg_add
(
volatile
int
*
atomic
,
int
value
)
{
{
return
InterlockedExchangeAdd
(
atomic
,
value
);
return
InterlockedExchangeAdd
(
atomic
,
value
);
}
}
static
__inline__
void
static
__inline__
void
SDL_atomic_int_add
(
volatile
int
*
atomic
,
int
value
)
SDL_atomic_int_add
(
volatile
int
*
atomic
,
int
value
)
{
{
InterlockedExchangeAdd
(
atomic
,
value
);
InterlockedExchangeAdd
(
atomic
,
value
);
}
}
# if (WINVER > 0X0400)
# if (WINVER > 0X0400)
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atmoic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
SDL_atmoic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
{
{
return
(
SDL_bool
)(
InterlockedCompareExchangePointer
((
PVOID
*
)
atomic
,
return
(
SDL_bool
)
(
InterlockedCompareExchangePointer
((
PVOID
*
)
atomic
,
(
PVOID
)
newvalue
,
(
PVOID
)
newvalue
,
(
PVOID
)
oldvalue
)
==
oldvalue
);
(
PVOID
)
oldvalue
)
==
oldvalue
);
}
}
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
void
*
newvalue
)
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
void
*
newvalue
)
{
{
return
(
InterlockedCompareExchangePointer
(
atomic
,
newvalue
,
oldvalue
)
==
oldvalue
);
return
(
InterlockedCompareExchangePointer
(
atomic
,
newvalue
,
oldvalue
)
==
oldvalue
);
}
}
# else
/* WINVER <= 0x0400 */
# else
/* WINVER <= 0x0400 */
# if (SIZEOF_VOIDP != 4)
# if (SIZEOF_VOIDP != 4)
...
@@ -584,66 +491,69 @@ SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
...
@@ -584,66 +491,69 @@ SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
# endif
# endif
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
SDL_atomic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
{
{
return
(
InterlockedCompareExchange
(
atomic
,
newvalue
,
oldvalue
)
==
oldvalue
);
return
(
InterlockedCompareExchange
(
atomic
,
newvalue
,
oldvalue
)
==
oldvalue
);
}
}
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
void
*
newvalue
)
SDL_atomic_ptr_cmp_xchg
(
volatile
void
**
atomic
,
void
*
oldvalue
,
void
*
newvalue
)
{
{
return
(
InterlockedCompareExchange
(
atomic
,
newvalue
,
oldvalue
)
==
oldvalue
);
return
(
InterlockedCompareExchange
(
atomic
,
newvalue
,
oldvalue
)
==
oldvalue
);
}
}
# endif
# endif
#else
/* when all else fails */
#else
/* when all else fails */
# define SDL_ATOMIC_OPS_NOT_SUPPORTED
# define SDL_ATOMIC_OPS_NOT_SUPPORTED
# warning "Atomic Ops for this platform not supported!"
# warning "Atomic Ops for this platform not supported!"
static
__inline__
int
static
__inline__
int
SDL_atomic_int_xchg_add
(
volatile
int
*
atomic
,
int
value
)
SDL_atomic_int_xchg_add
(
volatile
int
*
atomic
,
int
value
)
{
{
int
rv
=
*
atomic
;
int
rv
=
*
atomic
;
*
(
atomic
)
+=
value
;
*
(
atomic
)
+=
value
;
return
rv
;
return
rv
;
}
}
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
SDL_atomic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
{
{
return
(
*
atomic
==
oldvalue
)
?
return
(
*
atomic
==
oldvalue
)
?
((
*
atomic
=
newvalue
),
SDL_TRUE
)
:
SDL_FALSE
;
((
*
atomic
=
newvalue
),
SDL_TRUE
)
:
SDL_FALSE
;
}
}
static
__inline__
void
static
__inline__
void
SDL_atomic_int_add
(
volatile
int
*
atomic
,
int
value
)
SDL_atomic_int_add
(
volatile
int
*
atomic
,
int
value
)
{
{
*
atomic
+=
value
;
*
atomic
+=
value
;
}
}
#endif
/* arch & platforms */
#endif
/* arch & platforms */
#ifdef ATOMIC_INT_CMP_XCHG
#ifdef ATOMIC_INT_CMP_XCHG
static
__inline__
SDL_bool
static
__inline__
SDL_bool
SDL_atomic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
SDL_atomic_int_cmp_xchg
(
volatile
int
*
atomic
,
int
oldvalue
,
int
newvalue
)
{
{
return
(
SDL_bool
)
ATOMIC_INT_CMP_XCHG
(
atomic
,
oldvalue
,
newvalue
);
return
(
SDL_bool
)
ATOMIC_INT_CMP_XCHG
(
atomic
,
oldvalue
,
newvalue
);
}
}
static
__inline__
int
static
__inline__
int
SDL_atomic_int_xchg_add
(
volatile
int
*
atomic
,
int
value
)
SDL_atomic_int_xchg_add
(
volatile
int
*
atomic
,
int
value
)
{
{
int
rv
;
int
rv
;
do
do
rv
=
*
atomic
;
rv
=
*
atomic
;
while
(
!
ATOMIC_INT_CMP_XCHG
(
atomic
,
rv
,
rv
+
value
));
while
(
!
ATOMIC_INT_CMP_XCHG
(
atomic
,
rv
,
rv
+
value
));
return
rv
;
return
rv
;
}
}
static
__inline__
void
static
__inline__
void
SDL_atomic_int_add
(
volatile
int
*
atomic
,
int
value
)
SDL_atomic_int_add
(
volatile
int
*
atomic
,
int
value
)
{
{
int
rv
;
int
rv
;
do
do
rv
=
*
atomic
;
rv
=
*
atomic
;
while
(
!
ATOMIC_INT_CMP_XCHG
(
atomic
,
rv
,
rv
+
value
));
while
(
!
ATOMIC_INT_CMP_XCHG
(
atomic
,
rv
,
rv
+
value
));
}
}
#endif
/* ATOMIC_CMP_XCHG */
#endif
/* ATOMIC_CMP_XCHG */
...
...
src/events/SDL_mouse.c
View file @
d03a7700
...
@@ -369,6 +369,7 @@ SDL_SendProximity(int id, int x, int y, int type)
...
@@ -369,6 +369,7 @@ SDL_SendProximity(int id, int x, int y, int type)
event
.
proximity
.
y
=
y
;
event
.
proximity
.
y
=
y
;
event
.
proximity
.
cursor
=
mouse
->
current_end
;
event
.
proximity
.
cursor
=
mouse
->
current_end
;
event
.
proximity
.
type
=
type
;
event
.
proximity
.
type
=
type
;
event
.
proximity
.
windowID
=
mouse
->
focus
;
posted
=
(
SDL_PushEvent
(
&
event
)
>
0
);
posted
=
(
SDL_PushEvent
(
&
event
)
>
0
);
if
(
type
==
SDL_PROXIMITYIN
)
{
if
(
type
==
SDL_PROXIMITYIN
)
{
mouse
->
proximity
=
SDL_TRUE
;
mouse
->
proximity
=
SDL_TRUE
;
...
...
src/power/SDL_power.c
View file @
d03a7700
...
@@ -27,22 +27,23 @@
...
@@ -27,22 +27,23 @@
* SDL_FALSE to try next implementation.
* SDL_FALSE to try next implementation.
*/
*/
typedef
SDL_bool
typedef
SDL_bool
(
*
SDL_GetPowerInfo_Impl
)(
SDL_PowerState
*
state
,
int
*
seconds
,
int
*
percent
);
(
*
SDL_GetPowerInfo_Impl
)
(
SDL_PowerState
*
state
,
int
*
seconds
,
int
*
percent
);
SDL_bool
SDL_GetPowerInfo_Linux_sys_power
(
SDL_PowerState
*
,
int
*
,
int
*
);
SDL_bool
SDL_GetPowerInfo_Linux_proc_acpi
(
SDL_PowerState
*
,
int
*
,
int
*
);
SDL_bool
SDL_GetPowerInfo_Linux_sys_power
(
SDL_PowerState
*
,
int
*
,
int
*
);
SDL_bool
SDL_GetPowerInfo_Linux_proc_apm
(
SDL_PowerState
*
,
int
*
,
int
*
);
SDL_bool
SDL_GetPowerInfo_Linux_proc_acpi
(
SDL_PowerState
*
,
int
*
,
int
*
);
SDL_bool
SDL_GetPowerInfo_Windows
(
SDL_PowerState
*
,
int
*
,
int
*
);
SDL_bool
SDL_GetPowerInfo_Linux_proc_apm
(
SDL_PowerState
*
,
int
*
,
int
*
);
SDL_bool
SDL_GetPowerInfo_MacOSX
(
SDL_PowerState
*
,
int
*
,
int
*
);
SDL_bool
SDL_GetPowerInfo_Windows
(
SDL_PowerState
*
,
int
*
,
int
*
);
SDL_bool
SDL_GetPowerInfo_OS2
(
SDL_PowerState
*
,
int
*
,
int
*
);
SDL_bool
SDL_GetPowerInfo_MacOSX
(
SDL_PowerState
*
,
int
*
,
int
*
);
SDL_bool
SDL_GetPowerInfo_BeOS
(
SDL_PowerState
*
,
int
*
,
int
*
);
SDL_bool
SDL_GetPowerInfo_OS2
(
SDL_PowerState
*
,
int
*
,
int
*
);
SDL_bool
SDL_GetPowerInfo_NintendoDS
(
SDL_PowerState
*
,
int
*
,
int
*
);
SDL_bool
SDL_GetPowerInfo_BeOS
(
SDL_PowerState
*
,
int
*
,
int
*
);
SDL_bool
SDL_GetPowerInfo_NintendoDS
(
SDL_PowerState
*
,
int
*
,
int
*
);
#ifndef SDL_POWER_DISABLED
#ifndef SDL_POWER_DISABLED
#ifdef SDL_POWER_HARDWIRED
#ifdef SDL_POWER_HARDWIRED
/* This is for things that _never_ have a battery, like the Dreamcast, etc. */
/* This is for things that _never_ have a battery, like the Dreamcast, etc. */
static
SDL_bool
static
SDL_bool
SDL_GetPowerInfo_Hardwired
(
SDL_PowerState
*
state
,
int
*
seconds
,
int
*
percent
)
SDL_GetPowerInfo_Hardwired
(
SDL_PowerState
*
state
,
int
*
seconds
,
int
*
percent
)
{
{
*
seconds
=
-
1
;
*
seconds
=
-
1
;
*
percent
=
-
1
;
*
percent
=
-
1
;
...
@@ -55,24 +56,24 @@ SDL_GetPowerInfo_Hardwired(SDL_PowerState *state, int *seconds, int *percent)
...
@@ -55,24 +56,24 @@ SDL_GetPowerInfo_Hardwired(SDL_PowerState *state, int *seconds, int *percent)
static
SDL_GetPowerInfo_Impl
implementations
[]
=
{
static
SDL_GetPowerInfo_Impl
implementations
[]
=
{
#ifndef SDL_POWER_DISABLED
#ifndef SDL_POWER_DISABLED
#ifdef SDL_POWER_LINUX
/* in order of preference. More than could work. */
#ifdef SDL_POWER_LINUX
/* in order of preference. More than could work. */
SDL_GetPowerInfo_Linux_sys_power
,
SDL_GetPowerInfo_Linux_sys_power
,
SDL_GetPowerInfo_Linux_proc_acpi
,
SDL_GetPowerInfo_Linux_proc_acpi
,
SDL_GetPowerInfo_Linux_proc_apm
,
SDL_GetPowerInfo_Linux_proc_apm
,
#endif
#endif
#ifdef SDL_POWER_WINDOWS
/* handles Win32, Win64, PocketPC. */
#ifdef SDL_POWER_WINDOWS
/* handles Win32, Win64, PocketPC. */
SDL_GetPowerInfo_Windows
,
SDL_GetPowerInfo_Windows
,
#endif
#endif
#ifdef SDL_POWER_MACOSX
/* handles Mac OS X, Darwin, iPhone. */
#ifdef SDL_POWER_MACOSX
/* handles Mac OS X, Darwin, iPhone. */
SDL_GetPowerInfo_MacOSX
,
SDL_GetPowerInfo_MacOSX
,
#endif
#endif
#ifdef SDL_POWER_OS2
/* handles OS/2, Warp, eComStation. */
#ifdef SDL_POWER_OS2
/* handles OS/2, Warp, eComStation. */
SDL_GetPowerInfo_OS2
,
SDL_GetPowerInfo_OS2
,
#endif
#endif
#ifdef SDL_POWER_NINTENDODS
/* handles Nintendo DS. */
#ifdef SDL_POWER_NINTENDODS
/* handles Nintendo DS. */
SDL_GetPowerInfo_NintendoDS
,
SDL_GetPowerInfo_NintendoDS
,
#endif
#endif
#ifdef SDL_POWER_BEOS
/* handles BeOS, Zeta, with euc.jp apm driver. */
#ifdef SDL_POWER_BEOS
/* handles BeOS, Zeta, with euc.jp apm driver. */
SDL_GetPowerInfo_BeOS
,
SDL_GetPowerInfo_BeOS
,
#endif
#endif
#ifdef SDL_POWER_HARDWIRED
#ifdef SDL_POWER_HARDWIRED
...
@@ -84,7 +85,7 @@ static SDL_GetPowerInfo_Impl implementations[] = {
...
@@ -84,7 +85,7 @@ static SDL_GetPowerInfo_Impl implementations[] = {
SDL_PowerState
SDL_PowerState
SDL_GetPowerInfo
(
int
*
seconds
,
int
*
percent
)
SDL_GetPowerInfo
(
int
*
seconds
,
int
*
percent
)
{
{
const
int
total
=
sizeof
(
implementations
)
/
sizeof
(
implementations
[
0
]);
const
int
total
=
sizeof
(
implementations
)
/
sizeof
(
implementations
[
0
]);
int
_seconds
,
_percent
;
int
_seconds
,
_percent
;
SDL_PowerState
retval
;
SDL_PowerState
retval
;
int
i
;
int
i
;
...
@@ -99,7 +100,7 @@ SDL_GetPowerInfo(int *seconds, int *percent)
...
@@ -99,7 +100,7 @@ SDL_GetPowerInfo(int *seconds, int *percent)
}
}
for
(
i
=
0
;
i
<
total
;
i
++
)
{
for
(
i
=
0
;
i
<
total
;
i
++
)
{
if
(
implementations
[
i
](
&
retval
,
seconds
,
percent
))
{
if
(
implementations
[
i
]
(
&
retval
,
seconds
,
percent
))
{
return
retval
;
return
retval
;
}
}
}
}
...
@@ -111,4 +112,3 @@ SDL_GetPowerInfo(int *seconds, int *percent)
...
@@ -111,4 +112,3 @@ SDL_GetPowerInfo(int *seconds, int *percent)
}
}
/* vi: set ts=4 sw=4 expandtab: */
/* vi: set ts=4 sw=4 expandtab: */
src/power/beos/SDL_syspower.c
View file @
d03a7700
...
@@ -41,7 +41,7 @@
...
@@ -41,7 +41,7 @@
#include "SDL_power.h"
#include "SDL_power.h"
SDL_bool
SDL_bool
SDL_GetPowerInfo_BeOS
(
SDL_PowerState
*
state
,
int
*
seconds
,
int
*
percent
)
SDL_GetPowerInfo_BeOS
(
SDL_PowerState
*
state
,
int
*
seconds
,
int
*
percent
)
{
{
const
int
fd
=
open
(
"/dev/misc/apm"
,
O_RDONLY
);
const
int
fd
=
open
(
"/dev/misc/apm"
,
O_RDONLY
);
SDL_bool
need_details
=
SDL_FALSE
;
SDL_bool
need_details
=
SDL_FALSE
;
...
@@ -53,10 +53,10 @@ SDL_GetPowerInfo_BeOS(SDL_PowerState *state, int *seconds, int *percent)
...
@@ -53,10 +53,10 @@ SDL_GetPowerInfo_BeOS(SDL_PowerState *state, int *seconds, int *percent)
uint32
battery_time
;
uint32
battery_time
;
if
(
fd
==
-
1
)
{
if
(
fd
==
-
1
)
{
return
SDL_FALSE
;
/* maybe some other method will work? */
return
SDL_FALSE
;
/* maybe some other method will work? */
}
}
memset
(
regs
,
'\0'
,
sizeof
(
regs
));
memset
(
regs
,
'\0'
,
sizeof
(
regs
));
regs
[
0
]
=
APM_FUNC_OFFSET
+
APM_FUNC_GET_POWER_STATUS
;
regs
[
0
]
=
APM_FUNC_OFFSET
+
APM_FUNC_GET_POWER_STATUS
;
regs
[
1
]
=
APM_DEVICE_ALL
;
regs
[
1
]
=
APM_DEVICE_ALL
;
rc
=
ioctl
(
fd
,
APM_BIOS_CALL
,
regs
);
rc
=
ioctl
(
fd
,
APM_BIOS_CALL
,
regs
);
...
@@ -73,7 +73,7 @@ SDL_GetPowerInfo_BeOS(SDL_PowerState *state, int *seconds, int *percent)
...
@@ -73,7 +73,7 @@ SDL_GetPowerInfo_BeOS(SDL_PowerState *state, int *seconds, int *percent)
battery_time
=
(
uint32
)
regs
[
3
];
battery_time
=
(
uint32
)
regs
[
3
];
/* in theory, _something_ should be set in battery_flags, right? */
/* in theory, _something_ should be set in battery_flags, right? */
if
(
battery_flags
==
0x00
)
{
/* older APM BIOS? Less fields. */
if
(
battery_flags
==
0x00
)
{
/* older APM BIOS? Less fields. */
battery_time
=
0xFFFF
;
battery_time
=
0xFFFF
;
if
(
battery_status
==
0xFF
)
{
if
(
battery_status
==
0xFF
)
{
battery_flags
=
0xFF
;
battery_flags
=
0xFF
;
...
@@ -82,23 +82,23 @@ SDL_GetPowerInfo_BeOS(SDL_PowerState *state, int *seconds, int *percent)
...
@@ -82,23 +82,23 @@ SDL_GetPowerInfo_BeOS(SDL_PowerState *state, int *seconds, int *percent)
}
}
}
}
if
(
(
battery_time
!=
0xFFFF
)
&&
(
battery_time
&
(
1
<<
15
))
)
{
if
(
(
battery_time
!=
0xFFFF
)
&&
(
battery_time
&
(
1
<<
15
))
)
{
/* time is in minutes, not seconds */
/* time is in minutes, not seconds */
battery_time
=
(
battery_time
&
0x7FFF
)
*
60
;
battery_time
=
(
battery_time
&
0x7FFF
)
*
60
;
}
}
if
(
battery_flags
==
0xFF
)
{
/* unknown state */
if
(
battery_flags
==
0xFF
)
{
/* unknown state */
*
state
=
SDL_POWERSTATE_UNKNOWN
;
*
state
=
SDL_POWERSTATE_UNKNOWN
;
}
else
if
(
battery_flags
&
(
1
<<
7
))
{
/* no battery */
}
else
if
(
battery_flags
&
(
1
<<
7
))
{
/* no battery */
*
state
=
SDL_POWERSTATE_NO_BATTERY
;
*
state
=
SDL_POWERSTATE_NO_BATTERY
;
}
else
if
(
battery_flags
&
(
1
<<
3
))
{
/* charging */
}
else
if
(
battery_flags
&
(
1
<<
3
))
{
/* charging */
*
state
=
SDL_POWERSTATE_CHARGING
;
*
state
=
SDL_POWERSTATE_CHARGING
;
need_details
=
SDL_TRUE
;
need_details
=
SDL_TRUE
;
}
else
if
(
ac_status
==
1
)
{
}
else
if
(
ac_status
==
1
)
{
*
state
=
SDL_POWERSTATE_CHARGED
;
/* on AC, not charging. */
*
state
=
SDL_POWERSTATE_CHARGED
;
/* on AC, not charging. */
need_details
=
SDL_TRUE
;
need_details
=
SDL_TRUE
;
}
else
{
}
else
{
*
state
=
SDL_POWERSTATE_ON_BATTERY
;
/* not on AC. */
*
state
=
SDL_POWERSTATE_ON_BATTERY
;
/* not on AC. */
need_details
=
SDL_TRUE
;
need_details
=
SDL_TRUE
;
}
}
...
@@ -108,19 +108,18 @@ SDL_GetPowerInfo_BeOS(SDL_PowerState *state, int *seconds, int *percent)
...
@@ -108,19 +108,18 @@ SDL_GetPowerInfo_BeOS(SDL_PowerState *state, int *seconds, int *percent)
const
int
pct
=
(
int
)
battery_life
;
const
int
pct
=
(
int
)
battery_life
;
const
int
secs
=
(
int
)
battery_time
;
const
int
secs
=
(
int
)
battery_time
;
if
(
pct
!=
255
)
{
/* 255 == unknown */
if
(
pct
!=
255
)
{
/* 255 == unknown */
*
percent
=
(
pct
>
100
)
?
100
:
pct
;
/* clamp between 0%, 100% */
*
percent
=
(
pct
>
100
)
?
100
:
pct
;
/* clamp between 0%, 100% */
}
}
if
(
secs
!=
0xFFFF
)
{
/* 0xFFFF == unknown */
if
(
secs
!=
0xFFFF
)
{
/* 0xFFFF == unknown */
*
seconds
=
secs
;
*
seconds
=
secs
;
}
}
}
}
return
SDL_TRUE
;
/* the definitive answer if APM driver replied. */
return
SDL_TRUE
;
/* the definitive answer if APM driver replied. */
}
}
#endif
/* SDL_POWER_BEOS */
#endif
/* SDL_POWER_BEOS */
#endif
/* SDL_POWER_DISABLED */
#endif
/* SDL_POWER_DISABLED */
/* vi: set ts=4 sw=4 expandtab: */
/* vi: set ts=4 sw=4 expandtab: */
src/power/linux/SDL_syspower.c
View file @
d03a7700
...
@@ -34,28 +34,28 @@
...
@@ -34,28 +34,28 @@
#include "SDL_power.h"
#include "SDL_power.h"
SDL_bool
SDL_bool
SDL_GetPowerInfo_Linux_sys_power
(
SDL_PowerState
*
state
,
SDL_GetPowerInfo_Linux_sys_power
(
SDL_PowerState
*
state
,
int
*
seconds
,
int
*
percent
)
int
*
seconds
,
int
*
percent
)
{
{
return
SDL_FALSE
;
/* !!! FIXME: write me. */
return
SDL_FALSE
;
/* !!! FIXME: write me. */
#if 0
#if 0
const int fd = open("/sys/power", O_RDONLY);
const int fd = open("/sys/power", O_RDONLY);
if (fd == -1) {
if (fd == -1) {
return SDL_FALSE; /* can't use this interface. */
return SDL_FALSE;
/* can't use this interface. */
}
}
return SDL_TRUE;
return SDL_TRUE;
#endif
#endif
}
}
SDL_bool
SDL_bool
SDL_GetPowerInfo_Linux_proc_acpi
(
SDL_PowerState
*
state
,
SDL_GetPowerInfo_Linux_proc_acpi
(
SDL_PowerState
*
state
,
int
*
seconds
,
int
*
percent
)
int
*
seconds
,
int
*
percent
)
{
{
return
SDL_FALSE
;
/* !!! FIXME: write me. */
return
SDL_FALSE
;
/* !!! FIXME: write me. */
#if 0
#if 0
const int fd = open("/proc/acpi", O_RDONLY);
const int fd = open("/proc/acpi", O_RDONLY);
if (fd == -1) {
if (fd == -1) {
return SDL_FALSE; /* can't use this interface. */
return SDL_FALSE;
/* can't use this interface. */
}
}
return SDL_TRUE;
return SDL_TRUE;
#endif
#endif
...
@@ -67,7 +67,7 @@ next_string(char **_ptr, char **_str)
...
@@ -67,7 +67,7 @@ next_string(char **_ptr, char **_str)
char
*
ptr
=
*
_ptr
;
char
*
ptr
=
*
_ptr
;
char
*
str
=
*
_str
;
char
*
str
=
*
_str
;
while
(
*
ptr
==
' '
)
{
/* skip any spaces... */
while
(
*
ptr
==
' '
)
{
/* skip any spaces... */
ptr
++
;
ptr
++
;
}
}
...
@@ -91,14 +91,14 @@ static SDL_bool
...
@@ -91,14 +91,14 @@ static SDL_bool
int_string
(
char
*
str
,
int
*
val
)
int_string
(
char
*
str
,
int
*
val
)
{
{
char
*
endptr
=
NULL
;
char
*
endptr
=
NULL
;
*
val
=
(
int
)
strtol
(
str
+
2
,
&
endptr
,
16
);
*
val
=
(
int
)
strtol
(
str
+
2
,
&
endptr
,
16
);
return
((
*
str
!=
'\0'
)
&&
(
*
endptr
==
'\0'
));
return
((
*
str
!=
'\0'
)
&&
(
*
endptr
==
'\0'
));
}
}
/* http://lxr.linux.no/linux+v2.6.29/drivers/char/apm-emulation.c */
/* http://lxr.linux.no/linux+v2.6.29/drivers/char/apm-emulation.c */
SDL_bool
SDL_bool
SDL_GetPowerInfo_Linux_proc_apm
(
SDL_PowerState
*
state
,
SDL_GetPowerInfo_Linux_proc_apm
(
SDL_PowerState
*
state
,
int
*
seconds
,
int
*
percent
)
int
*
seconds
,
int
*
percent
)
{
{
SDL_bool
need_details
=
SDL_FALSE
;
SDL_bool
need_details
=
SDL_FALSE
;
int
ac_status
=
0
;
int
ac_status
=
0
;
...
@@ -113,44 +113,44 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state,
...
@@ -113,44 +113,44 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state,
ssize_t
br
;
ssize_t
br
;
if
(
fd
==
-
1
)
{
if
(
fd
==
-
1
)
{
return
SDL_FALSE
;
/* can't use this interface. */
return
SDL_FALSE
;
/* can't use this interface. */
}
}
br
=
read
(
fd
,
buf
,
sizeof
(
buf
)
-
1
);
br
=
read
(
fd
,
buf
,
sizeof
(
buf
)
-
1
);
close
(
fd
);
close
(
fd
);
if
(
br
<
0
)
{
if
(
br
<
0
)
{
return
SDL_FALSE
;
return
SDL_FALSE
;
}
}
buf
[
br
]
=
'\0'
;
// null-terminate the string.
buf
[
br
]
=
'\0'
;
// null-terminate the string.
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* driver version */
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* driver version */
return
SDL_FALSE
;
return
SDL_FALSE
;
}
}
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* BIOS version */
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* BIOS version */
return
SDL_FALSE
;
return
SDL_FALSE
;
}
}
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* APM flags */
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* APM flags */
return
SDL_FALSE
;
return
SDL_FALSE
;
}
}
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* AC line status */
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* AC line status */
return
SDL_FALSE
;
return
SDL_FALSE
;
}
else
if
(
!
int_string
(
str
,
&
ac_status
))
{
}
else
if
(
!
int_string
(
str
,
&
ac_status
))
{
return
SDL_FALSE
;
return
SDL_FALSE
;
}
}
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* battery status */
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* battery status */
return
SDL_FALSE
;
return
SDL_FALSE
;
}
else
if
(
!
int_string
(
str
,
&
battery_status
))
{
}
else
if
(
!
int_string
(
str
,
&
battery_status
))
{
return
SDL_FALSE
;
return
SDL_FALSE
;
}
}
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* battery flag */
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* battery flag */
return
SDL_FALSE
;
return
SDL_FALSE
;
}
else
if
(
!
int_string
(
str
,
&
battery_flag
))
{
}
else
if
(
!
int_string
(
str
,
&
battery_flag
))
{
return
SDL_FALSE
;
return
SDL_FALSE
;
}
}
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* remaining battery life percent */
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* remaining battery life percent */
return
SDL_FALSE
;
return
SDL_FALSE
;
}
}
if
(
str
[
strlen
(
str
)
-
1
]
==
'%'
)
{
if
(
str
[
strlen
(
str
)
-
1
]
==
'%'
)
{
...
@@ -160,27 +160,27 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state,
...
@@ -160,27 +160,27 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state,
return
SDL_FALSE
;
return
SDL_FALSE
;
}
}
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* remaining battery life time */
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* remaining battery life time */
return
SDL_FALSE
;
return
SDL_FALSE
;
}
else
if
(
!
int_string
(
str
,
&
battery_time
))
{
}
else
if
(
!
int_string
(
str
,
&
battery_time
))
{
return
SDL_FALSE
;
return
SDL_FALSE
;
}
}
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* remaining battery life time units */
if
(
!
next_string
(
&
ptr
,
&
str
))
{
/* remaining battery life time units */
return
SDL_FALSE
;
return
SDL_FALSE
;
}
else
if
(
strcmp
(
str
,
"min"
)
==
0
)
{
}
else
if
(
strcmp
(
str
,
"min"
)
==
0
)
{
battery_time
*=
60
;
battery_time
*=
60
;
}
}
if
(
battery_flag
==
0xFF
)
{
/* unknown state */
if
(
battery_flag
==
0xFF
)
{
/* unknown state */
*
state
=
SDL_POWERSTATE_UNKNOWN
;
*
state
=
SDL_POWERSTATE_UNKNOWN
;
}
else
if
(
battery_flag
&
(
1
<<
7
))
{
/* no battery */
}
else
if
(
battery_flag
&
(
1
<<
7
))
{
/* no battery */
*
state
=
SDL_POWERSTATE_NO_BATTERY
;
*
state
=
SDL_POWERSTATE_NO_BATTERY
;
}
else
if
(
battery_flag
&
(
1
<<
3
))
{
/* charging */
}
else
if
(
battery_flag
&
(
1
<<
3
))
{
/* charging */
*
state
=
SDL_POWERSTATE_CHARGING
;
*
state
=
SDL_POWERSTATE_CHARGING
;
need_details
=
SDL_TRUE
;
need_details
=
SDL_TRUE
;
}
else
if
(
ac_status
==
1
)
{
}
else
if
(
ac_status
==
1
)
{
*
state
=
SDL_POWERSTATE_CHARGED
;
/* on AC, not charging. */
*
state
=
SDL_POWERSTATE_CHARGED
;
/* on AC, not charging. */
need_details
=
SDL_TRUE
;
need_details
=
SDL_TRUE
;
}
else
{
}
else
{
*
state
=
SDL_POWERSTATE_ON_BATTERY
;
*
state
=
SDL_POWERSTATE_ON_BATTERY
;
...
@@ -193,10 +193,10 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state,
...
@@ -193,10 +193,10 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state,
const
int
pct
=
battery_percent
;
const
int
pct
=
battery_percent
;
const
int
secs
=
battery_time
;
const
int
secs
=
battery_time
;
if
(
pct
>=
0
)
{
/* -1 == unknown */
if
(
pct
>=
0
)
{
/* -1 == unknown */
*
percent
=
(
pct
>
100
)
?
100
:
pct
;
/* clamp between 0%, 100% */
*
percent
=
(
pct
>
100
)
?
100
:
pct
;
/* clamp between 0%, 100% */
}
}
if
(
secs
>=
0
)
{
/* -1 == unknown */
if
(
secs
>=
0
)
{
/* -1 == unknown */
*
seconds
=
secs
;
*
seconds
=
secs
;
}
}
}
}
...
@@ -208,4 +208,3 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state,
...
@@ -208,4 +208,3 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state,
#endif
/* SDL_POWER_DISABLED */
#endif
/* SDL_POWER_DISABLED */
/* vi: set ts=4 sw=4 expandtab: */
/* vi: set ts=4 sw=4 expandtab: */
src/power/macosx/SDL_syspower.c
View file @
d03a7700
...
@@ -37,10 +37,10 @@
...
@@ -37,10 +37,10 @@
/* Note that AC power sources also include a laptop battery it is charging. */
/* Note that AC power sources also include a laptop battery it is charging. */
static
void
static
void
checkps
(
CFDictionaryRef
dict
,
SDL_bool
*
have_ac
,
SDL_bool
*
have_battery
,
checkps
(
CFDictionaryRef
dict
,
SDL_bool
*
have_ac
,
SDL_bool
*
have_battery
,
SDL_bool
*
charging
,
int
*
seconds
,
int
*
percent
)
SDL_bool
*
charging
,
int
*
seconds
,
int
*
percent
)
{
{
CFStringRef
strval
;
/* don't CFRelease() this. */
CFStringRef
strval
;
/* don't CFRelease() this. */
CFBooleanRef
bval
;
CFBooleanRef
bval
;
CFNumberRef
numval
;
CFNumberRef
numval
;
SDL_bool
charge
=
SDL_FALSE
;
SDL_bool
charge
=
SDL_FALSE
;
...
@@ -51,7 +51,7 @@ checkps(CFDictionaryRef dict, SDL_bool *have_ac, SDL_bool *have_battery,
...
@@ -51,7 +51,7 @@ checkps(CFDictionaryRef dict, SDL_bool *have_ac, SDL_bool *have_battery,
int
pct
=
-
1
;
int
pct
=
-
1
;
if
((
GETVAL
(
kIOPSIsPresentKey
,
&
bval
))
&&
(
bval
==
kCFBooleanFalse
))
{
if
((
GETVAL
(
kIOPSIsPresentKey
,
&
bval
))
&&
(
bval
==
kCFBooleanFalse
))
{
return
;
/* nothing to see here. */
return
;
/* nothing to see here. */
}
}
if
(
!
GETVAL
(
kIOPSPowerSourceStateKey
,
&
strval
))
{
if
(
!
GETVAL
(
kIOPSPowerSourceStateKey
,
&
strval
))
{
...
@@ -61,7 +61,7 @@ checkps(CFDictionaryRef dict, SDL_bool *have_ac, SDL_bool *have_battery,
...
@@ -61,7 +61,7 @@ checkps(CFDictionaryRef dict, SDL_bool *have_ac, SDL_bool *have_battery,
if
(
STRMATCH
(
strval
,
CFSTR
(
kIOPSACPowerValue
)))
{
if
(
STRMATCH
(
strval
,
CFSTR
(
kIOPSACPowerValue
)))
{
is_ac
=
*
have_ac
=
SDL_TRUE
;
is_ac
=
*
have_ac
=
SDL_TRUE
;
}
else
if
(
!
STRMATCH
(
strval
,
CFSTR
(
kIOPSBatteryPowerValue
)))
{
}
else
if
(
!
STRMATCH
(
strval
,
CFSTR
(
kIOPSBatteryPowerValue
)))
{
return
;
/* not a battery? */
return
;
/* not a battery? */
}
}
if
((
GETVAL
(
kIOPSIsChargingKey
,
&
bval
))
&&
(
bval
==
kCFBooleanTrue
))
{
if
((
GETVAL
(
kIOPSIsChargingKey
,
&
bval
))
&&
(
bval
==
kCFBooleanTrue
))
{
...
@@ -92,12 +92,12 @@ checkps(CFDictionaryRef dict, SDL_bool *have_ac, SDL_bool *have_battery,
...
@@ -92,12 +92,12 @@ checkps(CFDictionaryRef dict, SDL_bool *have_ac, SDL_bool *have_battery,
/* Mac OS X reports 0 minutes until empty if you're plugged in. :( */
/* Mac OS X reports 0 minutes until empty if you're plugged in. :( */
if
((
val
==
0
)
&&
(
is_ac
))
{
if
((
val
==
0
)
&&
(
is_ac
))
{
val
=
-
1
;
/* !!! FIXME: calc from timeToFull and capacity? */
val
=
-
1
;
/* !!! FIXME: calc from timeToFull and capacity? */
}
}
secs
=
(
int
)
val
;
secs
=
(
int
)
val
;
if
(
secs
>
0
)
{
if
(
secs
>
0
)
{
secs
*=
60
;
/* value is in minutes, so convert to seconds. */
secs
*=
60
;
/* value is in minutes, so convert to seconds. */
}
}
}
}
...
@@ -108,7 +108,7 @@ checkps(CFDictionaryRef dict, SDL_bool *have_ac, SDL_bool *have_battery,
...
@@ -108,7 +108,7 @@ checkps(CFDictionaryRef dict, SDL_bool *have_ac, SDL_bool *have_battery,
}
}
if
((
pct
>
0
)
&&
(
maxpct
>
0
))
{
if
((
pct
>
0
)
&&
(
maxpct
>
0
))
{
pct
=
(
int
)
((((
double
)
pct
)
/
((
double
)
maxpct
))
*
100
.
0
);
pct
=
(
int
)
((((
double
)
pct
)
/
((
double
)
maxpct
))
*
100
.
0
);
}
}
if
(
pct
>
100
)
{
if
(
pct
>
100
)
{
...
@@ -121,7 +121,7 @@ checkps(CFDictionaryRef dict, SDL_bool *have_ac, SDL_bool *have_battery,
...
@@ -121,7 +121,7 @@ checkps(CFDictionaryRef dict, SDL_bool *have_ac, SDL_bool *have_battery,
*/
*/
if
((
secs
<
0
)
&&
(
*
seconds
<
0
))
{
if
((
secs
<
0
)
&&
(
*
seconds
<
0
))
{
if
((
pct
<
0
)
&&
(
*
percent
<
0
))
{
if
((
pct
<
0
)
&&
(
*
percent
<
0
))
{
choose
=
SDL_TRUE
;
/* at least we know there's a battery. */
choose
=
SDL_TRUE
;
/* at least we know there's a battery. */
}
}
if
(
pct
>
*
percent
)
{
if
(
pct
>
*
percent
)
{
choose
=
SDL_TRUE
;
choose
=
SDL_TRUE
;
...
@@ -142,7 +142,7 @@ checkps(CFDictionaryRef dict, SDL_bool *have_ac, SDL_bool *have_battery,
...
@@ -142,7 +142,7 @@ checkps(CFDictionaryRef dict, SDL_bool *have_ac, SDL_bool *have_battery,
SDL_bool
SDL_bool
SDL_GetPowerInfo_MacOSX
(
SDL_PowerState
*
state
,
int
*
seconds
,
int
*
percent
)
SDL_GetPowerInfo_MacOSX
(
SDL_PowerState
*
state
,
int
*
seconds
,
int
*
percent
)
{
{
CFTypeRef
blob
=
IOPSCopyPowerSourcesInfo
();
CFTypeRef
blob
=
IOPSCopyPowerSourcesInfo
();
...
@@ -161,7 +161,8 @@ SDL_GetPowerInfo_MacOSX(SDL_PowerState *state, int *seconds, int *percent)
...
@@ -161,7 +161,8 @@ SDL_GetPowerInfo_MacOSX(SDL_PowerState *state, int *seconds, int *percent)
CFIndex
i
;
CFIndex
i
;
for
(
i
=
0
;
i
<
total
;
i
++
)
{
for
(
i
=
0
;
i
<
total
;
i
++
)
{
CFTypeRef
ps
=
(
CFTypeRef
)
CFArrayGetValueAtIndex
(
list
,
i
);
CFTypeRef
ps
=
(
CFTypeRef
)
CFArrayGetValueAtIndex
(
list
,
i
);
CFDictionaryRef
dict
=
IOPSGetPowerSourceDescription
(
blob
,
ps
);
CFDictionaryRef
dict
=
IOPSGetPowerSourceDescription
(
blob
,
ps
);
if
(
dict
!=
NULL
)
{
if
(
dict
!=
NULL
)
{
checkps
(
dict
,
&
have_ac
,
&
have_battery
,
&
charging
,
checkps
(
dict
,
&
have_ac
,
&
have_battery
,
&
charging
,
seconds
,
percent
);
seconds
,
percent
);
...
@@ -183,11 +184,10 @@ SDL_GetPowerInfo_MacOSX(SDL_PowerState *state, int *seconds, int *percent)
...
@@ -183,11 +184,10 @@ SDL_GetPowerInfo_MacOSX(SDL_PowerState *state, int *seconds, int *percent)
CFRelease
(
blob
);
CFRelease
(
blob
);
}
}
return
SDL_TRUE
;
/* always the definitive answer on Mac OS X. */
return
SDL_TRUE
;
/* always the definitive answer on Mac OS X. */
}
}
#endif
/* SDL_POWER_MACOSX */
#endif
/* SDL_POWER_MACOSX */
#endif
/* SDL_POWER_DISABLED */
#endif
/* SDL_POWER_DISABLED */
/* vi: set ts=4 sw=4 expandtab: */
/* vi: set ts=4 sw=4 expandtab: */
src/power/nds/SDL_syspower.c
View file @
d03a7700
...
@@ -27,7 +27,8 @@
...
@@ -27,7 +27,8 @@
#include "SDL_power.h"
#include "SDL_power.h"
SDL_bool
SDL_bool
SDL_GetPowerInfo_NintendoDS
(
SDL_PowerState
*
state
,
int
*
seconds
,
int
*
percent
)
SDL_GetPowerInfo_NintendoDS
(
SDL_PowerState
*
state
,
int
*
seconds
,
int
*
percent
)
{
{
/* !!! FIXME: write me. */
/* !!! FIXME: write me. */
...
@@ -35,11 +36,10 @@ SDL_GetPowerInfo_NintendoDS(SDL_PowerState *state, int *seconds, int *percent)
...
@@ -35,11 +36,10 @@ SDL_GetPowerInfo_NintendoDS(SDL_PowerState *state, int *seconds, int *percent)
*
percent
=
-
1
;
*
percent
=
-
1
;
*
seconds
=
-
1
;
*
seconds
=
-
1
;
return
SDL_TRUE
;
/* always the definitive answer on Nintendo DS. */
return
SDL_TRUE
;
/* always the definitive answer on Nintendo DS. */
}
}
#endif
/* SDL_POWER_NINTENDODS */
#endif
/* SDL_POWER_NINTENDODS */
#endif
/* SDL_POWER_DISABLED */
#endif
/* SDL_POWER_DISABLED */
/* vi: set ts=4 sw=4 expandtab: */
/* vi: set ts=4 sw=4 expandtab: */
src/power/os2/SDL_syspower.c
View file @
d03a7700
...
@@ -38,7 +38,8 @@
...
@@ -38,7 +38,8 @@
#include "SDL_power.h"
#include "SDL_power.h"
typedef
struct
{
typedef
struct
{
USHORT
len
;
USHORT
len
;
USHORT
flags
;
USHORT
flags
;
UCHAR
ac_status
;
UCHAR
ac_status
;
...
@@ -48,11 +49,11 @@ typedef struct {
...
@@ -48,11 +49,11 @@ typedef struct {
USHORT
battery_time
;
USHORT
battery_time
;
UCHAR
battery_flags
;
UCHAR
battery_flags
;
}
PowerStatus
;
}
PowerStatus
;
extern
int
CompilerAssertPowerStatus
[(
sizeof
(
PowerStatus
)
==
10
)
?
1
:
-
1
];
extern
int
CompilerAssertPowerStatus
[(
sizeof
(
PowerStatus
)
==
10
)
?
1
:
-
1
];
SDL_bool
SDL_bool
SDL_GetPowerInfo_OS2
(
SDL_PowerState
*
state
,
int
*
seconds
,
int
*
percent
)
SDL_GetPowerInfo_OS2
(
SDL_PowerState
*
state
,
int
*
seconds
,
int
*
percent
)
{
{
PowerStatus
status
;
PowerStatus
status
;
HFILE
hfile
=
0
;
HFILE
hfile
=
0
;
...
@@ -69,11 +70,11 @@ SDL_GetPowerInfo_OS2(SDL_PowerState *state, int *seconds, int *percent)
...
@@ -69,11 +70,11 @@ SDL_GetPowerInfo_OS2(SDL_PowerState *state, int *seconds, int *percent)
if
(
rc
==
NO_ERROR
)
{
if
(
rc
==
NO_ERROR
)
{
USHORT
iorc
=
0
;
USHORT
iorc
=
0
;
ULONG
iorclen
=
sizeof
(
iorc
);
ULONG
iorclen
=
sizeof
(
iorc
);
ULONG
statuslen
=
sizeof
(
status
);
ULONG
statuslen
=
sizeof
(
status
);
SDL_memset
(
&
status
,
'\0'
,
sizeof
(
status
));
SDL_memset
(
&
status
,
'\0'
,
sizeof
(
status
));
status
.
len
=
sizeof
(
status
);
status
.
len
=
sizeof
(
status
);
rc
=
DosDevIOCtl
(
hfile
,
IOCTL_POWER
,
POWER_GETPOWERSTATUS
,
&
status
,
rc
=
DosDevIOCtl
(
hfile
,
IOCTL_POWER
,
POWER_GETPOWERSTATUS
,
&
status
,
statuslen
,
&
statuslen
,
&
iorc
,
iorclen
,
&
iorclen
);
statuslen
,
&
statuslen
,
&
iorc
,
iorclen
,
&
iorclen
);
...
@@ -81,7 +82,7 @@ SDL_GetPowerInfo_OS2(SDL_PowerState *state, int *seconds, int *percent)
...
@@ -81,7 +82,7 @@ SDL_GetPowerInfo_OS2(SDL_PowerState *state, int *seconds, int *percent)
/* (status.flags & 0x1) == power subsystem enabled. */
/* (status.flags & 0x1) == power subsystem enabled. */
if
((
rc
==
NO_ERROR
)
&&
(
status
.
flags
&
0x1
))
{
if
((
rc
==
NO_ERROR
)
&&
(
status
.
flags
&
0x1
))
{
if
(
statuslen
==
7
)
{
/* older OS/2 APM driver? Less fields. */
if
(
statuslen
==
7
)
{
/* older OS/2 APM driver? Less fields. */
status
.
battery_time_form
=
0xFF
;
status
.
battery_time_form
=
0xFF
;
status
.
battery_time
=
0
;
status
.
battery_time
=
0
;
if
(
status
.
battery_status
==
0xFF
)
{
if
(
status
.
battery_status
==
0xFF
)
{
...
@@ -91,18 +92,18 @@ SDL_GetPowerInfo_OS2(SDL_PowerState *state, int *seconds, int *percent)
...
@@ -91,18 +92,18 @@ SDL_GetPowerInfo_OS2(SDL_PowerState *state, int *seconds, int *percent)
}
}
}
}
if
(
status
.
battery_flags
==
0xFF
)
{
/* unknown state */
if
(
status
.
battery_flags
==
0xFF
)
{
/* unknown state */
*
state
=
SDL_POWERSTATE_UNKNOWN
;
*
state
=
SDL_POWERSTATE_UNKNOWN
;
}
else
if
(
status
.
battery_flags
&
(
1
<<
7
))
{
/* no battery */
}
else
if
(
status
.
battery_flags
&
(
1
<<
7
))
{
/* no battery */
*
state
=
SDL_POWERSTATE_NO_BATTERY
;
*
state
=
SDL_POWERSTATE_NO_BATTERY
;
}
else
if
(
status
.
battery_flags
&
(
1
<<
3
))
{
/* charging */
}
else
if
(
status
.
battery_flags
&
(
1
<<
3
))
{
/* charging */
*
state
=
SDL_POWERSTATE_CHARGING
;
*
state
=
SDL_POWERSTATE_CHARGING
;
need_details
=
SDL_TRUE
;
need_details
=
SDL_TRUE
;
}
else
if
(
status
.
ac_status
==
1
)
{
}
else
if
(
status
.
ac_status
==
1
)
{
*
state
=
SDL_POWERSTATE_CHARGED
;
/* on AC, not charging. */
*
state
=
SDL_POWERSTATE_CHARGED
;
/* on AC, not charging. */
need_details
=
SDL_TRUE
;
need_details
=
SDL_TRUE
;
}
else
{
}
else
{
*
state
=
SDL_POWERSTATE_ON_BATTERY
;
/* not on AC. */
*
state
=
SDL_POWERSTATE_ON_BATTERY
;
/* not on AC. */
need_details
=
SDL_TRUE
;
need_details
=
SDL_TRUE
;
}
}
...
@@ -110,13 +111,13 @@ SDL_GetPowerInfo_OS2(SDL_PowerState *state, int *seconds, int *percent)
...
@@ -110,13 +111,13 @@ SDL_GetPowerInfo_OS2(SDL_PowerState *state, int *seconds, int *percent)
const
int
pct
=
(
int
)
status
.
battery_life
;
const
int
pct
=
(
int
)
status
.
battery_life
;
const
int
secs
=
(
int
)
status
.
battery_time
;
const
int
secs
=
(
int
)
status
.
battery_time
;
if
(
pct
!=
0xFF
)
{
/* 255 == unknown */
if
(
pct
!=
0xFF
)
{
/* 255 == unknown */
*
percent
=
(
pct
>
100
)
?
100
:
pct
;
*
percent
=
(
pct
>
100
)
?
100
:
pct
;
}
}
if
(
status
.
battery_time_form
==
0xFF
)
{
/* unknown */
if
(
status
.
battery_time_form
==
0xFF
)
{
/* unknown */
*
seconds
=
-
1
;
*
seconds
=
-
1
;
}
else
if
(
status
.
battery_time_form
==
1
)
{
/* minutes */
}
else
if
(
status
.
battery_time_form
==
1
)
{
/* minutes */
*
seconds
=
secs
*
60
;
*
seconds
=
secs
*
60
;
}
else
{
}
else
{
*
seconds
=
secs
;
*
seconds
=
secs
;
...
@@ -125,11 +126,10 @@ SDL_GetPowerInfo_OS2(SDL_PowerState *state, int *seconds, int *percent)
...
@@ -125,11 +126,10 @@ SDL_GetPowerInfo_OS2(SDL_PowerState *state, int *seconds, int *percent)
}
}
}
}
return
SDL_TRUE
;
/* always the definitive answer on OS/2. */
return
SDL_TRUE
;
/* always the definitive answer on OS/2. */
}
}
#endif
/* SDL_POWER_OS2 */
#endif
/* SDL_POWER_OS2 */
#endif
/* SDL_POWER_DISABLED */
#endif
/* SDL_POWER_DISABLED */
/* vi: set ts=4 sw=4 expandtab: */
/* vi: set ts=4 sw=4 expandtab: */
src/power/windows/SDL_syspower.c
View file @
d03a7700
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
#include "SDL_power.h"
#include "SDL_power.h"
SDL_bool
SDL_bool
SDL_GetPowerInfo_Windows
(
SDL_PowerState
*
state
,
int
*
seconds
,
int
*
percent
)
SDL_GetPowerInfo_Windows
(
SDL_PowerState
*
state
,
int
*
seconds
,
int
*
percent
)
{
{
SYSTEM_POWER_STATUS
status
;
SYSTEM_POWER_STATUS
status
;
SDL_bool
need_details
=
SDL_FALSE
;
SDL_bool
need_details
=
SDL_FALSE
;
...
@@ -39,18 +39,18 @@ SDL_GetPowerInfo_Windows(SDL_PowerState *state, int *seconds, int *percent)
...
@@ -39,18 +39,18 @@ SDL_GetPowerInfo_Windows(SDL_PowerState *state, int *seconds, int *percent)
if
(
!
GetSystemPowerStatus
(
&
status
))
{
if
(
!
GetSystemPowerStatus
(
&
status
))
{
/* !!! FIXME: push GetLastError() into SDL_GetError() */
/* !!! FIXME: push GetLastError() into SDL_GetError() */
*
state
=
SDL_POWERSTATE_UNKNOWN
;
*
state
=
SDL_POWERSTATE_UNKNOWN
;
}
else
if
(
status
.
BatteryFlag
==
0xFF
)
{
/* unknown state */
}
else
if
(
status
.
BatteryFlag
==
0xFF
)
{
/* unknown state */
*
state
=
SDL_POWERSTATE_UNKNOWN
;
*
state
=
SDL_POWERSTATE_UNKNOWN
;
}
else
if
(
status
.
BatteryFlag
&
(
1
<<
7
))
{
/* no battery */
}
else
if
(
status
.
BatteryFlag
&
(
1
<<
7
))
{
/* no battery */
*
state
=
SDL_POWERSTATE_NO_BATTERY
;
*
state
=
SDL_POWERSTATE_NO_BATTERY
;
}
else
if
(
status
.
BatteryFlag
&
(
1
<<
3
))
{
/* charging */
}
else
if
(
status
.
BatteryFlag
&
(
1
<<
3
))
{
/* charging */
*
state
=
SDL_POWERSTATE_CHARGING
;
*
state
=
SDL_POWERSTATE_CHARGING
;
need_details
=
SDL_TRUE
;
need_details
=
SDL_TRUE
;
}
else
if
(
status
.
ACLineStatus
==
1
)
{
}
else
if
(
status
.
ACLineStatus
==
1
)
{
*
state
=
SDL_POWERSTATE_CHARGED
;
/* on AC, not charging. */
*
state
=
SDL_POWERSTATE_CHARGED
;
/* on AC, not charging. */
need_details
=
SDL_TRUE
;
need_details
=
SDL_TRUE
;
}
else
{
}
else
{
*
state
=
SDL_POWERSTATE_ON_BATTERY
;
/* not on AC. */
*
state
=
SDL_POWERSTATE_ON_BATTERY
;
/* not on AC. */
need_details
=
SDL_TRUE
;
need_details
=
SDL_TRUE
;
}
}
...
@@ -60,19 +60,18 @@ SDL_GetPowerInfo_Windows(SDL_PowerState *state, int *seconds, int *percent)
...
@@ -60,19 +60,18 @@ SDL_GetPowerInfo_Windows(SDL_PowerState *state, int *seconds, int *percent)
const
int
pct
=
(
int
)
status
.
BatteryLifePercent
;
const
int
pct
=
(
int
)
status
.
BatteryLifePercent
;
const
int
secs
=
(
int
)
status
.
BatteryLifeTime
;
const
int
secs
=
(
int
)
status
.
BatteryLifeTime
;
if
(
pct
!=
255
)
{
/* 255 == unknown */
if
(
pct
!=
255
)
{
/* 255 == unknown */
*
percent
=
(
pct
>
100
)
?
100
:
pct
;
/* clamp between 0%, 100% */
*
percent
=
(
pct
>
100
)
?
100
:
pct
;
/* clamp between 0%, 100% */
}
}
if
(
secs
!=
0xFFFFFFFF
)
{
/* ((DWORD)-1) == unknown */
if
(
secs
!=
0xFFFFFFFF
)
{
/* ((DWORD)-1) == unknown */
*
seconds
=
secs
;
*
seconds
=
secs
;
}
}
}
}
return
SDL_TRUE
;
/* always the definitive answer on Windows. */
return
SDL_TRUE
;
/* always the definitive answer on Windows. */
}
}
#endif
/* SDL_POWER_WINDOWS */
#endif
/* SDL_POWER_WINDOWS */
#endif
/* SDL_POWER_DISABLED */
#endif
/* SDL_POWER_DISABLED */
/* vi: set ts=4 sw=4 expandtab: */
/* vi: set ts=4 sw=4 expandtab: */
src/video/SDL_video.c
View file @
d03a7700
...
@@ -413,7 +413,7 @@ SDL_AddDisplayMode(int displayIndex, const SDL_DisplayMode * mode)
...
@@ -413,7 +413,7 @@ SDL_AddDisplayMode(int displayIndex, const SDL_DisplayMode * mode)
/* Re-sort video modes */
/* Re-sort video modes */
SDL_qsort
(
display
->
display_modes
,
display
->
num_display_modes
,
SDL_qsort
(
display
->
display_modes
,
display
->
num_display_modes
,
sizeof
(
SDL_DisplayMode
),
cmpmodes
);
sizeof
(
SDL_DisplayMode
),
cmpmodes
);
return
SDL_TRUE
;
return
SDL_TRUE
;
}
}
...
@@ -1634,32 +1634,33 @@ SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface)
...
@@ -1634,32 +1634,33 @@ SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface)
int
pfmt
;
int
pfmt
;
/* Pixel formats, sorted by best first */
/* Pixel formats, sorted by best first */
static
const
Uint32
sdl_pformats
[]
=
{
static
const
Uint32
sdl_pformats
[]
=
{
SDL_PIXELFORMAT_ARGB8888
,
SDL_PIXELFORMAT_ARGB8888
,
SDL_PIXELFORMAT_RGBA8888
,
SDL_PIXELFORMAT_RGBA8888
,
SDL_PIXELFORMAT_ABGR8888
,
SDL_PIXELFORMAT_ABGR8888
,
SDL_PIXELFORMAT_BGRA8888
,
SDL_PIXELFORMAT_BGRA8888
,
SDL_PIXELFORMAT_RGB888
,
SDL_PIXELFORMAT_RGB888
,
SDL_PIXELFORMAT_BGR888
,
SDL_PIXELFORMAT_BGR888
,
SDL_PIXELFORMAT_RGB24
,
SDL_PIXELFORMAT_RGB24
,
SDL_PIXELFORMAT_BGR24
,
SDL_PIXELFORMAT_BGR24
,
SDL_PIXELFORMAT_RGB565
,
SDL_PIXELFORMAT_RGB565
,
SDL_PIXELFORMAT_BGR565
,
SDL_PIXELFORMAT_BGR565
,
SDL_PIXELFORMAT_ARGB1555
,
SDL_PIXELFORMAT_ARGB1555
,
SDL_PIXELFORMAT_ABGR1555
,
SDL_PIXELFORMAT_ABGR1555
,
SDL_PIXELFORMAT_RGB555
,
SDL_PIXELFORMAT_RGB555
,
SDL_PIXELFORMAT_BGR555
,
SDL_PIXELFORMAT_BGR555
,
SDL_PIXELFORMAT_ARGB4444
,
SDL_PIXELFORMAT_ARGB4444
,
SDL_PIXELFORMAT_ABGR4444
,
SDL_PIXELFORMAT_ABGR4444
,
SDL_PIXELFORMAT_RGB444
,
SDL_PIXELFORMAT_RGB444
,
SDL_PIXELFORMAT_ARGB2101010
,
SDL_PIXELFORMAT_ARGB2101010
,
SDL_PIXELFORMAT_INDEX8
,
SDL_PIXELFORMAT_INDEX8
,
SDL_PIXELFORMAT_INDEX4LSB
,
SDL_PIXELFORMAT_INDEX4LSB
,
SDL_PIXELFORMAT_INDEX4MSB
,
SDL_PIXELFORMAT_INDEX4MSB
,
SDL_PIXELFORMAT_RGB332
,
SDL_PIXELFORMAT_RGB332
,
SDL_PIXELFORMAT_INDEX1LSB
,
SDL_PIXELFORMAT_INDEX1LSB
,
SDL_PIXELFORMAT_INDEX1MSB
,
SDL_PIXELFORMAT_INDEX1MSB
,
SDL_PIXELFORMAT_UNKNOWN
};
SDL_PIXELFORMAT_UNKNOWN
};
bpp
=
fmt
->
BitsPerPixel
;
bpp
=
fmt
->
BitsPerPixel
;
Rmask
=
fmt
->
Rmask
;
Rmask
=
fmt
->
Rmask
;
...
@@ -1667,7 +1668,8 @@ SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface)
...
@@ -1667,7 +1668,8 @@ SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface)
Bmask
=
fmt
->
Bmask
;
Bmask
=
fmt
->
Bmask
;
Amask
=
fmt
->
Amask
;
Amask
=
fmt
->
Amask
;
format
=
SDL_MasksToPixelFormatEnum
(
bpp
,
Rmask
,
Gmask
,
Bmask
,
Amask
);
format
=
SDL_MasksToPixelFormatEnum
(
bpp
,
Rmask
,
Gmask
,
Bmask
,
Amask
);
if
(
!
format
)
{
if
(
!
format
)
{
SDL_SetError
(
"Unknown pixel format"
);
SDL_SetError
(
"Unknown pixel format"
);
return
0
;
return
0
;
...
@@ -1675,53 +1677,47 @@ SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface)
...
@@ -1675,53 +1677,47 @@ SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface)
/* Search requested format in the supported texture */
/* Search requested format in the supported texture */
/* formats by current renderer */
/* formats by current renderer */
for
(
it
=
0
;
it
<
renderer
->
info
.
num_texture_formats
;
it
++
)
for
(
it
=
0
;
it
<
renderer
->
info
.
num_texture_formats
;
it
++
)
{
{
if
(
renderer
->
info
.
texture_formats
[
it
]
==
format
)
{
if
(
renderer
->
info
.
texture_formats
[
it
]
==
format
)
break
;
{
break
;
}
}
}
}
/* If requested format can't be found, search any best */
/* If requested format can't be found, search any best */
/* format which renderer provides */
/* format which renderer provides */
if
(
it
==
renderer
->
info
.
num_texture_formats
)
if
(
it
==
renderer
->
info
.
num_texture_formats
)
{
{
pfmt
=
0
;
pfmt
=
0
;
for
(;;)
{
for
(;;)
if
(
sdl_pformats
[
pfmt
]
==
SDL_PIXELFORMAT_UNKNOWN
)
{
{
if
(
sdl_pformats
[
pfmt
]
==
SDL_PIXELFORMAT_UNKNOWN
)
{
break
;
break
;
}
}
for
(
it
=
0
;
it
<
renderer
->
info
.
num_texture_formats
;
it
++
)
for
(
it
=
0
;
it
<
renderer
->
info
.
num_texture_formats
;
{
it
++
)
{
if
(
renderer
->
info
.
texture_formats
[
it
]
==
sdl_pformats
[
pfmt
])
if
(
renderer
->
info
.
texture_formats
[
it
]
==
{
sdl_pformats
[
pfmt
])
{
break
;
break
;
}
}
}
}
if
(
it
!=
renderer
->
info
.
num_texture_formats
)
if
(
it
!=
renderer
->
info
.
num_texture_formats
)
{
{
/* The best format has been found */
/* The best format has been found */
break
;
break
;
}
}
pfmt
++
;
pfmt
++
;
}
}
/* If any format can't be found, then return an error */
/* If any format can't be found, then return an error */
if
(
it
==
renderer
->
info
.
num_texture_formats
)
if
(
it
==
renderer
->
info
.
num_texture_formats
)
{
{
SDL_SetError
SDL_SetError
(
"Any of the supported pixel formats can't be found"
);
(
"Any of the supported pixel formats can't be found"
);
return
0
;
return
0
;
}
}
/* Convert found pixel format back to color masks */
/* Convert found pixel format back to color masks */
if
(
SDL_PixelFormatEnumToMasks
(
renderer
->
info
.
texture_formats
[
it
],
if
(
SDL_PixelFormatEnumToMasks
&
bpp
,
&
Rmask
,
&
Gmask
,
&
Bmask
,
&
Amask
)
!=
SDL_TRUE
)
(
renderer
->
info
.
texture_formats
[
it
],
&
bpp
,
&
Rmask
,
&
Gmask
,
{
&
Bmask
,
&
Amask
)
!=
SDL_TRUE
)
{
SDL_SetError
(
"Unknown pixel format"
);
SDL_SetError
(
"Unknown pixel format"
);
return
0
;
return
0
;
}
}
...
...
src/video/photon/SDL_photon.c
View file @
d03a7700
...
@@ -385,42 +385,42 @@ photon_videoinit(_THIS)
...
@@ -385,42 +385,42 @@ photon_videoinit(_THIS)
status
=
PgGetGraphicsHWCaps
(
&
hwcaps
);
status
=
PgGetGraphicsHWCaps
(
&
hwcaps
);
if
(
status
!=
0
)
{
if
(
status
!=
0
)
{
PhRect_t
extent
;
PhRect_t
extent
;
PdOffscreenContext_t
*
curctx
;
PdOffscreenContext_t
*
curctx
;
/* If error happens, this also could mean, that photon is working */
/* If error happens, this also could mean, that photon is working */
/* under custom (not listed by photon) video mode */
/* under custom (not listed by photon) video mode */
status
=
PhWindowQueryVisible
(
Ph_QUERY_GRAPHICS
,
0
,
0
,
&
extent
);
status
=
PhWindowQueryVisible
(
Ph_QUERY_GRAPHICS
,
0
,
0
,
&
extent
);
if
(
status
!=
0
)
{
if
(
status
!=
0
)
{
SDL_SetError
(
"Photon: Can't get graphics driver region"
);
SDL_SetError
(
"Photon: Can't get graphics driver region"
);
SDL_free
(
didata
->
cursor
);
SDL_free
(
didata
->
cursor
);
SDL_free
(
didata
);
SDL_free
(
didata
);
return
-
1
;
return
-
1
;
}
}
modeinfo
.
width
=
extent
.
lr
.
x
+
1
;
modeinfo
.
width
=
extent
.
lr
.
x
+
1
;
modeinfo
.
height
=
extent
.
lr
.
y
+
1
;
modeinfo
.
height
=
extent
.
lr
.
y
+
1
;
/* Hardcode 60Hz, as the base refresh rate frequency */
/* Hardcode 60Hz, as the base refresh rate frequency */
hwcaps
.
current_rrate
=
60
;
hwcaps
.
current_rrate
=
60
;
/* Clear current video driver name, no way to get it somehow */
/* Clear current video driver name, no way to get it somehow */
hwcaps
.
chip_name
[
0
]
=
0x00
;
hwcaps
.
chip_name
[
0
]
=
0x00
;
/* Create offscreen context from video memory, which is currently */
/* Create offscreen context from video memory, which is currently */
/* displayed on the screen */
/* displayed on the screen */
curctx
=
PdCreateOffscreenContext
(
0
,
0
,
0
,
Pg_OSC_MAIN_DISPLAY
);
curctx
=
PdCreateOffscreenContext
(
0
,
0
,
0
,
Pg_OSC_MAIN_DISPLAY
);
if
(
curctx
==
NULL
)
if
(
curctx
==
NULL
)
{
{
SDL_SetError
(
"Photon: Can't get display area capabilities"
);
SDL_SetError
(
"Photon: Can't get display area capabilities"
);
SDL_free
(
didata
->
cursor
);
SDL_free
(
didata
->
cursor
);
SDL_free
(
didata
);
SDL_free
(
didata
);
return
-
1
;
return
-
1
;
}
}
/* Retrieve current bpp */
/* Retrieve current bpp */
modeinfo
.
type
=
curctx
->
format
;
modeinfo
.
type
=
curctx
->
format
;
PhDCRelease
(
curctx
);
PhDCRelease
(
curctx
);
}
else
{
}
else
{
/* Get current video mode details */
/* Get current video mode details */
status
=
PgGetVideoModeInfo
(
hwcaps
.
current_video_mode
,
&
modeinfo
);
status
=
PgGetVideoModeInfo
(
hwcaps
.
current_video_mode
,
&
modeinfo
);
if
(
status
!=
0
)
{
if
(
status
!=
0
)
{
SDL_SetError
(
"Photon: Can't get current video mode information"
);
SDL_SetError
(
"Photon: Can't get current video mode information"
);
SDL_free
(
didata
->
cursor
);
SDL_free
(
didata
->
cursor
);
SDL_free
(
didata
);
SDL_free
(
didata
);
return
-
1
;
return
-
1
;
...
...
src/video/qnxgf/SDL_qnxgf.c
View file @
d03a7700
...
@@ -645,7 +645,7 @@ qnxgf_getdisplaymodes(_THIS)
...
@@ -645,7 +645,7 @@ qnxgf_getdisplaymodes(_THIS)
SDL_AddDisplayMode
(
_this
->
current_display
,
&
mode
);
SDL_AddDisplayMode
(
_this
->
current_display
,
&
mode
);
/* If mode is RGBA8888, add the same mode as RGBx888 */
/* If mode is RGBA8888, add the same mode as RGBx888 */
if
(
modeinfo
.
primary_format
==
GF_FORMAT_BGRA8888
)
{
if
(
modeinfo
.
primary_format
==
GF_FORMAT_BGRA8888
)
{
mode
.
w
=
generic_mode
[
jt
].
w
;
mode
.
w
=
generic_mode
[
jt
].
w
;
mode
.
h
=
generic_mode
[
jt
].
h
;
mode
.
h
=
generic_mode
[
jt
].
h
;
mode
.
refresh_rate
=
generic_mode
[
jt
].
refresh_rate
;
mode
.
refresh_rate
=
generic_mode
[
jt
].
refresh_rate
;
...
@@ -654,7 +654,7 @@ qnxgf_getdisplaymodes(_THIS)
...
@@ -654,7 +654,7 @@ qnxgf_getdisplaymodes(_THIS)
SDL_AddDisplayMode
(
_this
->
current_display
,
&
mode
);
SDL_AddDisplayMode
(
_this
->
current_display
,
&
mode
);
}
}
/* If mode is RGBA1555, add the same mode as RGBx555 */
/* If mode is RGBA1555, add the same mode as RGBx555 */
if
(
modeinfo
.
primary_format
==
GF_FORMAT_PACK_ARGB1555
)
{
if
(
modeinfo
.
primary_format
==
GF_FORMAT_PACK_ARGB1555
)
{
mode
.
w
=
generic_mode
[
jt
].
w
;
mode
.
w
=
generic_mode
[
jt
].
w
;
mode
.
h
=
generic_mode
[
jt
].
h
;
mode
.
h
=
generic_mode
[
jt
].
h
;
mode
.
refresh_rate
=
generic_mode
[
jt
].
refresh_rate
;
mode
.
refresh_rate
=
generic_mode
[
jt
].
refresh_rate
;
...
@@ -681,7 +681,7 @@ qnxgf_getdisplaymodes(_THIS)
...
@@ -681,7 +681,7 @@ qnxgf_getdisplaymodes(_THIS)
SDL_AddDisplayMode
(
_this
->
current_display
,
&
mode
);
SDL_AddDisplayMode
(
_this
->
current_display
,
&
mode
);
/* If mode is RGBA8888, add the same mode as RGBx888 */
/* If mode is RGBA8888, add the same mode as RGBx888 */
if
(
modeinfo
.
primary_format
==
GF_FORMAT_BGRA8888
)
{
if
(
modeinfo
.
primary_format
==
GF_FORMAT_BGRA8888
)
{
mode
.
w
=
modeinfo
.
xres
;
mode
.
w
=
modeinfo
.
xres
;
mode
.
h
=
modeinfo
.
yres
;
mode
.
h
=
modeinfo
.
yres
;
mode
.
refresh_rate
=
modeinfo
.
refresh
[
jt
];
mode
.
refresh_rate
=
modeinfo
.
refresh
[
jt
];
...
@@ -690,7 +690,8 @@ qnxgf_getdisplaymodes(_THIS)
...
@@ -690,7 +690,8 @@ qnxgf_getdisplaymodes(_THIS)
SDL_AddDisplayMode
(
_this
->
current_display
,
&
mode
);
SDL_AddDisplayMode
(
_this
->
current_display
,
&
mode
);
}
}
/* If mode is RGBA1555, add the same mode as RGBx555 */
/* If mode is RGBA1555, add the same mode as RGBx555 */
if
(
modeinfo
.
primary_format
==
GF_FORMAT_PACK_ARGB1555
)
{
if
(
modeinfo
.
primary_format
==
GF_FORMAT_PACK_ARGB1555
)
{
mode
.
w
=
modeinfo
.
xres
;
mode
.
w
=
modeinfo
.
xres
;
mode
.
h
=
modeinfo
.
yres
;
mode
.
h
=
modeinfo
.
yres
;
mode
.
refresh_rate
=
modeinfo
.
refresh
[
jt
];
mode
.
refresh_rate
=
modeinfo
.
refresh
[
jt
];
...
@@ -1573,8 +1574,7 @@ qnxgf_gl_createcontext(_THIS, SDL_Window * window)
...
@@ -1573,8 +1574,7 @@ qnxgf_gl_createcontext(_THIS, SDL_Window * window)
/* No available configs */
/* No available configs */
if
(
configs
==
0
)
{
if
(
configs
==
0
)
{
SDL_SetError
SDL_SetError
(
"GF: Can't find any configuration for OpenGL ES"
);
(
"GF: Can't find any configuration for OpenGL ES"
);
return
NULL
;
return
NULL
;
}
}
}
}
...
...
src/video/win32/SDL_win32modes.c
View file @
d03a7700
...
@@ -103,7 +103,7 @@ WIN_GetDisplayMode(LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
...
@@ -103,7 +103,7 @@ WIN_GetDisplayMode(LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
#endif
/* _WIN32_WCE */
#endif
/* _WIN32_WCE */
{
{
/* FIXME: Can we tell what this will be? */
/* FIXME: Can we tell what this will be? */
if
((
devmode
.
dmFields
&
DM_BITSPERPEL
)
==
DM_BITSPERPEL
)
{
if
((
devmode
.
dmFields
&
DM_BITSPERPEL
)
==
DM_BITSPERPEL
)
{
switch
(
devmode
.
dmBitsPerPel
)
{
switch
(
devmode
.
dmBitsPerPel
)
{
case
32
:
case
32
:
mode
->
format
=
SDL_PIXELFORMAT_RGB888
;
mode
->
format
=
SDL_PIXELFORMAT_RGB888
;
...
@@ -124,7 +124,7 @@ WIN_GetDisplayMode(LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
...
@@ -124,7 +124,7 @@ WIN_GetDisplayMode(LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
mode
->
format
=
SDL_PIXELFORMAT_INDEX4LSB
;
mode
->
format
=
SDL_PIXELFORMAT_INDEX4LSB
;
break
;
break
;
}
}
}
}
}
}
return
SDL_TRUE
;
return
SDL_TRUE
;
}
}
...
@@ -206,10 +206,10 @@ WIN_GetDisplayModes(_THIS)
...
@@ -206,10 +206,10 @@ WIN_GetDisplayModes(_THIS)
if
(
!
WIN_GetDisplayMode
(
data
->
DeviceName
,
i
,
&
mode
))
{
if
(
!
WIN_GetDisplayMode
(
data
->
DeviceName
,
i
,
&
mode
))
{
break
;
break
;
}
}
if
(
mode
.
format
!=
SDL_PIXELFORMAT_UNKNOWN
)
if
(
mode
.
format
!=
SDL_PIXELFORMAT_UNKNOWN
)
if
(
!
SDL_AddDisplayMode
(
_this
->
current_display
,
&
mode
))
{
if
(
!
SDL_AddDisplayMode
(
_this
->
current_display
,
&
mode
))
{
SDL_free
(
mode
.
driverdata
);
SDL_free
(
mode
.
driverdata
);
}
}
}
}
}
}
...
...
src/video/x11/SDL_x11events.c
View file @
d03a7700
...
@@ -339,6 +339,7 @@ X11_DispatchEvent(_THIS)
...
@@ -339,6 +339,7 @@ X11_DispatchEvent(_THIS)
if
(
xevent
.
type
==
data
->
proximity_in
)
{
if
(
xevent
.
type
==
data
->
proximity_in
)
{
XProximityNotifyEvent
*
proximity
=
XProximityNotifyEvent
*
proximity
=
(
XProximityNotifyEvent
*
)
&
xevent
;
(
XProximityNotifyEvent
*
)
&
xevent
;
SDL_SetMouseFocus
(
proximity
->
deviceid
,
data
->
windowID
);
SDL_SendProximity
(
proximity
->
deviceid
,
proximity
->
x
,
SDL_SendProximity
(
proximity
->
deviceid
,
proximity
->
x
,
proximity
->
y
,
SDL_PROXIMITYIN
);
proximity
->
y
,
SDL_PROXIMITYIN
);
return
;
return
;
...
@@ -346,6 +347,7 @@ X11_DispatchEvent(_THIS)
...
@@ -346,6 +347,7 @@ X11_DispatchEvent(_THIS)
if
(
xevent
.
type
==
data
->
proximity_out
)
{
if
(
xevent
.
type
==
data
->
proximity_out
)
{
XProximityNotifyEvent
*
proximity
=
XProximityNotifyEvent
*
proximity
=
(
XProximityNotifyEvent
*
)
&
xevent
;
(
XProximityNotifyEvent
*
)
&
xevent
;
SDL_SetMouseFocus
(
proximity
->
deviceid
,
data
->
windowID
);
SDL_SendProximity
(
proximity
->
deviceid
,
proximity
->
x
,
SDL_SendProximity
(
proximity
->
deviceid
,
proximity
->
x
,
proximity
->
y
,
SDL_PROXIMITYOUT
);
proximity
->
y
,
SDL_PROXIMITYOUT
);
return
;
return
;
...
...
test/common.c
View file @
d03a7700
...
@@ -11,56 +11,59 @@
...
@@ -11,56 +11,59 @@
#define AUDIO_USAGE \
#define AUDIO_USAGE \
"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
struct
pformat
{
struct
pformat
{
Uint32
id
;
Uint32
id
;
const
char
*
idstr
;
const
char
*
idstr
;
}
pixel_format
[]
=
{
}
pixel_format
[]
=
{
{
SDL_PIXELFORMAT_INDEX1LSB
,
"SDL_PIXELFORMAT_INDEX1LSB"
},
{
{
SDL_PIXELFORMAT_INDEX1MSB
,
"SDL_PIXELFORMAT_INDEX1MSB"
},
SDL_PIXELFORMAT_INDEX1LSB
,
"SDL_PIXELFORMAT_INDEX1LSB"
},
{
{
SDL_PIXELFORMAT_INDEX4LSB
,
"SDL_PIXELFORMAT_INDEX4LSB"
},
SDL_PIXELFORMAT_INDEX1MSB
,
"SDL_PIXELFORMAT_INDEX1MSB"
},
{
{
SDL_PIXELFORMAT_INDEX4MSB
,
"SDL_PIXELFORMAT_INDEX4MSB"
},
SDL_PIXELFORMAT_INDEX4LSB
,
"SDL_PIXELFORMAT_INDEX4LSB"
},
{
{
SDL_PIXELFORMAT_INDEX8
,
"SDL_PIXELFORMAT_INDEX8"
},
SDL_PIXELFORMAT_INDEX4MSB
,
"SDL_PIXELFORMAT_INDEX4MSB"
},
{
{
SDL_PIXELFORMAT_RGB332
,
"SDL_PIXELFORMAT_RGB332"
},
SDL_PIXELFORMAT_INDEX8
,
"SDL_PIXELFORMAT_INDEX8"
},
{
{
SDL_PIXELFORMAT_RGB444
,
"SDL_PIXELFORMAT_RGB444"
},
SDL_PIXELFORMAT_RGB332
,
"SDL_PIXELFORMAT_RGB332"
},
{
{
SDL_PIXELFORMAT_RGB555
,
"SDL_PIXELFORMAT_RGB555"
},
SDL_PIXELFORMAT_RGB444
,
"SDL_PIXELFORMAT_RGB444"
},
{
{
SDL_PIXELFORMAT_BGR555
,
"SDL_PIXELFORMAT_BGR555"
},
SDL_PIXELFORMAT_RGB555
,
"SDL_PIXELFORMAT_RGB555"
},
{
{
SDL_PIXELFORMAT_ARGB4444
,
"SDL_PIXELFORMAT_ARGB4444"
},
SDL_PIXELFORMAT_BGR555
,
"SDL_PIXELFORMAT_BGR555"
},
{
{
SDL_PIXELFORMAT_ABGR4444
,
"SDL_PIXELFORMAT_ABGR4444"
},
SDL_PIXELFORMAT_ARGB4444
,
"SDL_PIXELFORMAT_ARGB4444"
},
{
{
SDL_PIXELFORMAT_ARGB1555
,
"SDL_PIXELFORMAT_ARGB1555"
},
SDL_PIXELFORMAT_ABGR4444
,
"SDL_PIXELFORMAT_ABGR4444"
},
{
{
SDL_PIXELFORMAT_ABGR1555
,
"SDL_PIXELFORMAT_ABGR1555"
},
SDL_PIXELFORMAT_ARGB1555
,
"SDL_PIXELFORMAT_ARGB1555"
},
{
{
SDL_PIXELFORMAT_RGB565
,
"SDL_PIXELFORMAT_RGB565"
},
SDL_PIXELFORMAT_ABGR1555
,
"SDL_PIXELFORMAT_ABGR1555"
},
{
{
SDL_PIXELFORMAT_BGR565
,
"SDL_PIXELFORMAT_BGR565"
},
SDL_PIXELFORMAT_RGB565
,
"SDL_PIXELFORMAT_RGB565"
},
{
{
SDL_PIXELFORMAT_RGB24
,
"SDL_PIXELFORMAT_RGB24"
},
SDL_PIXELFORMAT_BGR565
,
"SDL_PIXELFORMAT_BGR565"
},
{
{
SDL_PIXELFORMAT_BGR24
,
"SDL_PIXELFORMAT_BGR24"
},
SDL_PIXELFORMAT_RGB24
,
"SDL_PIXELFORMAT_RGB24"
},
{
{
SDL_PIXELFORMAT_RGB888
,
"SDL_PIXELFORMAT_RGB888"
},
SDL_PIXELFORMAT_BGR24
,
"SDL_PIXELFORMAT_BGR24"
},
{
{
SDL_PIXELFORMAT_BGR888
,
"SDL_PIXELFORMAT_BGR888"
},
SDL_PIXELFORMAT_RGB888
,
"SDL_PIXELFORMAT_RGB888"
},
{
{
SDL_PIXELFORMAT_ARGB8888
,
"SDL_PIXELFORMAT_ARGB8888"
},
SDL_PIXELFORMAT_BGR888
,
"SDL_PIXELFORMAT_BGR888"
},
{
{
SDL_PIXELFORMAT_RGBA8888
,
"SDL_PIXELFORMAT_RGBA8888"
},
SDL_PIXELFORMAT_ARGB8888
,
"SDL_PIXELFORMAT_ARGB8888"
},
{
{
SDL_PIXELFORMAT_ABGR8888
,
"SDL_PIXELFORMAT_ABGR8888"
},
SDL_PIXELFORMAT_RGBA8888
,
"SDL_PIXELFORMAT_RGBA8888"
},
{
{
SDL_PIXELFORMAT_BGRA8888
,
"SDL_PIXELFORMAT_BGRA8888"
},
SDL_PIXELFORMAT_ABGR8888
,
"SDL_PIXELFORMAT_ABGR8888"
},
{
{
SDL_PIXELFORMAT_ARGB2101010
,
"SDL_PIXELFORMAT_ARGB2101010"
},
SDL_PIXELFORMAT_BGRA8888
,
"SDL_PIXELFORMAT_BGRA8888"
},
{
{
SDL_PIXELFORMAT_YV12
,
"SDL_PIXELFORMAT_YV12"
},
SDL_PIXELFORMAT_ARGB2101010
,
"SDL_PIXELFORMAT_ARGB2101010"
},
{
{
SDL_PIXELFORMAT_IYUV
,
"SDL_PIXELFORMAT_IYUV"
},
SDL_PIXELFORMAT_YV12
,
"SDL_PIXELFORMAT_YV12"
},
{
{
SDL_PIXELFORMAT_YUY2
,
"SDL_PIXELFORMAT_YUY2"
},
SDL_PIXELFORMAT_IYUV
,
"SDL_PIXELFORMAT_IYUV"
},
{
{
SDL_PIXELFORMAT_UYVY
,
"SDL_PIXELFORMAT_UYVY"
},
SDL_PIXELFORMAT_YUY2
,
"SDL_PIXELFORMAT_YUY2"
},
{
{
SDL_PIXELFORMAT_YVYU
,
"SDL_PIXELFORMAT_YVYU"
}
SDL_PIXELFORMAT_UYVY
,
"SDL_PIXELFORMAT_UYVY"
},
{
SDL_PIXELFORMAT_YVYU
,
"SDL_PIXELFORMAT_YVYU"
}
};
};
const
char
*
PixelFormatToString
(
Uint32
pformat
)
const
char
*
PixelFormatToString
(
Uint32
pformat
)
{
{
Uint32
it
=
0
;
Uint32
it
=
0
;
do
{
do
{
if
(
pixel_format
[
it
].
idstr
==
NULL
)
{
if
(
pixel_format
[
it
].
idstr
==
NULL
)
{
break
;
break
;
}
}
if
(
pixel_format
[
it
].
id
==
pformat
)
{
if
(
pixel_format
[
it
].
id
==
pformat
)
{
return
pixel_format
[
it
].
idstr
;
return
pixel_format
[
it
].
idstr
;
}
}
it
++
;
it
++
;
}
while
(
1
);
}
while
(
1
);
return
"SDL_PIXELFORMAT_UNKNOWN"
;
return
"SDL_PIXELFORMAT_UNKNOWN"
;
}
}
CommonState
*
CommonState
*
...
@@ -706,7 +709,7 @@ CommonInit(CommonState * state)
...
@@ -706,7 +709,7 @@ CommonInit(CommonState * state)
fullscreen_mode
.
w
=
state
->
window_w
;
fullscreen_mode
.
w
=
state
->
window_w
;
fullscreen_mode
.
h
=
state
->
window_h
;
fullscreen_mode
.
h
=
state
->
window_h
;
fullscreen_mode
.
refresh_rate
=
state
->
refresh_rate
;
fullscreen_mode
.
refresh_rate
=
state
->
refresh_rate
;
if
(
SDL_SetFullscreenDisplayMode
(
&
fullscreen_mode
)
<
0
)
{
if
(
SDL_SetFullscreenDisplayMode
(
&
fullscreen_mode
)
<
0
)
{
fprintf
(
stderr
,
"Can't switch to fullscreen display mode: %s
\n
"
,
fprintf
(
stderr
,
"Can't switch to fullscreen display mode: %s
\n
"
,
SDL_GetError
());
SDL_GetError
());
return
SDL_FALSE
;
return
SDL_FALSE
;
...
...
test/testatomic.c
View file @
d03a7700
#include "SDL.h"
#include "SDL.h"
int
int
main
(
int
argc
,
char
**
argv
)
main
(
int
argc
,
char
**
argv
)
{
{
int
rv
=
10
;
int
rv
=
10
;
volatile
int
atomic
;
volatile
int
atomic
;
SDL_atomic_int_set
(
&
atomic
,
10
);
SDL_atomic_int_set
(
&
atomic
,
10
);
if
(
SDL_atomic_int_get
(
&
atomic
)
!=
10
)
if
(
SDL_atomic_int_get
(
&
atomic
)
!=
10
)
printf
(
"Error: "
);
printf
(
"Error: "
);
printf
(
"SDL_atomic_int_set(atomic, 10): atomic-> %d
\n
"
,
printf
(
"SDL_atomic_int_set(atomic, 10): atomic-> %d
\n
"
,
SDL_atomic_int_get
(
&
atomic
));
SDL_atomic_int_get
(
&
atomic
));
SDL_atomic_int_add
(
&
atomic
,
10
);
SDL_atomic_int_add
(
&
atomic
,
10
);
if
(
SDL_atomic_int_get
(
&
atomic
)
!=
20
)
if
(
SDL_atomic_int_get
(
&
atomic
)
!=
20
)
printf
(
"Error: "
);
printf
(
"Error: "
);
printf
(
"SDL_atomic_int_add(atomic, 10): atomic-> %d
\n
"
,
printf
(
"SDL_atomic_int_add(atomic, 10): atomic-> %d
\n
"
,
SDL_atomic_int_get
(
&
atomic
));
SDL_atomic_int_get
(
&
atomic
));
rv
=
SDL_atomic_int_cmp_xchg
(
&
atomic
,
20
,
30
);
rv
=
SDL_atomic_int_cmp_xchg
(
&
atomic
,
20
,
30
);
if
(
rv
!=
SDL_TRUE
||
SDL_atomic_int_get
(
&
atomic
)
!=
30
)
if
(
rv
!=
SDL_TRUE
||
SDL_atomic_int_get
(
&
atomic
)
!=
30
)
printf
(
"Error: "
);
printf
(
"Error: "
);
printf
(
"SDL_atomic_int_cmp_xchg(atomic, 20, 30): rv-> %d, atomic-> %d
\n
"
,
printf
(
"SDL_atomic_int_cmp_xchg(atomic, 20, 30): rv-> %d, atomic-> %d
\n
"
,
rv
,
SDL_atomic_int_get
(
&
atomic
));
rv
,
SDL_atomic_int_get
(
&
atomic
));
rv
=
SDL_atomic_int_cmp_xchg
(
&
atomic
,
20
,
30
);
rv
=
SDL_atomic_int_cmp_xchg
(
&
atomic
,
20
,
30
);
if
(
rv
!=
SDL_FALSE
||
SDL_atomic_int_get
(
&
atomic
)
!=
30
)
if
(
rv
!=
SDL_FALSE
||
SDL_atomic_int_get
(
&
atomic
)
!=
30
)
printf
(
"Error: "
);
printf
(
"Error: "
);
printf
(
"SDL_atomic_int_cmp_xchg(atomic, 20, 40): rv-> %d, atomic-> %d
\n
"
,
printf
(
"SDL_atomic_int_cmp_xchg(atomic, 20, 40): rv-> %d, atomic-> %d
\n
"
,
rv
,
SDL_atomic_int_get
(
&
atomic
));
rv
,
SDL_atomic_int_get
(
&
atomic
));
rv
=
SDL_atomic_int_xchg_add
(
&
atomic
,
10
);
if
(
rv
!=
30
||
SDL_atomic_int_get
(
&
atomic
)
!=
40
)
printf
(
"Error: "
);
printf
(
"SDL_atomic_int_xchg_add(atomic, 10): rv-> %d, atomic-> %d
\n
"
,
rv
,
SDL_atomic_int_get
(
&
atomic
));
SDL_atomic_int_inc
(
&
atomic
);
rv
=
SDL_atomic_int_xchg_add
(
&
atomic
,
10
);
if
(
SDL_atomic_int_get
(
&
atomic
)
!=
41
)
if
(
rv
!=
30
||
SDL_atomic_int_get
(
&
atomic
)
!=
40
)
printf
(
"Error: "
);
printf
(
"Error: "
);
printf
(
"SDL_atomic_int_inc(atomic):
atomic-> %d
\n
"
,
printf
(
"SDL_atomic_int_xchg_add(atomic, 10): rv-> %d,
atomic-> %d
\n
"
,
SDL_atomic_int_get
(
&
atomic
));
rv
,
SDL_atomic_int_get
(
&
atomic
));
rv
=
SDL_atomic_int_dec_test
(
&
atomic
);
SDL_atomic_int_inc
(
&
atomic
);
if
(
rv
!=
SDL_FALSE
||
SDL_atomic_int_get
(
&
atomic
)
!=
40
)
if
(
SDL_atomic_int_get
(
&
atomic
)
!=
41
)
printf
(
"Error: "
);
printf
(
"Error: "
);
printf
(
"SDL_atomic_int_dec_test(atomic): rv-> %d, atomic-> %d
\n
"
,
printf
(
"SDL_atomic_int_inc(atomic): atomic-> %d
\n
"
,
rv
,
SDL_atomic_int_get
(
&
atomic
));
SDL_atomic_int_get
(
&
atomic
));
SDL_atomic_int_set
(
&
atomic
,
1
);
rv
=
SDL_atomic_int_dec_test
(
&
atomic
);
if
(
SDL_atomic_int_get
(
&
atomic
)
!=
1
)
if
(
rv
!=
SDL_FALSE
||
SDL_atomic_int_get
(
&
atomic
)
!=
40
)
printf
(
"Error: "
);
printf
(
"Error: "
);
printf
(
"SDL_atomic_int_dec_test(atomic): rv-> %d, atomic-> %d
\n
"
,
rv
,
SDL_atomic_int_get
(
&
atomic
));
SDL_atomic_int_set
(
&
atomic
,
1
);
if
(
SDL_atomic_int_get
(
&
atomic
)
!=
1
)
printf
(
"Error: "
);
printf
(
"SDL_atomic_int_set(atomic, 1): atomic-> %d
\n
"
,
printf
(
"SDL_atomic_int_set(atomic, 1): atomic-> %d
\n
"
,
SDL_atomic_int_get
(
&
atomic
));
SDL_atomic_int_get
(
&
atomic
));
rv
=
SDL_atomic_int_dec_test
(
&
atomic
);
rv
=
SDL_atomic_int_dec_test
(
&
atomic
);
if
(
rv
!=
SDL_TRUE
||
SDL_atomic_int_get
(
&
atomic
)
!=
0
)
if
(
rv
!=
SDL_TRUE
||
SDL_atomic_int_get
(
&
atomic
)
!=
0
)
printf
(
"Error: "
);
printf
(
"Error: "
);
printf
(
"SDL_atomic_int_dec_test(atomic): rv-> %d, atomic-> %d
\n
"
,
printf
(
"SDL_atomic_int_dec_test(atomic): rv-> %d, atomic-> %d
\n
"
,
rv
,
SDL_atomic_int_get
(
&
atomic
));
rv
,
SDL_atomic_int_get
(
&
atomic
));
return
0
;
return
0
;
}
}
test/testpower.c
View file @
d03a7700
...
@@ -3,33 +3,33 @@
...
@@ -3,33 +3,33 @@
#include <stdio.h>
#include <stdio.h>
#include "SDL.h"
#include "SDL.h"
static
void
report_power
(
void
)
static
void
report_power
(
void
)
{
{
int
seconds
,
percent
;
int
seconds
,
percent
;
const
SDL_PowerState
state
=
SDL_GetPowerInfo
(
&
seconds
,
&
percent
);
const
SDL_PowerState
state
=
SDL_GetPowerInfo
(
&
seconds
,
&
percent
);
char
*
statestr
=
NULL
;
char
*
statestr
=
NULL
;
printf
(
"SDL-reported power info...
\n
"
);
printf
(
"SDL-reported power info...
\n
"
);
switch
(
state
)
switch
(
state
)
{
{
case
SDL_POWERSTATE_UNKNOWN
:
case
SDL_POWERSTATE_UNKNOWN
:
statestr
=
"Unknown"
;
statestr
=
"Unknown"
;
break
;
break
;
case
SDL_POWERSTATE_ON_BATTERY
:
case
SDL_POWERSTATE_ON_BATTERY
:
statestr
=
"On battery"
;
statestr
=
"On battery"
;
break
;
break
;
case
SDL_POWERSTATE_NO_BATTERY
:
case
SDL_POWERSTATE_NO_BATTERY
:
statestr
=
"No battery"
;
statestr
=
"No battery"
;
break
;
break
;
case
SDL_POWERSTATE_CHARGING
:
case
SDL_POWERSTATE_CHARGING
:
statestr
=
"Charging"
;
statestr
=
"Charging"
;
break
;
break
;
case
SDL_POWERSTATE_CHARGED
:
case
SDL_POWERSTATE_CHARGED
:
statestr
=
"Charged"
;
statestr
=
"Charged"
;
break
;
break
;
default:
default:
statestr
=
"!!API ERROR!!"
;
statestr
=
"!!API ERROR!!"
;
break
;
break
;
}
}
printf
(
"State: %s
\n
"
,
statestr
);
printf
(
"State: %s
\n
"
,
statestr
);
...
@@ -43,12 +43,14 @@ static void report_power(void)
...
@@ -43,12 +43,14 @@ static void report_power(void)
if
(
seconds
==
-
1
)
{
if
(
seconds
==
-
1
)
{
printf
(
"Time left: unknown
\n
"
);
printf
(
"Time left: unknown
\n
"
);
}
else
{
}
else
{
printf
(
"Time left: %d minutes, %d seconds
\n
"
,
(
int
)
(
seconds
/
60
),
(
int
)
(
seconds
%
60
));
printf
(
"Time left: %d minutes, %d seconds
\n
"
,
(
int
)
(
seconds
/
60
),
(
int
)
(
seconds
%
60
));
}
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
if
(
SDL_Init
(
SDL_INIT_VIDEO
)
==
-
1
)
{
if
(
SDL_Init
(
SDL_INIT_VIDEO
)
==
-
1
)
{
fprintf
(
stderr
,
"SDL_Init() failed: %s
\n
"
,
SDL_GetError
());
fprintf
(
stderr
,
"SDL_Init() failed: %s
\n
"
,
SDL_GetError
());
...
@@ -62,4 +64,3 @@ int main(int argc, char *argv[])
...
@@ -62,4 +64,3 @@ int main(int argc, char *argv[])
}
}
/* end of testpower.c ... */
/* end of testpower.c ... */
test/testsprite2.c
View file @
d03a7700
...
@@ -61,13 +61,15 @@ LoadSprite(char *file)
...
@@ -61,13 +61,15 @@ LoadSprite(char *file)
}
else
{
}
else
{
switch
(
temp
->
format
->
BitsPerPixel
)
{
switch
(
temp
->
format
->
BitsPerPixel
)
{
case
15
:
case
15
:
SDL_SetColorKey
(
temp
,
SDL_SRCCOLORKEY
,
(
*
(
Uint16
*
)
temp
->
pixels
)
&
0x00007FFF
);
SDL_SetColorKey
(
temp
,
SDL_SRCCOLORKEY
,
(
*
(
Uint16
*
)
temp
->
pixels
)
&
0x00007FFF
);
break
;
break
;
case
16
:
case
16
:
SDL_SetColorKey
(
temp
,
SDL_SRCCOLORKEY
,
*
(
Uint16
*
)
temp
->
pixels
);
SDL_SetColorKey
(
temp
,
SDL_SRCCOLORKEY
,
*
(
Uint16
*
)
temp
->
pixels
);
break
;
break
;
case
24
:
case
24
:
SDL_SetColorKey
(
temp
,
SDL_SRCCOLORKEY
,
(
*
(
Uint32
*
)
temp
->
pixels
)
&
0x00FFFFFF
);
SDL_SetColorKey
(
temp
,
SDL_SRCCOLORKEY
,
(
*
(
Uint32
*
)
temp
->
pixels
)
&
0x00FFFFFF
);
break
;
break
;
case
32
:
case
32
:
SDL_SetColorKey
(
temp
,
SDL_SRCCOLORKEY
,
*
(
Uint32
*
)
temp
->
pixels
);
SDL_SetColorKey
(
temp
,
SDL_SRCCOLORKEY
,
*
(
Uint32
*
)
temp
->
pixels
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment