changeset 3384:04af265172f9

Continue working on 2D support in Photon.
author Mike Gorchak <lestat@i.com.ua>
date Mon, 12 Oct 2009 08:21:43 +0000
parents 90935231e9b6
children 45d7f0f70b27
files src/video/photon/SDL_photon.c src/video/photon/SDL_photon.h src/video/photon/SDL_photon_render.c
diffstat 3 files changed, 97 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/photon/SDL_photon.c	Sun Oct 11 18:45:39 2009 +0000
+++ b/src/video/photon/SDL_photon.c	Mon Oct 12 08:21:43 2009 +0000
@@ -382,6 +382,7 @@
         didata->device_id = it;
 
         /* Query photon about graphics hardware caps and current video mode */
+        SDL_memset(&hwcaps, 0x00, sizeof(PgHWCaps_t));
         status = PgGetGraphicsHWCaps(&hwcaps);
         if (status != 0) {
             PhRect_t extent;
@@ -425,6 +426,17 @@
                 SDL_free(didata);
                 return -1;
             }
+
+            /* Get current video mode 2D capabilities */
+            didata->mode_2dcaps=0;
+            if ((modeinfo.mode_capabilities2 & PgVM_MODE_CAP2_ALPHA_BLEND)==PgVM_MODE_CAP2_ALPHA_BLEND)
+            {
+               didata->mode_2dcaps|=SDL_VIDEO_CAP_ALPHA_BLEND;
+            }
+            if ((modeinfo.mode_capabilities2 & PgVM_MODE_CAP2_SCALED_BLIT)==PgVM_MODE_CAP2_SCALED_BLIT)
+            {
+               didata->mode_2dcaps|=SDL_VIDEO_CAP_SCALED_BLIT;
+            }
         }
 
         /* Setup current desktop mode for SDL */
@@ -749,6 +761,17 @@
     didata->current_mode = *mode;
     didata->current_mode.refresh_rate = refresh_rate;
 
+    /* Get current video mode 2D capabilities */
+    didata->mode_2dcaps=0;
+    if ((modeinfo.mode_capabilities2 & PgVM_MODE_CAP2_ALPHA_BLEND)==PgVM_MODE_CAP2_ALPHA_BLEND)
+    {
+       didata->mode_2dcaps|=SDL_VIDEO_CAP_ALPHA_BLEND;
+    }
+    if ((modeinfo.mode_capabilities2 & PgVM_MODE_CAP2_SCALED_BLIT)==PgVM_MODE_CAP2_SCALED_BLIT)
+    {
+       didata->mode_2dcaps|=SDL_VIDEO_CAP_SCALED_BLIT;
+    }
+
     return 0;
 }
 
--- a/src/video/photon/SDL_photon.h	Sun Oct 11 18:45:39 2009 +0000
+++ b/src/video/photon/SDL_photon.h	Mon Oct 12 08:21:43 2009 +0000
@@ -67,6 +67,10 @@
 /* Maximum event message size with data payload */
 #define SDL_VIDEO_PHOTON_EVENT_SIZE 8192
 
+/* Current video mode graphics capabilities */
+#define SDL_VIDEO_CAP_ALPHA_BLEND 0x00000001
+#define SDL_VIDEO_CAP_SCALED_BLIT 0x00000002
+
 typedef struct SDL_DisplayData
 {
     uint32_t device_id;
@@ -78,6 +82,7 @@
     PhCursorDef_t *cursor;              /* Global cursor settings             */
     SDL_bool cursor_visible;            /* SDL_TRUE if cursor visible         */
     uint32_t cursor_size;               /* Cursor size in memory w/ structure */
+    uint32_t mode_2dcaps;               /* Current video mode 2D capabilities */
 #if defined(SDL_VIDEO_OPENGL_ES)
     gf_display_t display;               /* GF display handle                  */
     gf_display_info_t display_info;     /* GF display information             */
--- a/src/video/photon/SDL_photon_render.c	Sun Oct 11 18:45:39 2009 +0000
+++ b/src/video/photon/SDL_photon_render.c	Mon Oct 12 08:21:43 2009 +0000
@@ -96,7 +96,7 @@
       SDL_TEXTUREMODULATE_ALPHA),
      (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND),
      (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_SLOW |
-      SDL_TEXTURESCALEMODE_FAST | SDL_TEXTURESCALEMODE_BEST),
+      SDL_TEXTURESCALEMODE_FAST),
      10,
      {SDL_PIXELFORMAT_INDEX8,
       SDL_PIXELFORMAT_RGB555,
@@ -167,7 +167,7 @@
     if ((didata->caps & SDL_PHOTON_ACCELERATED) == SDL_PHOTON_ACCELERATED) {
         renderer->info.flags = SDL_RENDERER_ACCELERATED;
     } else {
-        renderer->info.flags &= ~(SDL_RENDERER_ACCELERATED);
+        renderer->info.flags = 0;
     }
 
     /* Check if upper level requested synchronization on vsync signal */
@@ -214,7 +214,7 @@
         }
     }
 
-    /* Create new graphics context */
+    /* Create new graphics context for the renderer */
     if (rdata->gc==NULL)
     {
        rdata->gc=PgCreateGC(0);
@@ -225,6 +225,25 @@
     renderer->info.num_texture_formats=1;
     renderer->info.texture_formats[0]=didata->current_mode.format;
 
+    /* Initialize surfaces */
+    _photon_recreate_surfaces(renderer);
+
+    /* Set current scale blitting capabilities */
+    if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_OFFSCREEN)
+    {
+       renderer->info.scale_modes=SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_SLOW;
+       if ((didata->mode_2dcaps & SDL_VIDEO_CAP_SCALED_BLIT)==SDL_VIDEO_CAP_SCALED_BLIT)
+       {
+          /* This video mode supports hardware scaling */
+          renderer->info.scale_modes|=SDL_TEXTURESCALEMODE_FAST;
+       }
+    }
+    else
+    {
+       /* PhImage blit functions do not support scaling */
+       renderer->info.scale_modes=SDL_TEXTURESCALEMODE_NONE;
+    }
+
     return renderer;
 }
 
@@ -347,11 +366,8 @@
                {
                   rdata->osurfaces[it]=PdCreateOffscreenContext(0, window->w, window->h,
                   Pg_OSC_MEM_LINEAR_ACCESSIBLE | Pg_OSC_MEM_PAGE_ALIGN |
-                  /* in case if 2D acceleration is not available use CPU optimized surfaces */
-                  Pg_OSC_MEM_HINT_CPU_READ | Pg_OSC_MEM_HINT_CPU_WRITE |
                   /* in case if 2D acceleration is available use it */
                   Pg_OSC_MEM_2D_WRITABLE | Pg_OSC_MEM_2D_READABLE);
-
                   /* If we can't create an offscreen surface, then fallback to software */
                   if (rdata->osurfaces[it]==NULL)
                   {
@@ -634,13 +650,11 @@
        /* Try to allocate offscreen memory first */
        tdata->osurface=PdCreateOffscreenContext(0, texture->w, texture->h,
                        Pg_OSC_MEM_LINEAR_ACCESSIBLE | Pg_OSC_MEM_PAGE_ALIGN |
-                       /* in case if 2D acceleration is not available use CPU optimized surfaces */
-                       Pg_OSC_MEM_HINT_CPU_READ | Pg_OSC_MEM_HINT_CPU_WRITE |
                        /* in case if 2D acceleration is available use it */
                        Pg_OSC_MEM_2D_WRITABLE | Pg_OSC_MEM_2D_READABLE);
     }
 
-    /* Check if offscreen allocation has been failed */
+    /* Check if offscreen allocation has been failed or not performed */
     if (tdata->osurface==NULL)
     {
        PhPoint_t translation={0, 0};
@@ -819,7 +833,46 @@
 static int
 photon_settexturescalemode(SDL_Renderer * renderer, SDL_Texture * texture)
 {
-   /* TODO */
+   SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
+
+   switch (texture->scaleMode)
+   {
+      case SDL_TEXTURESCALEMODE_NONE:
+           return 0;
+      case SDL_TEXTURESCALEMODE_FAST:
+           if ((renderer->info.scale_modes & SDL_TEXTURESCALEMODE_FAST)==SDL_TEXTURESCALEMODE_FAST)
+           {
+              return 0;
+           }
+           else
+           {
+              SDL_Unsupported();
+              texture->scaleMode = SDL_TEXTURESCALEMODE_FAST;
+              return -1;
+           }
+           break;
+      case SDL_TEXTURESCALEMODE_SLOW:
+           if ((renderer->info.scale_modes & SDL_TEXTURESCALEMODE_SLOW)==SDL_TEXTURESCALEMODE_SLOW)
+           {
+              return 0;
+           }
+           else
+           {
+              SDL_Unsupported();
+              texture->scaleMode = SDL_TEXTURESCALEMODE_SLOW;
+              return -1;
+           }
+           break;
+      case SDL_TEXTURESCALEMODE_BEST:
+           SDL_Unsupported();
+           texture->scaleMode = SDL_TEXTURESCALEMODE_SLOW;
+           return -1;
+      default:
+           SDL_Unsupported();
+           texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
+           return -1;
+   }
+
    return -1;
 }
 
@@ -937,7 +990,12 @@
 photon_dirtytexture(SDL_Renderer * renderer, SDL_Texture * texture,
                     int numrects, const SDL_Rect * rects)
 {
-   /* TODO */
+   /* Check, if it is not initialized */
+   if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN)
+   {
+       SDL_SetError("Photon: can't update dirty texture for OpenGL ES window");
+       return;
+   }
 }
 
 static int