SDL_bool KMSDRM_GLES_SetupCrtc(_THIS, SDL_Window * window) { SDL_WindowData *wdata = ((SDL_WindowData *) window->driverdata); SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata; SDL_VideoData *vdata = ((SDL_VideoData *)_this->driverdata); KMSDRM_FBInfo *fb_info; if (!(_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, wdata->egl_surface))) { SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "eglSwapBuffers failed on CRTC setup"); return SDL_FALSE; } wdata->next_bo = KMSDRM_gbm_surface_lock_front_buffer(wdata->gs); if (wdata->next_bo == NULL) { SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not lock GBM surface front buffer on CRTC setup"); return SDL_FALSE; } fb_info = KMSDRM_FBFromBO(_this, wdata->next_bo); if (fb_info == NULL) { return SDL_FALSE; } if(KMSDRM_drmModeSetCrtc(vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id, 0, 0, &vdata->saved_conn_id, 1, &displaydata->cur_mode) != 0) { SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Could not set up CRTC to a GBM buffer"); return SDL_FALSE; } wdata->crtc_ready = SDL_TRUE; return SDL_TRUE; }
static SDL_Renderer * NDS_CreateRenderer(SDL_Window * window, Uint32 flags) { SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_DisplayMode *displayMode = &display->current_mode; SDL_Renderer *renderer; NDS_RenderData *data; int bpp; Uint32 Rmask, Gmask, Bmask, Amask; if (displayMode->format != SDL_PIXELFORMAT_ABGR1555) { SDL_SetError("Unsupported pixel format (%x)", displayMode->format); return NULL; } if (!SDL_PixelFormatEnumToMasks(displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { SDL_SetError("Unknown display format"); return NULL; } renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); if (!renderer) { SDL_OutOfMemory(); return NULL; } data = (NDS_RenderData *) SDL_calloc(1, sizeof(*data)); if (!data) { SDL_free(renderer); SDL_OutOfMemory(); return NULL; } renderer->info.name = NDS_RenderDriver.info.name; renderer->info.flags = 0; renderer->info.num_texture_formats = NDS_RenderDriver.info.num_texture_formats; SDL_memcpy(renderer->info.texture_formats, NDS_RenderDriver.info.texture_formats, sizeof(renderer->info.texture_formats)); renderer->info.max_texture_width = NDS_RenderDriver.info.max_texture_width; renderer->info.max_texture_height = NDS_RenderDriver.info.max_texture_height; renderer->UpdateViewport = NDS_UpdateViewport; renderer->CreateTexture = NDS_CreateTexture; renderer->DestroyTexture = NDS_DestroyTexture; renderer->RenderCopy = NDS_RenderCopy; renderer->UpdateTexture = NDS_UpdateTexture; renderer->LockTexture = NDS_LockTexture; renderer->UnlockTexture = NDS_UnlockTexture; renderer->RenderClear = NDS_RenderClear; renderer->RenderPresent = NDS_RenderPresent; renderer->RenderDrawPoints = NDS_RenderDrawPoints; renderer->RenderDrawLines = NDS_RenderDrawLines; renderer->RenderFillRects = NDS_RenderFillRects; return renderer; }
static int DirectFB_AcquireVidLayer(SDL_Renderer * renderer, SDL_Texture * texture) { //SDL_DFB_RENDERERDATA(renderer); SDL_Window *window = renderer->window; SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_DFB_DEVICEDATA(display->device); DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; DirectFB_TextureData *data = texture->driverdata; DFBDisplayLayerConfig layconf; DFBResult ret; if (devdata->use_yuv_direct && (dispdata->vidID >= 0) && (!dispdata->vidIDinuse) && SDL_ISPIXELFORMAT_FOURCC(data->format)) { layconf.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT | DLCONF_SURFACE_CAPS; layconf.width = texture->w; layconf.height = texture->h; layconf.pixelformat = DirectFB_SDLToDFBPixelFormat(data->format); layconf.surface_caps = DSCAPS_VIDEOONLY | DSCAPS_DOUBLE; SDL_DFB_CHECKERR(devdata->dfb->GetDisplayLayer(devdata->dfb, dispdata->vidID, &dispdata->vidlayer)); SDL_DFB_CHECKERR(dispdata-> vidlayer->SetCooperativeLevel(dispdata->vidlayer, DLSCL_EXCLUSIVE)); if (devdata->use_yuv_underlays) { ret = dispdata->vidlayer->SetLevel(dispdata->vidlayer, -1); if (ret != DFB_OK) SDL_DFB_DEBUG("Underlay Setlevel not supported\n"); } SDL_DFB_CHECKERR(dispdata-> vidlayer->SetConfiguration(dispdata->vidlayer, &layconf)); SDL_DFB_CHECKERR(dispdata-> vidlayer->GetSurface(dispdata->vidlayer, &data->surface)); dispdata->vidIDinuse = 1; data->display = display; return 0; } return 1; error: if (dispdata->vidlayer) { SDL_DFB_RELEASE(data->surface); SDL_DFB_CHECKERR(dispdata-> vidlayer->SetCooperativeLevel(dispdata->vidlayer, DLSCL_ADMINISTRATIVE)); SDL_DFB_RELEASE(dispdata->vidlayer); } return 1; }
static void DirectFB_DestroyRenderer(SDL_Renderer * renderer) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; SDL_VideoDisplay *display = SDL_GetDisplayForWindow(data->window); #if 0 if (display->palette) { SDL_DelPaletteWatch(display->palette, DisplayPaletteChanged, data); } #endif SDL_free(data); SDL_free(renderer); }
/* Warp the mouse to (x,y) */ static void DirectFB_WarpMouse(SDL_Window * window, int x, int y) { SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; DFB_WindowData *windata = (DFB_WindowData *) window->driverdata; int cx, cy; SDL_DFB_CHECKERR(windata->dfbwin->GetPosition(windata->dfbwin, &cx, &cy)); SDL_DFB_CHECKERR(dispdata->layer->WarpCursor(dispdata->layer, cx + x + windata->client.x, cy + y + windata->client.y)); error: return; }
void SDL_IBus_UpdateTextRect(SDL_Rect *rect) { SDL_Window *focused_win; SDL_SysWMinfo info; int x = 0, y = 0; SDL_DBusContext *dbus; if (rect) { SDL_memcpy(&ibus_cursor_rect, rect, sizeof(ibus_cursor_rect)); } focused_win = SDL_GetKeyboardFocus(); if (!focused_win) { return; } SDL_VERSION(&info.version); if (!SDL_GetWindowWMInfo(focused_win, &info)) { return; } SDL_GetWindowPosition(focused_win, &x, &y); #if SDL_VIDEO_DRIVER_X11 if (info.subsystem == SDL_SYSWM_X11) { SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayForWindow(focused_win)->driverdata; Display *x_disp = info.info.x11.display; Window x_win = info.info.x11.window; int x_screen = displaydata->screen; Window unused; X11_XTranslateCoordinates(x_disp, x_win, RootWindow(x_disp, x_screen), 0, 0, &x, &y, &unused); } #endif x += ibus_cursor_rect.x; y += ibus_cursor_rect.y; dbus = SDL_DBus_GetContext(); if (IBus_CheckConnection(dbus)) { SDL_DBus_CallVoidMethodOnConnection(ibus_conn, IBUS_SERVICE, input_ctx_path, IBUS_INPUT_INTERFACE, "SetCursorLocation", DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y, DBUS_TYPE_INT32, &ibus_cursor_rect.w, DBUS_TYPE_INT32, &ibus_cursor_rect.h, DBUS_TYPE_INVALID); } }
int WIN_CreateWindow(_THIS, SDL_Window * window) { SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); HWND hwnd; RECT rect; DWORD style = STYLE_BASIC; int x, y; int w, h; style |= GetWindowStyle(window); /* Figure out what the window area will be */ rect.left = window->x; rect.top = window->y; rect.right = window->x + window->w; rect.bottom = window->y + window->h; AdjustWindowRectEx(&rect, style, FALSE, 0); x = rect.left; y = rect.top; w = (rect.right - rect.left); h = (rect.bottom - rect.top); hwnd = CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, NULL, NULL, SDL_Instance, NULL); if (!hwnd) { WIN_SetError("Couldn't create window"); return -1; } WIN_PumpEvents(_this); if (SetupWindowData(_this, window, hwnd, SDL_TRUE) < 0) { DestroyWindow(hwnd); return -1; } #if SDL_VIDEO_OPENGL_WGL if (window->flags & SDL_WINDOW_OPENGL) { if (WIN_GL_SetupWindow(_this, window) < 0) { WIN_DestroyWindow(_this, window); return -1; } } #endif return 0; }
void WIN_SetWindowPosition(_THIS, SDL_Window * window) { SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; RECT rect; SDL_Rect bounds; DWORD style; HWND top; BOOL menu; int x, y; int w, h; /* Figure out what the window area will be */ if (window->flags & SDL_WINDOW_FULLSCREEN) { top = HWND_TOPMOST; } else { top = HWND_NOTOPMOST; } style = GetWindowLong(hwnd, GWL_STYLE); rect.left = 0; rect.top = 0; rect.right = window->w; rect.bottom = window->h; #ifdef _WIN32_WCE menu = FALSE; #else menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL); #endif AdjustWindowRectEx(&rect, style, menu, 0); w = (rect.right - rect.left); h = (rect.bottom - rect.top); WIN_GetDisplayBounds(_this, display, &bounds); if (SDL_WINDOWPOS_ISCENTERED(window->x)) { x = bounds.x + (bounds.w - w) / 2; } else { x = window->x + rect.left; } if (SDL_WINDOWPOS_ISCENTERED(window->y)) { y = bounds.y + (bounds.h - h) / 2; } else { y = window->y + rect.top; } SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE)); }
int MIR_SetWindowGammaRamp(_THIS, SDL_Window* window, Uint16 const* ramp) { MirOutput* output = SDL_GetDisplayForWindow(window)->driverdata; Uint32 ramp_size = 256; // FIXME Need to apply the changes to the output, once that public API function is around if (MIR_mir_output_is_gamma_supported(output) == mir_output_gamma_supported) { MIR_mir_output_set_gamma(output, ramp + ramp_size * 0, ramp + ramp_size * 1, ramp + ramp_size * 2, ramp_size); return 0; } return -1; }
int WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) { SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata; HDC hdc; BOOL succeeded = FALSE; hdc = CreateDC(data->DeviceName, NULL, NULL, NULL); if (hdc) { succeeded = GetDeviceGammaRamp(hdc, (LPVOID)ramp); if (!succeeded) { WIN_SetError("GetDeviceGammaRamp()"); } DeleteDC(hdc); } return succeeded ? 0 : -1; }
void DirectFB_SetContext(_THIS, SDL_Window *window) { #if (DFB_VERSION_ATLEAST(1,0,0)) /* FIXME: does not work on 1.0/1.2 with radeon driver * the approach did work with the matrox driver * This has simply no effect. */ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; /* FIXME: should we handle the error */ if (dispdata->vidIDinuse) SDL_DFB_CHECK(dispdata->vidlayer->SwitchContext(dispdata->vidlayer, DFB_TRUE)); #endif }
void Android_SetScreenResolution(int width, int height, Uint32 format, float rate) { static int times = 0; posix_print("#%i, Android_SetScreenResolution------(%ix%i), format: 0x%08x, rate: %7.2f, Android_Window: %p\n", times, width, height, format, rate, Android_Window); SDL_VideoDevice* device; SDL_VideoDisplay *display; Android_ScreenWidth = width; Android_ScreenHeight = height; Android_ScreenFormat = format; Android_ScreenRate = rate; /* Update the resolution of the desktop mode, so that the window can be properly resized. The screen resolution change can for example happen when the Activity enters or exists immersive mode, which can happen after VideoInit(). */ device = SDL_GetVideoDevice(); if (device && device->num_displays > 0) { display = &device->displays[0]; display->desktop_mode.format = Android_ScreenFormat; display->desktop_mode.w = Android_ScreenWidth; display->desktop_mode.h = Android_ScreenHeight; display->desktop_mode.refresh_rate = Android_ScreenRate; } if (Android_Window) { SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESIZED, width, height); /* Force the current mode to match the resize otherwise the SDL_WINDOWEVENT_RESTORED event * will fall back to the old mode */ display = SDL_GetDisplayForWindow(Android_Window); display->current_mode.format = format; display->current_mode.w = width; display->current_mode.h = height; display->current_mode.refresh_rate = rate; } times ++; }
int MIR_GetWindowGammaRamp(_THIS, SDL_Window* window, Uint16* ramp) { MirOutput* output = SDL_GetDisplayForWindow(window)->driverdata; Uint32 ramp_size = 256; if (MIR_mir_output_is_gamma_supported(output) == mir_output_gamma_supported) { if (MIR_mir_output_get_gamma_size(output) == ramp_size) { MIR_mir_output_get_gamma(output, ramp + ramp_size * 0, ramp + ramp_size * 1, ramp + ramp_size * 2, ramp_size); return 0; } } return -1; }
int FB_CreateWindow(_THIS, SDL_Window * window) { SDL_WindowData *wdata; SDL_VideoDisplay *display; /* Allocate window internal data */ wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData)); if (wdata == NULL) { return SDL_OutOfMemory(); } display = SDL_GetDisplayForWindow(window); /* Windows have one size for now */ window->w = display->desktop_mode.w; window->h = display->desktop_mode.h; /* OpenGL ES is the law here, buddy */ window->flags |= SDL_WINDOW_OPENGL; if (!_this->egl_data) { if (SDL_GL_LoadLibrary(NULL) < 0) { return -1; } } wdata->egl_surface = SDL_EGL_CreateSurface(_this, 0); if (wdata->egl_surface == EGL_NO_SURFACE) { return SDL_SetError("Could not create GLES window surface"); } /* Setup driver data for this window */ window->driverdata = wdata; /* One window, it always has focus */ SDL_SetMouseFocus(window); SDL_SetKeyboardFocus(window); /* Window has been successfully created */ return 0; }
/* Show the specified cursor, or hide if cursor is NULL */ static int DirectFB_ShowCursor(SDL_Cursor * cursor) { SDL_DFB_CURSORDATA(cursor); DFBResult ret; SDL_Window *window; window = SDL_GetFocusWindow(); if (!window) return -1; else { SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); if (display) { DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; DFB_WindowData *windata = (DFB_WindowData *) window->driverdata; if (cursor) SDL_DFB_CHECKERR(windata->dfbwin-> SetCursorShape(windata->dfbwin, curdata->surf, curdata->hotx, curdata->hoty)); SDL_DFB_CHECKERR(dispdata->layer-> SetCooperativeLevel(dispdata->layer, DLSCL_ADMINISTRATIVE)); SDL_DFB_CHECKERR(dispdata->layer-> SetCursorOpacity(dispdata->layer, cursor ? 0xC0 : 0x00)); SDL_DFB_CHECKERR(dispdata->layer-> SetCooperativeLevel(dispdata->layer, DLSCL_SHARED)); } } return 0; error: return -1; }
void PND_gl_swapwindow(_THIS, SDL_Window * window) { SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; SDL_DisplayData *didata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata; if (phdata->egl_initialized != SDL_TRUE) { SDL_SetError("PND: GLES initialization failed, no OpenGL ES support"); return; } /* Many applications do not uses glFinish(), so we call it for them */ glFinish(); /* Wait until OpenGL ES rendering is completed */ eglWaitGL(); eglSwapBuffers(phdata->egl_display, wdata->gles_surface); }
void DirectFB_MaximizeWindow(_THIS, SDL_Window * window) { SDL_DFB_WINDOWDATA(window); SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); DFBWindowOptions wopts; SDL_DFB_CHECK(windata->dfbwin->GetPosition(windata->dfbwin, &windata->restore.x, &windata->restore.y)); SDL_DFB_CHECK(windata->dfbwin->GetSize(windata->dfbwin, &windata->restore.w, &windata->restore.h)); DirectFB_WM_AdjustWindowLayout(window, window->flags | SDL_WINDOW_MAXIMIZED, display->current_mode.w, display->current_mode.h) ; SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, 0, 0)); SDL_DFB_CHECK(windata->dfbwin->Resize(windata->dfbwin, display->current_mode.w, display->current_mode.h)); /* Set Options */ SDL_DFB_CHECK(windata->dfbwin->GetOptions(windata->dfbwin, &wopts)); wopts |= DWOP_KEEP_SIZE | DWOP_KEEP_POSITION; SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts)); }
int WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) { #ifdef _WIN32_WCE SDL_Unsupported(); return -1; #else SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata; HDC hdc; BOOL succeeded = FALSE; hdc = CreateDC(data->DeviceName, NULL, NULL, NULL); if (hdc) { succeeded = SetDeviceGammaRamp(hdc, (LPVOID)ramp); if (!succeeded) { WIN_SetError("SetDeviceGammaRamp()"); } DeleteDC(hdc); } return succeeded ? 0 : -1; #endif }
void ZL_SetFullscreen(bool toFullscreen) { #if 0 //#ifndef ZL_USE_EXTERNAL_SDL SDL_VideoDevice *device = SDL_GetVideoDevice(); SDL_VideoDisplay *display = SDL_GetDisplayForWindow(ZL_SDL_Window); if (toFullscreen) { ZL_SDL_Window->flags |= SDL_WINDOW_FULLSCREEN; ZL_SDL_Window->x = 0; ZL_SDL_Window->y = 0; ZL_SDL_Window->w = display->desktop_mode.w; ZL_SDL_Window->h = display->desktop_mode.h; device->SetWindowSize(device, ZL_SDL_Window); } else { ZL_SDL_Window->flags &= ~SDL_WINDOW_FULLSCREEN; ZL_SDL_Window->x = ZL_SDL_Window->windowed.x; ZL_SDL_Window->y = ZL_SDL_Window->windowed.y; ZL_SDL_Window->w = ZL_SDL_Window->windowed.w; ZL_SDL_Window->h = ZL_SDL_Window->windowed.h; } device->SetWindowFullscreen(device, ZL_SDL_Window, display, (SDL_bool)toFullscreen); if(toFullscreen) SDL_OnWindowResized(ZL_SDL_Window); else SDL_SetWindowSize(ZL_SDL_Window, ZL_SDL_Window->windowed.w, ZL_SDL_Window->windowed.h); #else if (toFullscreen) { SDL_SetWindowFullscreen(ZL_SDL_Window, SDL_WINDOW_FULLSCREEN_DESKTOP); } else { SDL_SetWindowFullscreen(ZL_SDL_Window, 0); SDL_SetWindowSize(ZL_SDL_Window, ZL_SDL_Window->windowed.w, ZL_SDL_Window->windowed.h); } #endif }
static void X11_GetDisplaySize(_THIS, SDL_Window * window, int *w, int *h) { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata; XWindowAttributes attr; XGetWindowAttributes(data->display, RootWindow(data->display, displaydata->screen), &attr); if (window->flags & SDL_WINDOW_FULLSCREEN) { /* The bounds when this window is visible is the fullscreen mode */ SDL_DisplayMode fullscreen_mode; if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) { attr.width = fullscreen_mode.w; attr.height = fullscreen_mode.h; } } if (w) { *w = attr.width; } if (h) { *h = attr.height; } }
int DirectFB_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) { if(shaper == NULL || shape == NULL || shaper->driverdata == NULL) return -1; if(shape->format->Amask == 0 && SDL_SHAPEMODEALPHA(shape_mode->mode)) return -2; if(shape->w != shaper->window->w || shape->h != shaper->window->h) return -3; { SDL_VideoDisplay *display = SDL_GetDisplayForWindow(shaper->window); SDL_DFB_DEVICEDATA(display->device); Uint32 *pixels; Sint32 pitch; Uint32 h,w; Uint8 *src, *bitmap; DFBSurfaceDescription dsc; SDL_ShapeData *data = shaper->driverdata; SDL_DFB_RELEASE(data->surface); dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS; dsc.width = shape->w; dsc.height = shape->h; dsc.caps = DSCAPS_PREMULTIPLIED; dsc.pixelformat = DSPF_ARGB; SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc, &data->surface)); /* Assume that shaper->alphacutoff already has a value, because SDL_SetWindowShape() should have given it one. */ SDL_DFB_ALLOC_CLEAR(bitmap, shape->w * shape->h); SDL_CalculateShapeBitmap(shaper->mode,shape,bitmap,1); src = bitmap; SDL_DFB_CHECK(data->surface->Lock(data->surface, DSLF_WRITE | DSLF_READ, (void **) &pixels, &pitch)); h = shaper->window->h; while (h--) { for (w = 0; w < shaper->window->w; w++) { if (*src) pixels[w] = 0xFFFFFFFF; else pixels[w] = 0; src++; } pixels += (pitch >> 2); } SDL_DFB_CHECK(data->surface->Unlock(data->surface)); SDL_DFB_FREE(bitmap); /* FIXME: Need to call this here - Big ?? */ DirectFB_WM_RedrawLayout(SDL_GetDisplayForWindow(shaper->window)->device, shaper->window); } return 0; error: return -1; }
SDL_GLContext X11_GL_CreateContext(_THIS, SDL_Window * window) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; Display *display = data->videodata->display; int screen = ((SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata)->screen; XWindowAttributes xattr; XVisualInfo v, *vinfo; int n; GLXContext context = NULL, share_context; if (_this->gl_config.share_with_current_context) { share_context = (GLXContext)SDL_GL_GetCurrentContext(); } else { share_context = NULL; } /* We do this to create a clean separation between X and GLX errors. */ X11_XSync(display, False); errorHandlerOperation = "create GL context"; errorBase = _this->gl_data->errorBase; errorCode = Success; handler = X11_XSetErrorHandler(X11_GL_ErrorHandler); X11_XGetWindowAttributes(display, data->xwindow, &xattr); v.screen = screen; v.visualid = X11_XVisualIDFromVisual(xattr.visual); vinfo = X11_XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n); if (vinfo) { if (_this->gl_config.major_version < 3 && _this->gl_config.profile_mask == 0 && _this->gl_config.flags == 0) { /* Create legacy context */ context = _this->gl_data->glXCreateContext(display, vinfo, share_context, True); } else { /* max 10 attributes plus terminator */ int attribs[11] = { GLX_CONTEXT_MAJOR_VERSION_ARB, _this->gl_config.major_version, GLX_CONTEXT_MINOR_VERSION_ARB, _this->gl_config.minor_version, 0 }; int iattr = 4; /* SDL profile bits match GLX profile bits */ if( _this->gl_config.profile_mask != 0 ) { attribs[iattr++] = GLX_CONTEXT_PROFILE_MASK_ARB; attribs[iattr++] = _this->gl_config.profile_mask; } /* SDL flags match GLX flags */ if( _this->gl_config.flags != 0 ) { attribs[iattr++] = GLX_CONTEXT_FLAGS_ARB; attribs[iattr++] = _this->gl_config.flags; } /* only set if glx extension is available */ if( _this->gl_data->HAS_GLX_ARB_context_flush_control ) { attribs[iattr++] = GLX_CONTEXT_RELEASE_BEHAVIOR_ARB; attribs[iattr++] = _this->gl_config.release_behavior ? GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB : GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB; } attribs[iattr++] = 0; /* Get a pointer to the context creation function for GL 3.0 */ if (!_this->gl_data->glXCreateContextAttribsARB) { SDL_SetError("OpenGL 3.0 and later are not supported by this system"); } else { int glxAttribs[64]; /* Create a GL 3.x context */ GLXFBConfig *framebuffer_config = NULL; int fbcount = 0; X11_GL_GetAttributes(_this,display,screen,glxAttribs,64,SDL_TRUE); if (!_this->gl_data->glXChooseFBConfig || !(framebuffer_config = _this->gl_data->glXChooseFBConfig(display, DefaultScreen(display), glxAttribs, &fbcount))) { SDL_SetError("No good framebuffers found. OpenGL 3.0 and later unavailable"); } else { context = _this->gl_data->glXCreateContextAttribsARB(display, framebuffer_config[0], share_context, True, attribs); X11_XFree(framebuffer_config); } } } X11_XFree(vinfo); } X11_XSync(display, False); X11_XSetErrorHandler(handler); if (!context) { if (errorCode == Success) { SDL_SetError("Could not create GL context"); } return NULL; } if (X11_GL_MakeCurrent(_this, window, context) < 0) { X11_GL_DeleteContext(_this, context); return NULL; } return context; }
/* Create and set up our X11 dialog box indow. */ static int X11_MessageBoxCreateWindow( SDL_MessageBoxDataX11 *data ) { int x, y; XSizeHints *sizehints; XSetWindowAttributes wnd_attr; Atom _NET_WM_WINDOW_TYPE, _NET_WM_WINDOW_TYPE_DIALOG, _NET_WM_NAME, UTF8_STRING; Display *display = data->display; SDL_WindowData *windowdata = NULL; const SDL_MessageBoxData *messageboxdata = data->messageboxdata; if ( messageboxdata->window ) { SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayForWindow(messageboxdata->window)->driverdata; windowdata = (SDL_WindowData *)messageboxdata->window->driverdata; data->screen = displaydata->screen; } else { data->screen = DefaultScreen( display ); } data->event_mask = ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | StructureNotifyMask | FocusChangeMask | PointerMotionMask; wnd_attr.event_mask = data->event_mask; data->window = X11_XCreateWindow( display, RootWindow(display, data->screen), 0, 0, data->dialog_width, data->dialog_height, 0, CopyFromParent, InputOutput, CopyFromParent, CWEventMask, &wnd_attr ); if ( data->window == None ) { return SDL_SetError("Couldn't create X window"); } if ( windowdata ) { /* http://tronche.com/gui/x/icccm/sec-4.html#WM_TRANSIENT_FOR */ X11_XSetTransientForHint( display, data->window, windowdata->xwindow ); } X11_XStoreName( display, data->window, messageboxdata->title ); _NET_WM_NAME = X11_XInternAtom(display, "_NET_WM_NAME", False); UTF8_STRING = X11_XInternAtom(display, "UTF8_STRING", False); X11_XChangeProperty(display, data->window, _NET_WM_NAME, UTF8_STRING, 8, PropModeReplace, (unsigned char *) messageboxdata->title, strlen(messageboxdata->title) + 1 ); /* Let the window manager know this is a dialog box */ _NET_WM_WINDOW_TYPE = X11_XInternAtom(display, "_NET_WM_WINDOW_TYPE", False); _NET_WM_WINDOW_TYPE_DIALOG = X11_XInternAtom(display, "_NET_WM_WINDOW_TYPE_DIALOG", False); X11_XChangeProperty(display, data->window, _NET_WM_WINDOW_TYPE, XA_ATOM, 32, PropModeReplace, (unsigned char *)&_NET_WM_WINDOW_TYPE_DIALOG, 1); /* Allow the window to be deleted by the window manager */ data->wm_protocols = X11_XInternAtom( display, "WM_PROTOCOLS", False ); data->wm_delete_message = X11_XInternAtom( display, "WM_DELETE_WINDOW", False ); X11_XSetWMProtocols( display, data->window, &data->wm_delete_message, 1 ); if ( windowdata ) { XWindowAttributes attrib; Window dummy; X11_XGetWindowAttributes(display, windowdata->xwindow, &attrib); x = attrib.x + ( attrib.width - data->dialog_width ) / 2; y = attrib.y + ( attrib.height - data->dialog_height ) / 3 ; X11_XTranslateCoordinates(display, windowdata->xwindow, RootWindow(display, data->screen), x, y, &x, &y, &dummy); } else { const SDL_VideoDevice *dev = SDL_GetVideoDevice(); if ((dev) && (dev->displays) && (dev->num_displays > 0)) { const SDL_VideoDisplay *dpy = &dev->displays[0]; const SDL_DisplayData *dpydata = (SDL_DisplayData *) dpy->driverdata; x = dpydata->x + (( dpy->current_mode.w - data->dialog_width ) / 2); y = dpydata->y + (( dpy->current_mode.h - data->dialog_height ) / 3); } else { /* oh well. This will misposition on a multi-head setup. Init first next time. */ x = ( DisplayWidth( display, data->screen ) - data->dialog_width ) / 2; y = ( DisplayHeight( display, data->screen ) - data->dialog_height ) / 3 ; } } X11_XMoveWindow( display, data->window, x, y ); sizehints = X11_XAllocSizeHints(); if ( sizehints ) { sizehints->flags = USPosition | USSize | PMaxSize | PMinSize; sizehints->x = x; sizehints->y = y; sizehints->width = data->dialog_width; sizehints->height = data->dialog_height; sizehints->min_width = sizehints->max_width = data->dialog_width; sizehints->min_height = sizehints->max_height = data->dialog_height; X11_XSetWMNormalHints( display, data->window, sizehints ); X11_XFree( sizehints ); } X11_XMapRaised( display, data->window ); #if SDL_VIDEO_DRIVER_X11_XDBE /* Initialise a back buffer for double buffering */ if (SDL_X11_HAVE_XDBE) { int xdbe_major, xdbe_minor; if (X11_XdbeQueryExtension(display, &xdbe_major, &xdbe_minor) != 0) { data->xdbe = SDL_TRUE; data->buf = X11_XdbeAllocateBackBufferName(display, data->window, XdbeUndefined); } else { data->xdbe = SDL_FALSE; } } #endif return 0; }
static int NDS_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch) { struct NDS_WindowData *wdata; int bpp; Uint32 Rmask, Gmask, Bmask, Amask; const SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); const SDL_DisplayMode *mode = display->driverdata; const Uint32 fmt = mode->format; if (fmt != SDL_PIXELFORMAT_ABGR1555) { SDL_SetError("Unsupported pixel format (%x)", fmt); return -1; } if (!SDL_PixelFormatEnumToMasks (fmt, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { SDL_SetError("Unknown texture format"); return -1; } wdata = SDL_calloc(1, sizeof(struct NDS_WindowData)); if (!wdata) { SDL_OutOfMemory(); return -1; } if (bpp == 8) { wdata->pixels_length = (SCREEN_HEIGHT+SCREEN_GAP+SCREEN_HEIGHT)*SCREEN_WIDTH; } else { wdata->pixels_length = (SCREEN_HEIGHT+SCREEN_GAP+SCREEN_HEIGHT)*SCREEN_WIDTH*2; } wdata->pixels = SDL_calloc(1, wdata->pixels_length); if (!wdata->pixels) { SDL_free(wdata); SDL_SetError("Not enough memory"); return -1; } if (bpp == 8) { wdata->main.bg_id = bgInit(2, BgType_Bmp8, BgSize_B8_256x256, 0, 0); wdata->sub.bg_id = bgInitSub(3, BgType_Bmp8, BgSize_B8_256x256, 0, 0); wdata->main.length = SCREEN_HEIGHT*SCREEN_WIDTH; wdata->main.pixels = wdata->pixels; wdata->sub.length = SCREEN_HEIGHT*SCREEN_WIDTH; wdata->sub.pixels = (u8 *)wdata->pixels + wdata->main.length; /* or ...+SCREEN_GAP */ } else { wdata->main.bg_id = bgInit(2, BgType_Bmp16, BgSize_B16_256x256, 0, 0); wdata->sub.bg_id = bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0); wdata->main.length = SCREEN_HEIGHT*SCREEN_WIDTH*2; wdata->main.pixels = wdata->pixels; wdata->sub.length = SCREEN_HEIGHT*SCREEN_WIDTH*2; wdata->sub.pixels = (u8 *)wdata->pixels + wdata->main.length; /* or ...+SCREEN_GAP */ } wdata->pitch = (window->w) * ((bpp+1) / 8); wdata->bpp = bpp; wdata->rotate = 0; wdata->scale.x = 0x100; wdata->scale.y = 0x100; wdata->scroll.x = 0; wdata->scroll.y = 0; wdata->main.vram_pixels = bgGetGfxPtr(wdata->main.bg_id); wdata->sub.vram_pixels = bgGetGfxPtr(wdata->sub.bg_id); #if 0 bgSetCenter(wdata->main.bg_id, 0, 0); bgSetRotateScale(wdata->main.bg_id, wdata->rotate, wdata->scale.x, wdata->scale.y); bgSetScroll(wdata->main.bg_id, wdata->scroll.x, wdata->scroll.y); #endif #if 0 bgSetCenter(wdata->sub.bg_id, 0, 0); bgSetRotateScale(wdata->sub.bg_id, wdata->rotate, wdata->scale.x, wdata->scale.y); bgSetScroll(wdata->sub.bg_id, wdata->scroll.x, wdata->scroll.y); #endif bgUpdate(); *format = fmt; *pixels = wdata->pixels; *pitch = wdata->pitch; window->driverdata = wdata; return 0; }
SDL_GLContext X11_GL_CreateContext(_THIS, SDL_Window * window) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; Display *display = data->videodata->display; int screen = ((SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata)->screen; XWindowAttributes xattr; XVisualInfo v, *vinfo; int n; GLXContext context = NULL, share_context; PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = NULL; if (_this->gl_config.share_with_current_context) { share_context = (GLXContext)SDL_GL_GetCurrentContext(); } else { share_context = NULL; } /* We do this to create a clean separation between X and GLX errors. */ XSync(display, False); errorBase = _this->gl_data->errorBase; handler = XSetErrorHandler(X11_GL_CreateContextErrorHandler); XGetWindowAttributes(display, data->xwindow, &xattr); v.screen = screen; v.visualid = XVisualIDFromVisual(xattr.visual); vinfo = XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n); if (vinfo) { if (_this->gl_config.major_version < 3 && _this->gl_config.profile_mask == 0 && _this->gl_config.flags == 0) { /* Create legacy context */ context = _this->gl_data->glXCreateContext(display, vinfo, share_context, True); } else { /* If we want a GL 3.0 context or later we need to get a temporary context to grab the new context creation function */ GLXContext temp_context = _this->gl_data->glXCreateContext(display, vinfo, NULL, True); if (temp_context) { /* max 8 attributes plus terminator */ int attribs[9] = { GLX_CONTEXT_MAJOR_VERSION_ARB, _this->gl_config.major_version, GLX_CONTEXT_MINOR_VERSION_ARB, _this->gl_config.minor_version, 0 }; int iattr = 4; /* SDL profile bits match GLX profile bits */ if( _this->gl_config.profile_mask != 0 ) { attribs[iattr++] = GLX_CONTEXT_PROFILE_MASK_ARB; attribs[iattr++] = _this->gl_config.profile_mask; } /* SDL flags match GLX flags */ if( _this->gl_config.flags != 0 ) { attribs[iattr++] = GLX_CONTEXT_FLAGS_ARB; attribs[iattr++] = _this->gl_config.flags; } attribs[iattr++] = 0; /* Get a pointer to the context creation function for GL 3.0 */ glXCreateContextAttribs = (PFNGLXCREATECONTEXTATTRIBSARBPROC) _this->gl_data-> glXGetProcAddress((GLubyte *) "glXCreateContextAttribsARB"); if (!glXCreateContextAttribs) { SDL_SetError("GL 3.x is not supported"); context = temp_context; } else { int glxAttribs[64]; /* Create a GL 3.x context */ GLXFBConfig *framebuffer_config = NULL; int fbcount = 0; GLXFBConfig *(*glXChooseFBConfig) (Display * disp, int screen, const int *attrib_list, int *nelements); glXChooseFBConfig = (GLXFBConfig * (*)(Display *, int, const int *, int *)) _this->gl_data-> glXGetProcAddress((GLubyte *) "glXChooseFBConfig"); X11_GL_GetAttributes(_this,display,screen,glxAttribs,64,SDL_TRUE); if (!glXChooseFBConfig || !(framebuffer_config = glXChooseFBConfig(display, DefaultScreen(display), glxAttribs, &fbcount))) { SDL_SetError ("No good framebuffers found. GL 3.x disabled"); context = temp_context; } else { context = glXCreateContextAttribs(display, framebuffer_config[0], share_context, True, attribs); _this->gl_data->glXDestroyContext(display, temp_context); } } } } XFree(vinfo); } XSync(display, False); XSetErrorHandler(handler); if (!context) { SDL_SetError("Could not create GL context"); return NULL; } if (X11_GL_MakeCurrent(_this, window, context) < 0) { X11_GL_DeleteContext(_this, context); return NULL; } return context; }
/* Show the specified cursor, or hide if cursor is NULL */ static int RPI_ShowCursor(SDL_Cursor * cursor) { int ret; DISPMANX_UPDATE_HANDLE_T update; RPI_CursorData *curdata; VC_RECT_T src_rect, dst_rect; SDL_Mouse *mouse; SDL_VideoDisplay *display; SDL_DisplayData *data; VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FROM_SOURCE /* flags */ , 255 /*opacity 0->255*/, 0 /* mask */ }; mouse = SDL_GetMouse(); if (mouse == NULL) { return -1; } if (cursor == NULL) { /* FIXME: We hide the current mouse's cursor, what we actually need is *_HideCursor */ if ( mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) { curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata; if (curdata->element > DISPMANX_NO_HANDLE) { update = vc_dispmanx_update_start( 10 ); SDL_assert( update ); ret = vc_dispmanx_element_remove( update, curdata->element ); SDL_assert( ret == DISPMANX_SUCCESS ); ret = vc_dispmanx_update_submit_sync( update ); SDL_assert( ret == DISPMANX_SUCCESS ); curdata->element = DISPMANX_NO_HANDLE; } } return 0; } curdata = (RPI_CursorData *) cursor->driverdata; if (curdata == NULL) { return -1; } if (mouse->focus == NULL) { return -1; } display = SDL_GetDisplayForWindow(mouse->focus); if (display == NULL) { return -1; } data = (SDL_DisplayData*) display->driverdata; if (data == NULL) { return -1; } if (curdata->element == DISPMANX_NO_HANDLE) { vc_dispmanx_rect_set( &src_rect, 0, 0, curdata->w << 16, curdata->h << 16 ); vc_dispmanx_rect_set( &dst_rect, 0, 0, curdata->w, curdata->h); update = vc_dispmanx_update_start( 10 ); SDL_assert( update ); curdata->element = vc_dispmanx_element_add( update, data->dispman_display, SDL_RPI_MOUSELAYER, // layer &dst_rect, curdata->resource, &src_rect, DISPMANX_PROTECTION_NONE, &alpha, DISPMANX_NO_HANDLE, // clamp VC_IMAGE_ROT0 ); SDL_assert( curdata->element > DISPMANX_NO_HANDLE); ret = vc_dispmanx_update_submit_sync( update ); SDL_assert( ret == DISPMANX_SUCCESS ); } return 0; }
static int DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) { SDL_Window *window = renderer->window; SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_DFB_DEVICEDATA(display->device); DirectFB_TextureData *data; DFBSurfaceDescription dsc; DFBSurfacePixelFormat pixelformat; DirectFB_ActivateRenderer(renderer); SDL_DFB_ALLOC_CLEAR(data, sizeof(*data)); texture->driverdata = data; /* find the right pixelformat */ pixelformat = DirectFB_SDLToDFBPixelFormat(texture->format); if (pixelformat == DSPF_UNKNOWN) { SDL_SetError("Unknown pixel format %d\n", data->format); goto error; } data->format = texture->format; data->pitch = texture->w * DFB_BYTES_PER_PIXEL(pixelformat); if (DirectFB_AcquireVidLayer(renderer, texture) != 0) { /* fill surface description */ dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS; dsc.width = texture->w; dsc.height = texture->h; if(texture->format == SDL_PIXELFORMAT_YV12 || texture->format == SDL_PIXELFORMAT_IYUV) { /* dfb has problems with odd sizes -make them even internally */ dsc.width += (dsc.width % 2); dsc.height += (dsc.height % 2); } /* <1.2 Never use DSCAPS_VIDEOONLY here. It kills performance * No DSCAPS_SYSTEMONLY either - let dfb decide * 1.2: DSCAPS_SYSTEMONLY boosts performance by factor ~8 * Depends on other settings as well. Let dfb decide. */ dsc.caps = DSCAPS_PREMULTIPLIED; #if 0 if (texture->access == SDL_TEXTUREACCESS_STREAMING) dsc.caps |= DSCAPS_SYSTEMONLY; else dsc.caps |= DSCAPS_VIDEOONLY; #endif dsc.pixelformat = pixelformat; data->pixels = NULL; /* Create the surface */ SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc, &data->surface)); if (SDL_ISPIXELFORMAT_INDEXED(data->format) && !SDL_ISPIXELFORMAT_FOURCC(data->format)) { #if 1 SDL_DFB_CHECKERR(data->surface->GetPalette(data->surface, &data->palette)); #else /* DFB has issues with blitting LUT8 surfaces. * Creating a new palette does not help. */ DFBPaletteDescription pal_desc; pal_desc.flags = DPDESC_SIZE; /* | DPDESC_ENTRIES */ pal_desc.size = 256; SDL_DFB_CHECKERR(devdata->dfb->CreatePalette(devdata->dfb, &pal_desc,&data->palette)); SDL_DFB_CHECKERR(data->surface->SetPalette(data->surface, data->palette)); #endif } } #if (DFB_VERSION_ATLEAST(1,2,0)) data->render_options = DSRO_NONE; #endif if (texture->access == SDL_TEXTUREACCESS_STREAMING) { /* 3 plane YUVs return 1 bpp, but we need more space for other planes */ if(texture->format == SDL_PIXELFORMAT_YV12 || texture->format == SDL_PIXELFORMAT_IYUV) { SDL_DFB_ALLOC_CLEAR(data->pixels, (texture->h * data->pitch + ((texture->h + texture->h % 2) * (data->pitch + data->pitch % 2) * 2) / 4)); } else { SDL_DFB_ALLOC_CLEAR(data->pixels, texture->h * data->pitch); } } return 0; error: SDL_DFB_RELEASE(data->palette); SDL_DFB_RELEASE(data->surface); SDL_DFB_FREE(texture->driverdata); return -1; }
SDL_Renderer * DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags) { IDirectFBSurface *winsurf = get_dfb_surface(window); SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_Renderer *renderer = NULL; DirectFB_RenderData *data = NULL; DFBSurfaceCapabilities scaps; SDL_DFB_ALLOC_CLEAR(renderer, sizeof(*renderer)); SDL_DFB_ALLOC_CLEAR(data, sizeof(*data)); renderer->WindowEvent = DirectFB_WindowEvent; renderer->CreateTexture = DirectFB_CreateTexture; renderer->SetTextureAlphaMod = DirectFB_SetTextureAlphaMod; renderer->SetTextureColorMod = DirectFB_SetTextureColorMod; renderer->SetTextureBlendMode = DirectFB_SetTextureBlendMode; renderer->UpdateTexture = DirectFB_UpdateTexture; renderer->LockTexture = DirectFB_LockTexture; renderer->RenderClear = DirectFB_RenderClear; renderer->UnlockTexture = DirectFB_UnlockTexture; renderer->RenderDrawPoints = DirectFB_RenderDrawPoints; renderer->RenderDrawLines = DirectFB_RenderDrawLines; /* SetDrawColor - no needed */ renderer->RenderFillRects = DirectFB_RenderFillRects; renderer->RenderCopy = DirectFB_RenderCopy; renderer->RenderPresent = DirectFB_RenderPresent; /* FIXME: Yet to be tested */ renderer->RenderReadPixels = DirectFB_RenderReadPixels; /* renderer->RenderWritePixels = DirectFB_RenderWritePixels; */ renderer->DestroyTexture = DirectFB_DestroyTexture; renderer->DestroyRenderer = DirectFB_DestroyRenderer; renderer->UpdateViewport = DirectFB_UpdateViewport; renderer->UpdateClipRect = DirectFB_UpdateClipRect; renderer->SetRenderTarget = DirectFB_SetRenderTarget; #if 0 renderer->QueryTexturePixels = DirectFB_QueryTexturePixels; renderer->SetTexturePalette = DirectFB_SetTexturePalette; renderer->GetTexturePalette = DirectFB_GetTexturePalette; renderer->SetTextureScaleMode = DirectFB_SetTextureScaleMode; renderer->DirtyTexture = DirectFB_DirtyTexture; renderer->SetDrawBlendMode = DirectFB_SetDrawBlendMode; renderer->RenderDrawRects = DirectFB_RenderDrawRects; #endif renderer->info = DirectFB_RenderDriver.info; renderer->window = window; /* SDL window */ renderer->driverdata = data; renderer->info.flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE; data->window = window; data->target = winsurf; data->flipflags = DSFLIP_PIPELINE | DSFLIP_BLIT; if (flags & SDL_RENDERER_PRESENTVSYNC) { data->flipflags |= DSFLIP_WAITFORSYNC | DSFLIP_ONSYNC; renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; } else data->flipflags |= DSFLIP_ONSYNC; SDL_DFB_CHECKERR(winsurf->GetCapabilities(winsurf, &scaps)); #if 0 if (scaps & DSCAPS_DOUBLE) renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2; else if (scaps & DSCAPS_TRIPLE) renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3; else renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER; #endif DirectFB_SetSupportedPixelFormats(&renderer->info); #if 0 /* Set up a palette watch on the display palette */ if (display-> palette) { SDL_AddPaletteWatch(display->palette, DisplayPaletteChanged, data); } #endif return renderer; error: SDL_DFB_FREE(renderer); SDL_DFB_FREE(data); return NULL; }
SDL_GLContext PND_gl_createcontext(_THIS, SDL_Window * window) { SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; SDL_DisplayData *didata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata; EGLBoolean status; int32_t gfstatus; EGLint configs; uint32_t attr_pos; EGLint attr_value; EGLint cit; /* Check if EGL was initialized */ if (phdata->egl_initialized != SDL_TRUE) { SDL_SetError("PND: EGL initialization failed, no OpenGL ES support"); return NULL; } /* Prepare attributes list to pass them to OpenGL ES */ attr_pos = 0; wdata->gles_attributes[attr_pos++] = EGL_SURFACE_TYPE; wdata->gles_attributes[attr_pos++] = EGL_WINDOW_BIT; wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE; wdata->gles_attributes[attr_pos++] = _this->gl_config.red_size; wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE; wdata->gles_attributes[attr_pos++] = _this->gl_config.green_size; wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE; wdata->gles_attributes[attr_pos++] = _this->gl_config.blue_size; wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE; /* Setup alpha size in bits */ if (_this->gl_config.alpha_size) { wdata->gles_attributes[attr_pos++] = _this->gl_config.alpha_size; } else { wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; } /* Setup color buffer size */ if (_this->gl_config.buffer_size) { wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE; wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size; } else { wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE; wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; } /* Setup depth buffer bits */ wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE; wdata->gles_attributes[attr_pos++] = _this->gl_config.depth_size; /* Setup stencil bits */ if (_this->gl_config.stencil_size) { wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE; wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size; } else { wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE; wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; } /* Set number of samples in multisampling */ if (_this->gl_config.multisamplesamples) { wdata->gles_attributes[attr_pos++] = EGL_SAMPLES; wdata->gles_attributes[attr_pos++] = _this->gl_config.multisamplesamples; } /* Multisample buffers, OpenGL ES 1.0 spec defines 0 or 1 buffer */ if (_this->gl_config.multisamplebuffers) { wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS; wdata->gles_attributes[attr_pos++] = _this->gl_config.multisamplebuffers; } /* Finish attributes list */ wdata->gles_attributes[attr_pos] = EGL_NONE; /* Request first suitable framebuffer configuration */ status = eglChooseConfig(phdata->egl_display, wdata->gles_attributes, wdata->gles_configs, 1, &configs); if (status != EGL_TRUE) { SDL_SetError("PND: Can't find closest configuration for OpenGL ES"); return NULL; } /* Check if nothing has been found, try "don't care" settings */ if (configs == 0) { int32_t it; int32_t jt; GLint depthbits[4] = { 32, 24, 16, EGL_DONT_CARE }; for (it = 0; it < 4; it++) { for (jt = 16; jt >= 0; jt--) { /* Don't care about color buffer bits, use what exist */ /* Replace previous set data with EGL_DONT_CARE */ attr_pos = 0; wdata->gles_attributes[attr_pos++] = EGL_SURFACE_TYPE; wdata->gles_attributes[attr_pos++] = EGL_WINDOW_BIT; wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE; wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE; wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE; wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE; wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE; wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; /* Try to find requested or smallest depth */ if (_this->gl_config.depth_size) { wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE; wdata->gles_attributes[attr_pos++] = depthbits[it]; } else { wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE; wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; } if (_this->gl_config.stencil_size) { wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE; wdata->gles_attributes[attr_pos++] = jt; } else { wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE; wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; } wdata->gles_attributes[attr_pos++] = EGL_SAMPLES; wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS; wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; wdata->gles_attributes[attr_pos] = EGL_NONE; /* Request first suitable framebuffer configuration */ status = eglChooseConfig(phdata->egl_display, wdata->gles_attributes, wdata->gles_configs, 1, &configs); if (status != EGL_TRUE) { SDL_SetError ("PND: Can't find closest configuration for OpenGL ES"); return NULL; } if (configs != 0) { break; } } if (configs != 0) { break; } } /* No available configs */ if (configs == 0) { SDL_SetError("PND: Can't find any configuration for OpenGL ES"); return NULL; } } /* Initialize config index */ wdata->gles_config = 0; /* Now check each configuration to find out the best */ for (cit = 0; cit < configs; cit++) { uint32_t stencil_found; uint32_t depth_found; stencil_found = 0; depth_found = 0; if (_this->gl_config.stencil_size) { status = eglGetConfigAttrib(phdata->egl_display, wdata->gles_configs[cit], EGL_STENCIL_SIZE, &attr_value); if (status == EGL_TRUE) { if (attr_value != 0) { stencil_found = 1; } } } else { stencil_found = 1; } if (_this->gl_config.depth_size) { status = eglGetConfigAttrib(phdata->egl_display, wdata->gles_configs[cit], EGL_DEPTH_SIZE, &attr_value); if (status == EGL_TRUE) { if (attr_value != 0) { depth_found = 1; } } } else { depth_found = 1; } /* Exit from loop if found appropriate configuration */ if ((depth_found != 0) && (stencil_found != 0)) { break; } } /* If best could not be found, use first */ if (cit == configs) { cit = 0; } wdata->gles_config = cit; /* Create OpenGL ES context */ wdata->gles_context = eglCreateContext(phdata->egl_display, wdata->gles_configs[wdata->gles_config], NULL, NULL); if (wdata->gles_context == EGL_NO_CONTEXT) { SDL_SetError("PND: OpenGL ES context creation has been failed"); return NULL; } #ifdef WIZ_GLES_LITE if( !hNativeWnd ) { hNativeWnd = (NativeWindowType)malloc(16*1024); if(!hNativeWnd) printf( "Error : Wiz framebuffer allocatation failed\n" ); else printf( "SDL13: Wiz framebuffer allocated: %X\n", hNativeWnd ); } else { printf( "SDL13: Wiz framebuffer already allocated: %X\n", hNativeWnd ); } wdata->gles_surface = eglCreateWindowSurface(phdata->egl_display, wdata->gles_configs[wdata->gles_config], hNativeWnd, NULL ); #else wdata->gles_surface = eglCreateWindowSurface(phdata->egl_display, wdata->gles_configs[wdata->gles_config], (NativeWindowType) 0, NULL); #endif if (wdata->gles_surface == 0) { SDL_SetError("Error : eglCreateWindowSurface failed;\n"); return NULL; } /* Make just created context current */ status = eglMakeCurrent(phdata->egl_display, wdata->gles_surface, wdata->gles_surface, wdata->gles_context); if (status != EGL_TRUE) { /* Destroy OpenGL ES surface */ eglDestroySurface(phdata->egl_display, wdata->gles_surface); eglDestroyContext(phdata->egl_display, wdata->gles_context); wdata->gles_context = EGL_NO_CONTEXT; SDL_SetError("PND: Can't set OpenGL ES context on creation"); return NULL; } _this->gl_config.accelerated = 1; /* Always clear stereo enable, since OpenGL ES do not supports stereo */ _this->gl_config.stereo = 0; /* Get back samples and samplebuffers configurations. Rest framebuffer */ /* parameters could be obtained through the OpenGL ES API */ status = eglGetConfigAttrib(phdata->egl_display, wdata->gles_configs[wdata->gles_config], EGL_SAMPLES, &attr_value); if (status == EGL_TRUE) { _this->gl_config.multisamplesamples = attr_value; } status = eglGetConfigAttrib(phdata->egl_display, wdata->gles_configs[wdata->gles_config], EGL_SAMPLE_BUFFERS, &attr_value); if (status == EGL_TRUE) { _this->gl_config.multisamplebuffers = attr_value; } /* Get back stencil and depth buffer sizes */ status = eglGetConfigAttrib(phdata->egl_display, wdata->gles_configs[wdata->gles_config], EGL_DEPTH_SIZE, &attr_value); if (status == EGL_TRUE) { _this->gl_config.depth_size = attr_value; } status = eglGetConfigAttrib(phdata->egl_display, wdata->gles_configs[wdata->gles_config], EGL_STENCIL_SIZE, &attr_value); if (status == EGL_TRUE) { _this->gl_config.stencil_size = attr_value; } /* Under PND OpenGL ES output can't be double buffered */ _this->gl_config.double_buffer = 0; /* GL ES context was successfully created */ return wdata->gles_context; }
static int SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created) { SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_WindowData *data; /* Allocate the window data */ data = (SDL_WindowData *) SDL_malloc(sizeof(*data)); if (!data) { SDL_OutOfMemory(); return -1; } data->window = window; data->hwnd = hwnd; data->hdc = GetDC(hwnd); data->created = created; data->mouse_pressed = SDL_FALSE; data->videodata = videodata; /* Associate the data with the window */ if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) { ReleaseDC(hwnd, data->hdc); SDL_free(data); WIN_SetError("SetProp() failed"); return -1; } /* Set up the window proc function */ #ifdef GWLP_WNDPROC data->wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC); if (data->wndproc == WIN_WindowProc) { data->wndproc = NULL; } else { SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) WIN_WindowProc); } #else data->wndproc = (WNDPROC) GetWindowLong(hwnd, GWL_WNDPROC); if (data->wndproc == WIN_WindowProc) { data->wndproc = NULL; } else { SetWindowLong(hwnd, GWL_WNDPROC, (LONG_PTR) WIN_WindowProc); } #endif /* Fill in the SDL window with the window data */ { POINT point; point.x = 0; point.y = 0; if (ClientToScreen(hwnd, &point)) { window->x = point.x; window->y = point.y; } } { RECT rect; if (GetClientRect(hwnd, &rect)) { window->w = rect.right; window->h = rect.bottom; } } { DWORD style = GetWindowLong(hwnd, GWL_STYLE); if (style & WS_VISIBLE) { window->flags |= SDL_WINDOW_SHOWN; } else { window->flags &= ~SDL_WINDOW_SHOWN; } if (style & (WS_BORDER | WS_THICKFRAME)) { window->flags &= ~SDL_WINDOW_BORDERLESS; } else { window->flags |= SDL_WINDOW_BORDERLESS; } if (style & WS_THICKFRAME) { window->flags |= SDL_WINDOW_RESIZABLE; } else { window->flags &= ~SDL_WINDOW_RESIZABLE; } #ifdef WS_MAXIMIZE if (style & WS_MAXIMIZE) { window->flags |= SDL_WINDOW_MAXIMIZED; } else #endif { window->flags &= ~SDL_WINDOW_MAXIMIZED; } #ifdef WS_MINIMIZE if (style & WS_MINIMIZE) { window->flags |= SDL_WINDOW_MINIMIZED; } else #endif { window->flags &= ~SDL_WINDOW_MINIMIZED; } } if (GetFocus() == hwnd) { window->flags |= SDL_WINDOW_INPUT_FOCUS; SDL_SetKeyboardFocus(data->window); if (window->flags & SDL_WINDOW_INPUT_GRABBED) { RECT rect; GetClientRect(hwnd, &rect); ClientToScreen(hwnd, (LPPOINT) & rect); ClientToScreen(hwnd, (LPPOINT) & rect + 1); ClipCursor(&rect); } } /* Enable multi-touch */ if (videodata->RegisterTouchWindow) { videodata->RegisterTouchWindow(hwnd, (TWF_FINETOUCH|TWF_WANTPALM)); } /* All done! */ window->driverdata = data; return 0; }