comparison src/video/win32/SDL_gdirender.c @ 2926:27f2b5e7e899

In theory this implements GDI rendering, but it doesn't work for some reason. Also removed blending support from the advertised interface, since it's not actually supported.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 30 Dec 2008 04:38:39 +0000
parents 2f91a3847ae8
children 2133d2d300fd
comparison
equal deleted inserted replaced
2925:7e21f7662208 2926:27f2b5e7e899
53 int pitch); 53 int pitch);
54 static int GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, 54 static int GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
55 const SDL_Rect * rect, int markDirty, 55 const SDL_Rect * rect, int markDirty,
56 void **pixels, int *pitch); 56 void **pixels, int *pitch);
57 static void GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); 57 static void GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
58 static int GDI_RenderPoint(SDL_Renderer * renderer, int x, int y);
59 static int GDI_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
60 int y2);
58 static int GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); 61 static int GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
59 static int GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 62 static int GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
60 const SDL_Rect * srcrect, const SDL_Rect * dstrect); 63 const SDL_Rect * srcrect, const SDL_Rect * dstrect);
61 static void GDI_RenderPresent(SDL_Renderer * renderer); 64 static void GDI_RenderPresent(SDL_Renderer * renderer);
62 static void GDI_DestroyTexture(SDL_Renderer * renderer, 65 static void GDI_DestroyTexture(SDL_Renderer * renderer,
70 "gdi", 73 "gdi",
71 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY | 74 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
72 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 | 75 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
73 SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED), 76 SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED),
74 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_ALPHA), 77 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_ALPHA),
75 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND), 78 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK),
76 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST), 79 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST),
77 14, 80 14,
78 { 81 {
79 SDL_PIXELFORMAT_INDEX8, 82 SDL_PIXELFORMAT_INDEX8,
80 SDL_PIXELFORMAT_RGB555, 83 SDL_PIXELFORMAT_RGB555,
170 renderer->SetTextureBlendMode = GDI_SetTextureBlendMode; 173 renderer->SetTextureBlendMode = GDI_SetTextureBlendMode;
171 renderer->SetTextureScaleMode = GDI_SetTextureScaleMode; 174 renderer->SetTextureScaleMode = GDI_SetTextureScaleMode;
172 renderer->UpdateTexture = GDI_UpdateTexture; 175 renderer->UpdateTexture = GDI_UpdateTexture;
173 renderer->LockTexture = GDI_LockTexture; 176 renderer->LockTexture = GDI_LockTexture;
174 renderer->UnlockTexture = GDI_UnlockTexture; 177 renderer->UnlockTexture = GDI_UnlockTexture;
178 renderer->RenderPoint = GDI_RenderPoint;
179 renderer->RenderLine = GDI_RenderLine;
175 renderer->RenderFill = GDI_RenderFill; 180 renderer->RenderFill = GDI_RenderFill;
176 renderer->RenderCopy = GDI_RenderCopy; 181 renderer->RenderCopy = GDI_RenderCopy;
177 renderer->RenderPresent = GDI_RenderPresent; 182 renderer->RenderPresent = GDI_RenderPresent;
178 renderer->DestroyTexture = GDI_DestroyTexture; 183 renderer->DestroyTexture = GDI_DestroyTexture;
179 renderer->DestroyRenderer = GDI_DestroyRenderer; 184 renderer->DestroyRenderer = GDI_DestroyRenderer;
567 UpdateYUVTextureData(texture); 572 UpdateYUVTextureData(texture);
568 } 573 }
569 } 574 }
570 575
571 static int 576 static int
577 GDI_RenderPoint(SDL_Renderer * renderer, int x, int y)
578 {
579 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
580
581 if (data->makedirty) {
582 SDL_Rect rect;
583
584 rect.x = x;
585 rect.y = y;
586 rect.w = 1;
587 rect.h = 1;
588
589 SDL_AddDirtyRect(&data->dirty, &rect);
590 }
591
592 SetPixel(data->current_hdc, x, y, RGB(renderer->r, renderer->g, renderer->b));
593 return 0;
594 }
595
596 static int
597 GDI_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
598 {
599 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
600 POINT points[2];
601 HBRUSH brush;
602 BOOL status;
603
604 if (data->makedirty) {
605 SDL_Rect rect;
606
607 if (x1 < x2) {
608 rect.x = x1;
609 rect.w = (x2 - x1) + 1;
610 } else {
611 rect.x = x2;
612 rect.w = (x1 - x2) + 1;
613 }
614 if (y1 < y2) {
615 rect.y = y1;
616 rect.h = (y2 - y1) + 1;
617 } else {
618 rect.y = y2;
619 rect.h = (y1 - y2) + 1;
620 }
621 SDL_AddDirtyRect(&data->dirty, &rect);
622 }
623
624 /* Should we cache the brushes? .. it looks like GDI does for us. :) */
625 brush = CreateSolidBrush(RGB(renderer->r, renderer->g, renderer->b));
626 SelectObject(data->current_hdc, brush);
627 points[0].x = x1;
628 points[0].y = y1;
629 points[1].x = x2;
630 points[1].y = y2;
631 status = Polyline(data->current_hdc, points, 2);
632 DeleteObject(brush);
633
634 if (!status) {
635 WIN_SetError("FillRect()");
636 return -1;
637 }
638 return 0;
639 }
640
641 static int
572 GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) 642 GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
573 { 643 {
574 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata; 644 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
575 RECT rc; 645 RECT rc;
576 HBRUSH brush; 646 HBRUSH brush;
612 SelectObject(data->memory_hdc, texturedata->hbm); 682 SelectObject(data->memory_hdc, texturedata->hbm);
613 if (texturedata->hpal) { 683 if (texturedata->hpal) {
614 SelectPalette(data->memory_hdc, texturedata->hpal, TRUE); 684 SelectPalette(data->memory_hdc, texturedata->hpal, TRUE);
615 RealizePalette(data->memory_hdc); 685 RealizePalette(data->memory_hdc);
616 } 686 }
617 if (texture->blendMode & (SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND)) { 687 if (texture->blendMode & SDL_BLENDMODE_MASK) {
618 BLENDFUNCTION blendFunc = { 688 BLENDFUNCTION blendFunc = {
619 AC_SRC_OVER, 689 AC_SRC_OVER,
620 0, 690 0,
621 texture->a, 691 texture->a,
622 AC_SRC_ALPHA 692 AC_SRC_ALPHA
623 }; 693 };
624 /* FIXME: GDI uses premultiplied alpha! */ 694 /* FIXME: GDI uses premultiplied alpha!
695 * Once we solve this and somehow support blended drawing we can enable SDL_BLENDMODE_BLEND
696 */
625 if (!AlphaBlend 697 if (!AlphaBlend
626 (data->current_hdc, dstrect->x, dstrect->y, dstrect->w, 698 (data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
627 dstrect->h, data->memory_hdc, srcrect->x, srcrect->y, srcrect->w, 699 dstrect->h, data->memory_hdc, srcrect->x, srcrect->y, srcrect->w,
628 srcrect->h, blendFunc)) { 700 srcrect->h, blendFunc)) {
629 WIN_SetError("AlphaBlend()"); 701 WIN_SetError("AlphaBlend()");