Commits

Anonymous committed 55a0c40

Fix to video version check. Implement rest of testvidinfo

Comments (0)

Files changed (4)

 include unit/*.py
 include support/*.py
 include support/*.txt
-include doc/**
+recursive-include doc *
 include CHANGELOG
+exclude doc/*.tex
 
 def assert_version_compatible(name, since):
     '''Raises an exception if `since` is later than the loaded library.'''
-    if not version_compatible(version):
+    if not version_compatible(since):
         import SDL.error
         raise SDL.error.SDL_NotImplementedError, \
             '%s requires SDL version %s; currently using version %s' % \
 
     def __getattr__(self, name):
         if name == 'palette':
-            return self._palette.contents
+            if self._palette:
+                return self._palette.contents
+            return None
         raise AttributeError
 
     def __setattr__(self, attr, value):
     _fields_ = [('bitfield', c_uint),
                 ('video_mem', c_uint),
                 ('_vfmt', POINTER(SDL_PixelFormat)),
-                ('current_w', c_int),
-                ('current_h', c_int)]
+                ('_current_w', c_int),
+                ('_current_h', c_int)]
 
     def __getattr__(self, name):
         '''Retrieve bitfields as bool.  All bets are off about whether
         elif name == 'blit_fill':
             return self.bitfield & 0x8000 != 0
         elif name == 'vfmt':    # Dereference vfmt pointer.
-            return self._vfmt.contents
+            if self._vfmt:
+                return self._vfmt.contents
+            return None
         
         # current_w and current_h added in SDL 1.2.10
         if name in ('current_w', 'current_h'):
             SDL.dll.assert_version_compatible(name, (1,2,10))
+            return getattr(self, '_%s' % name)
         raise AttributeError, name
 
 

test/testvidinfo.py

     SDL_FillRect(screen, None, SDL_MapRGB(screen.format, 0, 0, 0))
     SDL_Flip(screen)
 
-    # while (SDL_PollEvent):
-    #   etc
+    while SDL_PollEvent():
+        if SDL_PollEventAndReturn().type == SDL_KEYDOWN:
+            return False
 
     bmp = SDL_LoadBMP(SAMPLE_BMP)
     print 'Running freshly loaded blit test: %dx%d at %d bpp, flags: ' % \
     SDL_FillRect(screen, None, SDL_MapRGB(screen.format, 0, 0, 0))
     SDL_Flip(screen)
 
-    # while (SDL_PollEvent):
-    #   etc
+    while SDL_PollEvent():
+        if SDL_PollEventAndReturn().type == SDL_KEYDOWN:
+            return False
 
     # run the colorkeyed blit test
     bmpcc = SDL_LoadBMP(SAMPLE_BMP)
     print 'Running freshly loaded cc blit test: %dx%d at %d bpp, flags: ' % \
         (bmpcc.w, bmpcc.h, bmpcc.format.BitsPerPixel)
-    # XXX should be reading bmpcc.pixels, but this is void_p at the moment.
-    SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, 0)
+    SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, bmpcc.pixels[0])
     PrintFlags(bmpcc.flags)
     print
     then = SDL_GetTicks()
     SDL_FillRect(screen, None, SDL_MapRGB(screen.format, 0, 0, 0))
     SDL_Flip(screen)
 
-    # while (SDL_PollEvent):
-    #   etc
+    while SDL_PollEvent():
+        if SDL_PollEventAndReturn().type == SDL_KEYDOWN:
+            return False
 
     # run the generic blit test 
     tmp = bmp
     SDL_FillRect(screen, None, SDL_MapRGB(screen.format, 0, 0, 0))
     SDL_Flip(screen)
 
-    # while (SDL_PollEvent):
-    #   etc
+    while SDL_PollEvent():
+        if SDL_PollEventAndReturn().type == SDL_KEYDOWN:
+            return False
 
     # run the colorkeyed blit test 
     tmp = bmpcc
     SDL_FillRect(screen, None, SDL_MapRGB(screen.format, 0, 0, 0))
     SDL_Flip(screen)
 
-    # while (SDL_PollEvent):
-    #   etc
+    while SDL_PollEvent():
+        if SDL_PollEventAndReturn().type == SDL_KEYDOWN:
+            return False
 
     # run the cc+alpha blit test only if screen bpp > 8
     if bmp.format.BitsPerPixel > 8:
         SDL_FreeSurface(bmpcc)
         bmpcc = SDL_LoadBMP(SAMPLE_BMP)
         SDL_SetAlpha(bmpcc, SDL_SRCALPHA, 85) # 85 - 33% alpha
-        # XXX cc color should be from pixel 
-        SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, 0)
+        SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, bmpcc.pixels[0])
         tmp = bmpcc
         bmpcc = SDL_DisplayFormat(bmpcc)
         SDL_FreeSurface(tmp)
     SDL_FreeSurface(bmpcc)
     SDL_FreeSurface(bmp)
 
-    # while (SDL_PollEvent):
-    #   etc
+    while SDL_PollEvent():
+        if SDL_PollEventAndReturn().type == SDL_KEYDOWN:
+            return False
+
+    return True
 
 def RunVideoTests():
     mode_list = [
         SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF]
 
     SDL_WM_SetCaption('SDL Video Benchmark', 'vidtest')
-    #SDL_ShowCursor(0)
+    SDL_ShowCursor(0)
     for mode in mode_list:
         for flags in flags_list:
             print '==================================='
                 PrintFlags(screen.flags)
                 print
                 continue
-            RunModeTests(screen)
+            if not RunModeTests(screen):
+                return
 
 if __name__ == '__main__':
     SDL_Init(SDL_INIT_VIDEO)
     print 'Video driver: %s' % SDL_VideoDriverName()
 
     info = SDL_GetVideoInfo()
-    print 'Current display: %dx%d, %d bits-per-pixel' % \
-        (info.current_w, info.current_h, info.vfmt.BitsPerPixel)
+    try:
+        print 'Current display: %dx%d, %d bits-per-pixel' % \
+            (info.current_w, info.current_h, info.vfmt.BitsPerPixel)
+    except:
+        print 'Current w and h not available (incompatible version)'
 
     if not info.vfmt.palette:
         print '    Red Mask = 0x%.8x' % info.vfmt.Rmask
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.