comparison src/video/photon/SDL_photon_render.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 7f684f249ec9
children 90935231e9b6
comparison
equal deleted inserted replaced
3374:725b16784e96 3375:dd105b317335
66 static void photon_unlocktexture(SDL_Renderer * renderer, 66 static void photon_unlocktexture(SDL_Renderer * renderer,
67 SDL_Texture * texture); 67 SDL_Texture * texture);
68 static void photon_dirtytexture(SDL_Renderer * renderer, 68 static void photon_dirtytexture(SDL_Renderer * renderer,
69 SDL_Texture * texture, int numrects, 69 SDL_Texture * texture, int numrects,
70 const SDL_Rect * rects); 70 const SDL_Rect * rects);
71 static int photon_setdrawcolor(SDL_Renderer * renderer);
72 static int photon_setdrawblendmode(SDL_Renderer * renderer);
71 static int photon_renderpoint(SDL_Renderer * renderer, int x, int y); 73 static int photon_renderpoint(SDL_Renderer * renderer, int x, int y);
72 static int photon_renderline(SDL_Renderer * renderer, int x1, int y1, int x2, 74 static int photon_renderline(SDL_Renderer * renderer, int x1, int y1, int x2,
73 int y2); 75 int y2);
74 static int photon_renderfill(SDL_Renderer * renderer, const SDL_Rect * rect); 76 static int photon_renderfill(SDL_Renderer * renderer, const SDL_Rect * rect);
75 static int photon_rendercopy(SDL_Renderer * renderer, SDL_Texture * texture, 77 static int photon_rendercopy(SDL_Renderer * renderer, SDL_Texture * texture,
78 static void photon_renderpresent(SDL_Renderer * renderer); 80 static void photon_renderpresent(SDL_Renderer * renderer);
79 static void photon_destroytexture(SDL_Renderer * renderer, 81 static void photon_destroytexture(SDL_Renderer * renderer,
80 SDL_Texture * texture); 82 SDL_Texture * texture);
81 static void photon_destroyrenderer(SDL_Renderer * renderer); 83 static void photon_destroyrenderer(SDL_Renderer * renderer);
82 84
85 static int _photon_recreate_surfaces(SDL_Renderer * renderer);
86
83 SDL_RenderDriver photon_renderdriver = { 87 SDL_RenderDriver photon_renderdriver = {
84 photon_createrenderer, 88 photon_createrenderer,
85 { 89 {
86 "photon", 90 "photon",
87 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY | 91 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
90 SDL_RENDERER_ACCELERATED), 94 SDL_RENDERER_ACCELERATED),
91 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR | 95 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
92 SDL_TEXTUREMODULATE_ALPHA), 96 SDL_TEXTUREMODULATE_ALPHA),
93 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | 97 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK |
94 SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD), 98 SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
95 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_SLOW), 99 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_SLOW |
96 13, 100 SDL_TEXTURESCALEMODE_FAST | SDL_TEXTURESCALEMODE_BEST),
97 { 101 10,
98 SDL_PIXELFORMAT_INDEX8, 102 {SDL_PIXELFORMAT_INDEX8,
99 SDL_PIXELFORMAT_RGB555, 103 SDL_PIXELFORMAT_RGB555,
100 SDL_PIXELFORMAT_RGB565, 104 SDL_PIXELFORMAT_RGB565,
105 SDL_PIXELFORMAT_RGB24,
101 SDL_PIXELFORMAT_RGB888, 106 SDL_PIXELFORMAT_RGB888,
102 SDL_PIXELFORMAT_BGR888,
103 SDL_PIXELFORMAT_ARGB8888, 107 SDL_PIXELFORMAT_ARGB8888,
104 SDL_PIXELFORMAT_RGBA8888,
105 SDL_PIXELFORMAT_ABGR8888,
106 SDL_PIXELFORMAT_BGRA8888,
107 SDL_PIXELFORMAT_YV12, 108 SDL_PIXELFORMAT_YV12,
108 SDL_PIXELFORMAT_YUY2, 109 SDL_PIXELFORMAT_YUY2,
109 SDL_PIXELFORMAT_UYVY, 110 SDL_PIXELFORMAT_UYVY,
110 SDL_PIXELFORMAT_YVYU}, 111 SDL_PIXELFORMAT_YVYU},
111 0, 112 0,
148 renderer->SetTextureScaleMode = photon_settexturescalemode; 149 renderer->SetTextureScaleMode = photon_settexturescalemode;
149 renderer->UpdateTexture = photon_updatetexture; 150 renderer->UpdateTexture = photon_updatetexture;
150 renderer->LockTexture = photon_locktexture; 151 renderer->LockTexture = photon_locktexture;
151 renderer->UnlockTexture = photon_unlocktexture; 152 renderer->UnlockTexture = photon_unlocktexture;
152 renderer->DirtyTexture = photon_dirtytexture; 153 renderer->DirtyTexture = photon_dirtytexture;
154 renderer->SetDrawColor = photon_setdrawcolor;
155 renderer->SetDrawBlendMode = photon_setdrawblendmode;
153 renderer->RenderPoint = photon_renderpoint; 156 renderer->RenderPoint = photon_renderpoint;
154 renderer->RenderLine = photon_renderline; 157 renderer->RenderLine = photon_renderline;
155 renderer->RenderFill = photon_renderfill; 158 renderer->RenderFill = photon_renderfill;
156 renderer->RenderCopy = photon_rendercopy; 159 renderer->RenderCopy = photon_rendercopy;
157 renderer->RenderPresent = photon_renderpresent; 160 renderer->RenderPresent = photon_renderpresent;
165 if ((didata->caps & SDL_PHOTON_ACCELERATED) == SDL_PHOTON_ACCELERATED) { 168 if ((didata->caps & SDL_PHOTON_ACCELERATED) == SDL_PHOTON_ACCELERATED) {
166 renderer->info.flags = SDL_RENDERER_ACCELERATED; 169 renderer->info.flags = SDL_RENDERER_ACCELERATED;
167 } else { 170 } else {
168 renderer->info.flags &= ~(SDL_RENDERER_ACCELERATED); 171 renderer->info.flags &= ~(SDL_RENDERER_ACCELERATED);
169 } 172 }
170
171 rdata->window = window;
172 173
173 /* Check if upper level requested synchronization on vsync signal */ 174 /* Check if upper level requested synchronization on vsync signal */
174 if ((flags & SDL_RENDERER_PRESENTVSYNC) == SDL_RENDERER_PRESENTVSYNC) { 175 if ((flags & SDL_RENDERER_PRESENTVSYNC) == SDL_RENDERER_PRESENTVSYNC) {
175 rdata->enable_vsync = SDL_TRUE; 176 rdata->enable_vsync = SDL_TRUE;
176 } else { 177 } else {
212 rdata->surface_render_idx = 0; 213 rdata->surface_render_idx = 0;
213 } 214 }
214 } 215 }
215 } 216 }
216 217
218 /* Create new graphics context */
219 if (rdata->gc==NULL)
220 {
221 rdata->gc=PgCreateGC(0);
222 PgDefaultGC(rdata->gc);
223 }
224
217 return renderer; 225 return renderer;
218 } 226 }
219 227
220 void 228 void
221 photon_addrenderdriver(_THIS) 229 photon_addrenderdriver(_THIS)
223 uint32_t it; 231 uint32_t it;
224 232
225 for (it = 0; it < _this->num_displays; it++) { 233 for (it = 0; it < _this->num_displays; it++) {
226 SDL_AddRenderDriver(it, &photon_renderdriver); 234 SDL_AddRenderDriver(it, &photon_renderdriver);
227 } 235 }
236 }
237
238 /****************************************************************************/
239 /* Render helper functions */
240 /****************************************************************************/
241
242 static int _photon_recreate_surfaces(SDL_Renderer * renderer)
243 {
244 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
245 SDL_VideoDisplay *display = NULL;
246 SDL_DisplayData *didata = NULL;
247 SDL_Window *window = NULL;
248 SDL_WindowData *wdata = NULL;
249 SDL_VideoData *phdata = NULL;
250 uint32_t allocate_task=SDL_PHOTON_SURFTYPE_UNKNOWN;
251 int32_t status;
252
253 /* Obtain window and display structures */
254 window=SDL_GetWindowFromID(renderer->window);
255 wdata=(SDL_WindowData*)window->driverdata;
256 display=SDL_GetDisplayFromWindow(window);
257 didata=(SDL_DisplayData *) display->driverdata;
258 phdata=(SDL_VideoData *) display->device->driverdata;
259
260 /* Check if it is OpenGL ES window */
261 if ((window->flags & SDL_WINDOW_OPENGL) == SDL_WINDOW_OPENGL) {
262 /* If so, do not waste surfaces */
263 rdata->surfaces_type=SDL_PHOTON_SURFTYPE_UNKNOWN;
264 return 0;
265 }
266
267 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN)
268 {
269 /* Try to allocate offscreen surfaces */
270 allocate_task=SDL_PHOTON_SURFTYPE_OFFSCREEN;
271 }
272 else
273 {
274 uint32_t it;
275
276 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_OFFSCREEN)
277 {
278 /* Create offscreen surfaces */
279 allocate_task=SDL_PHOTON_SURFTYPE_OFFSCREEN;
280
281 /* Destroy current surfaces */
282 for (it=0; it<SDL_PHOTON_MAX_SURFACES; it++)
283 {
284 if (rdata->osurfaces[it] != NULL)
285 {
286 PhDCRelease(rdata->osurfaces[it]);
287 rdata->osurfaces[it] = NULL;
288 }
289 }
290 }
291 else
292 {
293 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_PHIMAGE)
294 {
295 /* Create shared phimage surfaces */
296 allocate_task=SDL_PHOTON_SURFTYPE_PHIMAGE;
297
298 /* Destroy current surfaces */
299 for (it=0; it<SDL_PHOTON_MAX_SURFACES; it++)
300 {
301 if (rdata->pcontexts[it]!=NULL)
302 {
303 PmMemReleaseMC(rdata->pcontexts[it]);
304 rdata->pcontexts[it]=NULL;
305 }
306 if (rdata->psurfaces[it]!=NULL)
307 {
308 if (rdata->psurfaces[it]->palette!=NULL)
309 {
310 SDL_free(rdata->psurfaces[it]->palette);
311 rdata->psurfaces[it]->palette=NULL;
312 }
313 /* Destroy shared memory for PhImage_t */
314 PgShmemDestroy(rdata->psurfaces[it]->image);
315 rdata->psurfaces[it]->image=NULL;
316 SDL_free(rdata->psurfaces[it]);
317 rdata->psurfaces[it]=NULL;
318 }
319 }
320 }
321 }
322 }
323
324 /* Check if current device is not the same as target */
325 if (phdata->current_device_id != didata->device_id) {
326 /* Set target device as default for Pd and Pg functions */
327 status = PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
328 if (status != 0) {
329 SDL_SetError("Photon: Can't set default target device\n");
330 return -1;
331 }
332 phdata->current_device_id = didata->device_id;
333 }
334
335 switch (allocate_task)
336 {
337 case SDL_PHOTON_SURFTYPE_OFFSCREEN:
338 {
339 int32_t it;
340 int32_t jt;
341
342 /* Try the hardware accelerated offscreen surfaces first */
343 for (it=0; it<rdata->surfaces_count; it++)
344 {
345 rdata->osurfaces[it]=PdCreateOffscreenContext(0, window->w, window->h,
346 Pg_OSC_MEM_LINEAR_ACCESSIBLE |
347 /* in case if 2D acceleration is not available use CPU optimized surfaces */
348 Pg_OSC_MEM_HINT_CPU_READ | Pg_OSC_MEM_HINT_CPU_WRITE |
349 /* in case if 2D acceleration is available use it */
350 Pg_OSC_MEM_2D_WRITABLE | Pg_OSC_MEM_2D_READABLE);
351
352 /* If we can't create an offscreen surface, then fallback to software */
353 if (rdata->osurfaces[it]==NULL)
354 {
355 /* Destroy previously allocated surface(s) */
356 for (jt = it - 1; jt > 0; jt--)
357 {
358 PhDCRelease(rdata->osurfaces[jt]);
359 rdata->osurfaces[jt] = NULL;
360 }
361 break;
362 }
363 }
364
365 /* Check if all required surfaces have been created */
366 if (rdata->osurfaces[0]!=NULL)
367 {
368 rdata->surfaces_type=SDL_PHOTON_SURFTYPE_OFFSCREEN;
369 /* exit from switch if surfaces have been created */
370 break;
371 }
372 else
373 {
374 /* else fall through to software phimage surface allocation */
375 }
376 }
377 /* fall through */
378 case SDL_PHOTON_SURFTYPE_PHIMAGE:
379 {
380 int32_t it;
381 int32_t jt;
382 uint32_t image_pfmt=photon_sdl_to_image_pixelformat(didata->current_mode.format);
383
384 /* Try to allocate the software surfaces in shared memory */
385 for (it=0; it<rdata->surfaces_count; it++)
386 {
387 /* If this surface with palette, create a palette space */
388 if (image_pfmt==Pg_IMAGE_PALETTE_BYTE)
389 {
390 rdata->psurfaces[it]=PhCreateImage(NULL, window->w, window->h,
391 image_pfmt, NULL, 256, 1);
392 }
393 else
394 {
395 rdata->psurfaces[it]=PhCreateImage(NULL, window->w, window->h,
396 image_pfmt, NULL, 0, 1);
397 }
398
399 if (rdata->psurfaces[it]!=NULL)
400 {
401 PhPoint_t translation={0, 0};
402 PhDim_t dimension={window->w, window->h};
403
404 /* Create memory context for PhImage_t */
405 rdata->pcontexts[it]=PmMemCreateMC(rdata->psurfaces[it], &dimension, &translation);
406 }
407
408 if ((rdata->psurfaces[it]==NULL) || (rdata->pcontexts[it]==NULL))
409 {
410 /* Destroy previously allocated surface(s) */
411 for (jt = it - 1; jt > 0; jt--)
412 {
413 if (rdata->pcontexts[jt]!=NULL)
414 {
415 PmMemReleaseMC(rdata->pcontexts[it]);
416 rdata->pcontexts[jt]=NULL;
417 }
418 if (rdata->psurfaces[jt]!=NULL)
419 {
420 if (rdata->psurfaces[jt]->palette!=NULL)
421 {
422 SDL_free(rdata->psurfaces[jt]->palette);
423 rdata->psurfaces[jt]->palette=NULL;
424 }
425 /* Destroy shared memory for PhImage_t */
426 PgShmemDestroy(rdata->psurfaces[jt]->image);
427 rdata->psurfaces[jt]->image=NULL;
428 SDL_free(rdata->psurfaces[jt]);
429 rdata->psurfaces[jt] = NULL;
430 }
431 }
432 break;
433 }
434 }
435
436 /* Check if all required surfaces have been created */
437 if (rdata->psurfaces[0]!=NULL)
438 {
439 rdata->surfaces_type=SDL_PHOTON_SURFTYPE_PHIMAGE;
440 }
441 else
442 {
443 rdata->surfaces_type=SDL_PHOTON_SURFTYPE_UNKNOWN;
444 }
445 }
446 break;
447 case SDL_PHOTON_SURFTYPE_UNKNOWN:
448 {
449 /* do nothing with surface allocation */
450 rdata->surfaces_type=SDL_PHOTON_SURFTYPE_UNKNOWN;
451 }
452 break;
453 }
454
455 /* Check if one of two allocation scheme was successful */
456 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN)
457 {
458 SDL_SetError("Photon: primary surface(s) allocation failure");
459 return -1;
460 }
461
462 /* Store current surface dimensions */
463 rdata->window_width=window->w;
464 rdata->window_height=window->h;
465
466 /* If current copy/flip scheme is single buffer, then set initial parameters */
467 if ((renderer->info.flags & SDL_RENDERER_SINGLEBUFFER)==SDL_RENDERER_SINGLEBUFFER)
468 {
469 rdata->surface_visible_idx = 0;
470 rdata->surface_render_idx = 0;
471 }
472
473 /* If current copy/flip scheme is double buffer, then set initial parameters */
474 if ((renderer->info.flags & SDL_RENDERER_PRESENTFLIP2)==SDL_RENDERER_PRESENTFLIP2)
475 {
476 rdata->surface_visible_idx = 0;
477 rdata->surface_render_idx = 1;
478 }
479
480 /* If current copy/flip scheme is triple buffer, then set initial parameters */
481 if ((renderer->info.flags & SDL_RENDERER_PRESENTFLIP3)==SDL_RENDERER_PRESENTFLIP3)
482 {
483 rdata->surface_visible_idx = 0;
484 rdata->surface_render_idx = 1;
485 }
486
487 switch (rdata->surfaces_type)
488 {
489 case SDL_PHOTON_SURFTYPE_OFFSCREEN:
490 PgSetGCCx(rdata->osurfaces[rdata->surface_render_idx], rdata->gc);
491 break;
492 case SDL_PHOTON_SURFTYPE_PHIMAGE:
493 PgSetGCCx(rdata->pcontexts[rdata->surface_render_idx], rdata->gc);
494 break;
495 case SDL_PHOTON_SURFTYPE_UNKNOWN:
496 break;
497 }
498
499 return 0;
500 }
501
502 int _photon_update_rectangles(SDL_Renderer* renderer, PhRect_t* rect)
503 {
504 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
505 SDL_Window *window = window=SDL_GetWindowFromID(renderer->window);
506 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
507 PhPoint_t src_point;
508
509 /* If currently single buffer is in use, we have to flush all data */
510 if (rdata->surface_render_idx==rdata->surface_visible_idx)
511 {
512 /* Flush all undrawn graphics data to surface */
513 switch (rdata->surfaces_type)
514 {
515 case SDL_PHOTON_SURFTYPE_OFFSCREEN:
516 PgFlushCx(rdata->osurfaces[rdata->surface_visible_idx]);
517 PgWaitHWIdle();
518 break;
519 case SDL_PHOTON_SURFTYPE_PHIMAGE:
520 PmMemFlush(rdata->pcontexts[rdata->surface_visible_idx], rdata->psurfaces[rdata->surface_visible_idx]);
521 break;
522 case SDL_PHOTON_SURFTYPE_UNKNOWN:
523 return;
524 }
525 }
526
527 PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
528
529 src_point.x = rect->ul.x;
530 src_point.y = rect->ul.y;
531
532 switch (rdata->surfaces_type)
533 {
534 case SDL_PHOTON_SURFTYPE_OFFSCREEN:
535 PgContextBlit(rdata->osurfaces[rdata->surface_visible_idx], rect, NULL, rect);
536 break;
537 case SDL_PHOTON_SURFTYPE_PHIMAGE:
538 PgDrawPhImageRectv(&src_point, rdata->psurfaces[rdata->surface_visible_idx], rect, 0);
539 break;
540 case SDL_PHOTON_SURFTYPE_UNKNOWN:
541 break;
542 }
228 } 543 }
229 544
230 /****************************************************************************/ 545 /****************************************************************************/
231 /* SDL render interface */ 546 /* SDL render interface */
232 /****************************************************************************/ 547 /****************************************************************************/
548
549 static int
550 photon_activaterenderer(SDL_Renderer * renderer)
551 {
552 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
553 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
554 SDL_WindowData *wdata = (SDL_WindowData *)window->driverdata;
555
556 if ((rdata->window_width!=window->w) || (rdata->window_height!=window->h))
557 {
558 return _photon_recreate_surfaces(renderer);
559 }
560
561 switch (rdata->surfaces_type)
562 {
563 case SDL_PHOTON_SURFTYPE_OFFSCREEN:
564 PgSetGCCx(rdata->osurfaces[rdata->surface_render_idx], rdata->gc);
565 break;
566 case SDL_PHOTON_SURFTYPE_PHIMAGE:
567 PgSetGCCx(rdata->pcontexts[rdata->surface_render_idx], rdata->gc);
568 break;
569 case SDL_PHOTON_SURFTYPE_UNKNOWN:
570 break;
571 }
572
573 return 0;
574 }
575
233 static int 576 static int
234 photon_displaymodechanged(SDL_Renderer * renderer) 577 photon_displaymodechanged(SDL_Renderer * renderer)
235 { 578 {
236 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; 579 return _photon_recreate_surfaces(renderer);
237
238 /* Remove all allocated surfaces, they are no more valid */
239
240 /* TODO: Add video mode change detection and new parameters detection */
241
242 return 0;
243 }
244
245 static int
246 photon_activaterenderer(SDL_Renderer * renderer)
247 {
248 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
249 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(rdata->window);
250 SDL_DisplayData *didata = (SDL_DisplayData *) display->driverdata;
251
252 return 0;
253 } 580 }
254 581
255 static int 582 static int
256 photon_createtexture(SDL_Renderer * renderer, SDL_Texture * texture) 583 photon_createtexture(SDL_Renderer * renderer, SDL_Texture * texture)
257 { 584 {
267 return -1; 594 return -1;
268 } 595 }
269 596
270 /* Set texture driver data */ 597 /* Set texture driver data */
271 texture->driverdata = tdata; 598 texture->driverdata = tdata;
272
273 } 599 }
274 600
275 static int 601 static int
276 photon_querytexturepixels(SDL_Renderer * renderer, SDL_Texture * texture, 602 photon_querytexturepixels(SDL_Renderer * renderer, SDL_Texture * texture,
277 void **pixels, int *pitch) 603 void **pixels, int *pitch)
334 int numrects, const SDL_Rect * rects) 660 int numrects, const SDL_Rect * rects)
335 { 661 {
336 } 662 }
337 663
338 static int 664 static int
665 photon_setdrawcolor(SDL_Renderer * renderer)
666 {
667 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
668
669 switch (rdata->surfaces_type)
670 {
671 case SDL_PHOTON_SURFTYPE_OFFSCREEN:
672 case SDL_PHOTON_SURFTYPE_PHIMAGE:
673 PgSetFillColorCx(rdata->gc, PgRGB(renderer->r, renderer->g, renderer->b));
674 PgSetStrokeColorCx(rdata->gc, PgRGB(renderer->r, renderer->g, renderer->b));
675 break;
676 case SDL_PHOTON_SURFTYPE_UNKNOWN:
677 break;
678 }
679 }
680
681 static int
682 photon_setdrawblendmode(SDL_Renderer * renderer)
683 {
684 }
685
686 static int
339 photon_renderpoint(SDL_Renderer * renderer, int x, int y) 687 photon_renderpoint(SDL_Renderer * renderer, int x, int y)
340 { 688 {
689 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
690
691 switch (rdata->surfaces_type)
692 {
693 case SDL_PHOTON_SURFTYPE_OFFSCREEN:
694 PgDrawIPixelCx(rdata->osurfaces[rdata->surface_render_idx], x, y);
695 break;
696 case SDL_PHOTON_SURFTYPE_PHIMAGE:
697 PgDrawIPixelCx(rdata->pcontexts[rdata->surface_render_idx], x, y);
698 break;
699 case SDL_PHOTON_SURFTYPE_UNKNOWN:
700 break;
701 }
341 } 702 }
342 703
343 static int 704 static int
344 photon_renderline(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) 705 photon_renderline(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
345 { 706 {
707 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
708
709 switch (rdata->surfaces_type)
710 {
711 case SDL_PHOTON_SURFTYPE_OFFSCREEN:
712 PgDrawILineCx(rdata->osurfaces[rdata->surface_render_idx], x1, y1, x2, y2);
713 break;
714 case SDL_PHOTON_SURFTYPE_PHIMAGE:
715 PgDrawILineCx(rdata->pcontexts[rdata->surface_render_idx], x1, y1, x2, y2);
716 break;
717 case SDL_PHOTON_SURFTYPE_UNKNOWN:
718 break;
719 }
346 } 720 }
347 721
348 static int 722 static int
349 photon_renderfill(SDL_Renderer * renderer, const SDL_Rect * rect) 723 photon_renderfill(SDL_Renderer * renderer, const SDL_Rect * rect)
350 { 724 {
725 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
726
727 switch (rdata->surfaces_type)
728 {
729 case SDL_PHOTON_SURFTYPE_OFFSCREEN:
730 PgDrawIRectCx(rdata->osurfaces[rdata->surface_render_idx], rect->x, rect->y, rect->w+rect->x-1, rect->h+rect->y-1, Pg_DRAW_FILL);
731 break;
732 case SDL_PHOTON_SURFTYPE_PHIMAGE:
733 PgDrawIRectCx(rdata->pcontexts[rdata->surface_render_idx], rect->x, rect->y, rect->w+rect->x-1, rect->h+rect->y-1, Pg_DRAW_FILL);
734 break;
735 case SDL_PHOTON_SURFTYPE_UNKNOWN:
736 break;
737 }
351 } 738 }
352 739
353 static int 740 static int
354 photon_rendercopy(SDL_Renderer * renderer, SDL_Texture * texture, 741 photon_rendercopy(SDL_Renderer * renderer, SDL_Texture * texture,
355 const SDL_Rect * srcrect, const SDL_Rect * dstrect) 742 const SDL_Rect * srcrect, const SDL_Rect * dstrect)
357 } 744 }
358 745
359 static void 746 static void
360 photon_renderpresent(SDL_Renderer * renderer) 747 photon_renderpresent(SDL_Renderer * renderer)
361 { 748 {
749 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
750 SDL_Window *window = window=SDL_GetWindowFromID(renderer->window);
751 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
752 PhRect_t src_rect;
753 PhPoint_t src_point;
754
755 /* Flush all undrawn graphics data to surface */
756 switch (rdata->surfaces_type)
757 {
758 case SDL_PHOTON_SURFTYPE_OFFSCREEN:
759 PgFlushCx(rdata->osurfaces[rdata->surface_render_idx]);
760 PgWaitHWIdle();
761 break;
762 case SDL_PHOTON_SURFTYPE_PHIMAGE:
763 PmMemFlush(rdata->pcontexts[rdata->surface_render_idx], rdata->psurfaces[rdata->surface_render_idx]);
764 break;
765 case SDL_PHOTON_SURFTYPE_UNKNOWN:
766 return;
767 }
768
769 PgFFlush(Ph_START_DRAW);
770 PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
771
772 /* Set blit area */
773 src_rect.ul.x = 0;
774 src_rect.ul.y = 0;
775 src_rect.lr.x = rdata->window_width - 1;
776 src_rect.lr.y = rdata->window_height - 1;
777
778 src_point.x = 0;
779 src_point.y = 0;
780
781 switch (rdata->surfaces_type)
782 {
783 case SDL_PHOTON_SURFTYPE_OFFSCREEN:
784 PgContextBlit(rdata->osurfaces[rdata->surface_render_idx], &src_rect, NULL, &src_rect);
785 break;
786 case SDL_PHOTON_SURFTYPE_PHIMAGE:
787 PgDrawPhImagev(&src_point, rdata->psurfaces[rdata->surface_render_idx], 0);
788 break;
789 case SDL_PHOTON_SURFTYPE_UNKNOWN:
790 break;
791 }
792
793 /* finish blit */
794 PgFFlush(Ph_DONE_DRAW);
795 PgWaitHWIdle();
362 } 796 }
363 797
364 static void 798 static void
365 photon_destroytexture(SDL_Renderer * renderer, SDL_Texture * texture) 799 photon_destroytexture(SDL_Renderer * renderer, SDL_Texture * texture)
366 { 800 {
368 802
369 static void 803 static void
370 photon_destroyrenderer(SDL_Renderer * renderer) 804 photon_destroyrenderer(SDL_Renderer * renderer)
371 { 805 {
372 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; 806 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
807 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
808 SDL_WindowData *wdata = (SDL_WindowData *)window->driverdata;
373 uint32_t it; 809 uint32_t it;
374 810
811 /* Destroy graphics context */
812 if (rdata->gc!=NULL)
813 {
814 PgDestroyGC(rdata->gc);
815 rdata->gc=NULL;
816 }
817
818 switch (rdata->surfaces_type)
819 {
820 case SDL_PHOTON_SURFTYPE_OFFSCREEN:
821 {
822 /* Destroy current surfaces */
823 for (it=0; it<SDL_PHOTON_MAX_SURFACES; it++)
824 {
825 if (rdata->osurfaces[it] != NULL)
826 {
827 PhDCRelease(rdata->osurfaces[it]);
828 rdata->osurfaces[it] = NULL;
829 }
830 }
831 }
832 break;
833 case SDL_PHOTON_SURFTYPE_PHIMAGE:
834 {
835 /* Destroy current surfaces */
836 for (it=0; it<SDL_PHOTON_MAX_SURFACES; it++)
837 {
838 if (rdata->pcontexts[it]!=NULL)
839 {
840 PmMemReleaseMC(rdata->pcontexts[it]);
841 rdata->pcontexts[it]=NULL;
842 }
843 if (rdata->psurfaces[it]!=NULL)
844 {
845 if (rdata->psurfaces[it]->palette!=NULL)
846 {
847 SDL_free(rdata->psurfaces[it]->palette);
848 rdata->psurfaces[it]->palette=NULL;
849 }
850 /* Destroy shared memory for PhImage_t */
851 PgShmemDestroy(rdata->psurfaces[it]->image);
852 rdata->psurfaces[it]->image=NULL;
853 SDL_free(rdata->psurfaces[it]);
854 rdata->psurfaces[it]=NULL;
855 }
856 }
857 }
858 break;
859 case SDL_PHOTON_SURFTYPE_UNKNOWN:
860 {
861 /* nothing to do */
862 }
863 break;
864 }
375 } 865 }
376 866
377 /* vi: set ts=4 sw=4 expandtab: */ 867 /* vi: set ts=4 sw=4 expandtab: */