src/video/photon/SDL_ph_image.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 29 May 2006 04:04:35 +0000
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
permissions -rw-r--r--
more tweaking indent options
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@0
    23
slouken@0
    24
#include <Ph.h>
slouken@0
    25
#include <photon/Pg.h>
slouken@0
    26
slouken@0
    27
#include "SDL_endian.h"
slouken@571
    28
#include "SDL_video.h"
slouken@1361
    29
#include "../SDL_pixels_c.h"
slouken@910
    30
#include "SDL_ph_video.h"
slouken@0
    31
#include "SDL_ph_image_c.h"
slouken@663
    32
#include "SDL_ph_modes_c.h"
slouken@910
    33
#include "SDL_ph_gl.h"
slouken@315
    34
slouken@1662
    35
int
slouken@1668
    36
ph_SetupImage(_THIS, SDL_Surface * screen)
slouken@0
    37
{
slouken@1662
    38
    PgColor_t *palette = NULL;
slouken@1662
    39
    int type = 0;
slouken@380
    40
    int bpp;
slouken@1662
    41
slouken@1662
    42
    bpp = screen->format->BitsPerPixel;
slouken@0
    43
slouken@291
    44
    /* Determine image type */
slouken@1662
    45
    switch (bpp) {
slouken@1662
    46
    case 8:
slouken@1662
    47
        {
slouken@291
    48
            type = Pg_IMAGE_PALETTE_BYTE;
slouken@291
    49
        }
slouken@291
    50
        break;
slouken@1662
    51
    case 15:
slouken@1662
    52
        {
slouken@1662
    53
            type = Pg_IMAGE_DIRECT_555;
slouken@291
    54
        }
slouken@291
    55
        break;
slouken@1662
    56
    case 16:
slouken@1662
    57
        {
slouken@1662
    58
            type = Pg_IMAGE_DIRECT_565;
slouken@291
    59
        }
slouken@291
    60
        break;
slouken@1662
    61
    case 24:
slouken@1662
    62
        {
slouken@291
    63
            type = Pg_IMAGE_DIRECT_888;
slouken@291
    64
        }
slouken@291
    65
        break;
slouken@1662
    66
    case 32:
slouken@1662
    67
        {
slouken@291
    68
            type = Pg_IMAGE_DIRECT_8888;
slouken@291
    69
        }
slouken@291
    70
        break;
slouken@1662
    71
    default:
slouken@1662
    72
        {
slouken@1668
    73
            SDL_SetError("ph_SetupImage(): unsupported bpp=%d !\n", bpp);
slouken@291
    74
            return -1;
slouken@291
    75
        }
slouken@291
    76
        break;
slouken@291
    77
    }
slouken@0
    78
slouken@315
    79
    /* palette emulation code */
slouken@1662
    80
    if ((bpp == 8) && (desktoppal == SDLPH_PAL_EMULATE)) {
slouken@315
    81
        /* creating image palette */
slouken@1668
    82
        palette = SDL_malloc(_Pg_MAX_PALETTE * sizeof(PgColor_t));
slouken@1662
    83
        if (palette == NULL) {
slouken@1662
    84
            SDL_SetError
slouken@1662
    85
                ("ph_SetupImage(): can't allocate memory for palette !\n");
slouken@663
    86
            return -1;
slouken@663
    87
        }
slouken@1668
    88
        PgGetPalette(palette);
slouken@315
    89
slouken@315
    90
        /* using shared memory for speed (set last param to 1) */
slouken@1662
    91
        if ((SDL_Image =
slouken@1668
    92
             PhCreateImage(NULL, screen->w, screen->h, type, palette,
slouken@1668
    93
                           _Pg_MAX_PALETTE, 1)) == NULL) {
slouken@1662
    94
            SDL_SetError
slouken@1662
    95
                ("ph_SetupImage(): PhCreateImage() failed for bpp=8 !\n");
slouken@1668
    96
            SDL_free(palette);
slouken@315
    97
            return -1;
slouken@315
    98
        }
slouken@1662
    99
    } else {
slouken@315
   100
        /* using shared memory for speed (set last param to 1) */
slouken@1662
   101
        if ((SDL_Image =
slouken@1668
   102
             PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0,
slouken@1668
   103
                           1)) == NULL) {
slouken@1662
   104
            SDL_SetError
slouken@1662
   105
                ("ph_SetupImage(): PhCreateImage() failed for bpp=%d !\n",
slouken@1662
   106
                 bpp);
slouken@315
   107
            return -1;
slouken@315
   108
        }
slouken@291
   109
    }
slouken@571
   110
slouken@291
   111
    screen->pixels = SDL_Image->image;
slouken@663
   112
    screen->pitch = SDL_Image->bpl;
slouken@571
   113
slouken@291
   114
    this->UpdateRects = ph_NormalUpdate;
slouken@0
   115
slouken@291
   116
    return 0;
slouken@0
   117
}
slouken@0
   118
slouken@1662
   119
int
slouken@1668
   120
ph_SetupOCImage(_THIS, SDL_Surface * screen)
slouken@0
   121
{
slouken@370
   122
    int type = 0;
slouken@380
   123
    int bpp;
slouken@571
   124
slouken@571
   125
    OCImage.flags = screen->flags;
slouken@1662
   126
slouken@1662
   127
    bpp = screen->format->BitsPerPixel;
slouken@0
   128
slouken@370
   129
    /* Determine image type */
slouken@1662
   130
    switch (bpp) {
slouken@1662
   131
    case 8:
slouken@1662
   132
        {
slouken@1662
   133
            type = Pg_IMAGE_PALETTE_BYTE;
slouken@1662
   134
        }
slouken@1662
   135
        break;
slouken@1662
   136
    case 15:
slouken@1662
   137
        {
slouken@1662
   138
            type = Pg_IMAGE_DIRECT_555;
slouken@1662
   139
        }
slouken@1662
   140
        break;
slouken@1662
   141
    case 16:
slouken@1662
   142
        {
slouken@1662
   143
            type = Pg_IMAGE_DIRECT_565;
slouken@1662
   144
        }
slouken@1662
   145
        break;
slouken@1662
   146
    case 24:
slouken@1662
   147
        {
slouken@1662
   148
            type = Pg_IMAGE_DIRECT_888;
slouken@1662
   149
        }
slouken@1662
   150
        break;
slouken@1662
   151
    case 32:
slouken@1662
   152
        {
slouken@1662
   153
            type = Pg_IMAGE_DIRECT_8888;
slouken@1662
   154
        }
slouken@1662
   155
        break;
slouken@1662
   156
    default:
slouken@1662
   157
        {
slouken@1668
   158
            SDL_SetError("ph_SetupOCImage(): unsupported bpp=%d !\n", bpp);
slouken@1662
   159
            return -1;
slouken@1662
   160
        }
slouken@1662
   161
        break;
slouken@370
   162
    }
slouken@0
   163
slouken@886
   164
    /* Currently offscreen contexts with the same bit depth as display bpp only can be created */
slouken@1662
   165
    OCImage.offscreen_context =
slouken@1668
   166
        PdCreateOffscreenContext(0, screen->w, screen->h,
slouken@1668
   167
                                 Pg_OSC_MEM_PAGE_ALIGN);
slouken@0
   168
slouken@1662
   169
    if (OCImage.offscreen_context == NULL) {
slouken@1662
   170
        SDL_SetError
slouken@1662
   171
            ("ph_SetupOCImage(): PdCreateOffscreenContext() function failed !\n");
slouken@370
   172
        return -1;
slouken@370
   173
    }
slouken@0
   174
slouken@663
   175
    screen->pitch = OCImage.offscreen_context->pitch;
slouken@663
   176
slouken@1662
   177
    OCImage.dc_ptr =
slouken@1668
   178
        (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context);
slouken@663
   179
slouken@1662
   180
    if (OCImage.dc_ptr == NULL) {
slouken@1662
   181
        SDL_SetError
slouken@1662
   182
            ("ph_SetupOCImage(): PdGetOffscreenContextPtr function failed !\n");
slouken@1668
   183
        PhDCRelease(OCImage.offscreen_context);
slouken@370
   184
        return -1;
slouken@370
   185
    }
slouken@0
   186
slouken@663
   187
    OCImage.FrameData0 = OCImage.dc_ptr;
slouken@370
   188
    OCImage.CurrentFrameData = OCImage.FrameData0;
slouken@370
   189
    OCImage.current = 0;
slouken@370
   190
slouken@1668
   191
    PhDCSetCurrent(OCImage.offscreen_context);
slouken@370
   192
slouken@571
   193
    screen->pixels = OCImage.CurrentFrameData;
slouken@370
   194
slouken@370
   195
    this->UpdateRects = ph_OCUpdate;
slouken@370
   196
slouken@370
   197
    return 0;
slouken@0
   198
}
slouken@0
   199
slouken@1662
   200
int
slouken@1668
   201
ph_SetupFullScreenImage(_THIS, SDL_Surface * screen)
slouken@571
   202
{
slouken@571
   203
    OCImage.flags = screen->flags;
slouken@571
   204
slouken@910
   205
    /* Begin direct and fullscreen mode */
slouken@1668
   206
    if (!ph_EnterFullScreen(this, screen, PH_ENTER_DIRECTMODE)) {
slouken@571
   207
        return -1;
slouken@571
   208
    }
slouken@571
   209
slouken@663
   210
    /* store palette for fullscreen */
slouken@1662
   211
    if ((screen->format->BitsPerPixel == 8) && (desktopbpp != 8)) {
slouken@1668
   212
        PgGetPalette(savedpal);
slouken@1668
   213
        PgGetPalette(syspalph);
slouken@663
   214
    }
slouken@571
   215
slouken@1662
   216
    OCImage.offscreen_context =
slouken@1668
   217
        PdCreateOffscreenContext(0, 0, 0,
slouken@1668
   218
                                 Pg_OSC_MAIN_DISPLAY | Pg_OSC_MEM_PAGE_ALIGN
slouken@1668
   219
                                 | Pg_OSC_CRTC_SAFE);
slouken@1662
   220
    if (OCImage.offscreen_context == NULL) {
slouken@1662
   221
        SDL_SetError
slouken@1662
   222
            ("ph_SetupFullScreenImage(): PdCreateOffscreenContext() function failed !\n");
slouken@663
   223
        return -1;
slouken@663
   224
    }
slouken@1662
   225
slouken@1662
   226
    if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
slouken@1662
   227
        OCImage.offscreen_backcontext =
slouken@1668
   228
            PdDupOffscreenContext(OCImage.offscreen_context,
slouken@1668
   229
                                  Pg_OSC_MEM_PAGE_ALIGN | Pg_OSC_CRTC_SAFE);
slouken@1662
   230
        if (OCImage.offscreen_backcontext == NULL) {
slouken@1662
   231
            SDL_SetError
slouken@1662
   232
                ("ph_SetupFullScreenImage(): PdCreateOffscreenContext(back) function failed !\n");
slouken@663
   233
            return -1;
slouken@571
   234
        }
slouken@571
   235
    }
slouken@571
   236
slouken@1662
   237
    OCImage.FrameData0 =
slouken@1668
   238
        (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context);
slouken@1662
   239
    if (OCImage.FrameData0 == NULL) {
slouken@1662
   240
        SDL_SetError
slouken@1662
   241
            ("ph_SetupFullScreenImage(): PdGetOffscreenContextPtr() function failed !\n");
slouken@1668
   242
        ph_DestroyImage(this, screen);
slouken@571
   243
        return -1;
slouken@571
   244
    }
slouken@571
   245
slouken@1662
   246
    if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
slouken@1662
   247
        OCImage.FrameData1 =
slouken@1668
   248
            (unsigned char *) PdGetOffscreenContextPtr(OCImage.
slouken@1668
   249
                                                       offscreen_backcontext);
slouken@1662
   250
        if (OCImage.FrameData1 == NULL) {
slouken@1662
   251
            SDL_SetError
slouken@1662
   252
                ("ph_SetupFullScreenImage(back): PdGetOffscreenContextPtr() function failed !\n");
slouken@1668
   253
            ph_DestroyImage(this, screen);
slouken@663
   254
            return -1;
slouken@663
   255
        }
slouken@663
   256
    }
slouken@663
   257
slouken@663
   258
    /* wait for the hardware */
slouken@1668
   259
    PgFlush();
slouken@1668
   260
    PgWaitHWIdle();
slouken@571
   261
slouken@1662
   262
    if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
slouken@821
   263
        OCImage.current = 0;
slouken@1668
   264
        PhDCSetCurrent(OCImage.offscreen_context);
slouken@663
   265
        screen->pitch = OCImage.offscreen_context->pitch;
slouken@663
   266
        screen->pixels = OCImage.FrameData0;
slouken@821
   267
slouken@821
   268
        /* emulate 640x400 videomode */
slouken@1662
   269
        if (videomode_emulatemode == 1) {
slouken@1662
   270
            int i;
slouken@1662
   271
slouken@1662
   272
            for (i = 0; i < 40; i++) {
slouken@1668
   273
                SDL_memset(screen->pixels + screen->pitch * i, 0x00,
slouken@1668
   274
                           screen->pitch);
slouken@1662
   275
            }
slouken@1662
   276
            for (i = 440; i < 480; i++) {
slouken@1668
   277
                SDL_memset(screen->pixels + screen->pitch * i, 0x00,
slouken@1668
   278
                           screen->pitch);
slouken@1662
   279
            }
slouken@1662
   280
            screen->pixels += screen->pitch * 40;
slouken@1662
   281
        }
slouken@1668
   282
        PgSwapDisplay(OCImage.offscreen_backcontext, 0);
slouken@1662
   283
    } else {
slouken@1662
   284
        OCImage.current = 0;
slouken@1668
   285
        PhDCSetCurrent(OCImage.offscreen_context);
slouken@1662
   286
        screen->pitch = OCImage.offscreen_context->pitch;
slouken@1662
   287
        screen->pixels = OCImage.FrameData0;
slouken@1662
   288
slouken@1662
   289
        /* emulate 640x400 videomode */
slouken@1662
   290
        if (videomode_emulatemode == 1) {
slouken@1662
   291
            int i;
slouken@1662
   292
slouken@1662
   293
            for (i = 0; i < 40; i++) {
slouken@1668
   294
                SDL_memset(screen->pixels + screen->pitch * i, 0x00,
slouken@1668
   295
                           screen->pitch);
slouken@1662
   296
            }
slouken@1662
   297
            for (i = 440; i < 480; i++) {
slouken@1668
   298
                SDL_memset(screen->pixels + screen->pitch * i, 0x00,
slouken@1668
   299
                           screen->pitch);
slouken@1662
   300
            }
slouken@1662
   301
            screen->pixels += screen->pitch * 40;
slouken@821
   302
        }
slouken@663
   303
    }
slouken@571
   304
slouken@663
   305
    this->UpdateRects = ph_OCDCUpdate;
slouken@571
   306
slouken@821
   307
    /* wait for the hardware */
slouken@1668
   308
    PgFlush();
slouken@1668
   309
    PgWaitHWIdle();
slouken@692
   310
slouken@571
   311
    return 0;
slouken@571
   312
}
slouken@571
   313
slouken@1361
   314
#if SDL_VIDEO_OPENGL
slouken@701
   315
slouken@1662
   316
int
slouken@1668
   317
ph_SetupOpenGLImage(_THIS, SDL_Surface * screen)
slouken@701
   318
{
slouken@910
   319
    this->UpdateRects = ph_OpenGLUpdate;
slouken@1662
   320
    screen->pixels = NULL;
slouken@1662
   321
    screen->pitch = NULL;
slouken@701
   322
slouken@1662
   323
#if (_NTO_VERSION >= 630)
slouken@1662
   324
    if ((screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
slouken@1668
   325
        if (!ph_EnterFullScreen(this, screen, PH_IGNORE_DIRECTMODE)) {
slouken@1662
   326
            screen->flags &= ~SDL_FULLSCREEN;
slouken@1662
   327
            return -1;
slouken@910
   328
        }
slouken@1662
   329
    }
slouken@1662
   330
#endif /* 6.3.0 */
slouken@910
   331
slouken@1662
   332
    if (ph_SetupOpenGLContext
slouken@1662
   333
        (this, screen->w, screen->h, screen->format->BitsPerPixel,
slouken@1662
   334
         screen->flags) != 0) {
slouken@1658
   335
        screen->flags &= ~SDL_INTERNALOPENGL;
slouken@910
   336
        return -1;
slouken@910
   337
    }
slouken@1662
   338
slouken@910
   339
    return 0;
slouken@701
   340
}
slouken@701
   341
slouken@1361
   342
#endif /* SDL_VIDEO_OPENGL */
slouken@701
   343
slouken@1662
   344
void
slouken@1668
   345
ph_DestroyImage(_THIS, SDL_Surface * screen)
slouken@701
   346
{
slouken@701
   347
slouken@1361
   348
#if SDL_VIDEO_OPENGL
slouken@1662
   349
    if (screen->flags & SDL_INTERNALOPENGL) {
slouken@1662
   350
        if (oglctx) {
slouken@1662
   351
#if (_NTO_VERSION < 630)
slouken@1668
   352
            PhDCSetCurrent(NULL);
slouken@1668
   353
            PhDCRelease(oglctx);
slouken@1662
   354
#else
slouken@1668
   355
            qnxgl_context_destroy(oglctx);
slouken@1668
   356
            qnxgl_buffers_destroy(oglbuffers);
slouken@1668
   357
            qnxgl_finish();
slouken@1662
   358
#endif /* 6.3.0 */
slouken@1662
   359
            oglctx = NULL;
slouken@1662
   360
            oglbuffers = NULL;
slouken@1662
   361
            oglflags = 0;
slouken@1662
   362
            oglbpp = 0;
slouken@701
   363
        }
slouken@1662
   364
#if (_NTO_VERSION >= 630)
slouken@1662
   365
        if (currently_fullscreen) {
slouken@1668
   366
            ph_LeaveFullScreen(this);
slouken@1662
   367
        }
slouken@1662
   368
#endif /* 6.3.0 */
slouken@910
   369
slouken@701
   370
        return;
slouken@701
   371
    }
slouken@1361
   372
#endif /* SDL_VIDEO_OPENGL */
slouken@701
   373
slouken@1662
   374
    if (currently_fullscreen) {
slouken@663
   375
        /* if we right now in 8bpp fullscreen we must release palette */
slouken@1662
   376
        if ((screen->format->BitsPerPixel == 8) && (desktopbpp != 8)) {
slouken@1668
   377
            PgSetPalette(syspalph, 0, -1, 0, 0, 0);
slouken@1668
   378
            PgSetPalette(savedpal, 0, 0, _Pg_MAX_PALETTE,
slouken@1668
   379
                         Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0);
slouken@1668
   380
            PgFlush();
slouken@663
   381
        }
slouken@1668
   382
        ph_LeaveFullScreen(this);
slouken@663
   383
    }
slouken@663
   384
slouken@1662
   385
    if (OCImage.offscreen_context != NULL) {
slouken@1668
   386
        PhDCRelease(OCImage.offscreen_context);
slouken@291
   387
        OCImage.offscreen_context = NULL;
slouken@291
   388
        OCImage.FrameData0 = NULL;
slouken@663
   389
    }
slouken@1662
   390
    if (OCImage.offscreen_backcontext != NULL) {
slouken@1668
   391
        PhDCRelease(OCImage.offscreen_backcontext);
slouken@663
   392
        OCImage.offscreen_backcontext = NULL;
slouken@291
   393
        OCImage.FrameData1 = NULL;
slouken@291
   394
    }
slouken@663
   395
    OCImage.CurrentFrameData = NULL;
slouken@0
   396
slouken@1662
   397
    if (SDL_Image) {
slouken@315
   398
        /* if palette allocated, free it */
slouken@1662
   399
        if (SDL_Image->palette) {
slouken@1668
   400
            SDL_free(SDL_Image->palette);
slouken@315
   401
        }
slouken@1668
   402
        PgShmemDestroy(SDL_Image->image);
slouken@1668
   403
        SDL_free(SDL_Image);
slouken@291
   404
    }
slouken@0
   405
slouken@315
   406
    /* Must be zeroed everytime */
slouken@315
   407
    SDL_Image = NULL;
slouken@315
   408
slouken@1662
   409
    if (screen) {
slouken@291
   410
        screen->pixels = NULL;
slouken@291
   411
    }
slouken@0
   412
}
slouken@0
   413
slouken@1662
   414
int
slouken@1668
   415
ph_UpdateHWInfo(_THIS)
slouken@821
   416
{
slouken@821
   417
    PgVideoModeInfo_t vmode;
slouken@821
   418
    PgHWCaps_t hwcaps;
slouken@821
   419
slouken@821
   420
    /* Update video ram amount */
slouken@1668
   421
    if (PgGetGraphicsHWCaps(&hwcaps) < 0) {
slouken@1662
   422
        SDL_SetError
slouken@1662
   423
            ("ph_UpdateHWInfo(): GetGraphicsHWCaps() function failed !\n");
slouken@821
   424
        return -1;
slouken@821
   425
    }
slouken@1662
   426
    this->info.video_mem = hwcaps.currently_available_video_ram / 1024;
slouken@821
   427
slouken@821
   428
    /* obtain current mode capabilities */
slouken@1668
   429
    if (PgGetVideoModeInfo(hwcaps.current_video_mode, &vmode) < 0) {
slouken@1662
   430
        SDL_SetError
slouken@1662
   431
            ("ph_UpdateHWInfo(): GetVideoModeInfo() function failed !\n");
slouken@821
   432
        return -1;
slouken@821
   433
    }
slouken@821
   434
slouken@1662
   435
    if ((vmode.mode_capabilities1 & PgVM_MODE_CAP1_OFFSCREEN) ==
slouken@1662
   436
        PgVM_MODE_CAP1_OFFSCREEN) {
slouken@886
   437
        /* this is a special test for drivers which tries to lie about offscreen capability */
slouken@1662
   438
        if (hwcaps.currently_available_video_ram != 0) {
slouken@1662
   439
            this->info.hw_available = 1;
slouken@1662
   440
        } else {
slouken@1662
   441
            this->info.hw_available = 0;
slouken@886
   442
        }
slouken@1662
   443
    } else {
slouken@886
   444
        this->info.hw_available = 0;
slouken@886
   445
    }
slouken@886
   446
slouken@1662
   447
    if ((vmode.mode_capabilities2 & PgVM_MODE_CAP2_RECTANGLE) ==
slouken@1662
   448
        PgVM_MODE_CAP2_RECTANGLE) {
slouken@886
   449
        this->info.blit_fill = 1;
slouken@1662
   450
    } else {
slouken@886
   451
        this->info.blit_fill = 0;
slouken@886
   452
    }
slouken@886
   453
slouken@1662
   454
    if ((vmode.mode_capabilities2 & PgVM_MODE_CAP2_BITBLT) ==
slouken@1662
   455
        PgVM_MODE_CAP2_BITBLT) {
slouken@886
   456
        this->info.blit_hw = 1;
slouken@1662
   457
    } else {
slouken@886
   458
        this->info.blit_hw = 0;
slouken@886
   459
    }
slouken@821
   460
slouken@1662
   461
    if ((vmode.mode_capabilities2 & PgVM_MODE_CAP2_ALPHA_BLEND) ==
slouken@1662
   462
        PgVM_MODE_CAP2_ALPHA_BLEND) {
slouken@886
   463
        this->info.blit_hw_A = 1;
slouken@1662
   464
    } else {
slouken@886
   465
        this->info.blit_hw_A = 0;
slouken@821
   466
    }
slouken@1662
   467
slouken@1662
   468
    if ((vmode.mode_capabilities2 & PgVM_MODE_CAP2_CHROMA) ==
slouken@1662
   469
        PgVM_MODE_CAP2_CHROMA) {
slouken@886
   470
        this->info.blit_hw_CC = 1;
slouken@1662
   471
    } else {
slouken@886
   472
        this->info.blit_hw_CC = 0;
slouken@821
   473
    }
slouken@1662
   474
slouken@821
   475
    return 0;
slouken@821
   476
}
slouken@821
   477
slouken@1662
   478
int
slouken@1668
   479
ph_SetupUpdateFunction(_THIS, SDL_Surface * screen, Uint32 flags)
slouken@0
   480
{
slouken@1662
   481
    int setupresult = -1;
slouken@821
   482
slouken@1668
   483
    ph_DestroyImage(this, screen);
slouken@1662
   484
slouken@1361
   485
#if SDL_VIDEO_OPENGL
slouken@1662
   486
    if (flags & SDL_INTERNALOPENGL) {
slouken@1668
   487
        setupresult = ph_SetupOpenGLImage(this, screen);
slouken@1662
   488
    } else {
slouken@1361
   489
#endif
slouken@1662
   490
        if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
slouken@1668
   491
            setupresult = ph_SetupFullScreenImage(this, screen);
slouken@1662
   492
        } else {
slouken@1662
   493
            if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
slouken@1668
   494
                setupresult = ph_SetupOCImage(this, screen);
slouken@1662
   495
            } else {
slouken@1668
   496
                setupresult = ph_SetupImage(this, screen);
slouken@1662
   497
            }
slouken@1662
   498
        }
slouken@1361
   499
#if SDL_VIDEO_OPENGL
slouken@701
   500
    }
slouken@1361
   501
#endif
slouken@1662
   502
    if (setupresult != -1) {
slouken@1668
   503
        ph_UpdateHWInfo(this);
slouken@571
   504
    }
slouken@1662
   505
slouken@821
   506
    return setupresult;
slouken@0
   507
}
slouken@663
   508
slouken@1662
   509
int
slouken@1668
   510
ph_AllocHWSurface(_THIS, SDL_Surface * surface)
slouken@0
   511
{
slouken@821
   512
    PgHWCaps_t hwcaps;
slouken@821
   513
slouken@1662
   514
    if (surface->hwdata != NULL) {
slouken@1668
   515
        SDL_SetError("ph_AllocHWSurface(): hwdata already exists!\n");
slouken@821
   516
        return -1;
slouken@821
   517
    }
slouken@1668
   518
    surface->hwdata = SDL_malloc(sizeof(struct private_hwdata));
slouken@1668
   519
    SDL_memset(surface->hwdata, 0x00, sizeof(struct private_hwdata));
slouken@1662
   520
    surface->hwdata->offscreenctx =
slouken@1668
   521
        PdCreateOffscreenContext(0, surface->w, surface->h,
slouken@1668
   522
                                 Pg_OSC_MEM_PAGE_ALIGN);
slouken@1662
   523
    if (surface->hwdata->offscreenctx == NULL) {
slouken@1662
   524
        SDL_SetError
slouken@1662
   525
            ("ph_AllocHWSurface(): PdCreateOffscreenContext() function failed !\n");
slouken@821
   526
        return -1;
slouken@821
   527
    }
slouken@1668
   528
    surface->pixels = PdGetOffscreenContextPtr(surface->hwdata->offscreenctx);
slouken@1662
   529
    if (surface->pixels == NULL) {
slouken@1668
   530
        PhDCRelease(surface->hwdata->offscreenctx);
slouken@1662
   531
        SDL_SetError
slouken@1662
   532
            ("ph_AllocHWSurface(): PdGetOffscreenContextPtr() function failed !\n");
slouken@1662
   533
        return -1;
slouken@1662
   534
    }
slouken@1662
   535
    surface->pitch = surface->hwdata->offscreenctx->pitch;
slouken@1662
   536
    surface->flags |= SDL_HWSURFACE;
slouken@1662
   537
    surface->flags |= SDL_PREALLOC;
slouken@1662
   538
slouken@1662
   539
#if 0                           /* FIXME */
slouken@821
   540
    /* create simple offscreen lock */
slouken@1662
   541
    surface->hwdata->crlockparam.flags = 0;
slouken@1662
   542
    if (PdCreateOffscreenLock
slouken@1662
   543
        (surface->hwdata->offscreenctx, &surface->hwdata->crlockparam) != EOK)
slouken@821
   544
    {
slouken@1668
   545
        PhDCRelease(surface->hwdata->offscreenctx);
slouken@1668
   546
        SDL_SetError("ph_AllocHWSurface(): Can't create offscreen lock !\n");
slouken@821
   547
        return -1;
slouken@821
   548
    }
slouken@821
   549
#endif /* 0 */
slouken@821
   550
slouken@821
   551
    /* Update video ram amount */
slouken@1668
   552
    if (PgGetGraphicsHWCaps(&hwcaps) < 0) {
slouken@1668
   553
        PdDestroyOffscreenLock(surface->hwdata->offscreenctx);
slouken@1668
   554
        PhDCRelease(surface->hwdata->offscreenctx);
slouken@1662
   555
        SDL_SetError
slouken@1662
   556
            ("ph_AllocHWSurface(): GetGraphicsHWCaps() function failed !\n");
slouken@821
   557
        return -1;
slouken@821
   558
    }
slouken@1662
   559
    this->info.video_mem = hwcaps.currently_available_video_ram / 1024;
slouken@821
   560
slouken@821
   561
    return 0;
slouken@0
   562
}
slouken@0
   563
slouken@1662
   564
void
slouken@1668
   565
ph_FreeHWSurface(_THIS, SDL_Surface * surface)
slouken@0
   566
{
slouken@821
   567
    PgHWCaps_t hwcaps;
slouken@821
   568
slouken@1662
   569
    if (surface->hwdata == NULL) {
slouken@1668
   570
        SDL_SetError("ph_FreeHWSurface(): no hwdata!\n");
slouken@1662
   571
        return;
slouken@821
   572
    }
slouken@1662
   573
    if (surface->hwdata->offscreenctx == NULL) {
slouken@1668
   574
        SDL_SetError("ph_FreeHWSurface(): no offscreen context to delete!\n");
slouken@1662
   575
        return;
slouken@1662
   576
    }
slouken@1662
   577
#if 0                           /* FIXME */
slouken@1662
   578
    /* unlock the offscreen context if it has been locked before destroy it */
slouken@1668
   579
    if (PdIsOffscreenLocked(surface->hwdata->offscreenctx) == Pg_OSC_LOCKED) {
slouken@1668
   580
        PdUnlockOffscreen(surface->hwdata->offscreenctx);
slouken@821
   581
    }
slouken@821
   582
slouken@1668
   583
    PdDestroyOffscreenLock(surface->hwdata->offscreenctx);
slouken@821
   584
#endif /* 0 */
slouken@821
   585
slouken@1668
   586
    PhDCRelease(surface->hwdata->offscreenctx);
slouken@1662
   587
slouken@1668
   588
    SDL_free(surface->hwdata);
slouken@1662
   589
    surface->hwdata = NULL;
slouken@821
   590
slouken@821
   591
    /* Update video ram amount */
slouken@1668
   592
    if (PgGetGraphicsHWCaps(&hwcaps) < 0) {
slouken@1662
   593
        SDL_SetError
slouken@1662
   594
            ("ph_FreeHWSurface(): GetGraphicsHWCaps() function failed !\n");
slouken@821
   595
        return;
slouken@821
   596
    }
slouken@1662
   597
    this->info.video_mem = hwcaps.currently_available_video_ram / 1024;
slouken@821
   598
slouken@315
   599
    return;
slouken@0
   600
}
slouken@0
   601
slouken@1662
   602
int
slouken@1668
   603
ph_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst)
slouken@821
   604
{
slouken@1662
   605
    if ((src->hwdata == NULL) && (src != this->screen)) {
slouken@1662
   606
        SDL_SetError
slouken@1662
   607
            ("ph_CheckHWBlit(): Source surface haven't hardware specific data.\n");
slouken@1662
   608
        src->flags &= ~SDL_HWACCEL;
slouken@1662
   609
        return -1;
slouken@1662
   610
    }
slouken@1662
   611
    if ((src->flags & SDL_HWSURFACE) != SDL_HWSURFACE) {
slouken@1662
   612
        SDL_SetError
slouken@1662
   613
            ("ph_CheckHWBlit(): Source surface isn't a hardware surface.\n");
slouken@1662
   614
        src->flags &= ~SDL_HWACCEL;
slouken@1662
   615
        return -1;
slouken@1662
   616
    }
slouken@821
   617
slouken@1662
   618
    if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
slouken@1662
   619
        if (this->info.blit_hw_CC != 1) {
slouken@1662
   620
            src->flags &= ~SDL_HWACCEL;
slouken@1662
   621
            src->map->hw_blit = NULL;
slouken@1662
   622
            return -1;
slouken@1662
   623
        }
slouken@1662
   624
    }
slouken@821
   625
slouken@1662
   626
    if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
slouken@1662
   627
        if (this->info.blit_hw_A != 1) {
slouken@1662
   628
            src->flags &= ~SDL_HWACCEL;
slouken@1662
   629
            src->map->hw_blit = NULL;
slouken@1662
   630
            return -1;
slouken@1662
   631
        }
slouken@1662
   632
    }
slouken@821
   633
slouken@1662
   634
    src->flags |= SDL_HWACCEL;
slouken@1662
   635
    src->map->hw_blit = ph_HWAccelBlit;
slouken@821
   636
slouken@1662
   637
    return 1;
slouken@821
   638
}
slouken@821
   639
slouken@1662
   640
PgColor_t
slouken@1668
   641
ph_ExpandColor(_THIS, SDL_Surface * surface, Uint32 color)
slouken@821
   642
{
slouken@821
   643
    Uint32 truecolor;
slouken@821
   644
slouken@821
   645
    /* Photon API accepts true colors only during hw filling operations */
slouken@1662
   646
    switch (surface->format->BitsPerPixel) {
slouken@1662
   647
    case 8:
slouken@1662
   648
        {
slouken@1662
   649
            if ((surface->format->palette)
slouken@1662
   650
                && (color <= surface->format->palette->ncolors)) {
slouken@1662
   651
                truecolor =
slouken@1668
   652
                    PgRGB(surface->format->palette->colors[color].r,
slouken@1668
   653
                          surface->format->palette->colors[color].g,
slouken@1668
   654
                          surface->format->palette->colors[color].b);
slouken@1662
   655
            } else {
slouken@1662
   656
                SDL_SetError
slouken@1662
   657
                    ("ph_ExpandColor(): Color out of range for the 8bpp mode !\n");
slouken@821
   658
                return 0xFFFFFFFFUL;
slouken@821
   659
            }
slouken@1662
   660
        }
slouken@1662
   661
        break;
slouken@1662
   662
    case 15:
slouken@1662
   663
        {
slouken@1662
   664
            truecolor = ((color & 0x00007C00UL) << 9) | /* R */
slouken@1662
   665
                ((color & 0x000003E0UL) << 6) | /* G */
slouken@1662
   666
                ((color & 0x0000001FUL) << 3) | /* B */
slouken@1662
   667
                ((color & 0x00007000UL) << 4) | /* R compensation */
slouken@1662
   668
                ((color & 0x00000380UL) << 1) | /* G compensation */
slouken@1662
   669
                ((color & 0x0000001CUL) >> 2);  /* B compensation */
slouken@1662
   670
        }
slouken@1662
   671
        break;
slouken@1662
   672
    case 16:
slouken@1662
   673
        {
slouken@1662
   674
            truecolor = ((color & 0x0000F800UL) << 8) | /* R */
slouken@1662
   675
                ((color & 0x000007E0UL) << 5) | /* G */
slouken@1662
   676
                ((color & 0x0000001FUL) << 3) | /* B */
slouken@1662
   677
                ((color & 0x0000E000UL) << 3) | /* R compensation */
slouken@1662
   678
                ((color & 0x00000600UL) >> 1) | /* G compensation */
slouken@1662
   679
                ((color & 0x0000001CUL) >> 2);  /* B compensation */
slouken@1662
   680
slouken@1662
   681
        }
slouken@1662
   682
        break;
slouken@1662
   683
    case 24:
slouken@1662
   684
        {
slouken@1662
   685
            truecolor = color & 0x00FFFFFFUL;
slouken@1662
   686
        }
slouken@1662
   687
        break;
slouken@1662
   688
    case 32:
slouken@1662
   689
        {
slouken@1662
   690
            truecolor = color;
slouken@1662
   691
        }
slouken@1662
   692
        break;
slouken@1662
   693
    default:
slouken@1662
   694
        {
slouken@1662
   695
            SDL_SetError
slouken@1662
   696
                ("ph_ExpandColor(): Unsupported depth for the hardware operations !\n");
slouken@1662
   697
            return 0xFFFFFFFFUL;
slouken@1662
   698
        }
slouken@821
   699
    }
slouken@821
   700
slouken@821
   701
    return truecolor;
slouken@821
   702
}
slouken@821
   703
slouken@1662
   704
int
slouken@1668
   705
ph_FillHWRect(_THIS, SDL_Surface * surface, SDL_Rect * rect, Uint32 color)
slouken@821
   706
{
slouken@821
   707
    PgColor_t oldcolor;
slouken@821
   708
    Uint32 truecolor;
slouken@1662
   709
    int ydisp = 0;
slouken@821
   710
slouken@1662
   711
    if (this->info.blit_fill != 1) {
slouken@821
   712
        return -1;
slouken@821
   713
    }
slouken@821
   714
slouken@1668
   715
    truecolor = ph_ExpandColor(this, surface, color);
slouken@1662
   716
    if (truecolor == 0xFFFFFFFFUL) {
slouken@1662
   717
        return -1;
slouken@1662
   718
    }
slouken@1662
   719
slouken@1668
   720
    oldcolor = PgSetFillColor(truecolor);
slouken@821
   721
slouken@821
   722
    /* 640x400 videomode emulation */
slouken@1662
   723
    if (videomode_emulatemode == 1) {
slouken@1662
   724
        ydisp += 40;
slouken@821
   725
    }
slouken@821
   726
slouken@1668
   727
    PgDrawIRect(rect->x, rect->y + ydisp, rect->w + rect->x - 1,
slouken@1668
   728
                rect->h + rect->y + ydisp - 1, Pg_DRAW_FILL);
slouken@1668
   729
    PgSetFillColor(oldcolor);
slouken@1668
   730
    PgFlush();
slouken@1668
   731
    PgWaitHWIdle();
slouken@821
   732
slouken@821
   733
    return 0;
slouken@821
   734
}
slouken@821
   735
slouken@1662
   736
int
slouken@1668
   737
ph_FlipHWSurface(_THIS, SDL_Surface * screen)
slouken@0
   738
{
slouken@821
   739
    PhArea_t farea;
slouken@821
   740
slouken@1662
   741
    if ((screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
slouken@821
   742
        /* flush all drawing ops before blitting */
slouken@1668
   743
        PgFlush();
slouken@1668
   744
        PgWaitHWIdle();
slouken@821
   745
slouken@1662
   746
        farea.pos.x = 0;
slouken@1662
   747
        farea.pos.y = 0;
slouken@1662
   748
        farea.size.w = screen->w;
slouken@1662
   749
        farea.size.h = screen->h;
slouken@821
   750
slouken@821
   751
        /* emulate 640x400 videomode */
slouken@1662
   752
        if (videomode_emulatemode == 1) {
slouken@1662
   753
            farea.pos.y += 40;
slouken@663
   754
        }
slouken@821
   755
slouken@1668
   756
        PgContextBlitArea(OCImage.offscreen_context, &farea,
slouken@1668
   757
                          OCImage.offscreen_backcontext, &farea);
slouken@821
   758
slouken@821
   759
        /* flush the blitting */
slouken@1668
   760
        PgFlush();
slouken@1668
   761
        PgWaitHWIdle();
slouken@663
   762
    }
slouken@663
   763
    return 0;
slouken@0
   764
}
slouken@0
   765
slouken@1662
   766
int
slouken@1668
   767
ph_LockHWSurface(_THIS, SDL_Surface * surface)
slouken@0
   768
{
slouken@821
   769
slouken@1662
   770
#if 0                           /* FIXME */
slouken@821
   771
    int lockresult;
slouken@821
   772
slouken@1662
   773
    if (surface->hwdata == NULL) {
slouken@821
   774
        return;
slouken@821
   775
    }
slouken@821
   776
slouken@1662
   777
    surface->hwdata->lockparam.flags = 0;
slouken@1662
   778
    surface->hwdata->lockparam.time_out = NULL;
slouken@1662
   779
    lockresult =
slouken@1668
   780
        PdLockOffscreen(surface->hwdata->offscreenctx,
slouken@1668
   781
                        &surface->hwdata->lockparam);
slouken@821
   782
slouken@1662
   783
    switch (lockresult) {
slouken@1662
   784
    case EOK:
slouken@1662
   785
        break;
slouken@1662
   786
    case Pg_OSC_LOCK_DEADLOCK:
slouken@1668
   787
        SDL_SetError("ph_LockHWSurface(): Deadlock detected !\n");
slouken@1662
   788
        return -1;
slouken@1662
   789
    case Pg_OSC_LOCK_INVALID:
slouken@1668
   790
        SDL_SetError("ph_LockHWSurface(): Lock invalid !\n");
slouken@1662
   791
        return -1;
slouken@1662
   792
    default:
slouken@1668
   793
        SDL_SetError("ph_LockHWSurface(): Can't lock the surface !\n");
slouken@1662
   794
        return -1;
slouken@821
   795
    }
slouken@821
   796
#endif /* 0 */
slouken@821
   797
slouken@821
   798
    return 0;
slouken@0
   799
}
slouken@0
   800
slouken@1662
   801
void
slouken@1668
   802
ph_UnlockHWSurface(_THIS, SDL_Surface * surface)
slouken@0
   803
{
slouken@821
   804
slouken@1662
   805
#if 0                           /* FIXME */
slouken@821
   806
    int unlockresult;
slouken@821
   807
slouken@1662
   808
    if ((surface == NULL) || (surface->hwdata == NULL)) {
slouken@821
   809
        return;
slouken@821
   810
    }
slouken@821
   811
slouken@1668
   812
    if (PdIsOffscreenLocked(surface->hwdata->offscreenctx) == Pg_OSC_LOCKED) {
slouken@1668
   813
        unlockresult = PdUnlockOffscreen(surface->hwdata->offscreenctx);
slouken@821
   814
    }
slouken@821
   815
#endif /* 0 */
slouken@821
   816
slouken@315
   817
    return;
slouken@0
   818
}
slouken@0
   819
slouken@1662
   820
int
slouken@1668
   821
ph_HWAccelBlit(SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst,
slouken@1668
   822
               SDL_Rect * dstrect)
slouken@821
   823
{
slouken@1662
   824
    SDL_VideoDevice *this = current_video;
slouken@821
   825
    PhArea_t srcarea;
slouken@821
   826
    PhArea_t dstarea;
slouken@1662
   827
    int ydisp = 0;
slouken@821
   828
slouken@821
   829
    /* 640x400 videomode emulation */
slouken@1662
   830
    if (videomode_emulatemode == 1) {
slouken@1662
   831
        ydisp += 40;
slouken@821
   832
    }
slouken@821
   833
slouken@1662
   834
    srcarea.pos.x = srcrect->x;
slouken@1662
   835
    srcarea.pos.y = srcrect->y;
slouken@1662
   836
    srcarea.size.w = srcrect->w;
slouken@1662
   837
    srcarea.size.h = srcrect->h;
slouken@821
   838
slouken@1662
   839
    dstarea.pos.x = dstrect->x;
slouken@1662
   840
    dstarea.pos.y = dstrect->y;
slouken@1662
   841
    dstarea.size.w = dstrect->w;
slouken@1662
   842
    dstarea.size.h = dstrect->h;
slouken@821
   843
slouken@1662
   844
    if (((src == this->screen) || (src->hwdata != NULL))
slouken@1662
   845
        && ((dst == this->screen) || (dst->hwdata != NULL))) {
slouken@1662
   846
        if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
slouken@1668
   847
            ph_SetHWColorKey(this, src, src->format->colorkey);
slouken@1668
   848
            PgChromaOn();
slouken@821
   849
        }
slouken@821
   850
slouken@1662
   851
        if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
slouken@1668
   852
            ph_SetHWAlpha(this, src, src->format->alpha);
slouken@1668
   853
            PgAlphaOn();
slouken@886
   854
        }
slouken@886
   855
slouken@1662
   856
        if (dst == this->screen) {
slouken@1662
   857
            if (src == this->screen) {
slouken@821
   858
                /* blitting from main screen to main screen */
slouken@1662
   859
                dstarea.pos.y += ydisp;
slouken@1662
   860
                srcarea.pos.y += ydisp;
slouken@1668
   861
                PgContextBlitArea(OCImage.offscreen_context, &srcarea,
slouken@1668
   862
                                  OCImage.offscreen_context, &dstarea);
slouken@1662
   863
            } else {
slouken@1662
   864
                /* blitting from offscreen to main screen */
slouken@1662
   865
                dstarea.pos.y += ydisp;
slouken@1668
   866
                PgContextBlitArea(src->hwdata->offscreenctx, &srcarea,
slouken@1668
   867
                                  OCImage.offscreen_context, &dstarea);
slouken@821
   868
            }
slouken@1662
   869
        } else {
slouken@1662
   870
            if (src == this->screen) {
slouken@821
   871
                /* blitting from main screen to offscreen */
slouken@1662
   872
                srcarea.pos.y += ydisp;
slouken@1668
   873
                PgContextBlitArea(OCImage.offscreen_context, &srcarea,
slouken@1668
   874
                                  dst->hwdata->offscreenctx, &dstarea);
slouken@1662
   875
            } else {
slouken@821
   876
                /* blitting offscreen to offscreen */
slouken@1668
   877
                PgContextBlitArea(src->hwdata->offscreenctx, &srcarea,
slouken@1668
   878
                                  dst->hwdata->offscreenctx, &dstarea);
slouken@821
   879
            }
slouken@821
   880
        }
slouken@821
   881
slouken@1662
   882
        if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
slouken@1668
   883
            PgAlphaOff();
slouken@886
   884
        }
slouken@886
   885
slouken@1662
   886
        if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
slouken@1668
   887
            PgChromaOff();
slouken@821
   888
        }
slouken@1662
   889
    } else {
slouken@1662
   890
        SDL_SetError
slouken@1662
   891
            ("ph_HWAccelBlit(): Source or target surface is not a hardware surface !\n");
slouken@821
   892
        return -1;
slouken@821
   893
    }
slouken@821
   894
slouken@1668
   895
    PgFlush();
slouken@1668
   896
    PgWaitHWIdle();
slouken@821
   897
slouken@821
   898
    return 0;
slouken@821
   899
}
slouken@821
   900
slouken@1662
   901
int
slouken@1668
   902
ph_SetHWColorKey(_THIS, SDL_Surface * surface, Uint32 key)
slouken@821
   903
{
slouken@1662
   904
    if (this->info.blit_hw_CC != 1) {
slouken@1662
   905
        return -1;
slouken@886
   906
    }
slouken@886
   907
slouken@1662
   908
    if (surface->hwdata != NULL) {
slouken@1668
   909
        surface->hwdata->colorkey = ph_ExpandColor(this, surface, key);
slouken@1662
   910
        if (surface->hwdata->colorkey == 0xFFFFFFFFUL) {
slouken@821
   911
            return -1;
slouken@821
   912
        }
slouken@821
   913
    }
slouken@1668
   914
    PgSetChroma(surface->hwdata->colorkey,
slouken@1668
   915
                Pg_CHROMA_SRC_MATCH | Pg_CHROMA_NODRAW);
slouken@821
   916
slouken@821
   917
    return 0;
slouken@821
   918
}
slouken@821
   919
slouken@1662
   920
int
slouken@1668
   921
ph_SetHWAlpha(_THIS, SDL_Surface * surface, Uint8 alpha)
slouken@821
   922
{
slouken@1662
   923
    if (this->info.blit_hw_A != 1) {
slouken@1662
   924
        return -1;
slouken@886
   925
    }
slouken@886
   926
slouken@1668
   927
    PgSetAlphaBlend(NULL, alpha);
slouken@886
   928
slouken@886
   929
    return 0;
slouken@821
   930
}
slouken@821
   931
slouken@1361
   932
#if SDL_VIDEO_OPENGL
slouken@1662
   933
void
slouken@1668
   934
ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect * rects)
slouken@291
   935
{
slouken@1668
   936
    this->GL_SwapBuffers(this);
slouken@1662
   937
slouken@1662
   938
    return;
slouken@291
   939
}
slouken@1361
   940
#endif /* SDL_VIDEO_OPENGL */
slouken@291
   941
slouken@1662
   942
void
slouken@1668
   943
ph_NormalUpdate(_THIS, int numrects, SDL_Rect * rects)
slouken@0
   944
{
slouken@380
   945
    PhPoint_t ph_pos;
slouken@380
   946
    PhRect_t ph_rect;
slouken@380
   947
    int i;
slouken@380
   948
slouken@1662
   949
    for (i = 0; i < numrects; ++i) {
slouken@1662
   950
        if (rects[i].w == 0) {  /* Clipped? dunno why but this occurs sometime. */
slouken@315
   951
            continue;
slouken@0
   952
        }
slouken@0
   953
slouken@1662
   954
        if (rects[i].h == 0) {  /* Clipped? dunno why but this occurs sometime. */
slouken@663
   955
            continue;
slouken@663
   956
        }
slouken@663
   957
slouken@315
   958
        ph_pos.x = rects[i].x;
slouken@315
   959
        ph_pos.y = rects[i].y;
slouken@315
   960
        ph_rect.ul.x = rects[i].x;
slouken@315
   961
        ph_rect.ul.y = rects[i].y;
slouken@315
   962
        ph_rect.lr.x = rects[i].x + rects[i].w;
slouken@315
   963
        ph_rect.lr.y = rects[i].y + rects[i].h;
slouken@0
   964
slouken@1668
   965
        if (PgDrawPhImageRectmx(&ph_pos, SDL_Image, &ph_rect, 0) < 0) {
slouken@1668
   966
            SDL_SetError("ph_NormalUpdate(): PgDrawPhImageRectmx failed!\n");
slouken@821
   967
            return;
slouken@315
   968
        }
slouken@315
   969
    }
slouken@315
   970
slouken@1668
   971
    if (PgFlush() < 0) {
slouken@1668
   972
        SDL_SetError("ph_NormalUpdate(): PgFlush() function failed!\n");
slouken@0
   973
    }
slouken@0
   974
}
slouken@370
   975
slouken@1662
   976
void
slouken@1668
   977
ph_OCUpdate(_THIS, int numrects, SDL_Rect * rects)
slouken@0
   978
{
slouken@380
   979
    int i;
slouken@380
   980
slouken@1662
   981
    PhPoint_t zero = { 0, 0 };
slouken@370
   982
    PhArea_t src_rect;
slouken@370
   983
    PhArea_t dest_rect;
slouken@0
   984
slouken@1668
   985
    PgSetTranslation(&zero, 0);
slouken@1668
   986
    PgSetRegion(PtWidgetRid(window));
slouken@1668
   987
    PgSetClipping(0, NULL);
slouken@821
   988
slouken@1668
   989
    PgFlush();
slouken@1668
   990
    PgWaitHWIdle();
slouken@315
   991
slouken@1662
   992
    for (i = 0; i < numrects; ++i) {
slouken@1662
   993
        if (rects[i].w == 0) {  /* Clipped? */
slouken@315
   994
            continue;
slouken@0
   995
        }
slouken@0
   996
slouken@1662
   997
        if (rects[i].h == 0) {  /* Clipped? */
slouken@663
   998
            continue;
slouken@663
   999
        }
slouken@315
  1000
slouken@1662
  1001
        src_rect.pos.x = rects[i].x;
slouken@1662
  1002
        src_rect.pos.y = rects[i].y;
slouken@1662
  1003
        dest_rect.pos.x = rects[i].x;
slouken@1662
  1004
        dest_rect.pos.y = rects[i].y;
slouken@1662
  1005
slouken@1662
  1006
        src_rect.size.w = rects[i].w;
slouken@1662
  1007
        src_rect.size.h = rects[i].h;
slouken@1662
  1008
        dest_rect.size.w = rects[i].w;
slouken@1662
  1009
        dest_rect.size.h = rects[i].h;
slouken@1662
  1010
slouken@1668
  1011
        PgContextBlitArea(OCImage.offscreen_context, &src_rect, NULL,
slouken@1668
  1012
                          &dest_rect);
slouken@370
  1013
    }
slouken@315
  1014
slouken@1668
  1015
    if (PgFlush() < 0) {
slouken@1668
  1016
        SDL_SetError("ph_OCUpdate(): PgFlush failed.\n");
slouken@315
  1017
    }
slouken@0
  1018
}
slouken@663
  1019
slouken@1662
  1020
void
slouken@1668
  1021
ph_OCDCUpdate(_THIS, int numrects, SDL_Rect * rects)
slouken@663
  1022
{
slouken@1668
  1023
    PgWaitHWIdle();
slouken@663
  1024
slouken@1668
  1025
    if (PgFlush() < 0) {
slouken@1668
  1026
        SDL_SetError("ph_OCDCUpdate(): PgFlush failed.\n");
slouken@663
  1027
    }
slouken@663
  1028
}
slouken@1662
  1029
slouken@1662
  1030
/* vi: set ts=4 sw=4 expandtab: */