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