int ph_FlipHWSurface(_THIS, SDL_Surface* screen) { if ((screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { PgWaitHWIdle(); if (OCImage.current==0) { PgSwapDisplay(OCImage.offscreen_context, 0); OCImage.current=1; screen->pitch = OCImage.offscreen_backcontext->pitch; screen->pixels = OCImage.FrameData1; PhDCSetCurrent(OCImage.offscreen_backcontext); PgFlush(); } else { PgSwapDisplay(OCImage.offscreen_backcontext, 0); OCImage.current=0; screen->pitch = OCImage.offscreen_context->pitch; screen->pixels = OCImage.FrameData0; PhDCSetCurrent(OCImage.offscreen_context); PgFlush(); } } return 0; }
/* photon_clear_to_color: * Accelerated screen clear routine. */ static void photon_clear_to_color(BITMAP *bmp, int color) { struct Ph_rect dest_rect = { { bmp->cl + bmp->x_ofs, bmp->ct + bmp->y_ofs }, { bmp->x_ofs + bmp->cr, bmp->y_ofs + bmp->cb } }; struct BITMAP *parent; /* find parent */ parent = bmp; while (parent->id & BMP_ID_SUB) parent = (BITMAP *)parent->extra; /* set fill color */ /* if (bmp->vtable->color_depth == 8) PgSetFillColor(color); else */ PgSetFillColor(PgRGB(getr(color), getg(color), getb(color))); PhDCSetCurrent(BMP_EXTRA(parent)->context); PgDrawRect(&dest_rect, Pg_DRAW_FILL); if (parent == pseudo_screen) ph_update_window(&dest_rect); else PgFlush(); }
NS_IMETHODIMP nsRenderingContextPh :: FillRect( nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight ) { nscoord x,y,w,h; x = aX; y = aY; w = aWidth; h = aHeight; mTranMatrix->TransformCoord( &x, &y, &w, &h ); PgSetGC( NULL ); /* ATENTIE */ PhDCSetCurrent( mSurfaceDC ); UpdateGC(); PgSetStrokeColorCx( mGC, mCurrentColor ); PgSetStrokeDashCx( mGC, sLineStyle[mCurrentLineStyle], sLineStyleLen[mCurrentLineStyle], 0x10000 ); PgSetFillColorCx( mGC, mCurrentColor ); ConditionRect(x,y,w,h); if( w && h ) { int y2 = y + h - 1; if( y < SHRT_MIN ) y = SHRT_MIN; /* on very large documents, the PgDrawIRect will take only the short part from the int, which could lead to randomly, hazardous results see PR: 5864 */ if( y2 >= SHRT_MAX ) y2 = SHRT_MAX; /* on very large documents, the PgDrawIRect will take only the short part from the int, which could lead to randomly, hazardous results see PR: 5864 */ PgDrawIRectCx( mSurfaceDC, x, y, x + w - 1, y2, Pg_DRAW_FILL ); } return NS_OK; }
static int ph_GL_MakeCurrent(_THIS) { PgSetRegion(PtWidgetRid(window)); if (oglctx!=NULL) { PhDCSetCurrent(oglctx); } return 0; }
int ph_LeaveFullScreen(_THIS) { PgDisplaySettings_t oldmode_settings; if (currently_fullscreen) { if ((this->screen) && ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)) { #if !SDL_VIDEO_OPENGL || (_NTO_VERSION < 630) return 0; #endif } /* release routines starts here */ { if (OCImage.direct_context) { PdDirectStop(OCImage.direct_context); PdReleaseDirectContext(OCImage.direct_context); OCImage.direct_context=NULL; } if (OCImage.oldDC) { PhDCSetCurrent(OCImage.oldDC); OCImage.oldDC=NULL; } currently_fullscreen=0; /* Restore old video mode */ if (old_video_mode != -1) { oldmode_settings.mode = (unsigned short) old_video_mode; oldmode_settings.refresh = (unsigned short) old_refresh_rate; oldmode_settings.flags = 0; if (PgSetVideoMode(&oldmode_settings) < 0) { SDL_SetError("Ph_LeaveFullScreen(): PgSetVideoMode() function failed !\n"); return 0; } } old_video_mode=-1; old_refresh_rate=-1; } } return 1; }
/* ddraw_vline: * Accelerated vline routine. */ static void ddraw_vline(BITMAP *bmp, int x, int y1, int y2, int color) { struct Ph_rect dest_rect; struct BITMAP *parent; if (_drawing_mode != DRAW_MODE_SOLID) { _orig_vline(bmp, x, y1, y2, color); return; } if (y1 > y2) { int tmp = y1; y1 = y2; y2 = tmp; } if (bmp->clip) { if ((x < bmp->cl) || (x >= bmp->cr)) return; if (y1 < bmp->ct) y1 = bmp->ct; if (y2 >= bmp->cb) y2 = bmp->cb-1; if (y2 < y1) return; } dest_rect.ul.x = x + bmp->x_ofs; dest_rect.ul.y = y1 + bmp->y_ofs; dest_rect.lr.x = x + bmp->x_ofs; dest_rect.lr.y = y2 + bmp->y_ofs; /* find parent */ parent = bmp; while (parent->id & BMP_ID_SUB) parent = (BITMAP *)parent->extra; PhDCSetCurrent(BMP_EXTRA(parent)->context); PgDrawLine(&dest_rect.ul, &dest_rect.lr); if (parent == pseudo_screen) ph_update_window(&dest_rect); else PgFlush(); }
/* ddraw_hline: * Accelerated scanline fill routine. */ static void ddraw_hline(BITMAP *bmp, int x1, int y, int x2, int color) { struct Ph_rect dest_rect; struct BITMAP *parent; if (_drawing_mode != DRAW_MODE_SOLID) { _orig_hline(bmp, x1, y, x2, color); return; } if (x1 > x2) { int tmp = x1; x1 = x2; x2 = tmp; } if (bmp->clip) { if ((y < bmp->ct) || (y >= bmp->cb)) return; if (x1 < bmp->cl) x1 = bmp->cl; if (x2 >= bmp->cr) x2 = bmp->cr-1; if (x2 < x1) return; } dest_rect.ul.x = x1 + bmp->x_ofs; dest_rect.ul.y = y + bmp->y_ofs; dest_rect.lr.x = x2 + bmp->x_ofs; dest_rect.lr.y = y + bmp->y_ofs; /* find parent */ parent = bmp; while (parent->id & BMP_ID_SUB) parent = (BITMAP *)parent->extra; PhDCSetCurrent(BMP_EXTRA(parent)->context); PgDrawLine(&dest_rect.ul, &dest_rect.lr); if (parent == pseudo_screen) ph_update_window(&dest_rect); else PgFlush(); }
void ph_DestroyImage(_THIS, SDL_Surface* screen) { #ifdef HAVE_OPENGL if ((screen->flags & SDL_OPENGL)==SDL_OPENGL) { if (oglctx) { PhDCSetCurrent(NULL); PhDCRelease(oglctx); oglctx=NULL; oglflags=0; oglbpp=0; } return; } #endif /* HAVE_OPENGL */ if (currently_fullscreen) { /* if we right now in 8bpp fullscreen we must release palette */ if ((screen->format->BitsPerPixel==8) && (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_LeaveFullScreen(this); } if (OCImage.offscreen_context != NULL) { PhDCRelease(OCImage.offscreen_context); OCImage.offscreen_context = NULL; OCImage.FrameData0 = NULL; } if (OCImage.offscreen_backcontext != NULL) { PhDCRelease(OCImage.offscreen_backcontext); OCImage.offscreen_backcontext = NULL; OCImage.FrameData1 = NULL; } OCImage.CurrentFrameData = NULL; if (SDL_Image) { /* if palette allocated, free it */ if (SDL_Image->palette) { free(SDL_Image->palette); } PgShmemDestroy(SDL_Image->image); free(SDL_Image); } /* Must be zeroed everytime */ SDL_Image = NULL; if (screen) { screen->pixels = NULL; } }
static int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags) { PhDim_t dim; uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS]; int exposepost=0; int OGLargc; dim.w=width; dim.h=height; if ((oglctx!=NULL) && (oglflags==flags) && (oglbpp==bpp)) { PdOpenGLContextResize(oglctx, &dim); PhDCSetCurrent(oglctx); return 0; } else { if (oglctx!=NULL) { PhDCSetCurrent(NULL); PhDCRelease(oglctx); oglctx=NULL; exposepost=1; } } OGLargc=0; if (this->gl_config.depth_size) { OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS; OGLAttrib[OGLargc++]=this->gl_config.depth_size; } if (this->gl_config.stencil_size) { OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS; OGLAttrib[OGLargc++]=this->gl_config.stencil_size; } OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FORCE_SW; if (flags & SDL_FULLSCREEN) { OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN; OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DIRECT; OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_BEST; OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_CENTER; } OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE; if (this->gl_config.double_buffer) { oglctx=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib); } else { oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib); } if (oglctx==NULL) { SDL_SetError("ph_SetupOpenGLContext(): cannot create OpenGL context !\n"); return (-1); } PhDCSetCurrent(oglctx); PtFlush(); oglflags=flags; oglbpp=bpp; if (exposepost!=0) { /* OpenGL context has been recreated, so report about this fact */ SDL_PrivateExpose(); } 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; }
int ph_SetupOCImage(_THIS, SDL_Surface *screen) { int type = 0; int bpp; OCImage.flags = screen->flags; 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_SetupOCImage(): unsupported bpp=%d !\n", bpp); return -1; } break; } /* Currently only offscreen contexts with the same bit depth as the * display can be created. */ OCImage.offscreen_context = PdCreateOffscreenContext(0, screen->w, screen->h, Pg_OSC_MEM_PAGE_ALIGN); if (OCImage.offscreen_context == NULL) { SDL_SetError("ph_SetupOCImage(): PdCreateOffscreenContext() function failed !\n"); return -1; } screen->pitch = OCImage.offscreen_context->pitch; OCImage.dc_ptr = (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context); if (OCImage.dc_ptr == NULL) { SDL_SetError("ph_SetupOCImage(): PdGetOffscreenContextPtr function failed !\n"); PhDCRelease(OCImage.offscreen_context); return -1; } OCImage.FrameData0 = OCImage.dc_ptr; OCImage.CurrentFrameData = OCImage.FrameData0; OCImage.current = 0; PhDCSetCurrent(OCImage.offscreen_context); screen->pixels = OCImage.CurrentFrameData; this->UpdateRects = ph_OCUpdate; return 0; }
/* photon_rectfill: * Accelerated rectangle fill routine. */ static void photon_rectfill(BITMAP *bmp, int x1, int y1, int x2, int y2, int color) { struct Ph_rect dest_rect; struct BITMAP *parent; if (_drawing_mode != DRAW_MODE_SOLID) { _orig_rectfill(bmp, x1, y1, x2, y2, color); return; } if (x2 < x1) { int tmp = x1; x1 = x2; x2 = tmp; } if (y2 < y1) { int tmp = y1; y1 = y2; y2 = tmp; } if (bmp->clip) { if (x1 < bmp->cl) x1 = bmp->cl; if (x2 >= bmp->cr) x2 = bmp->cr-1; if (x2 < x1) return; if (y1 < bmp->ct) y1 = bmp->ct; if (y2 >= bmp->cb) y2 = bmp->cb-1; if (y2 < y1) return; } dest_rect.ul.x = x1 + bmp->x_ofs; dest_rect.ul.y = y1 + bmp->y_ofs; dest_rect.lr.x = x2 + bmp->x_ofs; dest_rect.lr.y = y2 + bmp->y_ofs; /* find parent */ parent = bmp; while (parent->id & BMP_ID_SUB) parent = (BITMAP *)parent->extra; /* set fill color */ /* if (bmp->vtable->color_depth == 8) PgSetFillColor(color); else */ PgSetFillColor(PgRGB(getr(color), getg(color), getb(color))); PhDCSetCurrent(BMP_EXTRA(parent)->context); PgDrawRect(&dest_rect, Pg_DRAW_FILL); if (parent == pseudo_screen) ph_update_window(&dest_rect); else PgFlush(); }
SDL_Overlay* ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface* display) { SDL_Overlay* overlay; struct private_yuvhwdata* hwdata; int vidport; int rtncode; int planes; int i=0; PhPoint_t pos; /* Create the overlay structure */ overlay = SDL_calloc(1, sizeof(SDL_Overlay)); if (overlay == NULL) { SDL_OutOfMemory(); return NULL; } /* Fill in the basic members */ overlay->format = format; overlay->w = width; overlay->h = height; overlay->hwdata = NULL; /* Set up the YUV surface function structure */ overlay->hwfuncs = &ph_yuvfuncs; /* Create the pixel data and lookup tables */ hwdata = SDL_calloc(1, sizeof(struct private_yuvhwdata)); if (hwdata == NULL) { SDL_OutOfMemory(); SDL_FreeYUVOverlay(overlay); return NULL; } overlay->hwdata = hwdata; PhDCSetCurrent(0); if (overlay->hwdata->channel == NULL) { if ((overlay->hwdata->channel = PgCreateVideoChannel(Pg_VIDEO_CHANNEL_SCALER, 0)) == NULL) { SDL_SetError("ph_CreateYUVOverlay(): Create channel failed: %s\n", strerror(errno)); SDL_FreeYUVOverlay(overlay); return NULL; } } overlay->hwdata->forcedredraw=0; PtGetAbsPosition(window, &pos.x, &pos.y); overlay->hwdata->CurrentWindowPos.x = pos.x; overlay->hwdata->CurrentWindowPos.y = pos.y; overlay->hwdata->CurrentViewPort.pos.x = 0; overlay->hwdata->CurrentViewPort.pos.y = 0; overlay->hwdata->CurrentViewPort.size.w = width; overlay->hwdata->CurrentViewPort.size.h = height; overlay->hwdata->State = OVERLAY_STATE_UNINIT; overlay->hwdata->FrameData0 = (FRAMEDATA *) SDL_calloc(1, sizeof(FRAMEDATA)); overlay->hwdata->FrameData1 = (FRAMEDATA *) SDL_calloc(1, sizeof(FRAMEDATA)); vidport = -1; i=0; overlay->hwdata->ischromakey=0; do { SDL_memset(&overlay->hwdata->caps, 0x00, sizeof(PgScalerCaps_t)); overlay->hwdata->caps.size = sizeof(PgScalerCaps_t); rtncode = PgGetScalerCapabilities(overlay->hwdata->channel, i, &overlay->hwdata->caps); if (rtncode==0) { if (overlay->hwdata->caps.format==format) { if ((overlay->hwdata->caps.flags & Pg_SCALER_CAP_DST_CHROMA_KEY) == Pg_SCALER_CAP_DST_CHROMA_KEY) { overlay->hwdata->ischromakey=1; } vidport=1; break; } } else { break; } i++; } while(1); if (vidport == -1) { SDL_SetError("No available video ports for requested format\n"); SDL_FreeYUVOverlay(overlay); return NULL; } overlay->hwdata->format = format; overlay->hwdata->props.format = format; overlay->hwdata->props.size = sizeof(PgScalerProps_t); overlay->hwdata->props.src_dim.w = width; overlay->hwdata->props.src_dim.h = height; /* overlay->hwdata->chromakey = PgGetOverlayChromaColor(); */ overlay->hwdata->chromakey = PgRGB(12, 6, 12); /* very dark pink color */ overlay->hwdata->props.color_key = overlay->hwdata->chromakey; PhAreaToRect(&overlay->hwdata->CurrentViewPort, &overlay->hwdata->props.viewport); overlay->hwdata->props.flags = Pg_SCALER_PROP_DOUBLE_BUFFER; if ((overlay->hwdata->ischromakey)&&(overlay->hwdata->chromakey)) { overlay->hwdata->props.flags |= Pg_SCALER_PROP_CHROMA_ENABLE; overlay->hwdata->props.flags |= Pg_SCALER_PROP_CHROMA_SPECIFY_KEY_MASK; } else { overlay->hwdata->props.flags &= ~Pg_SCALER_PROP_CHROMA_ENABLE; } rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &overlay->hwdata->props); switch(rtncode) { case -1: SDL_SetError("PgConfigScalerChannel failed\n"); SDL_FreeYUVOverlay(overlay); return NULL; case 1: case 0: default: break; } planes = grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1); if(overlay->hwdata->channel->yplane1 != NULL) overlay->hwdata->YStride = overlay->hwdata->channel->yplane1->pitch; if(overlay->hwdata->channel->vplane1 != NULL) overlay->hwdata->UStride = overlay->hwdata->channel->vplane1->pitch; if(overlay->hwdata->channel->uplane1 != NULL) overlay->hwdata->VStride = overlay->hwdata->channel->uplane1->pitch; /* check for the validness of all planes */ if ((overlay->hwdata->channel->yplane1 == NULL) && (overlay->hwdata->channel->uplane1 == NULL) && (overlay->hwdata->channel->vplane1 == NULL)) { SDL_FreeYUVOverlay(overlay); SDL_SetError("PgConfigScaler() returns all planes equal NULL\n"); return NULL; } /* overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel); if (overlay->hwdata->current==0) { overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0; } else { overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1; } */ overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0; /* overlay->hwdata->locked = 1; */ /* Find the pitch and offset values for the overlay */ overlay->planes = planes; overlay->pitches = SDL_calloc(overlay->planes, sizeof(Uint16)); overlay->pixels = SDL_calloc(overlay->planes, sizeof(Uint8*)); if (!overlay->pitches || !overlay->pixels) { SDL_OutOfMemory(); SDL_FreeYUVOverlay(overlay); return(NULL); } if (overlay->planes > 0) { overlay->pitches[0] = overlay->hwdata->channel->yplane1->pitch; overlay->pixels[0] = overlay->hwdata->CurrentFrameData->Y; } if (overlay->planes > 1) { overlay->pitches[1] = overlay->hwdata->channel->vplane1->pitch; overlay->pixels[1] = overlay->hwdata->CurrentFrameData->U; } if (overlay->planes > 2) { overlay->pitches[2] = overlay->hwdata->channel->uplane1->pitch; overlay->pixels[2] = overlay->hwdata->CurrentFrameData->V; } overlay->hwdata->State = OVERLAY_STATE_ACTIVE; overlay->hwdata->scaler_on = 0; overlay->hw_overlay = 1; current_overlay=overlay; return overlay; }