void * MGLAPI PH_getDefaultPalette(MGLDC *dc) /**************************************************************************** * * Function: PH_getDefaultPalette * Parameters: dc - Device context. * Returns: Pointer to the default palette structure * * Description: Get the current system palette entries and store in a * static array. Then return this as the default palette. * ****************************************************************************/ { static palette_t palette[_Pg_MAX_PALETTE]; if (PgGetPalette((PgColor_t *)palette) != 0) return (NULL); else return (palette); }
int ph_SetupImage(_THIS, SDL_Surface *screen) { PgColor_t* palette=NULL; int type=0; int bpp; bpp=screen->format->BitsPerPixel; /* Determine image type */ switch(bpp) { case 8:{ type = Pg_IMAGE_PALETTE_BYTE; } break; case 15:{ type = Pg_IMAGE_DIRECT_555; } break; case 16:{ type = Pg_IMAGE_DIRECT_565; } break; case 24:{ type = Pg_IMAGE_DIRECT_888; } break; case 32:{ type = Pg_IMAGE_DIRECT_8888; } break; default:{ SDL_SetError("ph_SetupImage(): unsupported bpp=%d !\n", bpp); return -1; } break; } /* palette emulation code */ if ((bpp==8) && (desktoppal==SDLPH_PAL_EMULATE)) { /* creating image palette */ palette=malloc(_Pg_MAX_PALETTE*sizeof(PgColor_t)); if (palette==NULL) { SDL_SetError("ph_SetupImage(): can't allocate memory for palette !\n"); return -1; } PgGetPalette(palette); /* using shared memory for speed (set last param to 1) */ if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, palette, _Pg_MAX_PALETTE, 1)) == NULL) { SDL_SetError("ph_SetupImage(): PhCreateImage() failed for bpp=8 !\n"); free(palette); return -1; } } else { /* using shared memory for speed (set last param to 1) */ if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0, 1)) == NULL) { SDL_SetError("ph_SetupImage(): PhCreateImage() failed for bpp=%d !\n", bpp); return -1; } } screen->pixels = SDL_Image->image; screen->pitch = SDL_Image->bpl; this->UpdateRects = ph_NormalUpdate; return 0; }
int ph_SetupFullScreenImage(_THIS, SDL_Surface* screen) { OCImage.flags = screen->flags; /* Begin direct mode */ if (!ph_EnterFullScreen(this, screen)) { return -1; } /* store palette for fullscreen */ if ((screen->format->BitsPerPixel==8) && (desktopbpp!=8)) { PgGetPalette(savedpal); PgGetPalette(syspalph); } OCImage.offscreen_context = PdCreateOffscreenContext(0, 0, 0, Pg_OSC_MAIN_DISPLAY | Pg_OSC_MEM_PAGE_ALIGN | Pg_OSC_CRTC_SAFE); if (OCImage.offscreen_context == NULL) { SDL_SetError("ph_SetupFullScreenImage(): PdCreateOffscreenContext() function failed !\n"); return -1; } if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { OCImage.offscreen_backcontext = PdDupOffscreenContext(OCImage.offscreen_context, Pg_OSC_CRTC_SAFE | Pg_OSC_MEM_PAGE_ALIGN); if (OCImage.offscreen_backcontext == NULL) { SDL_SetError("ph_SetupFullScreenImage(): PdCreateOffscreenContext(back) function failed !\n"); return -1; } } OCImage.FrameData0 = (unsigned char *)PdGetOffscreenContextPtr(OCImage.offscreen_context); if (OCImage.FrameData0 == NULL) { SDL_SetError("ph_SetupFullScreenImage(): PdGetOffscreenContextPtr() function failed !\n"); ph_DestroyImage(this, screen); return -1; } if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { OCImage.FrameData1 = (unsigned char *)PdGetOffscreenContextPtr(OCImage.offscreen_backcontext); if (OCImage.FrameData1 == NULL) { SDL_SetError("ph_SetupFullScreenImage(back): PdGetOffscreenContextPtr() function failed !\n"); ph_DestroyImage(this, screen); return -1; } } /* wait for the hardware */ PgWaitHWIdle(); if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { OCImage.current = 1; PhDCSetCurrent(OCImage.offscreen_backcontext); screen->pitch = OCImage.offscreen_backcontext->pitch; screen->pixels = OCImage.FrameData1; PgSwapDisplay(OCImage.offscreen_context, 0); } else { OCImage.current = 0; PhDCSetCurrent(OCImage.offscreen_context); screen->pitch = OCImage.offscreen_context->pitch; screen->pixels = OCImage.FrameData0; } this->UpdateRects = ph_OCDCUpdate; PgFlush(); return 0; }
static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat) { PgHWCaps_t my_hwcaps; int i; window=NULL; desktoppal=SDLPH_PAL_NONE; #ifdef HAVE_OPENGL oglctx=NULL; oglflags=0; oglbpp=0; #endif /* HAVE_OPENGL */ old_video_mode=-1; old_refresh_rate=-1; if (NULL == (event = malloc(EVENT_SIZE))) { SDL_OutOfMemory(); return -1; } memset(event, 0x00, EVENT_SIZE); window = ph_CreateWindow(this); if (window == NULL) { SDL_SetError("ph_VideoInit(): Couldn't create video window !\n"); return -1; } /* Create the blank cursor */ SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask, (int)BLANK_CWIDTH, (int)BLANK_CHEIGHT, (int)BLANK_CHOTX, (int)BLANK_CHOTY); if (SDL_BlankCursor == NULL) { return -1; } if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) { SDL_SetError("ph_VideoInit(): GetGraphicsHWCaps function failed !\n"); this->FreeWMCursor(this, SDL_BlankCursor); return -1; } if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &desktop_mode) < 0) { SDL_SetError("ph_VideoInit(): PgGetVideoModeInfo function failed !\n"); this->FreeWMCursor(this, SDL_BlankCursor); return -1; } /* We need to return BytesPerPixel as it in used by CreateRGBsurface */ vformat->BitsPerPixel = desktop_mode.bits_per_pixel; vformat->BytesPerPixel = desktop_mode.bytes_per_scanline/desktop_mode.width; desktopbpp = desktop_mode.bits_per_pixel; /* save current palette */ if (desktopbpp==8) { PgGetPalette(savedpal); PgGetPalette(syspalph); } else { for(i=0; i<_Pg_MAX_PALETTE; i++) { savedpal[i]=PgRGB(0, 0, 0); syspalph[i]=PgRGB(0, 0, 0); } } currently_fullscreen = 0; currently_hided = 0; current_overlay = NULL; OCImage.direct_context = NULL; OCImage.offscreen_context = NULL; OCImage.offscreen_backcontext = NULL; OCImage.oldDC = NULL; OCImage.CurrentFrameData = NULL; OCImage.FrameData0 = NULL; OCImage.FrameData1 = NULL; this->info.wm_available = 1; return 0; }