comparison src/video/photon/SDL_photon.c @ 3375:dd105b317335

Continue working on 2D support for Photon/QNX.
author Mike Gorchak <lestat@i.com.ua>
date Sat, 10 Oct 2009 20:15:20 +0000
parents 64e4442676a6
children 90935231e9b6
comparison
equal deleted inserted replaced
3374:725b16784e96 3375:dd105b317335
42 42
43 /* Use GF's pixel format functions for OpenGL ES context creation */ 43 /* Use GF's pixel format functions for OpenGL ES context creation */
44 #if defined(SDL_VIDEO_OPENGL_ES) 44 #if defined(SDL_VIDEO_OPENGL_ES)
45 #include "../qnxgf/SDL_gf_pixelfmt.h" 45 #include "../qnxgf/SDL_gf_pixelfmt.h"
46 46
47 /* If GF driver is not compiled in, include some of usefull functions */ 47 /* If GF driver is not compiled in, include some of usefull functions */
48 #if !defined(SDL_VIDEO_DRIVER_QNXGF) 48 #if !defined(SDL_VIDEO_DRIVER_QNXGF)
49 #include "../qnxgf/SDL_gf_pixelfmt.c" 49 #include "../qnxgf/SDL_gf_pixelfmt.c"
50 #endif /* SDL_VIDEO_DRIVER_QNXGF */ 50 #endif /* SDL_VIDEO_DRIVER_QNXGF */
51 #endif /* SDL_VIDEO_OPENGL_ES */ 51 #endif /* SDL_VIDEO_OPENGL_ES */
52 52
53 /* Use GF's OpenGL ES 1.1 functions emulation */ 53 /* Use GF's OpenGL ES 1.1 functions emulation */
54 #if defined(SDL_VIDEO_OPENGL_ES) 54 #if defined(SDL_VIDEO_OPENGL_ES)
55 #include "../qnxgf/SDL_gf_opengles.h" 55 #include "../qnxgf/SDL_gf_opengles.h"
56 56
57 /* If GF driver is not compiled in, include some of usefull functions */ 57 /* If GF driver is not compiled in, include some of usefull functions */
58 #if !defined(SDL_VIDEO_DRIVER_QNXGF) 58 #if !defined(SDL_VIDEO_DRIVER_QNXGF)
59 #include "../qnxgf/SDL_gf_opengles.c" 59 #include "../qnxgf/SDL_gf_opengles.c"
60 #endif /* SDL_VIDEO_DRIVER_QNXGF */ 60 #endif /* SDL_VIDEO_DRIVER_QNXGF */
61 #endif /* SDL_VIDEO_OPENGL_ES */ 61 #endif /* SDL_VIDEO_OPENGL_ES */
62 62
135 {"tvia", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} 135 {"tvia", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
136 , 136 ,
137 /* VIA UniChrome graphics driver (devg-unichrome.so) */ 137 /* VIA UniChrome graphics driver (devg-unichrome.so) */
138 {"unichrome", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} 138 {"unichrome", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
139 , 139 ,
140 /* VESA unaccelerated gfx driver (devg-vesa.so) */ 140 /* VESA unaccelerated gfx driver (devg-vesabios.so) */
141 {"vesa", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D} 141 {"vesa", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
142 , 142 ,
143 /* VmWare graphics driver (devg-volari.so) */ 143 /* VmWare graphics driver (devg-volari.so) */
144 {"vmware", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} 144 {"vmware", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
145 , 145 ,
153 static SDL_bool photon_initialized = SDL_FALSE; 153 static SDL_bool photon_initialized = SDL_FALSE;
154 154
155 static int 155 static int
156 photon_available(void) 156 photon_available(void)
157 { 157 {
158 int status; 158 int32_t status;
159 159
160 /* Check if Photon was initialized before */ 160 /* Check if Photon was initialized before */
161 if (photon_initialized == SDL_FALSE) { 161 if (photon_initialized == SDL_FALSE) {
162 /* Initialize Photon widget library and open channel to Photon */ 162 /* Initialize Photon widget library and open channel to Photon */
163 status = PtInit(NULL); 163 status = PtInit(NULL);
192 static SDL_VideoDevice * 192 static SDL_VideoDevice *
193 photon_create(int devindex) 193 photon_create(int devindex)
194 { 194 {
195 SDL_VideoDevice *device; 195 SDL_VideoDevice *device;
196 SDL_VideoData *phdata; 196 SDL_VideoData *phdata;
197 int status; 197 int32_t status;
198 198
199 /* Check if photon could be initialized */ 199 /* Check if photon could be initialized */
200 status = photon_available(); 200 status = photon_available();
201 if (status == 0) { 201 if (status == 0) {
202 /* Photon could not be used */ 202 /* Photon could not be used */
881 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_FALSE, 881 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_FALSE,
882 Ph_WM_STATE_ISFOCUS); 882 Ph_WM_STATE_ISFOCUS);
883 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE, 883 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE,
884 Ph_WM_STATE_ISALTKEY); 884 Ph_WM_STATE_ISALTKEY);
885 885
886 /* Special case, do not handle maximize events, if window can't be resized */
887 if ((window->flags & SDL_WINDOW_RESIZABLE) != SDL_WINDOW_RESIZABLE)
888 {
889 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE,
890 Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_RESIZE);
891 }
892
886 /* Set window dimension */ 893 /* Set window dimension */
887 winsize.w = window->w; 894 winsize.w = window->w;
888 winsize.h = window->h; 895 winsize.h = window->h;
889 PtSetArg(&winargs[winargc++], Pt_ARG_DIM, &winsize, 0); 896 PtSetArg(&winargs[winargc++], Pt_ARG_DIM, &winsize, 0);
890 897
1303 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; 1310 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
1304 1311
1305 if (phdata->gfinitialized != SDL_TRUE) { 1312 if (phdata->gfinitialized != SDL_TRUE) {
1306 SDL_SetError 1313 SDL_SetError
1307 ("Photon: GF initialization failed, no OpenGL ES support"); 1314 ("Photon: GF initialization failed, no OpenGL ES support");
1308 return NULL; 1315 return -1;
1309 } 1316 }
1310 1317
1311 /* Check if OpenGL ES library is specified for GF driver */ 1318 /* Check if OpenGL ES library is specified for GF driver */
1312 if (path == NULL) { 1319 if (path == NULL) {
1313 path = SDL_getenv("SDL_OPENGL_LIBRARY"); 1320 path = SDL_getenv("SDL_OPENGL_LIBRARY");
1916 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; 1923 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
1917 SDL_DisplayData *didata = 1924 SDL_DisplayData *didata =
1918 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata; 1925 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
1919 PhRect_t dst_rect; 1926 PhRect_t dst_rect;
1920 PhRect_t src_rect; 1927 PhRect_t src_rect;
1928 int32_t status;
1921 1929
1922 if (phdata->gfinitialized != SDL_TRUE) { 1930 if (phdata->gfinitialized != SDL_TRUE) {
1923 SDL_SetError 1931 SDL_SetError
1924 ("Photon: GF initialization failed, no OpenGL ES support"); 1932 ("Photon: GF initialization failed, no OpenGL ES support");
1925 return; 1933 return;
1948 dst_rect = *PtGetCanvas(wdata->window); 1956 dst_rect = *PtGetCanvas(wdata->window);
1949 src_rect.ul.x = 0; 1957 src_rect.ul.x = 0;
1950 src_rect.ul.y = 0; 1958 src_rect.ul.y = 0;
1951 src_rect.lr.x = window->w - 1; 1959 src_rect.lr.x = window->w - 1;
1952 src_rect.lr.y = window->h - 1; 1960 src_rect.lr.y = window->h - 1;
1961
1962 /* Check if current device is not the same as target */
1963 if (phdata->current_device_id != didata->device_id) {
1964 /* Set target device as default for Pd and Pg functions */
1965 status = PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
1966 if (status != 0) {
1967 SDL_SetError("Photon: Can't set default target device\n");
1968 return;
1969 }
1970 phdata->current_device_id = didata->device_id;
1971 }
1953 1972
1954 /* Blit OpenGL ES pixmap surface directly to window region */ 1973 /* Blit OpenGL ES pixmap surface directly to window region */
1955 PgFFlush(Ph_START_DRAW); 1974 PgFFlush(Ph_START_DRAW);
1956 PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window)); 1975 PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
1957 PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent())); 1976 PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
2322 2341
2323 /* Check if expose come to one of the our windows */ 2342 /* Check if expose come to one of the our windows */
2324 if ((wdata != NULL) && (window != NULL)) { 2343 if ((wdata != NULL) && (window != NULL)) {
2325 /* Check if window uses OpenGL ES */ 2344 /* Check if window uses OpenGL ES */
2326 if (wdata->uses_gles == SDL_TRUE) { 2345 if (wdata->uses_gles == SDL_TRUE) {
2327 PhRect_t dst_rect;
2328 PhRect_t src_rect;
2329
2330 /* Cycle through each rectangle */ 2346 /* Cycle through each rectangle */
2331 for (it = 0; it < event->num_rects; 2347 for (it = 0; it < event->num_rects; it++) {
2332 it++) {
2333 /* Blit OpenGL ES pixmap surface directly to window region */ 2348 /* Blit OpenGL ES pixmap surface directly to window region */
2334 PgFFlush(Ph_START_DRAW); 2349 PgFFlush(Ph_START_DRAW);
2335 PgSetRegionCx(PhDCGetCurrent(), 2350 PgSetRegionCx(PhDCGetCurrent(),
2336 PtWidgetRid(wdata-> 2351 PtWidgetRid(wdata->
2337 window)); 2352 window));
2343 &rects[it]); 2358 &rects[it]);
2344 PgFFlush(Ph_DONE_DRAW); 2359 PgFFlush(Ph_DONE_DRAW);
2345 PgWaitHWIdle(); 2360 PgWaitHWIdle();
2346 } 2361 }
2347 } else { 2362 } else {
2348 /* Normal window */ 2363 /* Cycle through each rectangle */
2349 /* TODO: update the damaged rectangles */ 2364 for (it = 0; it < event->num_rects;
2365 it++) {
2366 /* Blit 2D pixmap surface directly to window region */
2367 _photon_update_rectangles(window->renderer, &rects[it]);
2368 }
2369 PgFlush();
2370 PgWaitHWIdle();
2350 } 2371 }
2351 } 2372 }
2352 2373
2353 /* Flush all blittings */ 2374 /* Flush all blittings */
2354 PgFlush(); 2375 PgFlush();
2383 &src_rect, NULL, 2404 &src_rect, NULL,
2384 &dst_rect); 2405 &dst_rect);
2385 PgFFlush(Ph_DONE_DRAW); 2406 PgFFlush(Ph_DONE_DRAW);
2386 PgWaitHWIdle(); 2407 PgWaitHWIdle();
2387 } else { 2408 } else {
2388 /* Normal window */ 2409 PhRect_t rect;
2389 /* TODO: update the damaged rectangles */
2390 2410
2391 /* We need to redraw entire window */ 2411 /* We need to redraw entire window */
2412 rect.ul.x = 0;
2413 rect.ul.y = 0;
2414 rect.lr.x = window->w - 1;
2415 rect.lr.y = window->h - 1;
2416
2417 /* Blit 2D pixmap surface directly to window region */
2418 PgFFlush(Ph_START_DRAW);
2419 _photon_update_rectangles(window->renderer, &rect);
2420 PgFFlush(Ph_DONE_DRAW);
2421 PgWaitHWIdle();
2392 } 2422 }
2393 } 2423 }
2394 } 2424 }
2395 break; 2425 break;
2396 case Ph_GRAPHIC_EXPOSE: 2426 case Ph_GRAPHIC_EXPOSE:
2691 } 2721 }
2692 break; 2722 break;
2693 case Ph_WM_MAX: 2723 case Ph_WM_MAX:
2694 { 2724 {
2695 if (window != NULL) { 2725 if (window != NULL) {
2696 SDL_SendWindowEvent(window->id, 2726 if ((window->flags & SDL_WINDOW_RESIZABLE)==SDL_WINDOW_RESIZABLE)
2697 SDL_WINDOWEVENT_MAXIMIZED, 2727 {
2698 0, 0); 2728 SDL_SendWindowEvent(window->id,
2729 SDL_WINDOWEVENT_MAXIMIZED,
2730 0, 0);
2731 }
2732 else
2733 {
2734 /* otherwise ignor the resize events */
2735 }
2699 } 2736 }
2700 } 2737 }
2701 break; 2738 break;
2702 case Ph_WM_RESTORE: 2739 case Ph_WM_RESTORE:
2703 { 2740 {