src/video/directfb/SDL_DirectFB_shape.c
author Sam Lantinga
Fri, 27 Jan 2017 21:23:27 -0800
changeset 10861 71d8f9afb690
parent 10737 3406a0f8b041
child 11029 938d2ced5244
permissions -rw-r--r--
Fixed bug 3569 - GL_UpdateViewport leaves PROJECTION matrix selected

Tom Seddon

GL_ActivateRenderer may call GL_UpdateViewport, which leaves the GL_PROJECTION matrix selected. But after GL_ResetState, the GL_MODELVIEW matrix is selected, suggesting that's the intended default state.

It seems at least like these should be consistent. Presumably GL_UpdateViewport should be doing a glMatrixMode(GL_MODELVIEW) before it finishes.
slouken@5488
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
slouken@5488
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@5488
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@5488
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@5488
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@6044
    22
slouken@6044
    23
#if SDL_VIDEO_DRIVER_DIRECTFB
slouken@5488
    24
slouken@5488
    25
#include "SDL_assert.h"
slouken@5488
    26
#include "SDL_DirectFB_video.h"
slouken@5488
    27
#include "SDL_DirectFB_shape.h"
slouken@5488
    28
#include "SDL_DirectFB_window.h"
slouken@5488
    29
slouken@5488
    30
#include "../SDL_shape_internals.h"
slouken@5488
    31
slouken@5488
    32
SDL_Window*
slouken@5488
    33
DirectFB_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) {
gabomdq@7678
    34
    return SDL_CreateWindow(title,x,y,w,h,flags /* | SDL_DFB_WINDOW_SHAPED */);
slouken@5488
    35
}
slouken@5488
    36
slouken@5488
    37
SDL_WindowShaper*
slouken@5488
    38
DirectFB_CreateShaper(SDL_Window* window) {
slouken@5488
    39
    SDL_WindowShaper* result = NULL;
slouken@10613
    40
    SDL_ShapeData* data;
slouken@10613
    41
    int resized_properly;
slouken@5488
    42
slouken@5488
    43
    result = malloc(sizeof(SDL_WindowShaper));
slouken@5488
    44
    result->window = window;
slouken@5488
    45
    result->mode.mode = ShapeModeDefault;
slouken@5488
    46
    result->mode.parameters.binarizationCutoff = 1;
slouken@5488
    47
    result->userx = result->usery = 0;
slouken@10613
    48
    data = SDL_malloc(sizeof(SDL_ShapeData));
slouken@5488
    49
    result->driverdata = data;
slouken@5488
    50
    data->surface = NULL;
slouken@5488
    51
    window->shaper = result;
slouken@10613
    52
    resized_properly = DirectFB_ResizeWindowShape(window);
slouken@5488
    53
    SDL_assert(resized_properly == 0);
slouken@5488
    54
slouken@5488
    55
    return result;
slouken@5488
    56
}
slouken@5488
    57
slouken@5488
    58
int
slouken@5488
    59
DirectFB_ResizeWindowShape(SDL_Window* window) {
slouken@5488
    60
    SDL_ShapeData* data = window->shaper->driverdata;
slouken@5488
    61
    SDL_assert(data != NULL);
slouken@7191
    62
slouken@7191
    63
    if (window->x != -1000)
slouken@5488
    64
    {
slouken@7191
    65
        window->shaper->userx = window->x;
slouken@7191
    66
        window->shaper->usery = window->y;
slouken@5488
    67
    }
slouken@5488
    68
    SDL_SetWindowPosition(window,-1000,-1000);
slouken@7191
    69
slouken@5488
    70
    return 0;
slouken@5488
    71
}
slouken@7191
    72
slouken@5488
    73
int
slouken@5488
    74
DirectFB_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
slouken@7191
    75
slouken@5488
    76
    if(shaper == NULL || shape == NULL || shaper->driverdata == NULL)
slouken@5488
    77
        return -1;
slouken@5488
    78
    if(shape->format->Amask == 0 && SDL_SHAPEMODEALPHA(shape_mode->mode))
slouken@5488
    79
        return -2;
slouken@5488
    80
    if(shape->w != shaper->window->w || shape->h != shaper->window->h)
slouken@5488
    81
        return -3;
slouken@5488
    82
slouken@5488
    83
    {
slouken@5488
    84
        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(shaper->window);
slouken@5488
    85
        SDL_DFB_DEVICEDATA(display->device);
slouken@7191
    86
        Uint32 *pixels;
slouken@7191
    87
        Sint32 pitch;
slouken@7191
    88
        Uint32 h,w;
slouken@7191
    89
        Uint8  *src, *bitmap;
slouken@5488
    90
        DFBSurfaceDescription dsc;
slouken@5488
    91
slouken@5488
    92
        SDL_ShapeData *data = shaper->driverdata;
slouken@5488
    93
slouken@5488
    94
        SDL_DFB_RELEASE(data->surface);
slouken@5488
    95
slouken@5488
    96
        dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
slouken@5488
    97
        dsc.width = shape->w;
slouken@5488
    98
        dsc.height = shape->h;
slouken@5488
    99
        dsc.caps = DSCAPS_PREMULTIPLIED;
slouken@5488
   100
        dsc.pixelformat = DSPF_ARGB;
slouken@5488
   101
slouken@5488
   102
        SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc, &data->surface));
slouken@5488
   103
slouken@5488
   104
        /* Assume that shaper->alphacutoff already has a value, because SDL_SetWindowShape() should have given it one. */
slouken@5488
   105
        SDL_DFB_ALLOC_CLEAR(bitmap, shape->w * shape->h);
slouken@5488
   106
        SDL_CalculateShapeBitmap(shaper->mode,shape,bitmap,1);
slouken@5488
   107
slouken@7191
   108
        src = bitmap;
slouken@5488
   109
slouken@5488
   110
        SDL_DFB_CHECK(data->surface->Lock(data->surface, DSLF_WRITE | DSLF_READ, (void **) &pixels, &pitch));
slouken@5488
   111
slouken@7191
   112
        h = shaper->window->h;
slouken@7191
   113
        while (h--) {
slouken@7191
   114
            for (w = 0; w < shaper->window->w; w++) {
slouken@7191
   115
                if (*src)
slouken@7191
   116
                    pixels[w] = 0xFFFFFFFF;
slouken@7191
   117
                else
slouken@7191
   118
                    pixels[w] = 0;
slouken@7191
   119
                src++;
slouken@5488
   120
slouken@7191
   121
            }
slouken@7191
   122
            pixels += (pitch >> 2);
slouken@7191
   123
        }
slouken@5488
   124
        SDL_DFB_CHECK(data->surface->Unlock(data->surface));
slouken@7191
   125
        SDL_DFB_FREE(bitmap);
slouken@5488
   126
slouken@7191
   127
        /* FIXME: Need to call this here - Big ?? */
slouken@7191
   128
        DirectFB_WM_RedrawLayout(SDL_GetDisplayForWindow(shaper->window)->device, shaper->window);
slouken@5488
   129
    }
slouken@7191
   130
slouken@5488
   131
    return 0;
slouken@5488
   132
error:
slouken@7191
   133
    return -1;
slouken@5488
   134
}
slouken@5488
   135
slouken@6044
   136
#endif /* SDL_VIDEO_DRIVER_DIRECTFB */