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; }
void ph_OCDCUpdate(_THIS, int numrects, SDL_Rect *rects) { PgWaitHWIdle(); if (PgFlush() < 0) { SDL_SetError("ph_OCDCUpdate(): PgFlush failed.\n"); } }
void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects) { int i; PhPoint_t zero = {0}; PhArea_t src_rect; PhArea_t dest_rect; PgSetRegion(PtWidgetRid(window)); PgSetClipping(0, NULL); PgWaitHWIdle(); for (i=0; i<numrects; ++i) { if (rects[i].w == 0) /* Clipped? */ { continue; } if (rects[i].h == 0) /* Clipped? */ { continue; } src_rect.pos.x=rects[i].x; src_rect.pos.y=rects[i].y; dest_rect.pos.x=rects[i].x; dest_rect.pos.y=rects[i].y; src_rect.size.w=rects[i].w; src_rect.size.h=rects[i].h; dest_rect.size.w=rects[i].w; dest_rect.size.h=rects[i].h; zero.x = 0; zero.y = 0; PgSetTranslation(&zero, 0); PgSetRegion(PtWidgetRid(window)); PgSetClipping(0, NULL); PgContextBlitArea(OCImage.offscreen_context, &src_rect, NULL, &dest_rect); } if (PgFlush() < 0) { SDL_SetError("ph_OCUpdate(): PgFlush failed.\n"); } }
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; }
/** ---------------------------------------------------------------- * Draw the bitmap, this method has a source and destination coordinates * @update dc - 11/20/98 * @param aContext - the rendering context to draw with * @param aSurface - The HDC in a nsDrawingsurfacePh to copy the bits to. * @param aSX - source horizontal location * @param aSY - source vertical location * @param aSWidth - source width * @param aSHeight - source height * @param aDX - destination location * @param aDY - destination location * @param aDWidth - destination width * @param aDHeight - destination height * @result NS_OK if the draw worked */ NS_IMETHODIMP nsImagePh :: Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface, PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight, PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight) { PhRect_t clip = { {aDX, aDY}, {aDX + aDWidth-1, aDY + aDHeight-1} }; PhPoint_t pos = { aDX - aSX, aDY - aSY}; int use_zoom = 0; if( !aSWidth || !aSHeight || !aDWidth || !aDHeight ) return NS_OK; ///* ATENTIE */ printf( "this=%p size=%d,%d src=(%d %d %d %d) dest=(%d %d %d %d)\n", //this, mPhImage.size.w, mPhImage.size.h, aSX, aSY, aSWidth, aSHeight, aDX, aDY, aDWidth, aDHeight ); PhDrawContext_t *dc = ((nsDrawingSurfacePh*)aSurface)->GetDC(); PhGC_t *gc = PgGetGCCx( dc ); if( (aSWidth != aDWidth || aSHeight != aDHeight) ) { /* the case below happens frequently - a 1x1 image needs to be stretched, or a line or a column */ if( aSWidth == 1 && aSHeight == 1 || aSWidth == 1 && aSHeight == aDHeight || aDHeight == 1 && aSWidth == aDWidth ) { /* you can strech the image by drawing it repeateadly */ PhPoint_t space = { 0, 0 }; PhPoint_t rep = { aDWidth, aDHeight }; /* is this a 1x1 transparent image used for spacing? */ if( mWidth == 1 && mHeight == 1 && mAlphaDepth == 1 && mAlphaBits[0] == 0x0 ) return NS_OK; PgSetMultiClipCx( gc, 1, &clip ); if ((mAlphaDepth == 1) || (mAlphaDepth == 0)) { if( mImageFlags & IMAGE_SHMEM ) PgDrawRepPhImageCxv( dc, &mPhImage, 0, &pos, &rep, &space ); else PgDrawRepPhImageCx( dc, &mPhImage, 0, &pos, &rep, &space ); } else { PgMap_t map; map.dim.w = mAlphaWidth; map.dim.h = mAlphaHeight; map.bpl = mAlphaRowBytes; map.bpp = mAlphaDepth; map.map = (unsigned char *)mAlphaBits; PgSetAlphaBlendCx( gc, &map, 0 ); PgAlphaOnCx( gc ); if( mImageFlags & IMAGE_SHMEM ) PgDrawRepPhImageCxv( dc, &mPhImage, 0, &pos, &rep, &space ); else PgDrawRepPhImageCx( dc, &mPhImage, 0, &pos, &rep, &space ); PgAlphaOffCx( gc ); PgSetAlphaBlendCx( gc, NULL, 0 ); /* this shouldn't be necessary, but the ph lib's gc is holding onto our mAlphaBits */ } PgSetMultiClipCx( gc, 0, NULL ); return NS_OK; } else if( mPhImage.size.h > 0 ) { /* keeping the proportions, what is the size of mPhImageZoom that can give use the aDWidth and aDHeight? */ PRInt32 scaled_w = aDWidth * mPhImage.size.w / aSWidth; PRInt32 scaled_h = aDHeight * mPhImage.size.h / aSHeight; use_zoom = 1; if( mPhImageZoom == NULL || mPhImageZoom->size.w != scaled_w || mPhImageZoom->size.h != scaled_h || mDecodedY2_when_scaled != mDecodedY2 || mDirtyFlags != 0 ) { /* we already had a scaled image, but the scaling factor was different from what we need now */ mDirtyFlags = 0; if ( mPhImageZoom ) { if( mImageFlags & ZOOM_SHMEM ) { PgFlushCx( dc ); PgWaitHWIdle(); PgShmemDestroy( mPhImageZoom->image ); } else free( mPhImageZoom->image ); if( mPhImageZoom->mask_bm ) free( mPhImageZoom->mask_bm ); free( mPhImageZoom ); mPhImageZoom = NULL; } /* record the mDecodedY1 at the time of scaling */ mDecodedY2_when_scaled = mDecodedY2; /* this is trying to estimate the image data size of the zoom image */ if (( mPhImage.bpl * scaled_w * scaled_h / mPhImage.size.w ) < IMAGE_SHMEM_THRESHOLD) { mPhImageZoom = PiResizeImage( &mPhImage, NULL, scaled_w, scaled_h, Pi_USE_COLORS); mImageFlags &= ~ZOOM_SHMEM; } else { mPhImageZoom = PiResizeImage( &mPhImage, NULL, scaled_w, scaled_h, Pi_USE_COLORS|Pi_SHMEM); mImageFlags |= ZOOM_SHMEM; } ///* ATENTIE */ printf( "\t\t\tzoom from=%d,%d to=%d,%d\n", mPhImage.size.w, mPhImage.size.h, scaled_w, scaled_h ); } } } PgSetMultiClipCx( gc, 1, &clip ); if ((mAlphaDepth == 1) || (mAlphaDepth == 0)) { if( use_zoom ) { if( mImageFlags & ZOOM_SHMEM ) PgDrawPhImageCxv( dc, &pos, mPhImageZoom, 0 ); else PgDrawPhImageCx( dc, &pos, mPhImageZoom, 0 ); } else { if( mImageFlags & IMAGE_SHMEM ) PgDrawPhImageCxv( dc, &pos, &mPhImage, 0 ); else PgDrawPhImageCx( dc, &pos, &mPhImage, 0 ); } } else { PgMap_t map; map.dim.w = mAlphaWidth; map.dim.h = mAlphaHeight; map.bpl = mAlphaRowBytes; map.bpp = mAlphaDepth; map.map = (unsigned char *)mAlphaBits; PgSetAlphaBlendCx( gc, &map, 0 ); PgAlphaOnCx( gc ); if( use_zoom ) { if( mImageFlags & ZOOM_SHMEM ) PgDrawPhImageCxv( dc, &pos, mPhImageZoom, 0 ); else PgDrawPhImageCx( dc, &pos, mPhImageZoom, 0 ); } else { if( mImageFlags & IMAGE_SHMEM ) PgDrawPhImageCxv( dc, &pos, &mPhImage, 0 ); else PgDrawPhImageCx( dc, &pos, &mPhImage, 0 ); } PgAlphaOffCx( gc ); PgSetAlphaBlendCx( gc, NULL, 0 ); /* this shouldn't be necessary, but the ph lib's gc is holding onto our mAlphaBits */ } PgSetMultiClipCx( gc, 0, NULL ); return NS_OK; }