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; }
/* 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(); }
/* 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(); }
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; }
static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat) { PgHWCaps_t my_hwcaps; int i; window=NULL; desktoppal=SDLPH_PAL_NONE; #ifdef HAVE_OPENGL oglctx=NULL; oglflags=0; oglbpp=0; #endif /* HAVE_OPENGL */ old_video_mode=-1; old_refresh_rate=-1; if (NULL == (event = malloc(EVENT_SIZE))) { SDL_OutOfMemory(); return -1; } memset(event, 0x00, EVENT_SIZE); window = ph_CreateWindow(this); if (window == NULL) { SDL_SetError("ph_VideoInit(): Couldn't create video window !\n"); return -1; } /* Create the blank cursor */ SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask, (int)BLANK_CWIDTH, (int)BLANK_CHEIGHT, (int)BLANK_CHOTX, (int)BLANK_CHOTY); if (SDL_BlankCursor == NULL) { return -1; } if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) { SDL_SetError("ph_VideoInit(): GetGraphicsHWCaps function failed !\n"); this->FreeWMCursor(this, SDL_BlankCursor); return -1; } if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &desktop_mode) < 0) { SDL_SetError("ph_VideoInit(): PgGetVideoModeInfo function failed !\n"); this->FreeWMCursor(this, SDL_BlankCursor); return -1; } /* We need to return BytesPerPixel as it in used by CreateRGBsurface */ vformat->BitsPerPixel = desktop_mode.bits_per_pixel; vformat->BytesPerPixel = desktop_mode.bytes_per_scanline/desktop_mode.width; desktopbpp = desktop_mode.bits_per_pixel; /* save current palette */ if (desktopbpp==8) { PgGetPalette(savedpal); PgGetPalette(syspalph); } else { for(i=0; i<_Pg_MAX_PALETTE; i++) { savedpal[i]=PgRGB(0, 0, 0); syspalph[i]=PgRGB(0, 0, 0); } } currently_fullscreen = 0; currently_hided = 0; current_overlay = NULL; OCImage.direct_context = NULL; OCImage.offscreen_context = NULL; OCImage.offscreen_backcontext = NULL; OCImage.oldDC = NULL; OCImage.CurrentFrameData = NULL; OCImage.FrameData0 = NULL; OCImage.FrameData1 = NULL; this->info.wm_available = 1; return 0; }
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; }
void nsWidget::ProcessDrag( PhEvent_t *event, PRUint32 aEventType, PhPoint_t *pos ) { nsCOMPtr<nsIDragSession> currSession; sDragService->GetCurrentSession ( getter_AddRefs(currSession) ); if( !currSession ) return; int action = nsIDragService::DRAGDROP_ACTION_NONE; nsDragService *d = ( nsDragService * ) sDragService; if( d->mActionType & nsIDragService::DRAGDROP_ACTION_MOVE ) action = nsIDragService::DRAGDROP_ACTION_MOVE; else if( d->mActionType & nsIDragService::DRAGDROP_ACTION_LINK ) action = nsIDragService::DRAGDROP_ACTION_LINK; else if( d->mActionType & nsIDragService::DRAGDROP_ACTION_COPY ) action = nsIDragService::DRAGDROP_ACTION_COPY; currSession->SetDragAction( action ); DispatchDragDropEvent( event, aEventType, pos ); int old_subtype = event->subtype; event->subtype = Ph_EV_DND_ENTER; PRBool canDrop; currSession->GetCanDrop(&canDrop); if(!canDrop) { static PhCharacterCursorDescription_t nodrop_cursor = { { Ph_CURSOR_NOINPUT, sizeof(PhCharacterCursorDescription_t) }, PgRGB( 255, 255, 224 ) }; PhAckDnd( event, Ph_EV_DND_MOTION, ( PhCursorDescription_t * ) &nodrop_cursor ); } else { static PhCharacterCursorDescription_t drop_cursor = { { Ph_CURSOR_PASTE, sizeof(PhCharacterCursorDescription_t) }, PgRGB( 255, 255, 224 ) }; PhAckDnd( event, Ph_EV_DND_MOTION, ( PhCursorDescription_t * ) &drop_cursor ); } event->subtype = old_subtype; // Clear the cached value currSession->SetCanDrop(PR_FALSE); }