Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions gfxdrivers/gles2/gles2_2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,15 +450,18 @@ gles2_validate_COLORKEY(GLES2DriverData *gdrv,

D_DEBUG_AT(GLES2__2D, "%s()\n", __FUNCTION__);

/* convert RGB32 color values to int */
int r = (state->src_colorkey & 0x00FF0000) >> 16;
int g = (state->src_colorkey & 0x0000FF00) >> 8;
int b = (state->src_colorkey & 0x000000FF) ;
/* convert color values to int */
DFBColor colorkey;
DFBColor tolerance;
DFBSurfacePixelFormat format = state->source->config.format;
dfb_pixel_to_color(format, state->src_colorkey, &colorkey);
dfb_pixel_tolerance(format, &tolerance);

/* send converted color key to shader */
glUniform3i( prog->dfbColorkey, r, g, b );
glUniform3i( prog->dfbColorkey, colorkey.r, colorkey.g, colorkey.b );
glUniform3i( prog->dfbColorkeyTolerance, tolerance.r, tolerance.g, tolerance.b);

D_DEBUG_AT(GLES2__2D, " -> loaded colorkey %d %d %d\n", r, g, b);
D_DEBUG_AT(GLES2__2D, " -> loaded colorkey %d %d %d\n", colorkey.r, colorkey.g, colorkey.b);

// Set the flag.
GLES2_VALIDATE(COLORKEY);
Expand Down
1 change: 1 addition & 0 deletions gfxdrivers/gles2/gles2_gfxdriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ typedef struct {
GLint dfbMVPMatrix; // location of model-view-projection matrix
GLint dfbColor; // location of global RGBA color
GLint dfbColorkey; // location of colorkey RGB color
GLint dfbColorkeyTolerance; // location of colorkey RGB color tolerance
GLint dfbTexScale; // location of scale factors to normalized tex coords
GLint dfbSampler; // location of 2D texture sampler
char *name; // program object name for debugging
Expand Down
3 changes: 3 additions & 0 deletions gfxdrivers/gles2/gles2_shaders.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ gles2_init_shader_programs(GLES2DeviceData *dev)
dev->progs[i].dfbMVPMatrix = -1;
dev->progs[i].dfbColor = -1;
dev->progs[i].dfbColorkey = -1;
dev->progs[i].dfbColorkeyTolerance = -1;
dev->progs[i].dfbTexScale = -1;
dev->progs[i].dfbSampler = -1;
dev->progs[i].v_flags = 0;
Expand Down Expand Up @@ -325,6 +326,7 @@ gles2_init_shader_programs(GLES2DeviceData *dev)
GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY, dfbTexScale);
GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY, dfbSampler);
GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY, dfbColorkey);
GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY, dfbColorkeyTolerance);

// For now we always use texture unit 0 (GL_TEXTURE0).
glUniform1i(dev->progs[GLES2_BLIT_COLORKEY].dfbSampler, 0);
Expand All @@ -350,6 +352,7 @@ gles2_init_shader_programs(GLES2DeviceData *dev)
GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY_MAT, dfbTexScale);
GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY_MAT, dfbSampler);
GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY_MAT, dfbColorkey);
GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY_MAT, dfbColorkeyTolerance);

// For now we always use texture unit 0 (GL_TEXTURE0).
glUniform1i(dev->progs[GLES2_BLIT_COLORKEY_MAT].dfbSampler, 0);
Expand Down
14 changes: 9 additions & 5 deletions gfxdrivers/gles2/gles2_shaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,20 @@ static const char *blit_colorkey_frag_src = " \
uniform sampler2D dfbSampler; \
uniform "LOWP" vec4 dfbColor; \
uniform ivec3 dfbColorkey; \
uniform ivec3 dfbColorkeyTolerance; \
varying "LOWP" vec2 varTexCoord; \
\
ivec3 round_down(ivec3 x, ivec3 divisor) \
{ \
return (x / divisor) * divisor; \
} \
\
void main (void) \
{ \
"HIGHP" vec4 value = texture2D(dfbSampler, varTexCoord); \
\
int r = int(value.r*255.0+0.5); \
int g = int(value.g*255.0+0.5); \
int b = int(value.b*255.0+0.5); \
\
if (r == dfbColorkey.x && g == dfbColorkey.y && b == dfbColorkey.z) \
ivec3 color = ivec3(value.rgb * vec3(255.0) + vec3(0.5)); \
if (round_down(color, dfbColorkeyTolerance) == round_down(dfbColorkey, dfbColorkeyTolerance)) \
discard; \
\
gl_FragColor = value * dfbColor; \
Expand Down
2 changes: 2 additions & 0 deletions src/display/idirectfbsurface.c
Original file line number Diff line number Diff line change
Expand Up @@ -2574,6 +2574,8 @@ IDirectFBSurface_DrawString( IDirectFBSurface *thiz,
return ret;
}

D_ASSERT( num <= bytes );

/* Calculate string width. */
for (i=0; i<num; i++) {
unsigned int current = indices[i];
Expand Down
17 changes: 17 additions & 0 deletions src/gfx/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,23 @@ dfb_pixel_to_color( DFBSurfacePixelFormat format,
}
}

void
dfb_pixel_tolerance( DFBSurfacePixelFormat format,
DFBColor *tolerance )
{
switch (format) {
case DSPF_RGB16:
tolerance->r = 1<<(8-5);
tolerance->g = 1<<(8-6);
tolerance->b = 1<<(8-5);
break;
default:
tolerance->r = 1;
tolerance->g = 1;
tolerance->b = 1;
}
}

unsigned long
dfb_pixel_from_color( DFBSurfacePixelFormat format,
const DFBColor *color )
Expand Down
4 changes: 4 additions & 0 deletions src/gfx/convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ void dfb_pixel_to_color ( DFBSurfacePixelFormat format,
unsigned long pixel,
DFBColor *ret_color );

void dfb_pixel_tolerance ( DFBSurfacePixelFormat format,
DFBColor *ret_color );


unsigned long dfb_pixel_from_color( DFBSurfacePixelFormat format,
const DFBColor *color );

Expand Down
4 changes: 4 additions & 0 deletions src/media/idirectfbfont.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ IDirectFBFont_GetStringExtents( IDirectFBFont *thiz,
return ret;
}

D_ASSERT( num <= bytes );

for (i=0; i<num; i++) {
unsigned int current = indices[i];
CoreGlyphData *glyph;
Expand Down Expand Up @@ -428,6 +430,8 @@ IDirectFBFont_GetStringWidth( IDirectFBFont *thiz,
return ret;
}

D_ASSERT( num <= bytes );

/* Calculate string width. */
for (i=0; i<num; i++) {
unsigned int current = indices[i];
Expand Down
6 changes: 3 additions & 3 deletions src/misc/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ DFBResult dfb_config_set( const char *name, const char *value )
return DFB_INVARG;
}

if (id < 0 || id > D_ARRAY_SIZE(dfb_config->layers)) {
if (id < 0 || id >= D_ARRAY_SIZE(dfb_config->layers)) {
D_ERROR("DirectFB/Config '%s': ID %d out of bounds!\n", name, id);
return DFB_INVARG;
}
Expand Down Expand Up @@ -2455,7 +2455,7 @@ DFBResult dfb_config_init( int *argc, char *(*argv[]) )
DFBResult dfb_config_read( const char *filename )
{
DFBResult ret = DFB_OK;
char line[400];
char line[400+1];
FILE *f;

char *slash = 0;
Expand Down Expand Up @@ -2491,7 +2491,7 @@ DFBResult dfb_config_read( const char *filename )
}

/* must copy filename for path, due to const'ness */
char nwd[strlen(filename)];
char nwd[strlen(filename)+1];
strcpy( nwd, filename );
nwd[slash-filename] = 0;
if (chdir( nwd ))
Expand Down
1 change: 1 addition & 0 deletions systems/egl/egl_primary.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ primaryUpdateRegion( CoreLayer *layer,
if (left_update && !dfb_region_region_intersect( &region, left_update ))
return DFB_OK;

eglSurfaceAttrib(egl->eglDisplay, egl->eglSurface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED);
eglSwapBuffers(egl->eglDisplay, egl->eglSurface);


Expand Down
37 changes: 31 additions & 6 deletions systems/egl/egl_surface_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,22 @@ eglAllocateBuffer( CoreSurfacePool *pool,
return DFB_FAILURE;
}

glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->config.size.w, surface->config.size.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
switch (allocation->config.format) {
case DSPF_RGB32:
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->config.size.w, surface->config.size.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
case DSPF_ARGB:
glTexImage2D( GL_TEXTURE_2D, 0, GL_BGRA_EXT, surface->config.size.w, surface->config.size.h, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, NULL );
break;
case DSPF_RGB16:
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, surface->config.size.w, surface->config.size.h, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL );
break;
case DSPF_LUT8:
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->config.size.w, surface->config.size.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
break;
default:
D_ERROR( "DirectFB/EGL: glTexImage2D() unknown format %x\n" , allocation->config.format);
return DFB_UNSUPPORTED;
}

// glEGLImageTargetTexture2DOES( GL_TEXTURE_2D, alloc->eglImage );
if ((err = eglGetError()) != EGL_SUCCESS) {
Expand Down Expand Up @@ -752,11 +767,21 @@ fboWrite( CoreSurfacePool *pool,

glPixelStorei( GL_UNPACK_ALIGNMENT, 8 );

if (allocation->config.format == DSPF_ABGR) {
glTexSubImage2D(GL_TEXTURE_2D, 0, rect->x, rect->y, rect->w, rect->h, GL_RGBA, GL_UNSIGNED_BYTE, source);
}
else {
glTexSubImage2D(GL_TEXTURE_2D, 0, rect->x, rect->y, rect->w, rect->h, GL_BGRA_EXT, GL_UNSIGNED_BYTE, source);
switch (allocation->config.format)
{
case DSPF_ABGR:
glTexSubImage2D(GL_TEXTURE_2D, 0, rect->x, rect->y, rect->w, rect->h, GL_RGBA, GL_UNSIGNED_BYTE, source);
break;
case DSPF_ARGB:
glTexSubImage2D(GL_TEXTURE_2D, 0, rect->x, rect->y, rect->w, rect->h, GL_BGRA_EXT, GL_UNSIGNED_BYTE, source);
break;
case DSPF_RGB16:
glTexSubImage2D(GL_TEXTURE_2D, 0, rect->x, rect->y, rect->w, rect->h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, source);
break;
default:
D_ERROR( "DirectFB/RGL2D: glTexSubImage2D() unknown format %x\n", allocation->config.format );
return DFB_UNSUPPORTED;

}

if ((err = glGetError()) != 0) {
Expand Down
Loading