Commit b876226c authored by Sam Lantinga's avatar Sam Lantinga

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.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403388
parent 2b206b6e
...@@ -55,6 +55,9 @@ static int GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, ...@@ -55,6 +55,9 @@ static int GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, int markDirty, const SDL_Rect * rect, int markDirty,
void **pixels, int *pitch); void **pixels, int *pitch);
static void GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); static void GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int GDI_RenderPoint(SDL_Renderer * renderer, int x, int y);
static int GDI_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
int y2);
static int GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); static int GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
static int GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, static int GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect); const SDL_Rect * srcrect, const SDL_Rect * dstrect);
...@@ -72,7 +75,7 @@ SDL_RenderDriver GDI_RenderDriver = { ...@@ -72,7 +75,7 @@ SDL_RenderDriver GDI_RenderDriver = {
SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 | SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED), SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED),
(SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_ALPHA),
(SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND), (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK),
(SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST), (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST),
14, 14,
{ {
...@@ -172,6 +175,8 @@ GDI_CreateRenderer(SDL_Window * window, Uint32 flags) ...@@ -172,6 +175,8 @@ GDI_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->UpdateTexture = GDI_UpdateTexture; renderer->UpdateTexture = GDI_UpdateTexture;
renderer->LockTexture = GDI_LockTexture; renderer->LockTexture = GDI_LockTexture;
renderer->UnlockTexture = GDI_UnlockTexture; renderer->UnlockTexture = GDI_UnlockTexture;
renderer->RenderPoint = GDI_RenderPoint;
renderer->RenderLine = GDI_RenderLine;
renderer->RenderFill = GDI_RenderFill; renderer->RenderFill = GDI_RenderFill;
renderer->RenderCopy = GDI_RenderCopy; renderer->RenderCopy = GDI_RenderCopy;
renderer->RenderPresent = GDI_RenderPresent; renderer->RenderPresent = GDI_RenderPresent;
...@@ -568,6 +573,71 @@ GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) ...@@ -568,6 +573,71 @@ GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
} }
} }
static int
GDI_RenderPoint(SDL_Renderer * renderer, int x, int y)
{
GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
if (data->makedirty) {
SDL_Rect rect;
rect.x = x;
rect.y = y;
rect.w = 1;
rect.h = 1;
SDL_AddDirtyRect(&data->dirty, &rect);
}
SetPixel(data->current_hdc, x, y, RGB(renderer->r, renderer->g, renderer->b));
return 0;
}
static int
GDI_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
{
GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
POINT points[2];
HBRUSH brush;
BOOL status;
if (data->makedirty) {
SDL_Rect rect;
if (x1 < x2) {
rect.x = x1;
rect.w = (x2 - x1) + 1;
} else {
rect.x = x2;
rect.w = (x1 - x2) + 1;
}
if (y1 < y2) {
rect.y = y1;
rect.h = (y2 - y1) + 1;
} else {
rect.y = y2;
rect.h = (y1 - y2) + 1;
}
SDL_AddDirtyRect(&data->dirty, &rect);
}
/* Should we cache the brushes? .. it looks like GDI does for us. :) */
brush = CreateSolidBrush(RGB(renderer->r, renderer->g, renderer->b));
SelectObject(data->current_hdc, brush);
points[0].x = x1;
points[0].y = y1;
points[1].x = x2;
points[1].y = y2;
status = Polyline(data->current_hdc, points, 2);
DeleteObject(brush);
if (!status) {
WIN_SetError("FillRect()");
return -1;
}
return 0;
}
static int static int
GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
{ {
...@@ -614,14 +684,16 @@ GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, ...@@ -614,14 +684,16 @@ GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
SelectPalette(data->memory_hdc, texturedata->hpal, TRUE); SelectPalette(data->memory_hdc, texturedata->hpal, TRUE);
RealizePalette(data->memory_hdc); RealizePalette(data->memory_hdc);
} }
if (texture->blendMode & (SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND)) { if (texture->blendMode & SDL_BLENDMODE_MASK) {
BLENDFUNCTION blendFunc = { BLENDFUNCTION blendFunc = {
AC_SRC_OVER, AC_SRC_OVER,
0, 0,
texture->a, texture->a,
AC_SRC_ALPHA AC_SRC_ALPHA
}; };
/* FIXME: GDI uses premultiplied alpha! */ /* FIXME: GDI uses premultiplied alpha!
* Once we solve this and somehow support blended drawing we can enable SDL_BLENDMODE_BLEND
*/
if (!AlphaBlend if (!AlphaBlend
(data->current_hdc, dstrect->x, dstrect->y, dstrect->w, (data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
dstrect->h, data->memory_hdc, srcrect->x, srcrect->y, srcrect->w, dstrect->h, data->memory_hdc, srcrect->x, srcrect->y, srcrect->w,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment