src/video/directfb/SDL_DirectFB_shape.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 14 Jul 2013 11:28:44 -0700
changeset 7776 d4a39491577f
parent 7678 286c42d7c5ed
child 8093 b43765095a6f
permissions -rw-r--r--
Added the platform specific messagebox function to the video function list
slouken@5488
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6885
     3
  Copyright (C) 1997-2013 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
*/
slouken@6044
    21
#include "SDL_config.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@5488
    40
slouken@5488
    41
    result = malloc(sizeof(SDL_WindowShaper));
slouken@5488
    42
    result->window = window;
slouken@5488
    43
    result->mode.mode = ShapeModeDefault;
slouken@5488
    44
    result->mode.parameters.binarizationCutoff = 1;
slouken@5488
    45
    result->userx = result->usery = 0;
slouken@5488
    46
    SDL_ShapeData* data = SDL_malloc(sizeof(SDL_ShapeData));
slouken@5488
    47
    result->driverdata = data;
slouken@5488
    48
    data->surface = NULL;
slouken@5488
    49
    window->shaper = result;
slouken@5488
    50
    int resized_properly = DirectFB_ResizeWindowShape(window);
slouken@5488
    51
    SDL_assert(resized_properly == 0);
slouken@5488
    52
slouken@5488
    53
    return result;
slouken@5488
    54
}
slouken@5488
    55
slouken@5488
    56
int
slouken@5488
    57
DirectFB_ResizeWindowShape(SDL_Window* window) {
slouken@5488
    58
    SDL_ShapeData* data = window->shaper->driverdata;
slouken@5488
    59
    SDL_assert(data != NULL);
slouken@7191
    60
slouken@7191
    61
    if (window->x != -1000)
slouken@5488
    62
    {
slouken@7191
    63
        window->shaper->userx = window->x;
slouken@7191
    64
        window->shaper->usery = window->y;
slouken@5488
    65
    }
slouken@5488
    66
    SDL_SetWindowPosition(window,-1000,-1000);
slouken@7191
    67
slouken@5488
    68
    return 0;
slouken@5488
    69
}
slouken@7191
    70
slouken@5488
    71
int
slouken@5488
    72
DirectFB_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
slouken@7191
    73
slouken@5488
    74
    if(shaper == NULL || shape == NULL || shaper->driverdata == NULL)
slouken@5488
    75
        return -1;
slouken@5488
    76
    if(shape->format->Amask == 0 && SDL_SHAPEMODEALPHA(shape_mode->mode))
slouken@5488
    77
        return -2;
slouken@5488
    78
    if(shape->w != shaper->window->w || shape->h != shaper->window->h)
slouken@5488
    79
        return -3;
slouken@5488
    80
slouken@5488
    81
    {
slouken@5488
    82
        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(shaper->window);
slouken@5488
    83
        SDL_DFB_DEVICEDATA(display->device);
slouken@7191
    84
        Uint32 *pixels;
slouken@7191
    85
        Sint32 pitch;
slouken@7191
    86
        Uint32 h,w;
slouken@7191
    87
        Uint8  *src, *bitmap;
slouken@5488
    88
        DFBSurfaceDescription dsc;
slouken@5488
    89
slouken@5488
    90
        SDL_ShapeData *data = shaper->driverdata;
slouken@5488
    91
slouken@5488
    92
        SDL_DFB_RELEASE(data->surface);
slouken@5488
    93
slouken@5488
    94
        dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
slouken@5488
    95
        dsc.width = shape->w;
slouken@5488
    96
        dsc.height = shape->h;
slouken@5488
    97
        dsc.caps = DSCAPS_PREMULTIPLIED;
slouken@5488
    98
        dsc.pixelformat = DSPF_ARGB;
slouken@5488
    99
slouken@5488
   100
        SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc, &data->surface));
slouken@5488
   101
slouken@5488
   102
        /* Assume that shaper->alphacutoff already has a value, because SDL_SetWindowShape() should have given it one. */
slouken@5488
   103
        SDL_DFB_ALLOC_CLEAR(bitmap, shape->w * shape->h);
slouken@5488
   104
        SDL_CalculateShapeBitmap(shaper->mode,shape,bitmap,1);
slouken@5488
   105
slouken@7191
   106
        src = bitmap;
slouken@5488
   107
slouken@5488
   108
        SDL_DFB_CHECK(data->surface->Lock(data->surface, DSLF_WRITE | DSLF_READ, (void **) &pixels, &pitch));
slouken@5488
   109
slouken@7191
   110
        h = shaper->window->h;
slouken@7191
   111
        while (h--) {
slouken@7191
   112
            for (w = 0; w < shaper->window->w; w++) {
slouken@7191
   113
                if (*src)
slouken@7191
   114
                    pixels[w] = 0xFFFFFFFF;
slouken@7191
   115
                else
slouken@7191
   116
                    pixels[w] = 0;
slouken@7191
   117
                src++;
slouken@5488
   118
slouken@7191
   119
            }
slouken@7191
   120
            pixels += (pitch >> 2);
slouken@7191
   121
        }
slouken@5488
   122
        SDL_DFB_CHECK(data->surface->Unlock(data->surface));
slouken@7191
   123
        SDL_DFB_FREE(bitmap);
slouken@5488
   124
slouken@7191
   125
        /* FIXME: Need to call this here - Big ?? */
slouken@7191
   126
        DirectFB_WM_RedrawLayout(SDL_GetDisplayForWindow(shaper->window)->device, shaper->window);
slouken@5488
   127
    }
slouken@7191
   128
slouken@5488
   129
    return 0;
slouken@5488
   130
error:
slouken@7191
   131
    return -1;
slouken@5488
   132
}
slouken@5488
   133
slouken@6044
   134
#endif /* SDL_VIDEO_DRIVER_DIRECTFB */