Esempio n. 1
0
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;
}
Esempio n. 2
0
// this function blits the given buffer using our blit type method
inline void BlitBuffer(PtWidget_t *win,CoolImage *i)
{
	// For blit type 0, we use PgDrawImagemx(). We have to make sure 
	// to set the region to the windows region first.  Don't forget
	// to flush! :)
	if (blittype==0 || blittype==1)
	{
		PhPoint_t pos={0,0};
		PhDim_t size;
		
		//size.w = 768;
		size.w = m_W;
		size.h = m_H;
		//size.h = 576;

		PgSetRegion(PtWidgetRid(win)); 
		//PgDrawImagemx(i->buffer,Pg_IMAGE_DIRECT_565,&pos,&size,i->pitch,0);
		PgDrawImagemx(i->buffer,Pg_IMAGE_DIRECT_888,&pos,&size,i->pitch,0);

		PgFlush();
	}else
    if (blittype == 2)
	{
		PhRect_t r={{0,0},{i->width,i->height}};
		PgSetRegion(PtWidgetRid(win));
		PgContextBlit(i->ctx,&r,NULL,&r);
		PgFlush();
	}

}
Esempio n. 3
0
/* invoked by main tree code to update bitmap into screen */
void ph_window_update_display (struct mame_bitmap *bitmap)
{
   PhRegion_t region_info;	

//	fprintf(stderr,"Calling update display\n");

// TODO:  Not sure just yet what this is for...if it's only x related we can probably
//	  toss it.   
   (*ph_window_update_display_func) (bitmap);

   if (use_mouse &&
       keyboard_pressed (KEYCODE_LALT) &&
       keyboard_pressed_memory (KEYCODE_PGDN))
   {
      if (ph_grab_mouse)
      {
         region_info.cursor_type = 0;
	 region_info.rid = PtWidgetRid(P_mainWindow);
	 ph_grab_mouse = FALSE;
      }
      else
      {
	 region_info.cursor_type = Ph_CURSOR_NONE;
	 region_info.rid = PtWidgetRid(P_mainWindow);      
	 ph_grab_mouse = TRUE;
      }

      PhRegionChange (Ph_REGION_CURSOR, 0, &region_info, NULL, NULL);
   }

   PgFlush();         /* flush buffer to server */
}
Esempio n. 4
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();
}
Esempio n. 5
0
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 (phevent!=NULL)
    {
        SDL_free(phevent);
        phevent=NULL;
    }
}
Esempio n. 6
0
void ph_OCDCUpdate(_THIS, int numrects, SDL_Rect *rects)
{
    PgWaitHWIdle();

    if (PgFlush() < 0)
    {
        SDL_SetError("ph_OCDCUpdate(): PgFlush failed.\n");
    }
}
void ph_PumpEvents(_THIS)
{
    /* Flush the display connection and look to see if events are queued */
    PgFlush();

    while (ph_Pending(this))
    {
        PtEventHandler(event);
        ph_DispatchEvent(this);
    }
}
Esempio n. 8
0
/*****************************************************************************
 * QNXDisplay: displays previously rendered output
 *****************************************************************************
 * This function send the currently rendered image to QNX server, wait until
 * it is displayed and switch the two rendering buffer, preparing next frame.
 *****************************************************************************/
static void QNXDisplay( vout_thread_t *p_vout, picture_t *p_pic )
{
    if( p_vout->p_sys->i_mode == MODE_NORMAL_MEM ||
        p_vout->p_sys->i_mode == MODE_SHARED_MEM )
    {
        PhPoint_t pos = { 0, 0 };

        PgSetRegion( PtWidgetRid( p_vout->p_sys->p_window ) );
        if (p_vout->p_sys->i_screen_depth == 8)
        {
            PgSetPalette( p_vout->p_sys->p_colors, 0, 0, 255, Pg_PALSET_SOFT, 0);
        }
        PgDrawPhImagemx( &pos, p_pic->p_sys->p_image, 0 );
        PgFlush();
    }
    else if( p_vout->p_sys->i_mode == MODE_VIDEO_MEM )
    {
        PhRect_t rc = { { 0, 0 }, { p_vout->output.i_width, p_vout->output.i_height } };

//        PgSetRegion( PtWidgetRid ( p_vout->p_sys->p_window ) );
        PgContextBlit( p_pic->p_sys->p_ctx[0], &rc, NULL, &rc );
        PgFlush();
    }
}
Esempio n. 9
0
/* 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();
}
Esempio n. 10
0
/* 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();
}
Esempio n. 11
0
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");
    }
}
Esempio n. 12
0
/* perform a blocking read if no events available */
int ph_Pending(_THIS)
{
    /* Flush the display connection and look to see if events are queued */
    PgFlush();

    while (1)
    {
        switch(PhEventPeek(event, EVENT_SIZE))
        {
            case Ph_EVENT_MSG:
                 return 1;
                 break;
            case -1:
                 perror("ph_Pending(): PhEventNext failed");
                 break;
            default:
                 return 0;
        }
    }

    /* Oh well, nothing is ready .. */
    return(0);
}
Esempio n. 13
0
void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
{
    PhPoint_t ph_pos;
    PhRect_t ph_rect;
    int i;

    for (i=0; i<numrects; ++i) 
    {
    	if (rects[i].w==0) /* Clipped? */
        { 
            continue;
        }

    	if (rects[i].h==0) /* Clipped? */
        { 
            continue;
        }

        ph_pos.x = rects[i].x;
        ph_pos.y = rects[i].y;
        ph_rect.ul.x = rects[i].x;
        ph_rect.ul.y = rects[i].y;
        ph_rect.lr.x = rects[i].x + rects[i].w;
        ph_rect.lr.y = rects[i].y + rects[i].h;

        if (PgDrawPhImageRectmx(&ph_pos, SDL_Image, &ph_rect, 0) < 0)
        {
            SDL_SetError("ph_NormalUpdate(): PgDrawPhImageRectmx failed !\n");
        }
    }

    if (PgFlush() < 0)
    {
    	SDL_SetError("ph_NormalUpdate(): PgFlush failed.\n");
    }
}
Esempio n. 14
0
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);
}
Esempio n. 15
0
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;
    }
}
Esempio n. 16
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;
}
Esempio n. 17
0
int ph_EnterFullScreen(_THIS, SDL_Surface* screen, int fmode)
{
    PgDisplaySettings_t settings;
    int mode;
    char* refreshrate;
    int refreshratenum;

    if (!currently_fullscreen)
    {
        /* Get the video mode and set it */
        if (screen->flags & SDL_ANYFORMAT)
        {
            if ((mode = get_mode_any_format(screen->w, screen->h, screen->format->BitsPerPixel)) == 0)
            {
                SDL_SetError("ph_EnterFullScreen(): can't find appropriate video mode !\n");
                return 0;
            }
        }
        else
        {
            if ((mode = ph_GetVideoMode(screen->w, screen->h, screen->format->BitsPerPixel)) == 0)
            {
                SDL_SetError("ph_EnterFullScreen(): can't find appropriate video mode !\n");
                return 0;
            }
            if (PgGetVideoModeInfo(mode, &mode_info) < 0)
            {
                SDL_SetError("ph_EnterFullScreen(): can't get video mode capabilities !\n");
                return 0;
            }
            if (mode_info.height != screen->h)
            {
               if ((mode_info.height==480) && (screen->h==400))
               {
                  videomode_emulatemode=1;
               }
            }
            else
            {
               videomode_emulatemode=0;
            }
        }

        /* save old video mode caps */
        PgGetVideoMode(&settings);
        old_video_mode=settings.mode;
        old_refresh_rate=settings.refresh;

        /* setup new video mode */
        settings.mode = mode;
        settings.refresh = 0;
        settings.flags = 0;

        refreshrate=SDL_getenv("SDL_PHOTON_FULLSCREEN_REFRESH");
        if (refreshrate!=NULL)
        {
           if (SDL_sscanf(refreshrate, "%d", &refreshratenum)==1)
           {
               settings.refresh = refreshratenum;
           }
        }

        if (PgSetVideoMode(&settings) < 0)
        {
            SDL_SetError("ph_EnterFullScreen(): PgSetVideoMode() call failed !\n");
            return 0;
        }

        if (this->screen)
        {
            if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
            {
#if !SDL_VIDEO_OPENGL || (_NTO_VERSION < 630)
                return 0; /* 6.3.0 */
#endif
            }
        }

        if (fmode==0)
        {
            if (OCImage.direct_context==NULL)
            {
                OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext();
                if (!OCImage.direct_context)
                {
                    SDL_SetError("ph_EnterFullScreen(): Can't create direct context !\n");
                    ph_LeaveFullScreen(this);
                    return 0;
                }
            }
            OCImage.oldDC=PdDirectStart(OCImage.direct_context);
        }

        currently_fullscreen = 1;
    }
    PgFlush();

    return 1;
}
Esempio n. 18
0
int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* src, SDL_Rect* dst)
{
    int rtncode;
    PhPoint_t pos;
    SDL_Rect backrect;
    PhRect_t windowextent;
    int winchanged=0;

    if ((overlay == NULL) || (overlay->hwdata==NULL))
    {
        return -1;
    }

    if (overlay->hwdata->State == OVERLAY_STATE_UNINIT)
    {
        return -1;
    }

    PtGetAbsPosition(window, &pos.x, &pos.y);
    if ((pos.x!=overlay->hwdata->CurrentWindowPos.x) ||
        (pos.y!=overlay->hwdata->CurrentWindowPos.y))
    {
       winchanged=1;
       overlay->hwdata->CurrentWindowPos.x=pos.x;
       overlay->hwdata->CurrentWindowPos.y=pos.y;
    }

    /* If CurrentViewPort position/size has been changed, then move/resize the viewport */
    if ((overlay->hwdata->CurrentViewPort.pos.x != dst->x) ||
        (overlay->hwdata->CurrentViewPort.pos.y != dst->y) ||
        (overlay->hwdata->CurrentViewPort.size.w != dst->w) ||
        (overlay->hwdata->CurrentViewPort.size.h != dst->h) ||
        (overlay->hwdata->scaler_on==0) || (winchanged==1) ||
        (overlay->hwdata->forcedredraw==1))
    {

        if (overlay->hwdata->ischromakey==1)
        {
            /* restore screen behind the overlay/chroma color. */
            backrect.x=overlay->hwdata->CurrentViewPort.pos.x;
            backrect.y=overlay->hwdata->CurrentViewPort.pos.y;
            backrect.w=overlay->hwdata->CurrentViewPort.size.w;
            backrect.h=overlay->hwdata->CurrentViewPort.size.h;
            this->UpdateRects(this, 1, &backrect);

            /* Draw the new rectangle of the chroma color at the viewport position */
            PgSetFillColor(overlay->hwdata->chromakey);
            PgDrawIRect(dst->x, dst->y, dst->x+dst->w-1, dst->y+dst->h-1, Pg_DRAW_FILL);
            PgFlush();
        }

        overlay->hwdata->props.flags |= Pg_SCALER_PROP_SCALER_ENABLE;
        overlay->hwdata->scaler_on = 1;

        PhWindowQueryVisible(Ph_QUERY_CONSOLE, 0, PtWidgetRid(window), &windowextent);
        overlay->hwdata->CurrentViewPort.pos.x = pos.x-windowextent.ul.x+dst->x;
        overlay->hwdata->CurrentViewPort.pos.y = pos.y-windowextent.ul.y+dst->y;
        overlay->hwdata->CurrentViewPort.size.w = dst->w;
        overlay->hwdata->CurrentViewPort.size.h = dst->h;
        PhAreaToRect(&overlay->hwdata->CurrentViewPort, &overlay->hwdata->props.viewport);
        overlay->hwdata->CurrentViewPort.pos.x = dst->x;
        overlay->hwdata->CurrentViewPort.pos.y = dst->y;

        rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));

        switch(rtncode)
        {
            case -1:
                     SDL_SetError("PgConfigScalerChannel() function failed\n");
                     SDL_FreeYUVOverlay(overlay);
                     return -1;
            case 1:
                     grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
                     break;
            case 0:
            default:
                     break;
        }
    }


/*
    if (overlay->hwdata->locked==0)
    {
        overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
        if (overlay->hwdata->current == -1)
        {
            SDL_SetError("ph_LockYUVOverlay: PgNextFrame() failed, bailing out\n");
            SDL_FreeYUVOverlay(overlay);
            return 0;
        }

        if (overlay->hwdata->current == 0)
        {
            overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
        }
        else
        {
            overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
        }

        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->uplane1->pitch;
            overlay->pixels[1]  = overlay->hwdata->CurrentFrameData->U;
        }
        if (overlay->planes > 2)
        {
            overlay->pitches[2] = overlay->hwdata->channel->vplane1->pitch;
            overlay->pixels[2]  = overlay->hwdata->CurrentFrameData->V;
        }
    }
*/
        
    return 0;
}
Esempio n. 19
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();
}
Esempio n. 20
0
/*
 * Create a display screen, or window, large enough to accomodate a bitmap
 * of the given dimensions.
 */
int I_GetEvent(PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo, int bitmap_depth )
{
	int mask=FALSE;
	int kdosomething=FALSE;
	PhKeyEvent_t *kevent;
	PhPointerEvent_t *pevent;	
	int                         keycode,code;
	int                         *pt;
	struct xmame_keyboard_event mame_key_event;
	char                        keyname[16+1];
	
   	mame_key_event.press = FALSE;
   
	switch (cbinfo->event->type)
	{
		case Ph_EV_KEY:
		{
			kevent = PhGetData (cbinfo->event);
			if (PkIsFirstDown (kevent->key_flags))
			{
              	mask=TRUE;
				mame_key_event.press=TRUE;
				kdosomething = TRUE;
			}
			else if (!PkIsKeyDown(kevent->key_flags))
				kdosomething = TRUE;

				
        	if (kdosomething)
			{
				if (kevent->key_flags & Pk_KF_Cap_Valid)
					keycode = kevent->key_cap;
				else 
					goto getevent_done;		

				if ((keycode & 0xF000) == 0xF000)
				{
					pt=extended_code_table;
					keycode &= 0x00FF;
				}
				else
				{
					pt=code_table;
				}
				
		 		mame_key_event.scancode = *(pt+keycode);
				if (PhKeyToMb (keyname, kevent) == -1)
				{
					keyname[0]=0;
				}
				mame_key_event.unicode = keyname[0];
				//phkey [ *(pt+keycode) ] = mask;
				xmame_keyboard_register_event(&mame_key_event); }		
			break;
		}
		case Ph_EV_BUT_PRESS:
			pevent = PhGetData( cbinfo->event );
			
			if (pevent->buttons & Ph_BUTTON_SELECT)
			{
				mouse_data[0].buttons[0] = TRUE;
			}
			if (pevent->buttons & Ph_BUTTON_MENU)
			{
				mouse_data[0].buttons[1] = TRUE;
			}	
			if (pevent->buttons & Ph_BUTTON_ADJUST)
			{
				mouse_data[0].buttons[2] = TRUE;
			}
		break;
		case Ph_EV_BUT_RELEASE:
			
			if( cbinfo->event->subtype != Ph_EV_RELEASE_REAL )
				break;

			pevent = PhGetData( cbinfo->event );
			
			if (pevent->buttons & Ph_BUTTON_SELECT)
			{
				mouse_data[0].buttons[0] = FALSE;
			}
			if (pevent->buttons & Ph_BUTTON_MENU)
			{
				mouse_data[0].buttons[1] = FALSE;
			}	
			if (pevent->buttons & Ph_BUTTON_ADJUST)
			{
				mouse_data[0].buttons[2] = FALSE;
			}
		break;

		case Ph_EV_PTR_MOTION_NOBUTTON:
		case Ph_EV_PTR_MOTION_BUTTON:
			if (ph_grab_mouse == FALSE)
			{
				pevent = PhGetData( cbinfo->event );
				update_mouse=TRUE;
				mouse_data[0].deltas[0] = pevent->pos.x-current_mouse[0];
				mouse_data[0].deltas[1] = pevent->pos.y-current_mouse[1];
        		current_mouse[0] = pevent->pos.x;
        		current_mouse[1] = pevent->pos.y;
			}
	 	break;
		case Ph_EV_EXPOSE:
			if (ph_video_mode==0)
			{
				ph_window_refresh_screen();
				PgFlush();
			}

		break;
		case Ph_EV_INFO:
		{
			switch (cbinfo->event->subtype)
			{
				case Ph_OFFSCREEN_INVALID :
				fprintf (stderr,"info: got offscreen invalid\n");
				if (image != NULL)
				{
					fprintf(stderr,"info: creating new image\n");
					PhDCRelease(image);
					image = PdCreateOffscreenContext(0, view_size.w, view_size.h, Pg_OSC_MEM_PAGE_ALIGN);
					if (image == NULL)
					{
						fprintf(stderr_file, "error: failed to create offscreen context\n");
						exit(1);
					}

					scaled_buffer_ptr = PdGetOffscreenContextPtr (image);
					if (!scaled_buffer_ptr)
					{
						fprintf (stderr_file, "error: failed get a pointer to offscreen context.\n");
						PhDCRelease (image);
						exit(1);
					}
	
					depth = 0;

					switch (image->format)
					{
						case Pg_IMAGE_PALETTE_BYTE   :
						// TODO :
						break;
						case Pg_IMAGE_DIRECT_565  :
						depth = 16;
						pixels_per_line = image->pitch >> 1;
						break;
						case Pg_IMAGE_DIRECT_555  :
						// TODO:
						break;
						case Pg_IMAGE_DIRECT_888  :
						depth = 24;
						pixels_per_line = image->pitch / 3;
						break;	
						case Pg_IMAGE_DIRECT_8888 :
						depth = 32;
						pixels_per_line = image->pitch >> 2;
						break;
					}
					ph_init_palette_info();
					ph_window_update_display_func=NULL;
					if (bitmap_depth == 16)
					{
						switch(depth)
						{
							case 16:
								ph_window_update_display_func = ph_window_update_16_to_16bpp;
							break;
							case 24:
								ph_window_update_display_func = ph_window_update_16_to_24bpp;
							break;
							case 32:
								ph_window_update_display_func = ph_window_update_16_to_32bpp;
							break;
						}
					}

					if (ph_window_update_display_func == NULL)
					{
						fprintf(stderr_file, "error: Unsupported\n");
						exit(1);
					}
				}
				break;
				
			}
		} 
		break;
	}
Esempio n. 21
0
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;
}