David Rose 17 years ago
parent
commit
01a068a222

+ 42 - 8
panda/src/tinydisplay/tinySDLGraphicsWindow.cxx

@@ -132,16 +132,31 @@ end_frame(FrameMode mode, Thread *current_thread) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void TinySDLGraphicsWindow::
 void TinySDLGraphicsWindow::
 begin_flip() {
 begin_flip() {
-  if (SDL_MUSTLOCK(_screen)) {
-    if (SDL_LockSurface(_screen) < 0) {
-      tinydisplay_cat.error()
-        << "Can't lock screen: " << SDL_GetError() << "\n";
+  int fb_xsize = get_fb_x_size();
+  int fb_ysize = get_fb_y_size();
+
+  if (fb_xsize == _frame_buffer->xsize) {
+    // No zooming is necessary--copy directly to the screen.
+    if (SDL_MUSTLOCK(_screen)) {
+      if (SDL_LockSurface(_screen) < 0) {
+        tinydisplay_cat.error()
+          << "Can't lock screen: " << SDL_GetError() << "\n";
+      }
+    }
+    ZB_copyFrameBuffer(_frame_buffer, _screen->pixels, _pitch);
+    
+    if (SDL_MUSTLOCK(_screen)) {
+      SDL_UnlockSurface(_screen); 
     }
     }
-  }
-  ZB_copyFrameBuffer(_frame_buffer, _screen->pixels, _pitch);
 
 
-  if (SDL_MUSTLOCK(_screen)) {
-    SDL_UnlockSurface(_screen); 
+  } else {
+    // Copy to another surface, then scale it onto the screen.
+    SDL_Surface *temp = 
+      SDL_CreateRGBSurfaceFrom(_frame_buffer->pbuf, _frame_buffer->xsize, _frame_buffer->ysize,
+                               32, _frame_buffer->linesize, 0xff0000, 0x00ff00, 0x0000ff, 0xff000000);
+    SDL_SetAlpha(temp, SDL_RLEACCEL, 0);
+    SDL_BlitSurface(temp, NULL, _screen, NULL);
+    SDL_FreeSurface(temp);
   }
   }
 
 
   SDL_Flip(_screen);
   SDL_Flip(_screen);
@@ -248,6 +263,25 @@ set_properties_now(WindowProperties &properties) {
   }
   }
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: TinySDLGraphicsWindow::supports_pixel_zoom
+//       Access: Published, Virtual
+//  Description: Returns true if a call to set_pixel_zoom() will be
+//               respected, false if it will be ignored.  If this
+//               returns false, then get_pixel_factor() will always
+//               return 1.0, regardless of what value you specify for
+//               set_pixel_zoom().
+//
+//               This may return false if the underlying renderer
+//               doesn't support pixel zooming, or if you have called
+//               this on a DisplayRegion that doesn't have both
+//               set_clear_color() and set_clear_depth() enabled.
+////////////////////////////////////////////////////////////////////
+bool TinySDLGraphicsWindow::
+supports_pixel_zoom() const {
+  return true;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: TinySDLGraphicsWindow::close_window
 //     Function: TinySDLGraphicsWindow::close_window
 //       Access: Protected, Virtual
 //       Access: Protected, Virtual

+ 2 - 0
panda/src/tinydisplay/tinySDLGraphicsWindow.h

@@ -51,6 +51,8 @@ public:
   virtual void process_events();
   virtual void process_events();
   virtual void set_properties_now(WindowProperties &properties);
   virtual void set_properties_now(WindowProperties &properties);
 
 
+  virtual bool supports_pixel_zoom() const;
+
 protected:
 protected:
   virtual void close_window();
   virtual void close_window();
   virtual bool open_window();
   virtual bool open_window();