Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Continue working on 2D support in Photon.
Browse files Browse the repository at this point in the history
  • Loading branch information
llmike committed Oct 12, 2009
1 parent edca9e2 commit e0eae59
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 11 deletions.
23 changes: 23 additions & 0 deletions src/video/photon/SDL_photon.c
Expand Up @@ -382,6 +382,7 @@ photon_videoinit(_THIS)
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;
Expand Down Expand Up @@ -425,6 +426,17 @@ photon_videoinit(_THIS)
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 */
Expand Down Expand Up @@ -749,6 +761,17 @@ photon_setdisplaymode(_THIS, SDL_DisplayMode * mode)
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;
}

Expand Down
5 changes: 5 additions & 0 deletions src/video/photon/SDL_photon.h
Expand Up @@ -67,6 +67,10 @@ typedef struct SDL_VideoData
/* 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;
Expand All @@ -78,6 +82,7 @@ typedef struct SDL_DisplayData
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 */
Expand Down
80 changes: 69 additions & 11 deletions src/video/photon/SDL_photon_render.c
Expand Up @@ -96,7 +96,7 @@ SDL_RenderDriver photon_renderdriver = {
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,
Expand Down Expand Up @@ -167,7 +167,7 @@ photon_createrenderer(SDL_Window * window, Uint32 flags)
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 */
Expand Down Expand Up @@ -214,7 +214,7 @@ photon_createrenderer(SDL_Window * window, Uint32 flags)
}
}

/* Create new graphics context */
/* Create new graphics context for the renderer */
if (rdata->gc==NULL)
{
rdata->gc=PgCreateGC(0);
Expand All @@ -225,6 +225,25 @@ photon_createrenderer(SDL_Window * window, Uint32 flags)
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;
}

Expand Down Expand Up @@ -347,11 +366,8 @@ static int _photon_recreate_surfaces(SDL_Renderer * renderer)
{
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)
{
Expand Down Expand Up @@ -634,13 +650,11 @@ photon_createtexture(SDL_Renderer * renderer, SDL_Texture * texture)
/* 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};
Expand Down Expand Up @@ -819,7 +833,46 @@ photon_settextureblendmode(SDL_Renderer * renderer, SDL_Texture * texture)
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;
}

Expand Down Expand Up @@ -937,7 +990,12 @@ static void
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
Expand Down

0 comments on commit e0eae59

Please sign in to comment.