📄 sdl_dspvideo.c
字号:
PaintRect (&rect); SetPort (save_port); SetPortWindowPort (SDL_Window); SelectWindow (SDL_Window); if ( Mac_GL_Init (this) < 0 ) { SDL_SetError ("DSp_SetVideoMode : could not create OpenGL context."); return NULL; } current->flags |= SDL_OPENGL; } return current; }#ifdef DSP_TRY_CC_AND_AAstatic int DSp_MakeHWMask (_THIS, SDL_Surface *surface){ GDHandle save_device; CGrafPtr save_port; GWorldPtr temp; RGBColor black = { 0, 0, 0 }; RGBColor white = { 0xFFFF, 0xFFFF, 0xFFFF }; Rect rect; Uint32 depth = GetPixDepth ( GetGDevPixMap (SDL_Display) ); SetRect (&rect, 0, 0, surface->w, surface->h); if ( noErr != NewGWorld (&(surface->hwdata->mask), depth, &rect, 0, SDL_Display, 0 ) < 0 ) { SDL_OutOfMemory (); return (-1); } if ( noErr != NewGWorld (&temp, depth, &rect, 0 , SDL_Display, 0 ) ) { SDL_OutOfMemory (); return (-1); } GetGWorld (&save_port, &save_device); SetGWorld (surface->hwdata->mask, SDL_Display); RGBForeColor (&white); PaintRect (&rect); RGBBackColor (&(surface->hwdata->trans)); CopyBits ( GetPortBitMapForCopyBits(surface->hwdata->offscreen), GetPortBitMapForCopyBits(surface->hwdata->mask), &rect, &rect, transparent, NULL ); SetGWorld (surface->hwdata->mask, SDL_Display); SetGWorld (save_port, save_device); return (0);}static int DSp_SetHWAlpha(_THIS, SDL_Surface *surface, UInt8 alpha){ surface->hwdata->alpha.red = (alpha / 255.0) * 65535; surface->hwdata->alpha.blue = (alpha / 255.0) * 65535; surface->hwdata->alpha.green = (alpha / 255.0) * 65535; surface->flags |= SDL_SRCALPHA; if (surface->flags & SDL_SRCCOLORKEY) { return(DSp_MakeHWMask (this, surface)); } return(0);}static int DSp_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key){ CGrafPtr save_port; GDHandle save_device; GetGWorld (&save_port, &save_device); SetGWorld (surface->hwdata->offscreen, NULL); Index2Color (key, &(surface->hwdata->trans)); surface->flags |= SDL_SRCCOLORKEY; SetGWorld (save_port, save_device); if ( surface->flags & SDL_SRCALPHA ) { return(DSp_MakeHWMask (this, surface)); } return(0);}#endif /* DSP_TRY_CC_AND_AA */static int DSp_NewHWSurface(_THIS, CGrafPtr *port, int depth, int width, int height) { OSStatus err; Rect bounds; SetRect (&bounds, 0, 0, width, height); if (dsp_vram_available) { /* try VRAM */ err = NewGWorld (port, depth, &bounds, 0 , SDL_Display, useDistantHdwrMem | noNewDevice ); if (err != noErr) DSp_SetHWError (err, SDL_FALSE); else return (0); } if (dsp_agp_available) { /* try AGP */ err = NewGWorld (port, depth, &bounds, 0 , SDL_Display, useLocalHdwrMem | noNewDevice ); if (err != noErr) DSp_SetHWError (err, SDL_TRUE); else return (0); } return (-1); }static int DSp_AllocHWSurface(_THIS, SDL_Surface *surface){ GWorldPtr temp; if ( DSp_NewHWSurface (this, &temp, surface->format->BitsPerPixel, surface->w, surface->h) < 0 ) return (-1); surface->hwdata = (private_hwdata*) malloc (sizeof (private_hwdata)); if (surface->hwdata == NULL) { SDL_OutOfMemory (); return -1; } memset (surface->hwdata, 0, sizeof(private_hwdata)); surface->hwdata->offscreen = temp; surface->pitch = GetPixRowBytes (GetPortPixMap (temp)) & 0x3FFF; surface->pixels = GetPixBaseAddr (GetPortPixMap (temp)); surface->flags |= SDL_HWSURFACE;#ifdef DSP_TRY_CC_AND_AA surface->flags |= SDL_HWACCEL;#endif return 0;}static void DSp_FreeHWSurface(_THIS, SDL_Surface *surface){ if (surface->hwdata->offscreen != NULL) DisposeGWorld (surface->hwdata->offscreen); free (surface->hwdata); surface->pixels = NULL;}static int DSp_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dest){ int accelerated; /* Set initial acceleration on */ src->flags |= SDL_HWACCEL; /* Set the surface attributes */ if ( (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { if ( ! this->info.blit_hw_A ) { src->flags &= ~SDL_HWACCEL; } } if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { if ( ! this->info.blit_hw_CC ) { src->flags &= ~SDL_HWACCEL; } } /* Check to see if final surface blit is accelerated */ accelerated = !!(src->flags & SDL_HWACCEL); if ( accelerated ) { src->map->hw_blit = DSp_HWAccelBlit; } return(accelerated);}static int DSp_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect){ CGrafPtr save_port; GDHandle save_device; Rect src_rect, dst_rect; RGBColor black = { 0, 0, 0 }; RGBColor white = { 0xFFFF, 0xFFFF, 0xFFFF };#ifdef DSP_TRY_CC_AND_AA UInt32 mode; #endif SetRect (&src_rect, srcrect->x, srcrect->y, srcrect->x + srcrect->w, srcrect->y + srcrect->h); SetRect (&dst_rect, dstrect->x, dstrect->y, dstrect->x + dstrect->w, dstrect->y + dstrect->h); GetGWorld (&save_port, &save_device); SetGWorld (dst->hwdata->offscreen, NULL); RGBForeColor (&black); RGBBackColor (&white); #ifdef DSP_TRY_CC_AND_AA if ( (src->flags & SDL_SRCCOLORKEY) && (src->flags & SDL_SRCALPHA) ) { OpColor (&(src->hwdata->alpha)); CopyDeepMask ( GetPortBitMapForCopyBits(src->hwdata->offscreen), GetPortBitMapForCopyBits(src->hwdata->mask), GetPortBitMapForCopyBits(dst->hwdata->offscreen), &src_rect, &src_rect, &dst_rect, blend, NULL ); } else { if ( src->flags & SDL_SRCCOLORKEY) { RGBBackColor (&(src->hwdata->trans) ); mode = transparent; } else if (src->flags & SDL_SRCALPHA) { OpColor (&(src->hwdata->alpha)); mode = blend; } else { mode = srcCopy; } CopyBits ( GetPortBitMapForCopyBits(src->hwdata->offscreen), GetPortBitMapForCopyBits(dst->hwdata->offscreen), &src_rect, &dst_rect, mode, NULL ); } #else CopyBits ( &(((GrafPtr)(src->hwdata->offscreen))->portBits), &(((GrafPtr)(dst->hwdata->offscreen))->portBits), &src_rect, &dst_rect, srcCopy, NULL );#endif /* DSP_TRY_CC_AND_AA */ SetGWorld (save_port, save_device); return(0);}static int DSp_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color){ CGrafPtr save_port; GDHandle save_device; Rect fill_rect; RGBColor rgb; SetRect (&fill_rect, rect->x, rect->y, rect->x + rect->w, rect->y + rect->h); GetGWorld (&save_port, &save_device); SetGWorld (dst->hwdata->offscreen, NULL); Index2Color (color, &rgb); RGBForeColor (&rgb); PaintRect (&fill_rect); SetGWorld (save_port, save_device); return(0);}static int DSp_FlipHWSurface(_THIS, SDL_Surface *surface){ if ( (surface->flags & SDL_HWSURFACE) ) { CGrafPtr dsp_front_buffer, save_port; Rect rect; unsigned int old_count; /* pseudo page flipping for VRAM back buffer*/ DSpContext_GetFrontBuffer (dsp_context, &dsp_front_buffer); SetRect (&rect, 0, 0, surface->w-1, surface->h-1); GetPort ((GrafPtr *)&save_port); SetPort ((GrafPtr)dsp_front_buffer); /* wait for retrace */ /* I have tried doing the swap in interrupt routine (VBL Proc) to do */ /* it asynchronously, but apparently CopyBits isn't interrupt safe */ #if ! TARGET_API_MAC_OSX #ifndef DSP_NO_SYNC_VBL old_count = retrace_count; while (old_count == retrace_count) ; #endif #endif CopyBits ( GetPortBitMapForCopyBits(dsp_back_buffer), GetPortBitMapForCopyBits(dsp_front_buffer), &rect, &rect, srcCopy, NULL ); SetPort ((GrafPtr)save_port); } else { /* not really page flipping at all: DSp just blits the dirty rectangles from DSp_UpdateRects */ Boolean busy_flag; DSpContext_SwapBuffers (dsp_context, NULL, &busy_flag); /* this waits for VBL */ DSpContext_GetBackBuffer (dsp_context, kDSpBufferKind_Normal, &dsp_back_buffer); surface->pixels = GetPixBaseAddr( GetPortPixMap(dsp_back_buffer) ); } return(0);}static int DSp_LockHWSurface(_THIS, SDL_Surface *surface){ if ( LockPixels (GetGWorldPixMap (surface->hwdata->offscreen)) ) return 0; else return -1;}static void DSp_UnlockHWSurface(_THIS, SDL_Surface *surface){ UnlockPixels (GetGWorldPixMap (surface->hwdata->offscreen));}static void DSp_DirectUpdate(_THIS, int numrects, SDL_Rect *sdl_rects){ return;}static void DSp_DSpUpdate(_THIS, int numrects, SDL_Rect *sdl_rects){#if ! TARGET_API_MAC_OSX /* Unsupported DSp in here */ int i; Rect rect; for (i = 0; i < numrects; i++) { rect.top = sdl_rects[i].y; rect.left = sdl_rects[i].x; rect.bottom = sdl_rects[i].h + sdl_rects[i].y; rect.right = sdl_rects[i].w + sdl_rects[i].x; DSpContext_InvalBackBufferRect (dsp_context, &rect); }#endif}static int DSp_CreatePalette(_THIS) { /* Create our palette */ SDL_CTab = (CTabHandle)NewHandle(sizeof(ColorSpec)*256 + 8); if ( SDL_CTab == nil ) { SDL_OutOfMemory(); return(-1); } (**SDL_CTab).ctSeed = GetCTSeed(); (**SDL_CTab).ctFlags = 0; (**SDL_CTab).ctSize = 255; CTabChanged(SDL_CTab); SDL_CPal = NewPalette(256, SDL_CTab, pmExplicit+pmTolerant, 0); return 0;}static int DSp_DestroyPalette(_THIS) { /* Free palette and restore original one */ if ( SDL_CTab != nil ) { DisposeHandle((Handle)SDL_CTab); SDL_CTab = nil; } if ( SDL_CPal != nil ) { DisposePalette(SDL_CPal); SDL_CPal = nil; } RestoreDeviceClut(SDL_Display); return (0);}static int DSp_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors){ CTabHandle cTab; int i; cTab = SDL_CTab; /* Verify the range of colors */ if ( (firstcolor+ncolors) > ((**cTab).ctSize+1) ) { return(0); } /* Set the screen palette and update the display */ for(i = 0; i < ncolors; i++) { int j = firstcolor + i; (**cTab).ctTable[j].value = j; (**cTab).ctTable[j].rgb.red = colors[i].r << 8 | colors[i].r; (**cTab).ctTable[j].rgb.green = colors[i].g << 8 | colors[i].g; (**cTab).ctTable[j].rgb.blue = colors[i].b << 8 | colors[i].b; } SetGDevice(SDL_Display); SetEntries(0, (**cTab).ctSize, (ColorSpec *)&(**cTab).ctTable); return(1);}void DSp_VideoQuit(_THIS){ int i; /* Free current video mode */ DSp_UnsetVideoMode(this, this->screen); /* Free Palette and restore original */ DSp_DestroyPalette (this); /* Free list of video modes */ if ( SDL_modelist != NULL ) { for ( i=0; SDL_modelist[i]; i++ ) { free(SDL_modelist[i]); } free(SDL_modelist); SDL_modelist = NULL; } /* Unload DrawSprocket */ DSpShutdown ();}#ifdef HAVE_OPENGL/* swap buffers with v-sync */static void DSp_GL_SwapBuffers (_THIS) { #ifndef DSP_NO_SYNC_OPENGL unsigned int old_count; old_count = retrace_count; while (old_count == retrace_count) ; #endif aglSwapBuffers (glContext);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -