Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11render.c @ 3538:a1896642a47e
X11 driver compiles again, lines are not yet implemented
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 10 Dec 2009 09:27:23 +0000 |
parents | 83518f8fcd61 |
children | c2154674c0c1 |
comparison
equal
deleted
inserted
replaced
3537:e897a4a9f578 | 3538:a1896642a47e |
---|---|
46 static int X11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 46 static int X11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
47 const SDL_Rect * rect, int markDirty, | 47 const SDL_Rect * rect, int markDirty, |
48 void **pixels, int *pitch); | 48 void **pixels, int *pitch); |
49 static void X11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); | 49 static void X11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
50 static int X11_SetDrawBlendMode(SDL_Renderer * renderer); | 50 static int X11_SetDrawBlendMode(SDL_Renderer * renderer); |
51 static int X11_RenderPoint(SDL_Renderer * renderer, int x, int y); | 51 static int X11_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, |
52 static int X11_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, | 52 int count); |
53 int y2); | 53 static int X11_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, |
54 static int X11_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); | 54 int count); |
55 static int X11_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, | |
56 int count); | |
55 static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | 57 static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
56 const SDL_Rect * srcrect, const SDL_Rect * dstrect); | 58 const SDL_Rect * srcrect, const SDL_Rect * dstrect); |
57 static void X11_RenderPresent(SDL_Renderer * renderer); | 59 static void X11_RenderPresent(SDL_Renderer * renderer); |
58 static void X11_DestroyTexture(SDL_Renderer * renderer, | 60 static void X11_DestroyTexture(SDL_Renderer * renderer, |
59 SDL_Texture * texture); | 61 SDL_Texture * texture); |
198 renderer->SetTextureScaleMode = X11_SetTextureScaleMode; | 200 renderer->SetTextureScaleMode = X11_SetTextureScaleMode; |
199 renderer->UpdateTexture = X11_UpdateTexture; | 201 renderer->UpdateTexture = X11_UpdateTexture; |
200 renderer->LockTexture = X11_LockTexture; | 202 renderer->LockTexture = X11_LockTexture; |
201 renderer->UnlockTexture = X11_UnlockTexture; | 203 renderer->UnlockTexture = X11_UnlockTexture; |
202 renderer->SetDrawBlendMode = X11_SetDrawBlendMode; | 204 renderer->SetDrawBlendMode = X11_SetDrawBlendMode; |
203 renderer->RenderPoint = X11_RenderPoint; | 205 renderer->RenderPoints = X11_RenderPoints; |
204 renderer->RenderLine = X11_RenderLine; | 206 renderer->RenderLines = X11_RenderLines; |
205 renderer->RenderFill = X11_RenderFill; | 207 renderer->RenderRects = X11_RenderRects; |
206 renderer->RenderCopy = X11_RenderCopy; | 208 renderer->RenderCopy = X11_RenderCopy; |
207 renderer->RenderPresent = X11_RenderPresent; | 209 renderer->RenderPresent = X11_RenderPresent; |
208 renderer->DestroyTexture = X11_DestroyTexture; | 210 renderer->DestroyTexture = X11_DestroyTexture; |
209 renderer->DestroyRenderer = X11_DestroyRenderer; | 211 renderer->DestroyRenderer = X11_DestroyRenderer; |
210 renderer->info = X11_RenderDriver.info; | 212 renderer->info = X11_RenderDriver.info; |
588 else | 590 else |
589 return SDL_MapRGBA(&data->format, r, g, b, a); | 591 return SDL_MapRGBA(&data->format, r, g, b, a); |
590 } | 592 } |
591 | 593 |
592 static int | 594 static int |
593 X11_RenderPoint(SDL_Renderer * renderer, int x, int y) | 595 X11_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count) |
594 { | 596 { |
595 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; | 597 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; |
598 SDL_Window *window = SDL_GetWindowFromID(renderer->window); | |
596 unsigned long foreground; | 599 unsigned long foreground; |
600 XPoint *xpoints, *xpoint; | |
601 int i, xcount; | |
597 | 602 |
598 if (data->makedirty) { | 603 if (data->makedirty) { |
599 SDL_Rect rect; | 604 SDL_Rect rect; |
600 | 605 |
601 rect.x = x; | 606 /* Get the smallest rectangle that contains everything */ |
602 rect.y = y; | 607 rect.x = 0; |
603 rect.w = 1; | 608 rect.y = 0; |
604 rect.h = 1; | 609 rect.w = window->w; |
610 rect.h = window->h; | |
611 if (!SDL_EnclosePoints(points, count, &rect, &rect)) { | |
612 /* Nothing to draw */ | |
613 return 0; | |
614 } | |
605 SDL_AddDirtyRect(&data->dirty, &rect); | 615 SDL_AddDirtyRect(&data->dirty, &rect); |
606 } | 616 } |
607 | 617 |
608 foreground = renderdrawcolor(renderer, 1); | 618 foreground = renderdrawcolor(renderer, 1); |
609 XSetForeground(data->display, data->gc, foreground); | 619 XSetForeground(data->display, data->gc, foreground); |
610 XDrawPoint(data->display, data->drawable, data->gc, x, y); | 620 |
621 xpoint = xpoints = SDL_stack_alloc(XPoint, count); | |
622 xcount = 0; | |
623 for (i = 0; i < count; ++i) { | |
624 int x = points[i].x; | |
625 int y = points[i].y; | |
626 if (x < 0 || x >= window->w || y < 0 || y >= window->h) { | |
627 continue; | |
628 } | |
629 xpoint->x = (short)x; | |
630 xpoint->y = (short)y; | |
631 ++xpoint; | |
632 ++xcount; | |
633 } | |
634 if (xcount > 0) { | |
635 XDrawPoints(data->display, data->drawable, data->gc, xpoints, xcount, | |
636 CoordModeOrigin); | |
637 } | |
638 SDL_stack_free(xpoints); | |
639 | |
611 return 0; | 640 return 0; |
612 } | 641 } |
613 | 642 |
614 static int | 643 static int |
615 X11_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) | 644 X11_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count) |
616 { | 645 { |
617 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; | 646 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; |
647 SDL_Window *window = SDL_GetWindowFromID(renderer->window); | |
648 SDL_Rect clip, rect; | |
618 unsigned long foreground; | 649 unsigned long foreground; |
619 | 650 |
651 clip.x = 0; | |
652 clip.y = 0; | |
653 clip.w = window->w; | |
654 clip.h = window->h; | |
655 | |
620 if (data->makedirty) { | 656 if (data->makedirty) { |
621 SDL_Rect rect; | 657 /* Get the smallest rectangle that contains everything */ |
622 | 658 SDL_EnclosePoints(points, count, NULL, &rect); |
623 if (x1 < x2) { | 659 if (!SDL_IntersectRect(&rect, &clip, &rect)) { |
624 rect.x = x1; | 660 /* Nothing to draw */ |
625 rect.w = (x2 - x1) + 1; | 661 return 0; |
626 } else { | |
627 rect.x = x2; | |
628 rect.w = (x1 - x2) + 1; | |
629 } | |
630 if (y1 < y2) { | |
631 rect.y = y1; | |
632 rect.h = (y2 - y1) + 1; | |
633 } else { | |
634 rect.y = y2; | |
635 rect.h = (y1 - y2) + 1; | |
636 } | 662 } |
637 SDL_AddDirtyRect(&data->dirty, &rect); | 663 SDL_AddDirtyRect(&data->dirty, &rect); |
638 } | 664 } |
639 | 665 |
640 foreground = renderdrawcolor(renderer, 1); | 666 foreground = renderdrawcolor(renderer, 1); |
641 XSetForeground(data->display, data->gc, foreground); | 667 XSetForeground(data->display, data->gc, foreground); |
642 XDrawLine(data->display, data->drawable, data->gc, x1, y1, x2, y2); | 668 /* FIXME: Can we properly handle lines that extend beyond visible space? */ |
669 //XDrawLine(data->display, data->drawable, data->gc, x1, y1, x2, y2); | |
643 return 0; | 670 return 0; |
644 } | 671 } |
645 | 672 |
646 static int | 673 static int |
647 X11_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) | 674 X11_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) |
648 { | 675 { |
649 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; | 676 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; |
677 SDL_Window *window = SDL_GetWindowFromID(renderer->window); | |
678 SDL_Rect clip, rect; | |
650 unsigned long foreground; | 679 unsigned long foreground; |
651 | 680 XRectangle *xrects, *xrect; |
652 if (data->makedirty) { | 681 int i, xcount; |
653 SDL_AddDirtyRect(&data->dirty, rect); | 682 |
654 } | 683 clip.x = 0; |
684 clip.y = 0; | |
685 clip.w = window->w; | |
686 clip.h = window->h; | |
655 | 687 |
656 foreground = renderdrawcolor(renderer, 1); | 688 foreground = renderdrawcolor(renderer, 1); |
657 XSetForeground(data->display, data->gc, foreground); | 689 XSetForeground(data->display, data->gc, foreground); |
658 XFillRectangle(data->display, data->drawable, data->gc, rect->x, rect->y, | 690 |
659 rect->w, rect->h); | 691 xrect = xrects = SDL_stack_alloc(XRectangle, count); |
692 xcount = 0; | |
693 for (i = 0; i < count; ++i) { | |
694 if (!SDL_IntersectRect(rects[i], &clip, &rect)) { | |
695 continue; | |
696 } | |
697 | |
698 xrect->x = (short)rect.x; | |
699 xrect->y = (short)rect.y; | |
700 xrect->width = (unsigned short)rect.w; | |
701 xrect->height = (unsigned short)rect.h; | |
702 ++xrect; | |
703 ++xcount; | |
704 | |
705 if (data->makedirty) { | |
706 SDL_AddDirtyRect(&data->dirty, &rect); | |
707 } | |
708 } | |
709 if (xcount > 0) { | |
710 XFillRectangles(data->display, data->drawable, data->gc, | |
711 xrects, xcount); | |
712 } | |
713 SDL_stack_free(xpoints); | |
714 | |
660 return 0; | 715 return 0; |
661 } | 716 } |
662 | 717 |
663 static int | 718 static int |
664 X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | 719 X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |