SDL_Surface *CELL_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { /* Copy the video size into the device */ this->hidden->VideoMode.Width = width; this->hidden->VideoMode.Height = height; /* Update PSGL settings */ if(0 > CELL_PSGL_SetMode(this, current)) { /* PSGL Update failed */ return 0; } /* Allocate the new pixel format for the screen */ if(!SDL_ReallocFormat(current, 32, 0, 0, 0, 0)) { SDL_SetError("Couldn't allocate new pixel format for requested mode"); return 0; } /* Set up the new mode framebuffer */ /* TODO: What should we really return in flags? SDL_NOFRAME | SDL_FULLSCREEN | SDL_ASYNCBLIT ?*/ current->flags = flags | SDL_HWSURFACE; current->w = width; current->h = height; current->pitch = current->w * 4; current->pixels = 0; /* We're done */ return(current); }
SDL_Surface *DUMMY_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { if ( this->hidden->buffer ) { SDL_free( this->hidden->buffer ); } this->hidden->buffer = SDL_malloc(width * height * (bpp / 8)); if ( ! this->hidden->buffer ) { SDL_SetError("Couldn't allocate buffer for requested mode"); return(NULL); } /* printf("Setting mode %dx%d\n", width, height); */ SDL_memset(this->hidden->buffer, 0, width * height * (bpp / 8)); /* Allocate the new pixel format for the screen */ if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) { SDL_free(this->hidden->buffer); this->hidden->buffer = NULL; SDL_SetError("Couldn't allocate new pixel format for requested mode"); return(NULL); } /* Set up the new mode framebuffer */ current->flags = flags & SDL_FULLSCREEN; this->hidden->w = current->w = width; this->hidden->h = current->h = height; current->pitch = current->w * (bpp / 8); current->pixels = this->hidden->buffer; /* We're done */ return(current); }
static SDL_Surface *OHQ_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { if (flags & SDL_OPENGL) { OHQ_SwitchOff(this); return current_video->SetVideoMode(current_video,current,width,height,bpp,flags); } SDL_UnlockCursor(); SendSyncCommand(this,OGL_NONE); filter_video = current_video; SAVE_VIDEO; if (!SendSyncCommand(this,OGL_DEINIT)) return NULL; if (this->hidden->surface == NULL) { this->hidden->surface = malloc(sizeof(*current)); SDL_memcpy((SDL_Surface *)this->hidden->surface,current,sizeof(*current)); } flags &= ~(SDL_HWPALETTE|SDL_HWSURFACE|SDL_ASYNCBLIT); // some video drivers can't handle odd widths properly width = (width+1)&~1; this->hidden->width = width; this->hidden->height = height; this->hidden->flags = flags; if (getenv("SDL_OPENGLHQ_DOUBLEBUF")) { if (getenv("SDL_OPENGLHQ_DOUBLEBUF")[0] == '1') this->hidden->flags |= SDL_DOUBLEBUF; else this->hidden->flags &= ~(SDL_DOUBLEBUF); } this->hidden->bpp = bpp; this->hidden->postponed = 0; if (!SendSyncCommand(this,OGL_INIT)) return NULL; if (OHQ_NextMouseFilter == (void *)-1) { OHQ_NextMouseFilter = SDL_MouseFilter; SDL_MouseFilter = OHQ_MouseFilter; } bpp = this->hidden->bpp; if (!SDL_ReallocFormat(current, bpp, (bpp==32?0xff0000:bpp==16?0xf800:0x7c00), (bpp==32?0xff00:bpp==16?0x7e0:0x3e0), (bpp==32?0xff:0x1f), 0)) { return NULL; } current->w = this->hidden->width; current->h = this->hidden->height; current->pitch = this->hidden->pitch; current->flags = flags|SDL_PREALLOC; if (bpp == 8) current->flags |= SDL_HWPALETTE; current->pixels = this->hidden->framebuf; this->input_grab = this->hidden->real_video->input_grab; this->hidden->clip.x = 0; this->hidden->clip.y = 0; this->hidden->clip.w = current->w; this->hidden->clip.h = current->h; RESTORE_VIDEO; return current; }
SDL_Surface *ANDROID_SetVideoMode( _THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { if (memBuffer1) SDL_free(memBuffer1); if (memBuffer2) SDL_free(memBuffer2); memX = width; memY = height; memBuffer1 = SDL_malloc(memX * memY * (bpp / 8)); if (!memBuffer1) { SDL_SetError("Couldn't allocate buffer for requested mode"); return (NULL); } SDL_memset(memBuffer1, 0, memX * memY * (bpp / 8)); if (flags & SDL_DOUBLEBUF) { memBuffer2 = SDL_malloc(memX * memY * (bpp / 8)); if (!memBuffer2) { SDL_SetError("Couldn't allocate buffer for requested mode"); return (NULL); } SDL_memset(memBuffer2, 0, memX * memY * (bpp / 8)); } memBuffer = memBuffer1; openglInitialized = GL_State_Init; /* Allocate the new pixel format for the screen */ if (!SDL_ReallocFormat(current, bpp, 0, 0, 0, 0)) { SDL_free(memBuffer); memBuffer = NULL; SDL_SetError("Couldn't allocate new pixel format for requested mode"); return (NULL); } /* Set up the new mode framebuffer */ current->flags = SDL_FULLSCREEN; //(flags & SDL_FULLSCREEN) | (flags & SDL_DOUBLEBUF); current->w = width; current->h = height; current->pitch = memX * (bpp / 8); current->pixels = memBuffer; /* Wait 'till we can draw */ ANDROID_FlipHWSurface(this, current); /* We're done */ return (current); }
static SDL_Surface *iPod_SetVideoMode (_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { Uint32 Rmask, Gmask, Bmask; if (bpp > 8) { Rmask = 0xF800; Gmask = 0x07E0; Bmask = 0x001F; } else { Rmask = Gmask = Bmask = 0; } if (this->hidden->buffer) SDL_free (this->hidden->buffer); this->hidden->buffer = SDL_malloc (width * height * (bpp / 8)); if (!this->hidden->buffer) { SDL_SetError ("Couldn't allocate buffer for requested mode"); return 0; } memset (this->hidden->buffer, 0, width * height * (bpp / 8)); if (!SDL_ReallocFormat (current, bpp, Rmask, Gmask, Bmask, 0)) { SDL_SetError ("Couldn't allocate new pixel format"); SDL_free (this->hidden->buffer); this->hidden->buffer = 0; return 0; } if (bpp <= 8) { int i, j; for (i = 0; i < 256; i += 4) { for (j = 0; j < 4; j++) { current->format->palette->colors[i+j].r = 85 * j; current->format->palette->colors[i+j].g = 85 * j; current->format->palette->colors[i+j].b = 85 * j; } } } current->flags = flags & SDL_FULLSCREEN; this->hidden->w = current->w = width; this->hidden->h = current->h = height; current->pitch = current->w * (bpp / 8); current->pixels = this->hidden->buffer; return current; }
SDL_Surface *AA_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { int mode; if ( AA_buffer ) { SDL_free( AA_buffer ); } AA_buffer = SDL_malloc(width * height); if ( ! AA_buffer ) { SDL_SetError("Couldn't allocate buffer for requested mode"); return(NULL); } /* printf("Setting mode %dx%d\n", width, height); */ SDL_memset(aa_image(AA_context), 0, aa_imgwidth(AA_context) * aa_imgheight(AA_context)); SDL_memset(AA_buffer, 0, width * height); /* Allocate the new pixel format for the screen */ if ( ! SDL_ReallocFormat(current, 8, 0, 0, 0, 0) ) { return(NULL); } /* Set up the new mode framebuffer */ current->flags = SDL_FULLSCREEN; AA_w = current->w = width; AA_h = current->h = height; current->pitch = current->w; current->pixels = AA_buffer; AA_x_ratio = ((double)aa_imgwidth(AA_context)) / ((double)width); AA_y_ratio = ((double)aa_imgheight(AA_context)) / ((double)height); /* Set the blit function */ this->UpdateRects = AA_DirectUpdate; /* We're done */ return(current); }
SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { _kernel_swi_regs regs; Uint32 Rmask = 0; Uint32 Gmask = 0; Uint32 Bmask = 0; int create_back_buffer = riscos_backbuffer; switch(bpp) { case 8: flags |= SDL_HWPALETTE; break; case 15: case 16: Bmask = 0x00007c00; Gmask = 0x000003e0; Rmask = 0x0000001f; break; case 32: Bmask = 0x00ff0000; Gmask = 0x0000ff00; Rmask = 0x000000ff; break; default: SDL_SetError("Pixel depth not supported"); return NULL; break; } if (FULLSCREEN_SetMode(width, height, bpp) == 0) { SDL_SetError("Couldn't set requested mode"); return (NULL); } if ( ! SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0) ) { RISCOS_RestoreWimpMode(); SDL_SetError("Couldn't allocate new pixel format for requested mode"); return(NULL); } current->w = width; this->hidden->height = current->h = height; regs.r[0] = -1; regs.r[1] = 6; _kernel_swi(OS_ReadModeVariable, ®s, ®s); current->pitch = regs.r[2]; if (flags & SDL_DOUBLEBUF) { regs.r[0] = 2; _kernel_swi(OS_ReadDynamicArea, ®s, ®s); regs.r[0] = 2; regs.r[1] = (current->pitch * height * 2) - regs.r[1]; if (_kernel_swi(OS_ChangeDynamicArea, ®s, ®s) != NULL) { flags &= ~SDL_DOUBLEBUF; } } current->flags = flags | SDL_FULLSCREEN | SDL_HWSURFACE | SDL_PREALLOC; if (flags & SDL_DOUBLEBUF) { FULLSCREEN_SetWriteBank(0); FULLSCREEN_SetDisplayBank(1); create_back_buffer = 0; } FULLSCREEN_SetupBanks(this); if (create_back_buffer) { if (riscos_backbuffer == 3) this->hidden->bank[0] = WIMP_CreateBuffer(width, height, bpp); else this->hidden->bank[0] = SDL_malloc(height * current->pitch); if (this->hidden->bank[0] == 0) { RISCOS_RestoreWimpMode(); SDL_SetError("Couldnt allocate memory for back buffer"); return (NULL); } current->flags &= ~SDL_HWSURFACE; } if (this->hidden->alloc_bank) SDL_free(this->hidden->alloc_bank); if (create_back_buffer) { this->hidden->alloc_bank = this->hidden->bank[0]; if (riscos_backbuffer == 3) { this->hidden->bank[0] += 60; if (bpp == 8) this->hidden->bank[0] += 2048; } } else this->hidden->alloc_bank = 0; SDL_memset(this->hidden->bank[0], 0, height * current->pitch); SDL_memset(this->hidden->bank[1], 0, height * current->pitch); this->hidden->current_bank = 0; current->pixels = this->hidden->bank[0]; this->screen = current; FULLSCREEN_SetDeviceMode(this); return(current); }
static SDL_Surface *PS3_SetVideoMode(_THIS, SDL_Surface * current, int width, int height, int bpp, Uint32 flags) { s_bounded_input_width = width < s_writeable_width ? width : s_writeable_width; s_bounded_input_height = height < s_writeable_height ? height : s_writeable_height; s_bounded_input_width_offset = (s_writeable_width - s_bounded_input_width) >> 1; s_bounded_input_height_offset = (s_writeable_height - s_bounded_input_height) >> 1; s_input_line_length = width * s_fb_pixel_size; current->flags |= flags; if (ioctl(fb_dev_fd, FBIOGET_FSCREENINFO, &fb_finfo)) { SDL_SetError("[PS3] Can't get fixed screeninfo"); return NULL; } if (fb_finfo.type != FB_TYPE_PACKED_PIXELS) { SDL_SetError("[PS3] type %s not supported", fb_finfo.type); return NULL; } if ((frame_buffer = (uint8_t *) mmap(0, fb_finfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb_dev_fd, 0)) == (uint8_t *) - 1) { SDL_SetError("[PS3] Can't mmap for %s", PS3_DEV_FB); return NULL; } else { current->flags |= SDL_DOUBLEBUF; } if (!SDL_ReallocFormat(current, fb_bits_per_pixel, 0, 0, 0, 0)) { return (NULL); } memset(frame_buffer, 0x00, fb_finfo.smem_len); s_center[0] = frame_buffer + s_bounded_input_width_offset * s_fb_pixel_size + s_bounded_input_height_offset * fb_finfo.line_length; s_center[1] = s_center[0] + real_height * fb_finfo.line_length; s_center_index = 0; current->flags |= SDL_FULLSCREEN; current->w = width; current->h = height; current->pitch = SDL_CalculatePitch(current); s_pixels = memalign(16, current->h * current->pitch); current->pixels = (void *)s_pixels; if (!current->pixels) { SDL_OutOfMemory(); return NULL; } this->UpdateRects = PS3_DoubleBufferUpdate; return current; }
SDL_Surface *VGL_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { int mode_found; int i; VGLMode **modes; modes = VGLListModes(bpp, V_INFO_MM_DIRECT | V_INFO_MM_PACKED); mode_found = 0; for (i = 0; modes[i] != NULL; i++) { if ((modes[i]->ModeInfo.Xsize == width) && (modes[i]->ModeInfo.Ysize == height) && ((modes[i]->ModeInfo.Type == VIDBUF8) || (modes[i]->ModeInfo.Type == VIDBUF16) || (modes[i]->ModeInfo.Type == VIDBUF32))) { mode_found = 1; break; } } if (mode_found == 0) { SDL_SetError("No matching video mode found"); return NULL; } if (VGLCurMode != NULL) VGLEnd(); if (VGLInit(modes[i]->ModeId) != 0) { SDL_SetError("Unable to switch to requested mode"); return NULL; } VGLCurMode = SDL_realloc(VGLCurMode, sizeof(VGLMode)); VGLCurMode->ModeInfo = *VGLDisplay; VGLCurMode->Depth = modes[i]->Depth; VGLCurMode->ModeId = modes[i]->ModeId; VGLCurMode->Rmask = modes[i]->Rmask; VGLCurMode->Gmask = modes[i]->Gmask; VGLCurMode->Bmask = modes[i]->Bmask; if (VGLCurMode->ModeInfo.PixelBytes == 0) (VGLCurMode->ModeInfo.PixelBytes = 1); current->w = VGLCurMode->ModeInfo.Xsize; current->h = VGLCurMode->ModeInfo.Ysize; current->pixels = VGLCurMode->ModeInfo.Bitmap; current->pitch = VGLCurMode->ModeInfo.Xsize * VGLCurMode->ModeInfo.PixelBytes; current->flags = (SDL_FULLSCREEN | SDL_HWSURFACE); if (VGLCurMode->ModeInfo.Type == VIDBUF8) current->flags |= SDL_HWPALETTE; if (flags & SDL_DOUBLEBUF) { if (VGLCurMode->ModeInfo.Xsize * 2 <= VGLCurMode->ModeInfo.VYsize) { current->flags |= SDL_DOUBLEBUF; flip_page = 0; flip_address[0] = (byte *)current->pixels; flip_address[1] = (byte *)current->pixels + current->h * current->pitch; VGL_FlipHWSurface(this, current); } } if (! SDL_ReallocFormat(current, modes[i]->Depth, VGLCurMode->Rmask, VGLCurMode->Gmask, VGLCurMode->Bmask, 0)) { return NULL; } VGL_UpdateVideoInfo(this); this->UpdateRects = VGL_DirectUpdate; return current; }
static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { const struct ColourMasks* mask; /* Lock the event thread, in multi-threading environments */ SDL_Lock_EventThread(); current->flags = flags; /* if we do not have desired fullscreen mode, then fallback into window mode */ if (((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && (ph_GetVideoMode(width, height, bpp)==0)) { current->flags &= ~SDL_FULLSCREEN; current->flags &= ~SDL_NOFRAME; current->flags &= ~SDL_RESIZABLE; } ph_SetupWindow(this, width, height, current->flags); mask = ph_GetColourMasks(bpp); if (mask != NULL) { SDL_ReallocFormat(current, mask->bpp, mask->red, mask->green, mask->blue, 0); } else { SDL_SetError("ph_SetVideoMode(): desired bpp is not supported by photon !\n"); return NULL; } #ifdef HAVE_OPENGL if ((current->flags & SDL_OPENGL)==SDL_OPENGL) { #else if ((current->flags & SDL_OPENGL)==SDL_OPENGL) /* if no built-in OpenGL support */ { SDL_SetError("ph_SetVideoMode(): no OpenGL support, try to recompile library.\n"); current->flags &= ~SDL_OPENGL; return NULL; #endif /* HAVE_OPENGL */ } else { /* Initialize internal variables */ if ((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { if (bpp==8) { desktoppal=SDLPH_PAL_SYSTEM; } current->flags &= ~SDL_RESIZABLE; /* no resize for Direct Context */ current->flags |= SDL_HWSURFACE; } else { /* remove this if we'll support non-fullscreen sw/hw+doublebuf */ current->flags &= ~SDL_DOUBLEBUF; /* Use offscreen memory if SDL_HWSURFACE flag is set */ if ((current->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { if (desktopbpp!=bpp) { current->flags &= ~SDL_HWSURFACE; } } /* using palette emulation code in window mode */ if (bpp==8) { if (desktopbpp>=15) { desktoppal = SDLPH_PAL_EMULATE; } else { desktoppal = SDLPH_PAL_SYSTEM; } } else { desktoppal = SDLPH_PAL_NONE; } } } current->w = width; current->h = height; if (desktoppal==SDLPH_PAL_SYSTEM) { current->flags|=SDL_HWPALETTE; } /* Must call at least once for setup image planes */ if (ph_SetupUpdateFunction(this, current, current->flags)==-1) { return NULL; } /* finish window drawing, if we are not in fullscreen, of course */ if ((current->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) { PtFlush(); } else { PgFlush(); } SDL_Unlock_EventThread(); /* We're done! */ return (current); } static void ph_VideoQuit(_THIS) { /* restore palette */ if (desktopbpp==8) { PgSetPalette(syspalph, 0, -1, 0, 0, 0); PgSetPalette(savedpal, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0); PgFlush(); } ph_DestroyImage(this, SDL_VideoSurface); if (window) { PtUnrealizeWidget(window); PtDestroyWidget(window); window=NULL; } if (event!=NULL) { free(event); event=NULL; } } static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) { int i; SDL_Rect updaterect; updaterect.x = updaterect.y = 0; updaterect.w = this->screen->w; updaterect.h = this->screen->h; /* palette emulation code, using palette of the PhImage_t struct */ if (desktoppal==SDLPH_PAL_EMULATE) { if ((SDL_Image) && (SDL_Image->palette)) { for (i=firstcolor; i<firstcolor+ncolors; i++) { syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b); SDL_Image->palette[i] = syspalph[i]; } /* image needs to be redrawn */ this->UpdateRects(this, 1, &updaterect); } } else { if (desktoppal==SDLPH_PAL_SYSTEM) { for (i=firstcolor; i<firstcolor+ncolors; i++) { syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b); } if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) { /* window mode must use soft palette */ PgSetPalette(&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0); /* image needs to be redrawn */ this->UpdateRects(this, 1, &updaterect); } else { /* fullscreen mode must use hardware palette */ PgSetPalette(&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0); } } else { /* SDLPH_PAL_NONE do nothing */ } } return 1; }
SDL_Surface *AND_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { int req_orientation=width<height; int our_orientation=vinfo.xres<vinfo.yres; if ( mapped_mem==0 ) { SDL_SetError("Video memory is not mapped!"); return 0; } bpp=vinfo.bits_per_pixel; // let SDL emulate other bit depths for us if(AND_UseDirectFB==0 && this->hidden->buffer ) SDL_free( this->hidden->buffer ); // Determine - should we return direct ptr to vmem or not AND_UseDirectFB = req_orientation==our_orientation; if(width>vinfo.xres || height>vinfo.yres) AND_UseDirectFB=0; if(! (width*2<vinfo.xres && height*2<vinfo.yres)) // would use optimized pixel-doubled mode AND_UseDirectFB=0; if((flags&SDL_HWSURFACE) == 0) AND_UseDirectFB=0; if(AND_UseDirectFB) this->hidden->buffer = mapped_mem; else this->hidden->buffer = SDL_malloc(width * height * (bpp / 8)); if ( ! this->hidden->buffer ) { SDL_SetError("Couldn't allocate buffer for requested mode"); return(NULL); } /* printf("Setting mode %dx%d\n", width, height); */ SDL_memset(this->hidden->buffer, 0, width * height * (bpp / 8)); /* Allocate the new pixel format for the screen */ if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) { SDL_free(this->hidden->buffer); this->hidden->buffer = NULL; SDL_SetError("Couldn't allocate new pixel format for requested mode"); return(NULL); } /* Set up the new mode framebuffer */ current->flags = flags & SDL_FULLSCREEN; this->hidden->w = current->w = width; this->hidden->h = current->h = height; if(AND_UseDirectFB) current->pitch = finfo.line_length; else current->pitch = current->w * (bpp / 8); this->hidden->pitch = current->pitch; current->pixels = this->hidden->buffer; /* We're done */ return(current); }
SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { int mode; int vgamode; vga_modeinfo *modeinfo; int screenpage_len; /* Try to set the requested linear video mode */ bpp = (bpp+7)/8-1; for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) { if ( (SDL_modelist[bpp][mode]->w == width) && (SDL_modelist[bpp][mode]->h == height) ) { break; } } if ( SDL_modelist[bpp][mode] == NULL ) { SDL_SetError("Couldn't find requested mode in list"); return(NULL); } vga_setmode(SDL_vgamode[bpp][mode]); vga_setpage(0); vgamode=SDL_vgamode[bpp][mode]; if ((vga_setlinearaddressing()<0) && (vgamode!=G320x200x256)) { SDL_SetError("Unable to set linear addressing"); return(NULL); } modeinfo = vga_getmodeinfo(SDL_vgamode[bpp][mode]); /* Update hardware acceleration info */ SVGA_UpdateVideoInfo(this); /* Allocate the new pixel format for the screen */ bpp = (bpp+1)*8; if ( (bpp == 16) && (modeinfo->colors == 32768) ) { bpp = 15; } if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) { return(NULL); } /* Set up the new mode framebuffer */ current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE); if ( bpp == 8 ) { /* FIXME: What about DirectColor? */ current->flags |= SDL_HWPALETTE; } current->w = width; current->h = height; current->pitch = modeinfo->linewidth; current->pixels = vga_getgraphmem(); /* set double-buffering */ if ( flags & SDL_DOUBLEBUF ) { /* length of one screen page in bytes */ screenpage_len=current->h*modeinfo->linewidth; /* if start address should be aligned */ if ( modeinfo->linewidth_unit ) { if ( screenpage_len % modeinfo->linewidth_unit ) { screenpage_len += modeinfo->linewidth_unit - ( screenpage_len % modeinfo->linewidth_unit ); } } /* if we heve enough videomemory = ak je dost videopamete */ if ( modeinfo->memory > ( screenpage_len * 2 / 1024 ) ) { current->flags |= SDL_DOUBLEBUF; flip_page = 0; flip_offset[0] = 0; flip_offset[1] = screenpage_len; flip_address[0] = vga_getgraphmem(); flip_address[1] = flip_address[0]+screenpage_len; SVGA_FlipHWSurface(this,current); } } /* Set the blit function */ this->UpdateRects = SVGA_DirectUpdate; /* Set up the mouse handler again (buggy SVGAlib 1.40) */ mouse_seteventhandler(SVGA_mousecallback); /* We're done */ return(current); }
static SDL_Surface *PZM_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { Uint32 rmask = 0, gmask = 0, bmask = 0; width = ( width > SCREEN_WIDTH ) ? SCREEN_WIDTH : width; height = ( height > SCREEN_HEIGHT ) ? SCREEN_HEIGHT : height; bpp = ( bpp < 16 ) ? 8 : 16; PZM_DPRINT("Initializing display (%dx%dx%d)", width, height, bpp); this->info.current_w = width; this->info.current_h = height; if ( width < SCREEN_WIDTH || height < SCREEN_HEIGHT ) { int offset_x = (SCREEN_WIDTH - width) / 2; int offset_y = (SCREEN_HEIGHT - height) / 2; /*this->hidden->offset = this->hidden->cx ? (int)PZM_PIXEL_ADDR(0, offset_x, offset_y, 2 * SCREEN_WIDTH, 2) : (int)PZM_PIXEL_ADDR(0, offset_x / 2, offset_y, SCREEN_WIDTH / 2, 1); this->hidden->offset_x = offset_x; memset(VRAM, 0, SCREEN_BYTES_SIZE); } else this->hidden->offset = this->hidden->offset_x = 0;*/ rmask = PZM_RMASK16; gmask = PZM_GMASK16; bmask = PZM_BMASK16; } if ( this->hidden->buffer ) { SDL_free( this->hidden->buffer ); } this->hidden->buffer = SDL_malloc((bpp / 8) * width * height); if ( ! this->hidden->buffer ) { SDL_SetError("Couldn't allocate buffer for requested mode"); return(NULL); } memset(this->hidden->buffer, 0, (bpp / 8) * width * height); /* Allocate the new pixel format for the screen */ if ( ! SDL_ReallocFormat(current, bpp, rmask, gmask, bmask, 0) ) { SDL_free(this->hidden->buffer); this->hidden->buffer = NULL; SDL_SetError("Couldn't allocate new pixel format for requested mode"); return(NULL); } /* Set up the new mode framebuffer */ current->flags = flags; this->hidden->w = current->w = width; this->hidden->h = current->h = height; current->pitch = (bpp / 8) * current->w; current->pixels = this->hidden->buffer; PZM_DPRINT("Done (0x%p)", current); /* We're done */ return(current); }
static int NX_CreateWindow (_THIS, SDL_Surface * screen, int w, int h, int bpp, Uint32 flags) { Dprintf ("enter NX_CreateWindow\n") ; // If a window is already present, destroy it and start fresh if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) { NX_DestroyWindow (this, screen) ; } // See if we have been given a window id if (SDL_windowid) { SDL_Window = strtol (SDL_windowid, NULL, 0) ; } else { SDL_Window = 0 ; } if ( ! SDL_ReallocFormat (screen, bpp, SDL_Visual.red_mask, SDL_Visual.green_mask, SDL_Visual.blue_mask, 0)) return -1; // Create (or use) the nanox display window if (! SDL_windowid) { SDL_Window = GrNewWindow (GR_ROOT_WINDOW_ID, 0, 0, w, h, 0, BLACK, WHITE) ; GrSelectEvents (SDL_Window, (GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_FOCUS_IN | GR_EVENT_MASK_FOCUS_OUT | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP | GR_EVENT_MASK_MOUSE_ENTER | GR_EVENT_MASK_MOUSE_EXIT | GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_UPDATE | GR_EVENT_MASK_CLOSE_REQ)) ; } /* Create the graphics context here, once we have a window */ SDL_GC = GrNewGC () ; if (SDL_GC == 0) { SDL_SetError("Couldn't create graphics context"); return(-1); } // Map them both and go fullscreen, if requested if (! SDL_windowid) { GrMapWindow (SDL_Window) ; if (flags & SDL_FULLSCREEN) { screen -> flags |= SDL_FULLSCREEN ; NX_EnterFullScreen (this) ; } else { screen -> flags &= ~ SDL_FULLSCREEN ; } } #ifdef ENABLE_NANOX_DIRECT_FB /* attempt allocating the client side framebuffer */ Clientfb = GrOpenClientFramebuffer(); /* NULL return will default to using GrArea()*/ #endif Dprintf ("leave NX_CreateWindow\n") ; return 0 ; }
SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { SDL_PixelFormat format; int bpp1; __android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_SetVideoMode(): application requested mode %dx%d OpenGL %d HW %d BPP %d", width, height, flags & SDL_OPENGL, flags & SDL_HWSURFACE, SDL_ANDROID_BITSPERPIXEL); if( ! SDL_ANDROID_InsideVideoThread() ) { __android_log_print(ANDROID_LOG_INFO, "libSDL", "Error: calling %s not from the main thread!", __PRETTY_FUNCTION__); return NULL; } sdl_opengl = (flags & SDL_OPENGL) ? 1 : 0; SDL_ANDROID_sFakeWindowWidth = width; SDL_ANDROID_sFakeWindowHeight = height; current->flags = (flags & SDL_FULLSCREEN) | (flags & SDL_OPENGL) | SDL_DOUBLEBUF | ( flags & SDL_HWSURFACE ); current->w = width; current->h = height; current->pitch = SDL_ANDROID_sFakeWindowWidth * SDL_ANDROID_BYTESPERPIXEL; current->pixels = NULL; current->hwdata = NULL; HwSurfaceCount = 0; HwSurfaceList = NULL; DEBUGOUT("ANDROID_SetVideoMode() HwSurfaceCount %d HwSurfaceList %p", HwSurfaceCount, HwSurfaceList); if( ! sdl_opengl ) { SDL_DisplayMode mode; SDL_RendererInfo SDL_VideoRendererInfo; SDL_SelectVideoDisplay(0); SDL_VideoWindow = SDL_CreateWindow("", 0, 0, width, height, SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL); SDL_memset(&mode, 0, sizeof(mode)); mode.format = PixelFormatEnum; SDL_SetWindowDisplayMode(SDL_VideoWindow, &mode); if (SDL_CreateRenderer(SDL_VideoWindow, -1, 0) < 0) { __android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_SetVideoMode(): Error creating renderer"); return NULL; } SDL_GetRendererInfo(&SDL_VideoRendererInfo); current->hwdata = NULL; if( ! (flags & SDL_HWSURFACE) ) { current->pixels = SDL_malloc(width * height * SDL_ANDROID_BYTESPERPIXEL); if ( ! current->pixels ) { __android_log_print(ANDROID_LOG_INFO, "libSDL", "Couldn't allocate buffer for requested mode"); SDL_SetError("Couldn't allocate buffer for requested mode"); return(NULL); } SDL_memset(current->pixels, 0, width * height * SDL_ANDROID_BYTESPERPIXEL); current->hwdata = (struct private_hwdata *)SDL_CreateTexture(PixelFormatEnum, SDL_TEXTUREACCESS_STATIC, width, height); if( !current->hwdata ) { __android_log_print(ANDROID_LOG_INFO, "libSDL", "Couldn't allocate texture for SDL_CurrentVideoSurface"); SDL_free(current->pixels); current->pixels = NULL; SDL_OutOfMemory(); return(NULL); } if( SDL_ANDROID_SmoothVideo ) SDL_SetTextureScaleMode((SDL_Texture *)current->hwdata, SDL_SCALEMODE_SLOW); // Register main video texture to be recreated when needed HwSurfaceCount++; HwSurfaceList = SDL_realloc( HwSurfaceList, HwSurfaceCount * sizeof(SDL_Surface *) ); HwSurfaceList[HwSurfaceCount-1] = current; DEBUGOUT("ANDROID_SetVideoMode() HwSurfaceCount %d HwSurfaceList %p", HwSurfaceCount, HwSurfaceList); } glViewport(0, 0, SDL_ANDROID_sRealWindowWidth, SDL_ANDROID_sRealWindowHeight); glOrthof(0.0, (GLfloat) SDL_ANDROID_sWindowWidth, (GLfloat) SDL_ANDROID_sWindowHeight, 0.0, 0.0, 1.0); } /* Allocate the new pixel format for the screen */ SDL_memset(&format, 0, sizeof(format)); SDL_PixelFormatEnumToMasks( PixelFormatEnum, &bpp1, &format.Rmask, &format.Gmask, &format.Bmask, &format.Amask ); format.BitsPerPixel = bpp1; format.BytesPerPixel = SDL_ANDROID_BYTESPERPIXEL; if ( ! SDL_ReallocFormat(current, SDL_ANDROID_BITSPERPIXEL, format.Rmask, format.Gmask, format.Bmask, format.Amask) ) { __android_log_print(ANDROID_LOG_INFO, "libSDL", "Couldn't allocate new pixel format for requested mode"); SDL_SetError("Couldn't allocate new pixel format for requested mode"); return(NULL); } /* Set up the new mode framebuffer */ SDL_CurrentVideoSurface = current; /* We're done */ return(current); }
static SDL_Surface *DISPMANX_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { //MAC Recuerda que aquà ya nos llegan las dimensiones de un modo de vÃdeo // aproximado en SDL_Video.c de entre los modos de vÃdeo disponibles. //La jugada es dejar que un modo de 320x200 se vea en el modo que se nos ha //aproximado, seguramente mucho mayor, y luego escalar por hardware el área //visible al modo aproximado (de ahà que creemos el plano de overlay a parte, //ya que cuando SDL_Video.c llama a SetVideoMode aún no se tienen listos los //offsets horizontal y vertical donde empieza el modo de vÃdeo pequeño //(el original, ideal) sobre el grande (que serÃa el aproximado). //Otra cosa es la tasa de refresco. Tendrás que usar modos fÃsicos //concretos (config.txt) para ajustarte a 50, 60 o 70 Hz. Uint32 Rmask; Uint32 Gmask; Uint32 Bmask; char *surfaces_mem; int surfaces_len; dispvars->bits_per_pixel = bpp; switch (bpp){ case 8: dispvars->pix_format = VC_IMAGE_8BPP; break; case 16: dispvars->pix_format = VC_IMAGE_RGB565; break; case 32: dispvars->pix_format = VC_IMAGE_XRGB8888; break; default: printf ("\nERR - wrong bpp: %d\n",bpp); return (NULL); } //MAC blah this->UpdateRects = DISPMANX_DirectUpdate; //MAC Establecemos los rects para el escalado //this->offset_x = (dispvars->amode.width - width)/2; //this->offset_y = (dispvars->amode.height - height)/2; printf ("\nUsing internal program mode: width=%d height=%d\n", width, height); //MAC Por ahora en DISPMANX usamos el mismo modo q ya está establecido printf ("\nUsing physical mode: %d x %d %d bpp\n", dispvars->amode.width, dispvars->amode.height, dispvars->bits_per_pixel); //MAC Establecemos el pitch en fn del bpp deseado //Lo alineamos a 32 porque es el aligment interno de dispmanx(en ejemp) dispvars->pitch = ( ALIGN_UP( width, 16 ) * (bpp/8) ); //Alineamos la atura a 16 por el mismo motivo (ver ejemplo hello_disp) height = ALIGN_UP( height, 16); //Dejamos configurados los rects vc_dispmanx_rect_set (&(dispvars->bmp_rect), 0, 0, width, height); vc_dispmanx_rect_set (&(dispvars->src_rect), 0, 0, width << 16, height << 16); vc_dispmanx_rect_set( &(dispvars->dst_rect), 0, 0, dispvars->amode.width , dispvars->amode.height ); //MAC Establecemos alpha. Para transparencia descomentar flags con or. VC_DISPMANX_ALPHA_T layerAlpha; layerAlpha.flags = (DISPMANX_FLAGS_ALPHA_FROM_SOURCE | DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS); /*layerAlpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS;*/ layerAlpha.opacity = 255; layerAlpha.mask = 0; dispvars->alpha = &layerAlpha; //MAC Creo los resources. Me hacen falta dos para el double buffering dispvars->resources[0] = vc_dispmanx_resource_create( dispvars->pix_format, width, height, &(dispvars->vc_image_ptr) ); assert (dispvars->resources[0]); dispvars->resources[1] = vc_dispmanx_resource_create( dispvars->pix_format, width, height, &(dispvars->vc_image_ptr) ); assert (dispvars->resources[1]); //Reservo memoria para el array de pixles en RAM dispvars->pixmem=calloc( 1, dispvars->pitch * height); //dispvars->pixmem=malloc ( dispvars->pitch * dispvars->amode.height ); //MAC Esto se usa, como mÃnimo y que yo sepa, para DirectUpdate //cache_modinfo = *modinfo; //cache_fbinfo = *(drmModeGetFB (fd, fb_id)); //MAC Esta llamada a ReallocFormat es lo que impedÃa ver algo... Rmask = 0; Gmask = 0; Bmask = 0; if ( ! SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0) ) { return(NULL); } //Preparamos SDL para trabajar sobre el nuevo framebuffer shadow_fb = 0; current->flags |= SDL_HWSURFACE; current->flags |= SDL_FULLSCREEN; current->flags |= SDL_HWPALETTE; if (flags & SDL_DOUBLEBUF) current->flags |= SDL_DOUBLEBUF; current->w = width; current->h = height; mapped_mem = dispvars->pixmem; mapped_memlen = (dispvars->pitch * height); current->pitch = dispvars->pitch; current->pixels = mapped_mem; /* Set up the information for hardware surfaces */ surfaces_mem = (char *)current->pixels + (dispvars->pitch * height); surfaces_len = (mapped_memlen-(surfaces_mem-mapped_mem)); DISPMANX_FreeHWSurfaces(this); DISPMANX_InitHWSurfaces(this, current, surfaces_mem, surfaces_len); /* Update for double-buffering, if we can */ //Recuerda que necesitamos dos buffers porque hay que mantener uno //sin tocar durante todo el ciclo de fotograma (16ms) ya que es el que //el monitor lee como scanout durante ese tiempo. this->screen = current; this->screen = NULL; //Colocamos el element. Alpha 0 estabiliza %uso de cpu dispvars->update = vc_dispmanx_update_start( 0 ); dispvars->element = vc_dispmanx_element_add( dispvars->update, dispvars->display, 2000 /*layer*/, &(dispvars->dst_rect), dispvars->resources[flip_page], &(dispvars->src_rect), DISPMANX_PROTECTION_NONE, dispvars->alpha, 0 /*clamp*/, /*VC_IMAGE_ROT0*/ 0 ); vc_dispmanx_update_submit_sync( dispvars->update ); /* We're done */ //MAC Disable graphics 1 // Set the terminal into graphics mode printf ("\nDISPMANX_SetVideoMode activating keyboard and exiting"); if ( DISPMANX_EnterGraphicsMode(this) < 0 ) return(NULL); return(current); }
static SDL_Surface* ph_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { const struct ColourMasks* mask; /* Lock the event thread, in multi-threading environments */ SDL_Lock_EventThread(); current->flags = flags; /* if we do not have desired fullscreen mode, then fallback into window mode */ if (((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && (ph_GetVideoMode(width, height, bpp)==0)) { current->flags &= ~SDL_FULLSCREEN; current->flags &= ~SDL_NOFRAME; current->flags &= ~SDL_RESIZABLE; } ph_SetupWindow(this, width, height, current->flags); mask = ph_GetColourMasks(bpp); if (mask != NULL) { SDL_ReallocFormat(current, mask->bpp, mask->red, mask->green, mask->blue, 0); } else { SDL_SetError("ph_SetVideoMode(): desired bpp is not supported by photon !\n"); return NULL; } if ((current->flags & SDL_OPENGL)==SDL_OPENGL) { #if !SDL_VIDEO_OPENGL /* if no built-in OpenGL support */ SDL_SetError("ph_SetVideoMode(): no OpenGL support, you need to recompile SDL.\n"); current->flags &= ~SDL_OPENGL; return NULL; #endif /* SDL_VIDEO_OPENGL */ } else { /* Initialize internal variables */ if ((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { if (bpp==8) { desktoppal=SDLPH_PAL_SYSTEM; } current->flags &= ~SDL_RESIZABLE; /* no resize for Direct Context */ current->flags |= SDL_HWSURFACE; } else { /* remove this if we'll have support for the non-fullscreen sw/hw+doublebuf one day */ current->flags &= ~SDL_DOUBLEBUF; /* Use offscreen memory if SDL_HWSURFACE flag is set */ if ((current->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { if (desktopbpp!=bpp) { current->flags &= ~SDL_HWSURFACE; } } /* using palette emulation code in window mode */ if (bpp==8) { if (desktopbpp>=15) { desktoppal = SDLPH_PAL_EMULATE; } else { desktoppal = SDLPH_PAL_SYSTEM; } } else { desktoppal = SDLPH_PAL_NONE; } } } current->w = width; current->h = height; if (desktoppal==SDLPH_PAL_SYSTEM) { current->flags|=SDL_HWPALETTE; } /* Must call at least once for setup image planes */ if (ph_SetupUpdateFunction(this, current, current->flags)==-1) { /* Error string was filled in the ph_SetupUpdateFunction() */ return NULL; } /* finish window drawing, if we are not in fullscreen, of course */ if ((current->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) { PtFlush(); } else { PgFlush(); } visualbpp=bpp; ph_UpdateHWInfo(this); SDL_Unlock_EventThread(); /* We've done! */ return (current); }
SDL_Surface *AN_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { int disp_mode,pixel_mode,pitch; Uint32 Rmask, Gmask, Bmask; if (width==320 && height==240) disp_mode=DM_320x240; else if (width==640 && height==480) disp_mode=DM_640x480; else if (width==800 && height==600) disp_mode=DM_800x608; else { SDL_SetError("Couldn't find requested mode in list"); return(NULL); } switch(bpp) { case 15: pixel_mode = PM_RGB555; pitch = width*2; /* 5-5-5 */ Rmask = 0x00007c00; Gmask = 0x000003e0; Bmask = 0x0000001f; break; case 16: pixel_mode = PM_RGB565; pitch = width*2; /* 5-6-5 */ Rmask = 0x0000f800; Gmask = 0x000007e0; Bmask = 0x0000001f; break; case 24: bpp = 32; case 32: pixel_mode = PM_RGB888; pitch = width*4; Rmask = 0x00ff0000; Gmask = 0x0000ff00; Bmask = 0x000000ff; #if SDL_VIDEO_OPENGL if (!(flags & SDL_OPENGL)) #endif break; default: SDL_SetError("Couldn't find requested mode in list"); return(NULL); } // if ( bpp != current->format->BitsPerPixel ) { if ( ! SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0) ) { return(NULL); } // } /* Set up the new mode framebuffer */ current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE); current->w = width; current->h = height; current->pitch = pitch; #if SDL_VIDEO_OPENGL if (pvr_inited) { pvr_inited = 0; pvr_shutdown(); } #endif printf("Android set mode %s,%s uimplemeneted\n", __FILE__, __FUNCTION__); //vid_set_mode(disp_mode,pixel_mode); // TODO: SDL_SetError("Android video not unimplemented"); return NULL; current->pixels = NULL; //vram_s; #if SDL_VIDEO_OPENGL if (flags & SDL_OPENGL) { this->gl_config.driver_loaded = 1; current->flags = SDL_FULLSCREEN | SDL_OPENGL; current->pixels = NULL; pvr_inited = 1; pvr_init(¶ms); glKosInit(); glKosBeginFrame(); } else #endif if (flags | SDL_DOUBLEBUF) { current->flags |= SDL_DOUBLEBUF; current->pixels = (void*)((int)current->pixels | 0x400000); } /* We're done */ return(current); }
SDL_Surface *VGL_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { int mode_found; int i; VGLMode **modes; modes = VGLListModes(bpp, V_INFO_MM_DIRECT | V_INFO_MM_PACKED); mode_found = 0; for (i = 0; modes[i] != NULL; i++) { if ((modes[i]->ModeInfo.Xsize == width) && (modes[i]->ModeInfo.Ysize == height) && ((modes[i]->ModeInfo.Type == VIDBUF8) || (modes[i]->ModeInfo.Type == VIDBUF16) || (modes[i]->ModeInfo.Type == VIDBUF32))) { mode_found = 1; break; } } if (mode_found == 0) { SDL_SetError("No matching video mode found"); return NULL; } /* Shutdown previous videomode (if any) */ if (VGLCurMode != NULL) VGLEnd(); /* Try to set the requested linear video mode */ if (VGLInit(modes[i]->ModeId) != 0) { SDL_SetError("Unable to switch to requested mode"); return NULL; } VGLCurMode = SDL_realloc(VGLCurMode, sizeof(VGLMode)); VGLCurMode->ModeInfo = *VGLDisplay; VGLCurMode->Depth = modes[i]->Depth; VGLCurMode->ModeId = modes[i]->ModeId; VGLCurMode->Rmask = modes[i]->Rmask; VGLCurMode->Gmask = modes[i]->Gmask; VGLCurMode->Bmask = modes[i]->Bmask; /* Workaround a bug in libvgl */ if (VGLCurMode->ModeInfo.PixelBytes == 0) (VGLCurMode->ModeInfo.PixelBytes = 1); current->w = VGLCurMode->ModeInfo.Xsize; current->h = VGLCurMode->ModeInfo.Ysize; current->pixels = VGLCurMode->ModeInfo.Bitmap; current->pitch = VGLCurMode->ModeInfo.Xsize * VGLCurMode->ModeInfo.PixelBytes; current->flags = (SDL_FULLSCREEN | SDL_HWSURFACE); /* Check if we are in a pseudo-color mode */ if (VGLCurMode->ModeInfo.Type == VIDBUF8) current->flags |= SDL_HWPALETTE; /* Check if we can do doublebuffering */ if (flags & SDL_DOUBLEBUF) { if (VGLCurMode->ModeInfo.Xsize * 2 <= VGLCurMode->ModeInfo.VYsize) { current->flags |= SDL_DOUBLEBUF; flip_page = 0; flip_address[0] = (byte *)current->pixels; flip_address[1] = (byte *)current->pixels + current->h * current->pitch; VGL_FlipHWSurface(this, current); } } if (! SDL_ReallocFormat(current, modes[i]->Depth, VGLCurMode->Rmask, VGLCurMode->Gmask, VGLCurMode->Bmask, 0)) { return NULL; } /* Update hardware acceleration info */ VGL_UpdateVideoInfo(this); /* Set the blit function */ this->UpdateRects = VGL_DirectUpdate; /* We're done */ return current; }
static SDL_Surface *DISPMANX_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { //MAC Recuerda que aquiÂ,originalmente, nos llegaban las dimensiones de un modo de video // aproximado en SDL_Video.c de entre los modos de video disponibles. AHORA YA NO. //Ahora lo que hacemos es que nos lleguen directamente la altura y anchura del modo //en el que quiere correr la aplicacion, //Luego se escala ese modo, de cuanta menos resolucion mejor, (ya que hay //que hacer una escritura de ram a grafica en la funcion FlipHWScreen), al modo fisico, que //es en realidad el unico modo grafico que existe, el modo en que hemos arrancado. //Esto explica por que creamos el plano de overlay a parte, //ya que cuando SDL_Video.c llama a SetVideoMode aun no se tienen listos los //offsets horizontal y vertical donde empieza el modo de video pequenio //(el modo en que corre la app internamente) sobre el grande (el modo fisico). //Si nos pasan width=0 y height=0, interpreto que el programa no quiere video sino //que solo necesita entrar en modo grafico, asi que salto alli: if ((width == 0) | (height == 0)) goto go_video_console; //MAC Inicializamos el SOC (bcm_host_init) SOLO si no hemos pasado antes por aquiÂ. Lo mismo con el fondo. //Si ya hemos pasado antes, hacemos limpieza, pero dejamos el fondo sin tocar. if (dispvars->pixmem != NULL){ //Hacemos limpieza de resources, pero dejamos el fondo. No hay problema porque solo lo ponemos //si no hemos pasado por aqui antes. DISPMANX_FreeResources(); } else { uint32_t screen = 0; bcm_host_init(); //MAC Abrimos el display dispmanx printf("Dispmanx: Opening display %i\n", screen ); dispvars->display = vc_dispmanx_display_open( screen ); //MAC Recuperamos algunos datos de la configuracion del buffer actual vc_dispmanx_display_get_info( dispvars->display, &(dispvars->amode)); printf( "Dispmanx: Physical video mode is %d x %d\n", dispvars->amode.width, dispvars->amode.height ); //Ponemos el element de fondo negro tanto si se respeta el ratio como si no, //porque si no, se nos veraÂa la consola al cambiar de resolucion durante el programa. DISPMANX_BlankBackground(); } //-------Bloque de lista de resoluciones, originalmente en VideoInit-------------- //Para la aplicacion SDL, el unico modo de video disponible va a ser siempre el que pida. DISPMANX_AddMode(this, width, height, (((bpp+7)/8)-1)); //--------------------------------------------------------------------------------- Uint32 Rmask; Uint32 Gmask; Uint32 Bmask; //dispvars->pitch = width * ((bpp+7) /8); //MAC Establecemos el pitch en funcion del bpp deseado //Lo alineamos a 16 porque es el aligment interno de dispmanx(en ejemp) dispvars->bits_per_pixel = bpp; dispvars->pitch = ( ALIGN_UP( width, 16 ) * (bpp/8) ); //Alineamos la atura a 16 por el mismo motivo (ver ejemplo hello_disp) height = ALIGN_UP( height, 16); switch (bpp){ case 8: dispvars->pix_format = VC_IMAGE_8BPP; break; case 16: dispvars->pix_format = VC_IMAGE_RGB565; break; case 32: dispvars->pix_format = VC_IMAGE_XRGB8888; break; default: printf ("\n[ERROR] - wrong bpp: %d\n",bpp); return (NULL); } //MAC blah this->UpdateRects = DISPMANX_DirectUpdate; printf ("\nUsing internal program mode: %d x %d %d bpp", width, height, dispvars->bits_per_pixel); //MAC Por ahora en DISPMANX usamos el mismo modo q ya esta establecido printf ("\nUsing physical mode: %d x %d %d bpp", dispvars->amode.width, dispvars->amode.height, dispvars->bits_per_pixel); //----------------------------------------------------------------------------- //Esta parte no es fundamental, solo sirve para conservar el ratio del juego. //Si no se hace y simplemente quitas estas lineas, se estira al modo fisico y ya, //quedando la imagen deformada si es de 4:3 en una tele de 16:9, que es lo que pasaba antes. //Simplemente hallamos ese ratio y con el hallamos la nueva anchura, considerando //como altura la maxima fisica que tenemos establecida, o sea, la altura del modo fisico establecido. //Tambien se calcula la posicion horizontal en que debe empezar el rect de destino (dst_ypos), //para que no quede pegado a la parte izquierda de la pantalla al ser menor que la resolucion fisica, que //obviamente no cambia. //Queda obsoleto si cambiamos la resolucion a una que tenga el mismo ratio que el modo original del juego. dispvars->ignore_ratio = (int) SDL_getenv("SDL_DISPMANX_IGNORE_RATIO"); if (dispvars->ignore_ratio) vc_dispmanx_rect_set( &(dispvars->dst_rect), 0, 0, dispvars->amode.width , dispvars->amode.height ); else { float orig_ratio = ((float)width / (float)height); int dst_width = dispvars->amode.height * orig_ratio; //Si la anchura de la imagen escalada nos sale mayor que el ancho fisico de pantalla, //mantenemos el ancho fisico de pantalla como anchura maxima. if (dst_width > dispvars->amode.width) dst_width = dispvars->amode.width; int dst_ypos = (dispvars->amode.width - dst_width) / 2; printf ("\nUsing proportion ratio: %d / %d = %f", width, height, orig_ratio); printf ("\nProgram rect, respecting original ratio: %d x %d \n", dst_width, dispvars->amode.height); vc_dispmanx_rect_set( &(dispvars->dst_rect), dst_ypos, 0, dst_width , dispvars->amode.height ); } //---------------------------Dejamos configurados los rects--------------------- //Recuerda que los rects NO contienen ninguna informacion visual, solo son tamanio, rectangulos //descritos para que los entiendan las funciones vc, solo tamanios de areas. // //bmp_rect: se usa solo para el volcado del buffer en RAM al resource que toque. Define el tamanio //del area a copiar de RAM (pixmem) al resource (dispmam->resources[]) usando write_data(), por //eso, y para acabarlo de entender del todo, su altura y anchura son las internas del juego, width y height. // //src_rect y dst_rect: se usan porque un element necesita dos rects definidos: src_rect es el tamanio del area //de entrada,o sea, el tamanio con el que clipeamos la imagen de origen, y dst_rect es el tamanio del area de //salida, o sea, el tamanio con que se vera, escalada por hardware, en el element. // //Por todo esto, src_rect tendra generalmente la altura y anchura de la imagen original, o dicho de otro //modo la altura y anchura que usa el juego internamente (width << 16 y height << 16 por algun rollo de //tamanio de variable), y dst_rect tendra las dimensiones del area de pantalla a la que queremos escalar //esa imagen: si le damos las dimensiones fisicas totales de la pantalla, escalara sin respetar el ratio. //AsiÂque lo he corregido manteniendo la altura maxima de la pantalla fisica, y calculando la anchura //a partir de dicha altura y el ratio de la imagen (de la resolucion del juego) original. // //Debes pensar siempre de la siguiente manera: un element, que es como un cristal-lupa, un resource //(aunque tengas dos, en un momento dado el element solo tiene uno) que es como la imagen original, //muy pequenita al fondo, y un "embudo", cuyo tamanio del extremo inferior pegado a la imagen original //es de tamanio src_rect, y cuyo tamanio del extremo superior, pegado al element, es de tamanio dst_rect. vc_dispmanx_rect_set (&(dispvars->bmp_rect), 0, 0, width, height); vc_dispmanx_rect_set (&(dispvars->src_rect), 0, 0, width << 16, height << 16); //------------------------------------------------------------------------------ //MAC Establecemos alpha. Para transparencia descomentar flags con or. VC_DISPMANX_ALPHA_T layerAlpha; /*layerAlpha.flags = (DISPMANX_FLAGS_ALPHA_FROM_SOURCE | DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS);*/ layerAlpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS; layerAlpha.opacity = 255; layerAlpha.mask = 0; dispvars->alpha = &layerAlpha; //MAC Creo los resources. Me hacen falta dos para el double buffering dispvars->resources[0] = vc_dispmanx_resource_create( dispvars->pix_format, width, height, &(dispvars->vc_image_ptr) ); dispvars->resources[1] = vc_dispmanx_resource_create( dispvars->pix_format, width, height, &(dispvars->vc_image_ptr) ); //Reservo memoria para el array de pixles en RAM dispvars->pixmem = calloc( 1, dispvars->pitch * height); //dispvars->pixmem=malloc ( dispvars->pitch * dispvars->amode.height ); //MAC Esta llamada a ReallocFormat es lo que impediaÂa ver algo... Rmask = 0; Gmask = 0; Bmask = 0; if ( ! SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0) ) { return(NULL); } //Preparamos SDL para trabajar sobre el nuevo framebuffer //No queremos HWSURFACEs por la manera en que funciona nuestro backend, ya que la app solo //debe conocer el buffer en RAM para que las actualizaciones no sean bloqueantes. //TAMPOCO queremos DOUBLEBUFFER: realmente piensa lo que estas haciendo: actualizas la //superficie de video, que esta en la RAM, copias a VRAM y, saltandote las normas del API, //esperas a evento de vsync para hacer el buffer swapping. Asi que la app NO SABE NADA de //double buffering ni debe saberlo. UpdateRect() debe hacer lo que antes haciaÂa FlipHWSurface, //ya que de cara a la APP, solo hay una actualizacion del buffer de dibujado, NO de pantalla, //ya que carecemos de acceso directo a la VRAM. //Permitimos HWPALETTEs, cosa que solo se activa si el juego pide un modo de 8bpp porque, //tanto si conseguimos modificar la paleta por hard como si tenemos que indexar los valores //como estamos haciendo hasta ahora emulando asi la paleta, nos interesa que los juegos //entren en SetColors(), y sin paleta por hardware no entran. current->flags |= SDL_FULLSCREEN; if (flags & SDL_DOUBLEBUF){ current->flags &= ~SDL_DOUBLEBUF; } if (flags & SDL_HWSURFACE){ current->flags &= ~SDL_HWSURFACE; current->flags |= SDL_SWSURFACE; } if (flags & SDL_HWPALETTE) current->flags |= SDL_HWPALETTE; current->w = width; current->h = height; current->pitch = dispvars->pitch; current->pixels = dispvars->pixmem; //DISPMANX_FreeHWSurfaces(this); //DISPMANX_InitHWSurfaces(this, current, surfaces_mem, surfaces_len); //this->screen = current; //this->screen = NULL; //Aniadimos el element. dispvars->update = vc_dispmanx_update_start( 0 ); dispvars->element = vc_dispmanx_element_add( dispvars->update, dispvars->display, 0 /*layer*/, &(dispvars->dst_rect), dispvars->resources[flip_page], &(dispvars->src_rect), DISPMANX_PROTECTION_NONE, dispvars->alpha, 0 /*clamp*/, /*VC_IMAGE_ROT0*/ 0 ); vc_dispmanx_update_submit_sync( dispvars->update ); /* We're done */ //MAC Disable graphics 1 //Aqui ponemos la terminal en modo grafico. Ya no se imprimiran mas mensajes en la consola a partir de aqui. go_video_console: if ( DISPMANX_EnterGraphicsMode(this) < 0 ) return(NULL); return(current); }
SDL_Surface *PG_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { if ( this->hidden->bitmap ) { /* Free old bitmap */ if (current->pixels) { shmdt(current->pixels); current->pixels = NULL; } pgDelete(this->hidden->bitmap); } /* Allocate the new pixel format for the screen */ if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) { SDL_SetError("Couldn't allocate new pixel format for requested mode"); return(NULL); } /* Create a new picogui bitmap */ this->hidden->bitmap = pgCreateBitmap(width,height); this->hidden->shm = *pgMakeSHMBitmap(this->hidden->bitmap); current->pixels = shmat(shmget(this->hidden->shm.shm_key, this->hidden->shm.shm_length,0),NULL,0); /* Reset the canvas, and draw persistent and incremental grops. * Use mapping and offsets to center it. */ pgWriteCmd(this->hidden->wCanvas, PGCANVAS_NUKE, 0); /* 0. Set the source position during incremental rendering */ pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROP, 5, PG_GROP_SETSRC,0,0,0,0); pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROPFLAGS, 1, PG_GROPF_INCREMENTAL); /* 1. Incremental bitmap rendering */ pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROP, 6, PG_GROP_BITMAP, 0,0,0,0,this->hidden->bitmap); pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROPFLAGS, 1, PG_GROPF_INCREMENTAL); /* 2. Normal bitmap rendering */ pgWriteCmd(this->hidden->wCanvas, PGCANVAS_GROP, 6, PG_GROP_BITMAP, 0,0,this->hidden->shm.width,this->hidden->shm.height,this->hidden->bitmap); /* Set up the new mode framebuffer */ current->flags = 0; current->w = this->hidden->shm.width; current->h = this->hidden->shm.height; current->pitch = this->hidden->shm.pitch; /* Set up pixel format */ current->format->BitsPerPixel = this->hidden->shm.bpp; current->format->BytesPerPixel = this->hidden->shm.bpp >> 3; if (this->hidden->shm.bpp & 7) current->format->BytesPerPixel++; current->format->palette = NULL; current->format->Rmask = this->hidden->shm.red_mask; current->format->Gmask = this->hidden->shm.green_mask; current->format->Bmask = this->hidden->shm.blue_mask; current->format->Amask = this->hidden->shm.alpha_mask; current->format->Rshift = this->hidden->shm.red_shift; current->format->Gshift = this->hidden->shm.green_shift; current->format->Bshift = this->hidden->shm.blue_shift; current->format->Ashift = this->hidden->shm.alpha_shift; current->format->Rloss = 8 - this->hidden->shm.red_length; current->format->Gloss = 8 - this->hidden->shm.green_length; current->format->Bloss = 8 - this->hidden->shm.blue_length; current->format->Aloss = 8 - this->hidden->shm.alpha_length; /* Draw the app */ pgUpdate(); /* We're done */ return(current); }
SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { int maxwidth, maxheight; Uint32 modeflags, screensize; SDL_bool use_shadow; GEM_FreeBuffers(this); /*--- Verify if asked mode can be used ---*/ if (flags & SDL_FULLSCREEN) { maxwidth=VDI_w; maxheight=VDI_h; } else { /* Windowed mode */ maxwidth=GEM_desk_w; maxheight=GEM_desk_h; } if ((maxwidth < width) || (maxheight < height) || (VDI_bpp != bpp)) { SDL_SetError("Couldn't find requested mode in list"); return(NULL); } /*--- Allocate the new pixel format for the screen ---*/ if ( ! SDL_ReallocFormat(current, VDI_bpp, VDI_redmask, VDI_greenmask, VDI_bluemask, VDI_alphamask) ) { SDL_SetError("Couldn't allocate new pixel format for requested mode"); return(NULL); } /*--- Allocate shadow buffer if needed ---*/ use_shadow=SDL_FALSE; if (flags & SDL_FULLSCREEN) { if (!VDI_screen) { /* No access to real framebuffer, use shadow surface */ use_shadow=SDL_TRUE; } else { if (VDI_format==VDI_FORMAT_INTER) { /* Real framebuffer, interleaved bitplanes, use shadow surface */ use_shadow=SDL_TRUE; } else if (flags & SDL_DOUBLEBUF) { /* Real framebuffer, double-buffered, use shadow surface */ use_shadow=SDL_TRUE; modeflags |= SDL_DOUBLEBUF; } } } else { /* Windowed mode, always with shadow surface */ use_shadow=SDL_TRUE; } if (use_shadow) { screensize = width * height * VDI_pixelsize; GEM_buffer = Atari_SysMalloc(screensize, MX_PREFTTRAM); if (GEM_buffer==NULL) { fprintf(stderr,"Unable to allocate shadow buffer\n"); return NULL; } memset(GEM_buffer, 0, screensize); } /*--- Initialize screen ---*/ modeflags = 0; if (VDI_bpp == 8) { modeflags |= SDL_HWPALETTE; } if (flags & SDL_FULLSCREEN) { GEM_LockScreen(this); GEM_ClearScreen(this); modeflags |= SDL_FULLSCREEN; if (VDI_screen && (VDI_format==VDI_FORMAT_PACK) && !use_shadow) { modeflags |= SDL_HWSURFACE; } else { modeflags |= SDL_SWSURFACE; } } else { int posx,posy; short x2,y2,w2,h2; GEM_UnlockScreen(this); /* Center our window */ posx = GEM_desk_x; posy = GEM_desk_y; if (width<GEM_desk_w) posx += (GEM_desk_w - width) >> 1; if (height<GEM_desk_h) posy += (GEM_desk_h - height) >> 1; /* Calculate our window size and position */ if (!(flags & SDL_NOFRAME)) { GEM_win_type=NAME|MOVER|CLOSER|SMALLER; if (flags & SDL_RESIZABLE) { GEM_win_type |= FULLER|SIZER; modeflags |= SDL_RESIZABLE; } } else { GEM_win_type=0; modeflags |= SDL_NOFRAME; } if (!wind_calc(0, GEM_win_type, posx, posy, width, height, &x2, &y2, &w2, &h2)) { GEM_FreeBuffers(this); fprintf(stderr,"Can not calculate window attributes\n"); return NULL; } /* Create window */ GEM_handle=wind_create(GEM_win_type, x2, y2, w2, h2); if (GEM_handle<0) { GEM_FreeBuffers(this); fprintf(stderr,"Can not create window\n"); return NULL; } /* Setup window name */ wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0); /* Open the window */ wind_open(GEM_handle,x2,y2,w2,h2); modeflags |= SDL_SWSURFACE; } /* Set up the new mode framebuffer */ current->flags = modeflags; current->w = width; current->h = height; if (use_shadow) { current->pixels = GEM_buffer; current->pitch = width * (VDI_bpp >> 3); } else {
SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { _kernel_swi_regs regs; Uint32 Rmask = 0; Uint32 Gmask = 0; Uint32 Bmask = 0; int create_back_buffer = riscos_backbuffer; switch(bpp) { case 8: flags |= SDL_HWPALETTE; break; case 15: case 16: Bmask = 0x00007c00; Gmask = 0x000003e0; Rmask = 0x0000001f; break; case 32: Bmask = 0x00ff0000; Gmask = 0x0000ff00; Rmask = 0x000000ff; break; default: SDL_SetError("Pixel depth not supported"); return NULL; break; } if (FULLSCREEN_SetMode(width, height, bpp) == 0) { SDL_SetError("Couldn't set requested mode"); return (NULL); } /* printf("Setting mode %dx%d\n", width, height); */ /* Allocate the new pixel format for the screen */ if ( ! SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0) ) { RISCOS_RestoreWimpMode(); SDL_SetError("Couldn't allocate new pixel format for requested mode"); return(NULL); } /* Set up the new mode framebuffer */ current->w = width; this->hidden->height = current->h = height; regs.r[0] = -1; /* -1 for current screen mode */ /* Get screen width in bytes */ regs.r[1] = 6; // Screen Width in bytes _kernel_swi(OS_ReadModeVariable, ®s, ®s); current->pitch = regs.r[2]; if (flags & SDL_DOUBLEBUF) { regs.r[0] = 2; /* Screen area */ _kernel_swi(OS_ReadDynamicArea, ®s, ®s); /* Reg 1 has amount of memory currently used for display */ regs.r[0] = 2; /* Screen area */ regs.r[1] = (current->pitch * height * 2) - regs.r[1]; if (_kernel_swi(OS_ChangeDynamicArea, ®s, ®s) != NULL) { /* Can't allocate enough screen memory for double buffer */ flags &= ~SDL_DOUBLEBUF; } } current->flags = flags | SDL_FULLSCREEN | SDL_HWSURFACE | SDL_PREALLOC; /* Need to set display banks here for double buffering */ if (flags & SDL_DOUBLEBUF) { FULLSCREEN_SetWriteBank(0); FULLSCREEN_SetDisplayBank(1); create_back_buffer = 0; /* Don't need a back buffer for a double buffered display */ } FULLSCREEN_SetupBanks(this); if (create_back_buffer) { /* If not double buffered we may need to create a memory ** back buffer to simulate processing on other OS's. ** This is turned on by setting the enviromental variable ** SDL$<name>$BackBuffer to 1 */ this->hidden->bank[0] = malloc(height * current->pitch); if (this->hidden->bank[0] == 0) { RISCOS_RestoreWimpMode(); SDL_SetError("Couldnt allocate memory for back buffer"); return (NULL); } /* Surface updated in programs is now a software surface */ current->flags &= ~SDL_HWSURFACE; } /* Store address of allocated screen bank to be freed later */ if (this->hidden->alloc_bank) free(this->hidden->alloc_bank); if (create_back_buffer) { this->hidden->alloc_bank = this->hidden->bank[0]; } else this->hidden->alloc_bank = 0; // Clear both banks to black memset(this->hidden->bank[0], 0, height * current->pitch); memset(this->hidden->bank[1], 0, height * current->pitch); this->hidden->current_bank = 0; current->pixels = this->hidden->bank[0]; /* Reset device functions for the wimp */ FULLSCREEN_SetDeviceMode(this); /* FULLSCREEN_DisableEscape(); */ /* We're done */ return(current); }
SDL_Surface *L4FB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { char* apptitle = APPTITLE; char* wintitle = WINTITLE; printf("L4FB_SetVideoMode: %dx%d@%d:\n", width, height, bpp); /* * is requested resolution higher than the framebuffer's one? */ if( width > (int)this->hidden->vvi.width || height > (int)this->hidden->vvi.height) { return (NULL); } /* * calc the offsets for current resolution the center the image */ this->hidden->x_offset = (this->hidden->vvi.width - width ) / 2; this->hidden->y_offset = (this->hidden->vvi.height - height) / 2; // make sure to have correct scale if (L4FB_video_scale_factor<=0) L4FB_video_scale_factor = 1.0; // reject unsupported bpp if (bpp != 16) return NULL; // reject unsupported flags if (flags & SDL_OPENGL) return NULL; /* Allocate the new pixel format for the screen */ if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) { SDL_SetError("Couldn't allocate new pixel format for requested mode"); return(NULL); } // if we were double buffered clear shadow buffer if (current->flags & SDL_DOUBLEBUF) { FreeAndNull(current->pixels); } // init new window if (this->wm_title) wintitle = this->wm_title; if (this->wm_icon) apptitle = this->wm_icon; // L4FB_SetCaption(this, wintitle, apptitle); if (l4_is_invalid_cap(this->hidden->ev_ds) || !this->hidden->ev_ds) L4FB_InstallEventHandler(this); /* Set up the new mode framebuffer */ current->w = width; current->h = height; current->pitch = SDL_CalculatePitch(current); this->hidden->pitch = current->pitch; current->flags = SDL_PREALLOC | SDL_ASYNCBLIT; // if (current->pixels) // { // /* TODO: ERROR HANDLING */ // } // memset(current->pixels, 0, current->h*current->pitch); /* since we want to center image in fb we allway have to use doublebuf... */ this->hidden->fb_start = this->hidden->fbmem_vaddr + this->hidden->vvi.buffer_offset; current->pixels = malloc(current->h*current->pitch); if (current->pixels) { // success! printf("allocated shadow buffer\n"); this->hidden->pixels = current->pixels; memset(current->pixels, 0, current->h*current->pitch); } else return NULL; if (flags&SDL_DOUBLEBUF) { current->flags |= SDL_DOUBLEBUF|SDL_HWSURFACE; // try to alloc shadow buffer } /* We're done */ return(current); }
static SDL_Surface *NSP_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { Uint32 rmask, gmask, bmask; NSP_DEBUG("Initializing display (%dx%dx%d)", width, height, bpp); if ( flags != SDL_SWSURFACE ) NSP_WARNING("Initializing with non-typical flags"); if ( width < SCREEN_WIDTH || height < SCREEN_HEIGHT ) { int win_x = (SCREEN_WIDTH - width) / 2; int win_y = (SCREEN_HEIGHT - height) / 2; this->hidden->offset = this->hidden->cx ? (int)NSP_PIXEL_ADDR(0, win_x, win_y, 2 * SCREEN_WIDTH, 2) : (int)NSP_PIXEL_ADDR(0, win_x / 2, win_y, SCREEN_WIDTH / 2, 1); this->hidden->win_x = win_x; memset(SCREEN_BASE_ADDRESS, 0, SCREEN_BYTES_SIZE); } else this->hidden->offset = this->hidden->win_x = 0; if ( (! this->hidden->cx && bpp == 16) || (bpp != 16 && bpp != 8) ) { NSP_WARNING("Invalid display bit depth, forcing to 8 bpp"); bpp = 8; } if ( bpp == 16 ) { rmask = NSP_RMASK16; gmask = NSP_GMASK16; bmask = NSP_BMASK16; } else rmask = gmask = bmask = 0; if ( this->hidden->buffer ) { SDL_free( this->hidden->buffer ); } this->hidden->buffer = SDL_malloc((bpp / 8) * width * height); if ( ! this->hidden->buffer ) { SDL_SetError("Couldn't allocate buffer for requested mode"); return(NULL); } memset(this->hidden->buffer, 0, (bpp / 8) * width * height); /* Allocate the new pixel format for the screen */ if ( ! SDL_ReallocFormat(current, bpp, rmask, gmask, bmask, 0) ) { SDL_free(this->hidden->buffer); this->hidden->buffer = NULL; SDL_SetError("Couldn't allocate new pixel format for requested mode"); return(NULL); } /* Set up the new mode framebuffer */ current->flags = flags; this->hidden->w = this->info.current_w = current->w = width; this->hidden->h = this->info.current_h = current->h = height; current->pitch = (bpp / 8) * current->w; current->pixels = this->hidden->buffer; NSP_DEBUG("Done (0x%p)", current); /* We're done */ return(current); }
SDL_Surface *NDS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { Uint32 Rmask, Gmask, Bmask, Amask; //if (width > 1024 || height > 512 || bpp > 16) // return NULL; if (bpp > 8) { bpp = 16; Rmask = 0x0000001F; Gmask = 0x000003E0; Bmask = 0x00007C00; Amask = 0x00008000; videoSetMode(MODE_5_2D| DISPLAY_BG2_ACTIVE); vramSetMainBanks(VRAM_A_MAIN_BG,VRAM_B_MAIN_BG,VRAM_C_MAIN_BG,VRAM_D_MAIN_BG); BG2_CR = BG_BMP16_512x512; BG2_XDX = ((width / 256) << 8) | (width % 256) ; BG2_XDY = 0; BG2_YDX = 0; BG2_YDY = ((height / 192) << 8) | ((height % 192) + (height % 192) / 3) ; BG2_CX = 0; BG2_CY = 0; // for (i = 0;i<256*192;i++) // frontBuffer[i] = RGB15(31,0,0)|BIT(15); } else if (bpp <= 8) { bpp = 8; Rmask = 0x00000000; Gmask = 0x00000000; Bmask = 0x00000000; BG2_CR = BG_BMP8_1024x512; BG2_XDX = ((width / 256) << 8) | (width % 256) ; BG2_XDY = 0; BG2_YDX = 0; BG2_YDY = ((height / 192) << 8) | ((height % 192) + (height % 192) / 3) ; } else if (bpp < 15) bpp = 15; if (width <= 256) width = 256; else if (width < 256) width = 256; if (height <= 192) height = 192; else if (height < 192) height = 192; if (bpp == 8) { if (width < 256) width = 256; if (height < 192) height = 192; this->hidden->ndsmode = 4; } if (bpp==15) { if (width < 256) this->hidden->ndsmode = 5; else this->hidden->ndsmode = 3; } this->hidden->buffer = frontBuffer;//NDS_VRAM_BASE; //NDS_DISPCNT = NDS_DISP_MODE(this->hidden->ndsmode) | NDS_DISP_BG2; //fprintf(stderr,"Setting mode %dx%d (ndsmode %d)\n", width, height,this->hidden->ndsmode); // FIXME: How do I tell that 15 bits mode is 555? SDL_memset(this->hidden->buffer, 0, 1024 * 512 * (this->hidden->ndsmode == 4 || this->hidden->ndsmode == 5 ? 2 : 1) * ((bpp + 7) / 8)); /* Allocate the new pixel format for the screen */ if (!SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, Amask)) { this->hidden->buffer = NULL; SDL_SetError("Couldn't allocate new pixel format for requested mode"); return NULL; } /* Set up the new mode framebuffer */ current->flags = flags | SDL_FULLSCREEN | SDL_HWSURFACE | (this->hidden->ndsmode > 0 ? SDL_DOUBLEBUF : 0); this->hidden->w = current->w = width; this->hidden->h = current->h = height; current->pixels = frontBuffer; if (flags & SDL_DOUBLEBUF) { this->hidden->secondbufferallocd = 1; backBuffer = (u16*)SDL_malloc(1024*512*2); current->pixels = backBuffer; } if (bpp == 8) current->pitch = 1024; else current->pitch = 512*2; /* We're done */ return current; }
SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { Uint32 Rmask = 0; Uint32 Gmask = 0; Uint32 Bmask = 0; char *buffer = NULL; int bytesPerPixel = 1; /* Don't support double buffering in Wimp mode */ flags &= ~SDL_DOUBLEBUF; flags &= ~SDL_HWSURFACE; switch(bpp) { case 8: /* Emulated palette using ColourTrans */ flags |= SDL_HWPALETTE; break; case 15: case 16: Bmask = 0x00007c00; Gmask = 0x000003e0; Rmask = 0x0000001f; bytesPerPixel = 2; break; case 32: Bmask = 0x00ff0000; Gmask = 0x0000ff00; Rmask = 0x000000ff; bytesPerPixel = 4; break; default: SDL_SetError("Pixel depth not supported"); return NULL; break; } /* printf("Setting mode %dx%d\n", width, height);*/ /* Allocate the new pixel format for the screen */ if ( ! SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0) ) { SDL_SetError("Couldn't allocate new pixel format for requested mode"); return(NULL); } /* Set up the new mode framebuffer */ current->w = width; this->hidden->height = current->h = height; if (bpp == 15) bpp = 16; buffer = WIMP_CreateBuffer(width, height, bpp); if (buffer == NULL) { SDL_SetError("Couldn't create sprite for video memory"); return (NULL); } this->hidden->bank[0] = buffer + 60; /* Start of sprite data */ if (bpp == 8) this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */ this->hidden->bank[1] = buffer; /* Start of buffer */ /* Remember sprite buffer so it can be freed later */ if (this->hidden->alloc_bank) SDL_free(this->hidden->alloc_bank); this->hidden->alloc_bank = buffer; current->pitch = width * bytesPerPixel; if ((current->pitch & 3)) { /* Sprites are 32bit word aligned */ current->pitch += (4 - (current->pitch & 3)); } current->flags = flags | SDL_PREALLOC; WIMP_ReadModeInfo(this); SDL_memset(this->hidden->bank[0], 0, height * current->pitch); this->hidden->current_bank = 0; current->pixels = this->hidden->bank[0]; if (WIMP_SetupWindow(this, current) == 0) { SDL_SetError("Unable to create window to display surface"); return NULL; } /* Reset device functions for the wimp */ WIMP_SetDeviceMode(this); /* Needs to set up plot info after window has been created */ /* Not sure why, but plots don't work if I do it earlier */ WIMP_SetupPlotInfo(this); /* Poll until window is shown */ { /* We wait until it gets the focus, but give up after 5 seconds in case the focus is prevented in any way. */ Uint32 now = SDL_GetTicks(); while (!hasFocus && SDL_GetTicks() - now < 5000) { WIMP_Poll(this, 0); } } /* We're done */ return(current); }