Skip to content

Instantly share code, notes, and snippets.

@chenzx
Created March 7, 2013 06:11
Show Gist options
  • Save chenzx/5105896 to your computer and use it in GitHub Desktop.
Save chenzx/5105896 to your computer and use it in GitHub Desktop.
Convert EA::Raster::ISurface*'s partly update (Code from EAWebKit-1.21) to SDL_Surface
static SDL_Surface * convert_EAISurface_to_SDLSurface(SDL_Surface * screen, EA::Raster::ISurface* easurface, int x, int y, int w, int h){
int stride = easurface->GetStride();
typedef uint8_t Uint8;
Uint8 *bits = (Uint8*)easurface->GetData() + y*stride + x*4;
//The following code is mainly from "D:\SDL-1.2.15\test\testbitmap.c"(18,14):SDL_Surface *LoadXBM(SDL_Surface *screen, int w, int h, Uint8 *bits)
SDL_Surface *bitmap;
Uint8 *line;
/* Allocate the bitmap */
bitmap = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0);
if ( bitmap == NULL ) {
fprintf(stderr, "Couldn't allocate bitmap: %s\n",
SDL_GetError());
return(NULL);
}
/* Copy the pixels */
line = (Uint8 *)bitmap->pixels;
while ( h-- ) {
memcpy(line, bits, w*4);
line += bitmap->pitch;
bits += stride;
}
return(bitmap);
}
//Outside caller:
void doViewUpdateRepaint(EA::Raster::ISurface* EAsurface, EA::WebKit::ViewUpdateInfo& view_update_info, SDL_Surface* SDLsurface){
if( view_update_info.mDrawEvent == EA::WebKit::ViewUpdateInfo::kViewDrawEnd )
return;
int x = view_update_info.mX;
int y = view_update_info.mY;
int w = view_update_info.mW;
int h = view_update_info.mH;
SDL_Surface* bitmap = convert_EAISurface_to_SDLSurface(SDLsurface, EAsurface, x, y, w, h);
SDL_Rect dst;
dst.x = x;
dst.y = y;
dst.w = w;
dst.h = h;
SDL_BlitSurface(bitmap, NULL, SDLsurface, &dst);
SDL_FreeSurface(bitmap);
SDL_Flip(SDLsurface);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment