Ticket #8987: sci.patch

File sci.patch, 78.8 KB (added by bluegr, 15 years ago)

SCI objectification WIP (new) - with wjp's suggestion

  • engine/kgraphics.cpp

     
    23502350                        UKPV(3), UKPV(2));
    23512351                // FIXME: Should really only invalidate all loaded pic resources here;
    23522352                // this is overkill
    2353                 gfxr_free_all_resources(s->gfx_state->driver, s->gfx_state->resstate);
     2353                gfxr_free_all_resources(s->gfx_state->resstate);
    23542354
    23552355                break;
    23562356        }
  • engine/scriptdebug.cpp

     
    20112011        gfxop_set_pointer_cursor(s->gfx_state, GFXOP_NO_POINTER);
    20122012        sciprintf("Flushing resources...\n");
    20132013        s->visual->widfree(GFXW(s->visual));
    2014         gfxr_free_all_resources(s->gfx_state->driver, s->gfx_state->resstate);
     2014        gfxr_free_all_resources(s->gfx_state->resstate);
    20152015        s->visual = NULL;
    20162016
    20172017        return 0;
  • gfx/gfx_driver.cpp

     
    9494        int i;
    9595        if (S) {
    9696                for (i = 0; i < 2; i++) {
    97                         gfx_free_pixmap(drv, S->priority[i]);
     97                        gfx_free_pixmap(S->priority[i]);
    9898                        S->priority[i] = NULL;
    9999                }
    100100
  • gfx/gfx_resmgr.h

     
    114114** The options are considered to be read-only, as they belong to the overlying state object.
    115115*/
    116116
    117 void gfxr_free_resource_manager(gfx_driver_t *driver, gfx_resstate_t *state);
     117void gfxr_free_resource_manager(gfx_resstate_t *state);
    118118/* Frees a previously allocated resource manager, and all allocated resources.
    119 ** Parameters: (gfx_driver_t *) driver: The graphics driver; used to free pixmaps that
    120 **                                      are installed in a driver-specific registry
    121 **             (gfx_resstate_t *) state: The state manager to free
     119** Parameters: (gfx_resstate_t *) state: The state manager to free
    122120** Return    : (void)
    123121*/
    124122
    125 void gfxr_free_all_resources(gfx_driver_t *driver, gfx_resstate_t *state);
     123void gfxr_free_all_resources(gfx_resstate_t *state);
    126124/* Frees all resources currently allocated
    127 ** Parameter: (gfx_driver_t *) driver: The driver to free with
    128 **            (gfx_resstate_t *) state: The state to do this on
     125** Parameter: (gfx_resstate_t *) state: The state to do this on
    129126** Returns  : (void)
    130127** This function is intended to be used primarily for debugging.
    131128*/
    132129
    133 void gfxr_tag_resources(gfx_resstate_t *state);
    134 /* 'Tags' all resources for deletion
    135 ** Paramters: (gfx_resstate_t *) state: The resource state to modify
    136 ** Returns  : (void)
    137 ** Tagged resources are untagged if they are referenced.
    138 */
    139 
    140 void gfxr_free_tagged_resources(gfx_driver_t *driver, gfx_resstate_t *state);
     130void gfxr_free_tagged_resources(gfx_resstate_t *state);
    141131/* Frees all tagged resources.
    142 ** Parameters: (gfx_driver_t *) driver: The graphics driver the pixmaps are potentially
    143 **                                      registered in
    144 **             (gfx_resstate_t *) state: The state to alter
     132** Parameters: (gfx_resstate_t *) state: The state to alter
    145133** Returns   : (void)
    146134** Resources are tagged by calling gfx_tag_resources(), and untagged by calling the
    147135** approprate dereferenciation function.
     
    150138*/
    151139
    152140
    153 gfxr_pic_t *gfxr_get_pic(gfx_resstate_t *state, int nr, int maps, int flags,
    154         int default_palette, int scaled);
    155 /* Retreives a displayable (translated) pic resource
    156 ** Parameters: (gfx_resstate_t *) state: The resource state
    157 **             (int) nr: Number of the pic resource
    158 **             (int) maps: The maps to translate (ORred GFX_MASK_*)
    159 **             (int) flags: Interpreter-dependant pic flags
    160 **             (int) default_palette: The default palette to use for drawing (if applicable)
    161 **             (int) scaled: Whether to return the scaled maps, or the unscaled
    162 **                           ones (which may be identical) for some special operations.
    163 ** Returns   : (gfx_pic_t *) The appropriate pic resource with all maps as index (but not
    164 **                           neccessarily translated) data.
    165 */
     141class GfxResManager {
     142public:
     143        GfxResManager(gfx_resstate_t *state) : _state(state) {}
     144        ~GfxResManager() {}
    166145
     146        /* 'Tags' all resources for deletion
     147        ** Paramters: (void)
     148        ** Returns  : (void)
     149        ** Tagged resources are untagged if they are referenced.
     150        */
     151        void tagResources() { (_state->tag_lock_counter)++; }
     152
     153        /* Retreives an SCI0/SCI01 mouse cursor
     154        ** Parameters: (int) num: The cursor number
     155        ** Returns   : (gfx_font_t *) The approprate cursor as a pixmap, or NULL on error
     156        */
     157        gfx_pixmap_t *getCursor(int num);
     158
     159
     160        /* Retreives the static palette from the interpreter-specific code
     161        ** Parameters: (int *) colors_nr: Number of colors to use
     162        **             (int) nr: The palette to read
     163        ** Returns   : (gfx_pixmap_color_t *) *colors_nr static color entries
     164        **             if a static palette must be used, NULL otherwise
     165        */
     166        Palette *getPalette(int *colors_nr, int num = 999);
     167
     168
     169        /* Retreives a font
     170        ** Parameters: (int) nr: The font number
     171        **             (int) scaled: Whether the font should be font-scaled
     172        ** Returns   : (gfx_font_t *) The appropriate font, or NULL on error
     173        */
     174        gfx_bitmap_font_t *getFont(int num, bool scaled = false);
     175
     176
     177        /* Retreives a displayable (translated) pic resource
     178        ** Parameters: (int) nr: Number of the pic resource
     179        **             (int) maps: The maps to translate (ORred GFX_MASK_*)
     180        **             (int) flags: Interpreter-dependant pic flags
     181        **             (int) default_palette: The default palette to use for drawing (if applicable)
     182        **             (bool) scaled: Whether to return the scaled maps, or the unscaled
     183        **                           ones (which may be identical) for some special operations.
     184        ** Returns   : (gfx_pic_t *) The appropriate pic resource with all maps as index (but not
     185        **                           neccessarily translated) data.
     186        */
     187        gfxr_pic_t *getPic(int num, int maps, int flags, int default_palette, bool scaled = false);
     188
     189
     190        /* Determines whether support for pointers with more than two colors is required
     191        ** Returns   : (bool) false if no support for multi-colored pointers is required, true
     192        **                   otherwise
     193        */
     194        bool multicoloredPointers() { return _state->version > SCI_VERSION_1; }
     195
     196private:
     197        gfx_resstate_t *_state;
     198};
     199
    167200gfxr_pic_t *gfxr_add_to_pic(gfx_resstate_t *state, int old_nr, int new_nr, int maps, int flags,
    168201        int old_default_palette, int default_palette, int scaled);
    169202/* Retreives a displayable (translated) pic resource written ontop of an existing pic
     
    195228** loop and cel numbers have to be interpreted as 'maximum' or 'minimum' by the interpreter)
    196229*/
    197230
    198 gfx_bitmap_font_t *gfxr_get_font(ResourceManager& resourceManager, gfx_resstate_t *state, int nr, int scaled);
    199 /* Retreives a font
    200 ** Parameters: (ResourceManager&) resourceManager: supplies the resource repository capability
    201 **                         (gfx_resstate_t *) state: The relevant resource state
    202 **             (int) nr: The font number
    203 **             (int) scaled: Whether the font should be font-scaled
    204 ** Returns   : (gfx_font_t *) The appropriate font, or NULL on error
    205 */
    206 
    207 gfx_pixmap_t *gfxr_get_cursor(gfx_resstate_t *state, int nr);
    208 /* Retreives an SCI0/SCI01 mouse cursor
    209 ** Parameters: (gfx_resstate_t *) state: The resource state
    210 **             (int) nr: The cursour number
    211 ** Returns   : (gfx_font_t *) The approprate cursor as a pixmap, or NULL on error
    212 */
    213 
    214 gfx_pixmap_color_t *gfxr_get_palette(gfx_resstate_t *state, int nr);
    215 /* Retreives a palette
    216 ** Parameters: (gfx_resstate_t *) state: The resource state
    217 **             (int) nr: The cursour number
    218 ** Returns   : (gfx_font_t *) The approprate cursor as a pixmap, or NULL on error
    219 */
    220 
    221 
    222231/* =========================== */
    223232/* Interpreter-dependant stuff */
    224233/* =========================== */
     
    241250** (Yes, this isn't really a "hash" in the traditional sense...)
    242251*/
    243252
    244 gfxr_pic_t *gfxr_interpreter_init_pic(int version, gfx_mode_t *mode, int ID);
    245 /* Initializes a pic
    246 ** Parameters: (int) version: Interpreter version to use
    247 **             (gfx_mode_t *) mode: The graphics mode the pic will be using
    248 **             (int) ID: The ID to assign to the gfxr_pic_t structure
    249 ** Returns   : (gfxr_pic_t *) A newly allocated pic
    250 ** This function is typically called befode gfxr_interpreter_clear_pic().
    251 */
    252 
    253 void gfxr_interpreter_clear_pic(int version, gfxr_pic_t *pic);
    254 /* Clears a previously allocated pic
    255 ** Parameters: (int) version: Interpreter version
    256 **             (gfxr_pic_t *) pic: The pic to clear
    257 ** Returns  :  (void)
    258 ** This function is called in preparation for the pic to be drawn with gfxr_interpreter_calculate_pic.
    259 */
    260 
    261253int gfxr_interpreter_calculate_pic(gfx_resstate_t *state, gfxr_pic_t *scaled_pic, gfxr_pic_t *unscaled_pic,
    262254        int flags, int default_palette, int nr);
    263255/* Instructs the interpreter-specific code to calculate a picture
     
    281273** Returns   : (gfx_view_t *) The appropriate view, or NULL on error
    282274*/
    283275
    284 gfx_bitmap_font_t *gfxr_interpreter_get_font(ResourceManager& resourceManager, int nr);
    285 /* Instructs the interpreter-specific code to calculate a font
    286 ** Parameters: (ResourceManager& ) resourceManager: The resource manager
    287 **             (int) nr: The font resource number
    288 ** Returns   : (gfx_font_t *) The newly calculated font, or NULL on error
    289 */
    290 
    291 gfx_pixmap_t *gfxr_interpreter_get_cursor(ResourceManager& resourceManager, int nr, int version);
    292 /* Instructs the interpreter-specific code to calculate a cursor
    293 ** Parameters: (ResourceManager& ) state: The resource manager
    294 **             (int nr): The cursor resource number
    295 **             (int version): The SCI version used
    296 ** Returns   : (gfx_pixmap_t *) The cursor pixmap, or NULL on error
    297 */
    298 
    299 Palette *gfxr_interpreter_get_static_palette(ResourceManager& resourceManager, int version, int *colors_nr);
    300 /* Retreives the static palette (palette 999) from the interpreter-specific code
    301 ** Parameters: (ResourceManager& ) state: The resource manager
    302 **             (int) version: Interpreter version to use
    303 **             (int *) colors_nr: Number of colors to use
    304 ** Returns   : (gfx_pixmap_color_t *) *colors_nr static color entries
    305 **             if a static palette must be used, NULL otherwise
    306 */
    307 
    308 Palette *gfxr_interpreter_get_palette(ResourceManager& resourceManager, int version, int *colors_nr, int nr);
    309 /* Retreives the static palette from the interpreter-specific code
    310 ** Parameters: (ResourceManager& ) state: The resource manager
    311 **             (int) version: Interpreter version to use
    312 **             (int *) colors_nr: Number of colors to use
    313 **             (int) nr: The palette to read
    314 ** Returns   : (gfx_pixmap_color_t *) *colors_nr static color entries
    315 **             if a static palette must be used, NULL otherwise
    316 */
    317 
    318 int gfxr_interpreter_needs_multicolored_pointers(int version);
    319 /* Determines whether support for pointers with more than two colors is required
    320 ** Parameters: (int) version: Interpreter version to test for
    321 ** Returns   : (int) 0 if no support for multi-colored pointers is required, non-0
    322 **                   otherwise
    323 */
    324 
    325276} // End of namespace Sci
    326277
    327278#endif // SCI_GFX_GFX_RSMGR_H
  • gfx/gfx_resource.cpp

     
    4040};
    4141
    4242
    43 static void gfxr_free_loop(gfx_driver_t *driver, gfxr_loop_t *loop) {
     43static void gfxr_free_loop(gfxr_loop_t *loop) {
    4444        int i;
    4545
    4646        if (loop->cels) {
    4747                for (i = 0; i < loop->cels_nr; i++)
    4848                        if (loop->cels[i])
    49                                 gfx_free_pixmap(driver, loop->cels[i]);
     49                                gfx_free_pixmap(loop->cels[i]);
    5050
    5151                free(loop->cels);
    5252        }
    5353}
    5454
    55 void gfxr_free_view(gfx_driver_t *driver, gfxr_view_t *view) {
     55void gfxr_free_view(gfxr_view_t *view) {
    5656        int i;
    5757
    5858        if (view->palette)
     
    6060
    6161        if (view->loops) {
    6262                for (i = 0; i < view->loops_nr; i++)
    63                         gfxr_free_loop(driver, view->loops + i);
     63                        gfxr_free_loop(view->loops + i);
    6464
    6565                free(view->loops);
    6666        }
     
    393393        }
    394394}
    395395
    396 void gfxr_free_pic(gfx_driver_t *driver, gfxr_pic_t *pic) {
    397         gfx_free_pixmap(driver, pic->visual_map);
    398         gfx_free_pixmap(driver, pic->priority_map);
    399         gfx_free_pixmap(driver, pic->control_map);
     396void gfxr_free_pic(gfxr_pic_t *pic) {
     397        gfx_free_pixmap(pic->visual_map);
     398        gfx_free_pixmap(pic->priority_map);
     399        gfx_free_pixmap(pic->control_map);
    400400        pic->visual_map = NULL;
    401401        pic->priority_map = NULL;
    402402        pic->control_map = NULL;
  • gfx/gfx_resource.h

     
    140140** This function allocates memory for use by resource drawer functions.
    141141*/
    142142
    143 void gfxr_free_pic(gfx_driver_t *driver, gfxr_pic_t *pic);
     143void gfxr_free_pic(gfxr_pic_t *pic);
    144144/* Uninitializes a pic resource
    145 ** Parameters: (gfx_driver_t *) driver: The driver the pic should be removed from
    146 **             (gfxr_pic_t *) pic: The pic to free
     145** Parameters: (gfxr_pic_t *) pic: The pic to free
    147146** Returns   : (void)
    148147*/
    149148
    150 void gfxr_free_view(gfx_driver_t *driver, gfxr_view_t *view);
     149void gfxr_free_view(gfxr_view_t *view);
    151150/* Frees all memory associated with a view
    152 ** Paremeters: (gfx_driver_t *) driver: The driver the view should be removed from
    153 **             (gfxr_view_t *) view: The view to free
     151** Paremeters: (gfxr_view_t *) view: The view to free
    154152** Returns   : (void)
    155153*/
    156154
  • gfx/gfx_tools.cpp

     
    8181        if (mode->palette)
    8282                mode->palette->free();
    8383        free(mode);
     84        mode = NULL;
    8485}
    8586
    8687void gfx_copy_pixmap_box_i(gfx_pixmap_t *dest, gfx_pixmap_t *src, rect_t box) {
     
    146147        return pxm;
    147148}
    148149
    149 void gfx_free_pixmap(gfx_driver_t *driver, gfx_pixmap_t *pxm) {
    150         if (driver) {
    151                 if (driver->mode->palette) {
    152                         if (pxm->palette)
    153                                 pxm->palette->free();
    154                 }
    155         }
     150void gfx_free_pixmap(gfx_pixmap_t *pxm) {
     151        if (pxm->palette)
     152                pxm->palette->free();
    156153
    157154        free(pxm->index_data);
    158155        free(pxm->alpha_map);
  • gfx/gfx_tools.h

     
    118118** Returns   : (gfx_pixmap_t *) pixmap
    119119*/
    120120
    121 void gfx_free_pixmap(gfx_driver_t *driver, gfx_pixmap_t *pxm);
     121void gfx_free_pixmap(gfx_pixmap_t *pxm);
    122122/* Frees all memory associated with a pixmap
    123 ** Parameters: (gfx_driver_t *) driver: The driver the pixmap is to be removed from
    124 **             (gfx_pixmap_t *) pxm: The pixmap to free
     123** Parameters: (gfx_pixmap_t *) pxm: The pixmap to free
    125124** Returns   : (void)
    126125*/
    127126
  • gfx/operations.cpp

     
    433433                return GFX_FATAL;
    434434        }
    435435
    436         int size;
    437         state->static_palette = gfxr_interpreter_get_static_palette(*(state->resstate->resManager), state->version, &size);
     436        state->static_palette = NULL;
    438437
     438        if (state->version < SCI_VERSION_01_VGA) {
     439                state->static_palette = gfx_sci0_pic_colors->getref();
     440        } else if (state->version == SCI_VERSION_1_1 || state->version == SCI_VERSION_32) {
     441                GFXDEBUG("Palettes are not yet supported in this SCI version\n");
     442        } else {
     443                Resource *res = state->resstate->resManager->findResource(kResourceTypePalette, 999, 0);
     444                if (res && res->data)
     445                        state->static_palette = gfxr_read_pal1(res->id, res->data, res->size);
     446        }
     447
    439448        state->visible_map = GFX_MASK_VISUAL;
    440449        state->fullscreen_override = NULL; // No magical override
    441450        gfxop_set_clip_zone(state, gfx_rect(0, 0, 320, 200));
     
    495504
    496505int gfxop_exit(gfx_state_t *state) {
    497506        BASIC_CHECKS(GFX_ERROR);
    498         gfxr_free_resource_manager(state->driver, state->resstate);
     507        gfxr_free_resource_manager(state->resstate);
    499508
    500509        if (state->control_map) {
    501                 gfx_free_pixmap(state->driver, state->control_map);
     510                gfx_free_pixmap(state->control_map);
    502511                state->control_map = NULL;
    503512        }
    504513
    505514        if (state->priority_map) {
    506                 gfx_free_pixmap(state->driver, state->priority_map);
     515                gfx_free_pixmap(state->priority_map);
    507516                state->priority_map = NULL;
    508517        }
    509518
    510519        if (state->static_priority_map) {
    511                 gfx_free_pixmap(state->driver, state->static_priority_map);
     520                gfx_free_pixmap(state->static_priority_map);
    512521                state->static_priority_map = NULL;
    513522        }
    514523
     
    11621171
    11631172        if (state->tag_mode) {
    11641173                // This usually happens after a pic and all resources have been drawn
    1165                 gfxr_free_tagged_resources(state->driver, state->resstate);
     1174                gfxr_free_tagged_resources(state->resstate);
    11661175                state->tag_mode = 0;
    11671176        }
    11681177
     
    12371246        if (nr == GFXOP_NO_POINTER)
    12381247                new_pointer = NULL;
    12391248        else {
    1240                 new_pointer = gfxr_get_cursor(state->resstate, nr);
     1249                // FIXME: the initialization of the GFX resource manager should
     1250                // be pushed up, and it shouldn't occur here
     1251                GfxResManager *_gfx = new GfxResManager(state->resstate);
     1252                new_pointer = _gfx->getCursor(nr);
     1253                delete _gfx;
    12411254
    12421255                if (!new_pointer) {
    12431256                        GFXWARN("Attempt to set invalid pointer #%d\n", nr);
     
    18481861int gfxop_new_pic(gfx_state_t *state, int nr, int flags, int default_palette) {
    18491862        BASIC_CHECKS(GFX_FATAL);
    18501863
    1851         gfxr_tag_resources(state->resstate);
     1864        // FIXME: the initialization of the GFX resource manager should
     1865        // be pushed up, and it shouldn't occur here
     1866        GfxResManager *_gfx = new GfxResManager(state->resstate);
     1867        _gfx->tagResources();
    18521868        state->tag_mode = 1;
    18531869        state->palette_nr = default_palette;
     1870        state->pic = _gfx->getPic(nr, GFX_MASK_VISUAL, flags, default_palette, true);
     1871        delete _gfx;
    18541872
    1855         state->pic = gfxr_get_pic(state->resstate, nr, GFX_MASK_VISUAL, flags, default_palette, 1);
    1856 
    1857         if (state->driver->mode->xfact == 1 && state->driver->mode->yfact == 1)
     1873        if (state->driver->mode->xfact == 1 && state->driver->mode->yfact == 1) {
    18581874                state->pic_unscaled = state->pic;
    1859         else
    1860                 state->pic_unscaled = gfxr_get_pic(state->resstate, nr, GFX_MASK_VISUAL, flags, default_palette, 0);
     1875        } else {
     1876                // FIXME: the initialization of the GFX resource manager should
     1877                // be pushed up, and it shouldn't occur here
     1878                GfxResManager *_gfx = new GfxResManager(state->resstate);
     1879                state->pic = _gfx->getPic(nr, GFX_MASK_VISUAL, flags, default_palette, false);
     1880                delete _gfx;
     1881        }
    18611882
    18621883        if (!state->pic || !state->pic_unscaled) {
    18631884                GFXERROR("Could not retrieve background pic %d!\n", nr);
     
    19041925        gfx_bitmap_font_t *font;
    19051926        BASIC_CHECKS(GFX_FATAL);
    19061927
    1907         font = gfxr_get_font(*(state->resstate->resManager), state->resstate, font_nr, 0);
     1928        // FIXME: the initialization of the GFX resource manager should
     1929        // be pushed up, and it shouldn't occur here
     1930        GfxResManager *_gfx = new GfxResManager(state->resstate);
     1931        font = _gfx->getFont(font_nr);
     1932        delete _gfx;
     1933
    19081934        if (!font)
    19091935                return GFX_ERROR;
    19101936
     
    19181944
    19191945        BASIC_CHECKS(GFX_FATAL);
    19201946
    1921         font = gfxr_get_font(*(state->resstate->resManager), state->resstate, font_nr, 0);
     1947        // FIXME: the initialization of the GFX resource manager should
     1948        // be pushed up, and it shouldn't occur here
     1949        GfxResManager *_gfx = new GfxResManager(state->resstate);
     1950        font = _gfx->getFont(font_nr);
     1951        delete _gfx;
    19221952
    19231953        if (!font) {
    19241954                GFXERROR("Attempt to calculate text size with invalid font #%d\n", font_nr);
     
    19561986                return NULL;
    19571987        }
    19581988
    1959         font = gfxr_get_font(*(state->resstate->resManager), state->resstate, font_nr, 0);
     1989        // FIXME: the initialization of the GFX resource manager should
     1990        // be pushed up, and it shouldn't occur here
     1991        GfxResManager *_gfx = new GfxResManager(state->resstate);
     1992        font = _gfx->getFont(font_nr);
     1993        delete _gfx;
    19601994
    19611995        if (!font) {
    19621996                GFXERROR("Attempt to draw text with invalid font #%d\n", font_nr);
     
    20012035                        int j;
    20022036
    20032037                        for (j = 0; j < i; j++)
    2004                                 gfx_free_pixmap(state->driver, handle->text_pixmaps[j]);
     2038                                gfx_free_pixmap(handle->text_pixmaps[j]);
    20052039
    20062040                        free(handle->text_pixmaps);
    20072041                        free(handle->text);
     
    20272061
    20282062        if (handle->text_pixmaps) {
    20292063                for (j = 0; j < handle->lines_nr; j++)
    2030                         gfx_free_pixmap(state->driver, handle->text_pixmaps[j]);
     2064                        gfx_free_pixmap(handle->text_pixmaps[j]);
    20312065                free(handle->text_pixmaps);
    20322066        }
    20332067
     
    21672201
    21682202int gfxop_free_pixmap(gfx_state_t *state, gfx_pixmap_t *pxm) {
    21692203        BASIC_CHECKS(GFX_ERROR);
    2170         gfx_free_pixmap(state->driver, pxm);
     2204        gfx_free_pixmap(pxm);
    21712205        return GFX_OK;
    21722206}
    21732207
  • gfx/resmgr.cpp

     
    4040
    4141namespace Sci {
    4242
    43 #undef TIME_PICDRAWING
    44 
    4543// Invalid hash mode: Used to invalidate modified pics
    4644#define MODE_INVALID -1
    4745
     
    6664
    6765#define FREEALL(freecmd, type) \
    6866        if (resource->scaled_data.type) \
    69                 freecmd(driver, resource->scaled_data.type); \
    70         resource->scaled_data.type = NULL; \
    71         if (resource->unscaled_data.type) \
    72                 freecmd(driver, resource->unscaled_data.type); \
    73         resource->unscaled_data.type = NULL;
    74 
    75 #define FREEALL_SIMPLE(freecmd, type) \
    76         if (resource->scaled_data.type) \
    7767                freecmd(resource->scaled_data.type); \
    7868        resource->scaled_data.type = NULL; \
    7969        if (resource->unscaled_data.type) \
    8070                freecmd(resource->unscaled_data.type); \
    8171        resource->unscaled_data.type = NULL;
    8272
    83 void gfxr_free_resource(gfx_driver_t *driver, gfx_resource_t *resource, int type) {
     73void gfxr_free_resource(gfx_resource_t *resource, int type) {
    8474        if (!resource)
    8575                return;
    8676
     
    9585                break;
    9686
    9787        case GFX_RESOURCE_TYPE_FONT:
    98                 FREEALL_SIMPLE(gfxr_free_font, font);
     88                FREEALL(gfxr_free_font, font);
    9989                break;
    10090
    10191        case GFX_RESOURCE_TYPE_CURSOR:
     
    10999        free(resource);
    110100}
    111101
    112 void gfxr_free_all_resources(gfx_driver_t *driver, gfx_resstate_t *state) {
     102void gfxr_free_all_resources(gfx_resstate_t *state) {
    113103        for (int type = 0; type < GFX_RESOURCE_TYPES_NR; ++type) {
    114104                for (IntResMap::iterator iter = state->_resourceMaps[type].begin(); iter != state->_resourceMaps[type].end(); ++iter) {
    115                         gfxr_free_resource(driver, iter->_value, type);
     105                        gfxr_free_resource(iter->_value, type);
    116106                        iter->_value = 0;
    117107                }
    118108        }
    119109}
    120110
    121 void gfxr_free_resource_manager(gfx_driver_t *driver, gfx_resstate_t *state) {
    122         gfxr_free_all_resources(driver, state);
     111void gfxr_free_resource_manager(gfx_resstate_t *state) {
     112        gfxr_free_all_resources(state);
    123113        delete state;
    124114}
    125115
    126 void gfxr_tag_resources(gfx_resstate_t *state) {
    127         (state->tag_lock_counter)++;
    128 }
    129 
    130 void gfxr_free_tagged_resources(gfx_driver_t *driver, gfx_resstate_t *state) {
     116void gfxr_free_tagged_resources(gfx_resstate_t *state) {
    131117        // Current heuristics: free tagged views and old pics
    132118
    133119        IntResMap::iterator iter;
     
    140126
    141127                if (resource) {
    142128                        if (resource->lock_sequence_nr < tmp) {
    143                                 gfxr_free_resource(driver, resource, type);
     129                                gfxr_free_resource(resource, type);
    144130                                iter->_value = 0;
    145131                        } else {
    146132                                resource->lock_sequence_nr = 0;
     
    154140
    155141                if (resource) {
    156142                        if (resource->lock_sequence_nr < 0) {
    157                                 gfxr_free_resource(driver, resource, type);
     143                                gfxr_free_resource(resource, type);
    158144                                iter->_value = 0;
    159145                        } else {
    160146                                resource->lock_sequence_nr--;
     
    191177}
    192178#undef XLATE_AS_APPROPRIATE
    193179
    194 gfxr_pic_t *gfxr_get_pic(gfx_resstate_t *state, int nr, int maps, int flags, int default_palette, int scaled) {
     180gfxr_pic_t *GfxResManager::getPic(int num, int maps, int flags, int default_palette, bool scaled) {
    195181        gfxr_pic_t *npic = NULL;
    196182        gfx_resource_type_t restype = GFX_RESOURCE_TYPE_PIC;
    197         IntResMap &resMap = state->_resourceMaps[restype];
     183        IntResMap &resMap = _state->_resourceMaps[restype];
    198184        gfx_resource_t *res = NULL;
    199         int hash = gfxr_interpreter_options_hash(restype, state->version, state->options, 0);
     185        int hash = gfxr_interpreter_options_hash(restype, _state->version, _state->options, 0);
    200186        int must_post_process_pic = 0;
    201         int need_unscaled = (state->driver->mode->xfact != 1 || state->driver->mode->yfact != 1);
     187        int need_unscaled = (_state->driver->mode->xfact != 1 || _state->driver->mode->yfact != 1);
    202188
    203189        hash |= (flags << 20) | ((default_palette & 0x7) << 28);
    204190
    205         res = resMap.contains(nr) ? resMap[nr] : NULL;
     191        res = resMap.contains(num) ? resMap[num] : NULL;
    206192
    207193        if (!res || res->mode != hash) {
    208194                gfxr_pic_t *pic;
    209195                gfxr_pic_t *unscaled_pic = NULL;
    210196
    211                 if (state->options->pic0_unscaled) {
     197                if (_state->options->pic0_unscaled) {
    212198                        need_unscaled = 0;
    213                         pic = gfxr_interpreter_init_pic(state->version, &mode_1x1_color_index, GFXR_RES_ID(restype, nr));
     199                        pic = gfxr_init_pic(&mode_1x1_color_index, GFXR_RES_ID(restype, num), _state->version >= SCI_VERSION_01_VGA);
    214200                } else
    215                         pic = gfxr_interpreter_init_pic(state->version, state->driver->mode, GFXR_RES_ID(restype, nr));
    216 
     201                        pic = gfxr_init_pic(_state->driver->mode, GFXR_RES_ID(restype, num), _state->version >= SCI_VERSION_01_VGA);
    217202                if (!pic) {
    218203                        GFXERROR("Failed to allocate scaled pic!\n");
    219204                        return NULL;
    220205                }
    221206
    222                 gfxr_interpreter_clear_pic(state->version, pic);
     207                gfxr_clear_pic0(pic, SCI_TITLEBAR_SIZE);
    223208
    224209                if (need_unscaled) {
    225                         unscaled_pic = gfxr_interpreter_init_pic(state->version, &mode_1x1_color_index, GFXR_RES_ID(restype, nr));
     210                        unscaled_pic = gfxr_init_pic(&mode_1x1_color_index, GFXR_RES_ID(restype, num), _state->version >= SCI_VERSION_01_VGA);
    226211                        if (!unscaled_pic) {
    227212                                GFXERROR("Failed to allocate unscaled pic!\n");
    228213                                return NULL;
    229214                        }
    230                         gfxr_interpreter_clear_pic(state->version, unscaled_pic);
     215                        gfxr_clear_pic0(pic, SCI_TITLEBAR_SIZE);
    231216                }
    232 #ifdef TIME_PICDRAWING
    233                 {
    234                         uint32 start_msec, end_msec;
    235                         start_msec = g_system->getMillis();
    236 #endif
    237                         if (gfxr_interpreter_calculate_pic(state, pic, unscaled_pic, flags, default_palette, nr)) {
    238                                 gfxr_free_pic(state->driver, pic);
    239                                 if (unscaled_pic)
    240                                         gfxr_free_pic(state->driver, unscaled_pic);
    241 
    242                                 return NULL;
    243                         }
    244 #ifdef TIME_PICDRAWING
    245                         end_msec = g_system->getMillis();
    246                         printf("\nTIME: %d      ms for drawing pic.%03d\n", end_msec - start_msec, nr);
     217                if (gfxr_interpreter_calculate_pic(_state, pic, unscaled_pic, flags, default_palette, num)) {
     218                        gfxr_free_pic(pic);
     219                        if (unscaled_pic)
     220                                gfxr_free_pic(unscaled_pic);
     221                        return NULL;
    247222                }
    248 #endif
    249 
    250223                if (!res) {
    251224                        res = (gfx_resource_t *)sci_malloc(sizeof(gfx_resource_t));
    252                         res->ID = GFXR_RES_ID(restype, nr);
    253                         res->lock_sequence_nr = state->options->buffer_pics_nr;
    254                         resMap[nr] = res;
     225                        res->ID = GFXR_RES_ID(restype, num);
     226                        res->lock_sequence_nr = _state->options->buffer_pics_nr;
     227                        resMap[num] = res;
    255228                } else {
    256                         gfxr_free_pic(state->driver, res->scaled_data.pic);
     229                        gfxr_free_pic(res->scaled_data.pic);
    257230                        if (res->unscaled_data.pic)
    258                                 gfxr_free_pic(state->driver, res->unscaled_data.pic);
     231                                gfxr_free_pic(res->unscaled_data.pic);
    259232                }
    260233
    261234                res->mode = hash;
    262235                res->scaled_data.pic = pic;
    263236                res->unscaled_data.pic = unscaled_pic;
    264237        } else {
    265                 res->lock_sequence_nr = state->options->buffer_pics_nr; // Update lock counter
     238                res->lock_sequence_nr = _state->options->buffer_pics_nr; // Update lock counter
    266239        }
    267240
    268241        must_post_process_pic = res->scaled_data.pic->visual_map->data == NULL;
    269242        // If the pic was only just drawn, we'll have to endianness-adjust it now
    270243
    271         npic = gfxr_pic_xlate_common(res, maps, scaled || state->options->pic0_unscaled, 0, state->driver->mode,
    272                                      state->options->pic_xlate_filter, 0, state->options);
     244        npic = gfxr_pic_xlate_common(res, maps, scaled || _state->options->pic0_unscaled, 0, _state->driver->mode,
     245                                     _state->options->pic_xlate_filter, 0, _state->options);
    273246
    274247
    275248        if (must_post_process_pic) {
    276                 gfxr_endianness_adjust(npic->visual_map, state->driver->mode);
     249                gfxr_endianness_adjust(npic->visual_map, _state->driver->mode);
    277250        }
    278251
    279252        return npic;
     
    338311        res = resMap.contains(old_nr) ? resMap[old_nr] : NULL;
    339312
    340313        if (!res || (res->mode != MODE_INVALID && res->mode != hash)) {
    341                 gfxr_get_pic(state, old_nr, 0, flags, old_default_palette, scaled);
     314                // FIXME: the initialization of the GFX resource manager should
     315                // be pushed up, and it shouldn't occur here
     316                GfxResManager *_gfx = new GfxResManager(state);
     317                _gfx->getPic(old_nr, 0, flags, old_default_palette, scaled);
     318                delete _gfx;
    342319
    343320                res = resMap.contains(old_nr) ? resMap[old_nr] : NULL;
    344321
     
    398375                        res->mode = hash;
    399376                        resMap[nr] = res;
    400377                } else {
    401                         gfxr_free_view(state->driver, res->unscaled_data.view);
     378                        gfxr_free_view(res->unscaled_data.view);
    402379                }
    403380
    404381                res->mode = hash;
     
    453430        return view;
    454431}
    455432
    456 gfx_bitmap_font_t *gfxr_get_font(ResourceManager& resourceManager, gfx_resstate_t *state, int nr, int scaled) {
     433gfx_bitmap_font_t *GfxResManager::getFont(int num, bool scaled) {
    457434        gfx_resource_type_t restype = GFX_RESOURCE_TYPE_FONT;
    458         IntResMap &resMap = state->_resourceMaps[restype];
     435        IntResMap &resMap = _state->_resourceMaps[restype];
    459436        gfx_resource_t *res = NULL;
    460437        int hash;
    461438
    462         hash = gfxr_interpreter_options_hash(restype, state->version, state->options, 0);
     439        hash = gfxr_interpreter_options_hash(restype, _state->version, _state->options, 0);
    463440
    464         res = resMap.contains(nr) ? resMap[nr] : NULL;
     441        res = resMap.contains(num) ? resMap[num] : NULL;
    465442
    466443        if (!res || res->mode != hash) {
    467                 gfx_bitmap_font_t *font = gfxr_interpreter_get_font(resourceManager, nr);
    468 
    469                 if (!font)
     444                Resource *fontRes = _state->resManager->findResource(kResourceTypeFont, num, 0);
     445                if (!fontRes || !fontRes->data)
    470446                        return NULL;
    471447
     448                gfx_bitmap_font_t *font = gfxr_read_font(fontRes->id, fontRes->data, fontRes->size);
     449
    472450                if (!res) {
    473451                        res = (gfx_resource_t *)sci_malloc(sizeof(gfx_resource_t));
    474452                        res->scaled_data.font = NULL;
    475                         res->ID = GFXR_RES_ID(restype, nr);
    476                         res->lock_sequence_nr = state->tag_lock_counter;
     453                        res->ID = GFXR_RES_ID(restype, num);
     454                        res->lock_sequence_nr = _state->tag_lock_counter;
    477455                        res->mode = hash;
    478                         resMap[nr] = res;
     456                        resMap[num] = res;
    479457                } else {
    480458                        gfxr_free_font(res->unscaled_data.font);
    481459                }
     
    484462
    485463                return font;
    486464        } else {
    487                 res->lock_sequence_nr = state->tag_lock_counter; // Update lock counter
     465                res->lock_sequence_nr = _state->tag_lock_counter; // Update lock counter
    488466                if (res->unscaled_data.pointer)
    489467                        return res->unscaled_data.font;
    490468                else
     
    492470        }
    493471}
    494472
    495 gfx_pixmap_t *gfxr_get_cursor(gfx_resstate_t *state, int nr) {
     473gfx_pixmap_t *GfxResManager::getCursor(int num) {
    496474        gfx_resource_type_t restype = GFX_RESOURCE_TYPE_CURSOR;
    497         IntResMap &resMap = state->_resourceMaps[restype];
     475        IntResMap &resMap = _state->_resourceMaps[restype];
    498476        gfx_resource_t *res = NULL;
    499         int hash = gfxr_interpreter_options_hash(restype, state->version, state->options, 0);
     477        int hash = gfxr_interpreter_options_hash(restype, _state->version, _state->options, 0);
    500478
    501         res = resMap.contains(nr) ? resMap[nr] : NULL;
     479        res = resMap.contains(num) ? resMap[num] : NULL;
    502480
    503481        if (!res || res->mode != hash) {
    504                 gfx_pixmap_t *cursor = gfxr_interpreter_get_cursor(*(state->resManager), nr, state->version);
     482                Resource *cursorRes = _state->resManager->findResource(kResourceTypeCursor, num, 0);
     483                if (!cursorRes || !cursorRes->data)
     484                        return NULL;
    505485
     486                if (_state->version >= SCI_VERSION_1_1) {
     487                        GFXWARN("Attempt to retrieve cursor in SCI1.1 or later\n");
     488                        return NULL;
     489                }
     490
     491                gfx_pixmap_t *cursor = gfxr_draw_cursor(GFXR_RES_ID(GFX_RESOURCE_TYPE_CURSOR, num),
     492                                                                                cursorRes->data, cursorRes->size, _state->version != SCI_VERSION_0);
     493
    506494                if (!cursor)
    507495                        return NULL;
    508496
    509497                if (!res) {
    510498                        res = (gfx_resource_t *)sci_malloc(sizeof(gfx_resource_t));
    511499                        res->scaled_data.pointer = NULL;
    512                         res->ID = GFXR_RES_ID(restype, nr);
    513                         res->lock_sequence_nr = state->tag_lock_counter;
     500                        res->ID = GFXR_RES_ID(restype, num);
     501                        res->lock_sequence_nr = _state->tag_lock_counter;
    514502                        res->mode = hash;
    515                         resMap[nr] = res;
     503                        resMap[num] = res;
    516504                } else {
    517                         gfx_free_pixmap(state->driver, res->unscaled_data.pointer);
     505                        gfx_free_pixmap(res->unscaled_data.pointer);
    518506                }
    519                 gfx_get_res_config(state->options, cursor);
    520                 gfx_xlate_pixmap(cursor, state->driver->mode, state->options->cursor_xlate_filter);
    521                 gfxr_endianness_adjust(cursor, state->driver->mode);
     507                gfx_get_res_config(_state->options, cursor);
     508                gfx_xlate_pixmap(cursor, _state->driver->mode, _state->options->cursor_xlate_filter);
     509                gfxr_endianness_adjust(cursor, _state->driver->mode);
    522510
    523511                res->unscaled_data.pointer = cursor;
    524512
    525513                return cursor;
    526514        } else {
    527                 res->lock_sequence_nr = state->tag_lock_counter; // Update lock counter
     515                res->lock_sequence_nr = _state->tag_lock_counter; // Update lock counter
    528516                return res->unscaled_data.pointer;
    529517        }
    530518}
  • gfx/resource/res_manager.cpp

     
    4949                               | (options->pic0_dither_pattern << 8) | (options->pic0_brush_mode << 4) | (options->pic0_line_mode);
    5050
    5151        case GFX_RESOURCE_TYPE_FONT:
    52                 return 0;
    53 
    5452        case GFX_RESOURCE_TYPE_CURSOR:
    5553                return 0;
    5654
     
    6159        }
    6260}
    6361
    64 gfxr_pic_t *gfxr_interpreter_init_pic(int version, gfx_mode_t *mode, int ID) {
    65         return gfxr_init_pic(mode, ID, version >= SCI_VERSION_01_VGA);
    66 }
    67 
    68 void gfxr_interpreter_clear_pic(int version, gfxr_pic_t *pic) {
    69         gfxr_clear_pic0(pic, SCI_TITLEBAR_SIZE);
    70 }
    71 
    7262int gfxr_interpreter_calculate_pic(gfx_resstate_t *state, gfxr_pic_t *scaled_pic, gfxr_pic_t *unscaled_pic,
    7363        int flags, int default_palette, int nr) {
    7464        ResourceManager& resourceManager = *(state->resManager);
     
    152142
    153143        if (version < SCI_VERSION_01) palette = -1;
    154144
    155         switch (version) {
    156         case SCI_VERSION_0:
    157         case SCI_VERSION_01:
     145        if (version <= SCI_VERSION_01)
    158146                result = gfxr_draw_view0(resid, res->data, res->size, palette);
    159                 break;
    160         case SCI_VERSION_01_VGA:
    161         case SCI_VERSION_01_VGA_ODD:
    162         case SCI_VERSION_1_EARLY:
    163         case SCI_VERSION_1_LATE:
     147        else if (version >= SCI_VERSION_01_VGA && version <= SCI_VERSION_1_LATE)
    164148                result = gfxr_draw_view1(resid, res->data, res->size, staticPalette);
    165                 break;
    166         case SCI_VERSION_1_1:
    167         case SCI_VERSION_32:
     149        else if (version >= SCI_VERSION_1_1)
    168150                result = gfxr_draw_view11(resid, res->data, res->size);
    169                 break;
    170         }
    171151
    172152        if (version >= SCI_VERSION_01_VGA) {
    173153                if (!result->palette) {
     
    179159        return result;
    180160}
    181161
    182 gfx_bitmap_font_t *gfxr_interpreter_get_font(ResourceManager& resourceManager, int nr) {
    183         Resource *res = resourceManager.findResource(kResourceTypeFont, nr, 0);
    184         if (!res || !res->data)
    185                 return NULL;
    186 
    187         return gfxr_read_font(res->id, res->data, res->size);
    188 }
    189 
    190 gfx_pixmap_t *gfxr_interpreter_get_cursor(ResourceManager& resourceManager, int nr, int version) {
    191         Resource *res = resourceManager.findResource(kResourceTypeCursor, nr, 0);
    192         int resid = GFXR_RES_ID(GFX_RESOURCE_TYPE_CURSOR, nr);
    193 
    194         if (!res || !res->data)
    195                 return NULL;
    196 
    197         if (version >= SCI_VERSION_1_1) {
    198                 GFXWARN("Attempt to retrieve cursor in SCI1.1 or later\n");
    199                 return NULL;
    200         }
    201 
    202         return gfxr_draw_cursor(resid, res->data, res->size, version != SCI_VERSION_0);
    203 }
    204 
    205 Palette *gfxr_interpreter_get_static_palette(ResourceManager& resourceManager, int version, int *colors_nr) {
    206         if (version >= SCI_VERSION_01_VGA)
    207                 return gfxr_interpreter_get_palette(resourceManager, version, colors_nr, 999);
    208 
    209         *colors_nr = GFX_SCI0_PIC_COLORS_NR;
    210         return gfx_sci0_pic_colors->getref();
    211 }
    212 
    213 Palette *gfxr_interpreter_get_palette(ResourceManager& resourceManager, int version, int *colors_nr, int nr) {
    214         Resource *res;
    215 
    216         if (version < SCI_VERSION_01_VGA)
    217                 return NULL;
    218 
    219         res = resourceManager.findResource(kResourceTypePalette, nr, 0);
    220         if (!res || !res->data)
    221                 return NULL;
    222 
    223         switch (version) {
    224         case SCI_VERSION_01_VGA :
    225         case SCI_VERSION_01_VGA_ODD :
    226         case SCI_VERSION_1_EARLY :
    227         case SCI_VERSION_1_LATE :
    228                 return gfxr_read_pal1(res->id, res->data, res->size);
    229         case SCI_VERSION_1_1 :
    230         case SCI_VERSION_32 :
    231                 GFXDEBUG("Palettes are not yet supported in this SCI version\n");
    232                 return NULL;
    233 
    234         default:
    235                 BREAKPOINT();
    236                 return NULL;
    237         }
    238 }
    239 
    240 int gfxr_interpreter_needs_multicolored_pointers(int version) {
    241         return (version > SCI_VERSION_1);
    242 }
    243 
    244162} // End of namespace Sci
  • gfx/resource/res_pic.cpp

     
    16991699
    17001700                                gfx_xlate_pixmap(view, mode, GFX_XLATE_FILTER_NONE);
    17011701                                gfx_free_mode(mode);
     1702                                // When the mode is freed, the associated view
     1703                                // palette is freed too, so set it to NULL
     1704                                view->palette = NULL;
    17021705
    17031706                                if (flags & DRAWPIC01_FLAG_OVERLAID_PIC)
    17041707                                        view_transparentize(view, pic->visual_map, posx, sci_titlebar_size + posy,
     
    17081711                                                      view->index_data, pic->visual_map->index_width, view->index_width,
    17091712                                                      view->index_width, view->index_height, 1);
    17101713
    1711                                 gfx_free_pixmap(NULL, view);
     1714                                gfx_free_pixmap(view);
     1715                                view = NULL;
    17121716                        }
    17131717                        goto end_op_loop;
    17141718
  • gfx/resource/res_view0.cpp

     
    5757        }
    5858
    5959        if (xl <= 0 || yl <= 0) {
    60                 gfx_free_pixmap(NULL, retval);
     60                gfx_free_pixmap(retval);
    6161                GFXERROR("View %02x:(%d/%d) has invalid xl=%d or yl=%d\n", id, loop, cel, xl, yl);
    6262                return NULL;
    6363        }
     
    218218                if (error_token || gfxr_draw_loop0(view->loops + i, id, i, resource, loop_offset, size, view, mirrored)) {
    219219                        // An error occured
    220220                        view->loops_nr = i;
    221                         gfxr_free_view(NULL, view);
     221                        gfxr_free_view(view);
    222222                        return NULL;
    223223                }
    224224        }
  • gfx/resource/res_view1.cpp

     
    246246
    247247        if (view)
    248248                retval->palette = view->palette->getref();
     249        else
     250                retval->palette = NULL;
    249251
    250252        if (xl <= 0 || yl <= 0) {
    251                 gfx_free_pixmap(NULL, retval);
     253                gfx_free_pixmap(retval);
    252254                GFXERROR("View %02x:(%d/%d) has invalid xl=%d or yl=%d\n", id, loop, cel, xl, yl);
    253255                return NULL;
    254256        }
     
    261263                                                        pos, xl, yl, retval->color_key);
    262264
    263265        if (decompress_failed) {
    264                 gfx_free_pixmap(NULL, retval);
     266                gfx_free_pixmap(retval);
    265267                return NULL;
    266268        }
    267269
     
    381383                if (error_token || gfxr_draw_loop1(view->loops + i, id, i, mirror_mask & (1 << i), resource, loop_offset, size, view, amiga_game)) {
    382384                        // An error occured
    383385                        view->loops_nr = i;
    384                         gfxr_free_view(NULL, view);
     386                        gfxr_free_view(view);
    385387                        return NULL;
    386388                }
    387389        }
     
    429431                retval->palette = view->palette->getref();
    430432
    431433        if (xl <= 0 || yl <= 0) {
    432                 gfx_free_pixmap(NULL, retval);
     434                gfx_free_pixmap(retval);
    433435                GFXERROR("View %02x:(%d/%d) has invalid xl=%d or yl=%d\n", id, loop, cel, xl, yl);
    434436                return NULL;
    435437        }
     
    438440                                                runlength_offset, literal_offset, xl, yl, retval->color_key);
    439441
    440442        if (decompress_failed) {
    441                 gfx_free_pixmap(NULL, retval);
     443                gfx_free_pixmap(retval);
    442444                return NULL;
    443445        }
    444446
  • engine/kgraphics.cpp

     
    23502350                        UKPV(3), UKPV(2));
    23512351                // FIXME: Should really only invalidate all loaded pic resources here;
    23522352                // this is overkill
    2353                 gfxr_free_all_resources(s->gfx_state->driver, s->gfx_state->resstate);
     2353                gfxr_free_all_resources(s->gfx_state->resstate);
    23542354
    23552355                break;
    23562356        }
  • engine/scriptdebug.cpp

     
    20112011        gfxop_set_pointer_cursor(s->gfx_state, GFXOP_NO_POINTER);
    20122012        sciprintf("Flushing resources...\n");
    20132013        s->visual->widfree(GFXW(s->visual));
    2014         gfxr_free_all_resources(s->gfx_state->driver, s->gfx_state->resstate);
     2014        gfxr_free_all_resources(s->gfx_state->resstate);
    20152015        s->visual = NULL;
    20162016
    20172017        return 0;
  • gfx/gfx_driver.cpp

     
    9494        int i;
    9595        if (S) {
    9696                for (i = 0; i < 2; i++) {
    97                         gfx_free_pixmap(drv, S->priority[i]);
     97                        gfx_free_pixmap(S->priority[i]);
    9898                        S->priority[i] = NULL;
    9999                }
    100100
  • gfx/gfx_resmgr.h

     
    114114** The options are considered to be read-only, as they belong to the overlying state object.
    115115*/
    116116
    117 void gfxr_free_resource_manager(gfx_driver_t *driver, gfx_resstate_t *state);
     117void gfxr_free_resource_manager(gfx_resstate_t *state);
    118118/* Frees a previously allocated resource manager, and all allocated resources.
    119 ** Parameters: (gfx_driver_t *) driver: The graphics driver; used to free pixmaps that
    120 **                                      are installed in a driver-specific registry
    121 **             (gfx_resstate_t *) state: The state manager to free
     119** Parameters: (gfx_resstate_t *) state: The state manager to free
    122120** Return    : (void)
    123121*/
    124122
    125 void gfxr_free_all_resources(gfx_driver_t *driver, gfx_resstate_t *state);
     123void gfxr_free_all_resources(gfx_resstate_t *state);
    126124/* Frees all resources currently allocated
    127 ** Parameter: (gfx_driver_t *) driver: The driver to free with
    128 **            (gfx_resstate_t *) state: The state to do this on
     125** Parameter: (gfx_resstate_t *) state: The state to do this on
    129126** Returns  : (void)
    130127** This function is intended to be used primarily for debugging.
    131128*/
    132129
    133 void gfxr_tag_resources(gfx_resstate_t *state);
    134 /* 'Tags' all resources for deletion
    135 ** Paramters: (gfx_resstate_t *) state: The resource state to modify
    136 ** Returns  : (void)
    137 ** Tagged resources are untagged if they are referenced.
    138 */
    139 
    140 void gfxr_free_tagged_resources(gfx_driver_t *driver, gfx_resstate_t *state);
     130void gfxr_free_tagged_resources(gfx_resstate_t *state);
    141131/* Frees all tagged resources.
    142 ** Parameters: (gfx_driver_t *) driver: The graphics driver the pixmaps are potentially
    143 **                                      registered in
    144 **             (gfx_resstate_t *) state: The state to alter
     132** Parameters: (gfx_resstate_t *) state: The state to alter
    145133** Returns   : (void)
    146134** Resources are tagged by calling gfx_tag_resources(), and untagged by calling the
    147135** approprate dereferenciation function.
     
    150138*/
    151139
    152140
    153 gfxr_pic_t *gfxr_get_pic(gfx_resstate_t *state, int nr, int maps, int flags,
    154         int default_palette, int scaled);
    155 /* Retreives a displayable (translated) pic resource
    156 ** Parameters: (gfx_resstate_t *) state: The resource state
    157 **             (int) nr: Number of the pic resource
    158 **             (int) maps: The maps to translate (ORred GFX_MASK_*)
    159 **             (int) flags: Interpreter-dependant pic flags
    160 **             (int) default_palette: The default palette to use for drawing (if applicable)
    161 **             (int) scaled: Whether to return the scaled maps, or the unscaled
    162 **                           ones (which may be identical) for some special operations.
    163 ** Returns   : (gfx_pic_t *) The appropriate pic resource with all maps as index (but not
    164 **                           neccessarily translated) data.
    165 */
     141class GfxResManager {
     142public:
     143        GfxResManager(gfx_resstate_t *state) : _state(state) {}
     144        ~GfxResManager() {}
    166145
     146        /* 'Tags' all resources for deletion
     147        ** Paramters: (void)
     148        ** Returns  : (void)
     149        ** Tagged resources are untagged if they are referenced.
     150        */
     151        void tagResources() { (_state->tag_lock_counter)++; }
     152
     153        /* Retreives an SCI0/SCI01 mouse cursor
     154        ** Parameters: (int) num: The cursor number
     155        ** Returns   : (gfx_font_t *) The approprate cursor as a pixmap, or NULL on error
     156        */
     157        gfx_pixmap_t *getCursor(int num);
     158
     159
     160        /* Retreives the static palette from the interpreter-specific code
     161        ** Parameters: (int *) colors_nr: Number of colors to use
     162        **             (int) nr: The palette to read
     163        ** Returns   : (gfx_pixmap_color_t *) *colors_nr static color entries
     164        **             if a static palette must be used, NULL otherwise
     165        */
     166        Palette *getPalette(int *colors_nr, int num = 999);
     167
     168
     169        /* Retreives a font
     170        ** Parameters: (int) nr: The font number
     171        **             (int) scaled: Whether the font should be font-scaled
     172        ** Returns   : (gfx_font_t *) The appropriate font, or NULL on error
     173        */
     174        gfx_bitmap_font_t *getFont(int num, bool scaled = false);
     175
     176
     177        /* Retreives a displayable (translated) pic resource
     178        ** Parameters: (int) nr: Number of the pic resource
     179        **             (int) maps: The maps to translate (ORred GFX_MASK_*)
     180        **             (int) flags: Interpreter-dependant pic flags
     181        **             (int) default_palette: The default palette to use for drawing (if applicable)
     182        **             (bool) scaled: Whether to return the scaled maps, or the unscaled
     183        **                           ones (which may be identical) for some special operations.
     184        ** Returns   : (gfx_pic_t *) The appropriate pic resource with all maps as index (but not
     185        **                           neccessarily translated) data.
     186        */
     187        gfxr_pic_t *getPic(int num, int maps, int flags, int default_palette, bool scaled = false);
     188
     189
     190        /* Determines whether support for pointers with more than two colors is required
     191        ** Returns   : (bool) false if no support for multi-colored pointers is required, true
     192        **                   otherwise
     193        */
     194        bool multicoloredPointers() { return _state->version > SCI_VERSION_1; }
     195
     196private:
     197        gfx_resstate_t *_state;
     198};
     199
    167200gfxr_pic_t *gfxr_add_to_pic(gfx_resstate_t *state, int old_nr, int new_nr, int maps, int flags,
    168201        int old_default_palette, int default_palette, int scaled);
    169202/* Retreives a displayable (translated) pic resource written ontop of an existing pic
     
    195228** loop and cel numbers have to be interpreted as 'maximum' or 'minimum' by the interpreter)
    196229*/
    197230
    198 gfx_bitmap_font_t *gfxr_get_font(ResourceManager& resourceManager, gfx_resstate_t *state, int nr, int scaled);
    199 /* Retreives a font
    200 ** Parameters: (ResourceManager&) resourceManager: supplies the resource repository capability
    201 **                         (gfx_resstate_t *) state: The relevant resource state
    202 **             (int) nr: The font number
    203 **             (int) scaled: Whether the font should be font-scaled
    204 ** Returns   : (gfx_font_t *) The appropriate font, or NULL on error
    205 */
    206 
    207 gfx_pixmap_t *gfxr_get_cursor(gfx_resstate_t *state, int nr);
    208 /* Retreives an SCI0/SCI01 mouse cursor
    209 ** Parameters: (gfx_resstate_t *) state: The resource state
    210 **             (int) nr: The cursour number
    211 ** Returns   : (gfx_font_t *) The approprate cursor as a pixmap, or NULL on error
    212 */
    213 
    214 gfx_pixmap_color_t *gfxr_get_palette(gfx_resstate_t *state, int nr);
    215 /* Retreives a palette
    216 ** Parameters: (gfx_resstate_t *) state: The resource state
    217 **             (int) nr: The cursour number
    218 ** Returns   : (gfx_font_t *) The approprate cursor as a pixmap, or NULL on error
    219 */
    220 
    221 
    222231/* =========================== */
    223232/* Interpreter-dependant stuff */
    224233/* =========================== */
     
    241250** (Yes, this isn't really a "hash" in the traditional sense...)
    242251*/
    243252
    244 gfxr_pic_t *gfxr_interpreter_init_pic(int version, gfx_mode_t *mode, int ID);
    245 /* Initializes a pic
    246 ** Parameters: (int) version: Interpreter version to use
    247 **             (gfx_mode_t *) mode: The graphics mode the pic will be using
    248 **             (int) ID: The ID to assign to the gfxr_pic_t structure
    249 ** Returns   : (gfxr_pic_t *) A newly allocated pic
    250 ** This function is typically called befode gfxr_interpreter_clear_pic().
    251 */
    252 
    253 void gfxr_interpreter_clear_pic(int version, gfxr_pic_t *pic);
    254 /* Clears a previously allocated pic
    255 ** Parameters: (int) version: Interpreter version
    256 **             (gfxr_pic_t *) pic: The pic to clear
    257 ** Returns  :  (void)
    258 ** This function is called in preparation for the pic to be drawn with gfxr_interpreter_calculate_pic.
    259 */
    260 
    261253int gfxr_interpreter_calculate_pic(gfx_resstate_t *state, gfxr_pic_t *scaled_pic, gfxr_pic_t *unscaled_pic,
    262254        int flags, int default_palette, int nr);
    263255/* Instructs the interpreter-specific code to calculate a picture
     
    281273** Returns   : (gfx_view_t *) The appropriate view, or NULL on error
    282274*/
    283275
    284 gfx_bitmap_font_t *gfxr_interpreter_get_font(ResourceManager& resourceManager, int nr);
    285 /* Instructs the interpreter-specific code to calculate a font
    286 ** Parameters: (ResourceManager& ) resourceManager: The resource manager
    287 **             (int) nr: The font resource number
    288 ** Returns   : (gfx_font_t *) The newly calculated font, or NULL on error
    289 */
    290 
    291 gfx_pixmap_t *gfxr_interpreter_get_cursor(ResourceManager& resourceManager, int nr, int version);
    292 /* Instructs the interpreter-specific code to calculate a cursor
    293 ** Parameters: (ResourceManager& ) state: The resource manager
    294 **             (int nr): The cursor resource number
    295 **             (int version): The SCI version used
    296 ** Returns   : (gfx_pixmap_t *) The cursor pixmap, or NULL on error
    297 */
    298 
    299 Palette *gfxr_interpreter_get_static_palette(ResourceManager& resourceManager, int version, int *colors_nr);
    300 /* Retreives the static palette (palette 999) from the interpreter-specific code
    301 ** Parameters: (ResourceManager& ) state: The resource manager
    302 **             (int) version: Interpreter version to use
    303 **             (int *) colors_nr: Number of colors to use
    304 ** Returns   : (gfx_pixmap_color_t *) *colors_nr static color entries
    305 **             if a static palette must be used, NULL otherwise
    306 */
    307 
    308 Palette *gfxr_interpreter_get_palette(ResourceManager& resourceManager, int version, int *colors_nr, int nr);
    309 /* Retreives the static palette from the interpreter-specific code
    310 ** Parameters: (ResourceManager& ) state: The resource manager
    311 **             (int) version: Interpreter version to use
    312 **             (int *) colors_nr: Number of colors to use
    313 **             (int) nr: The palette to read
    314 ** Returns   : (gfx_pixmap_color_t *) *colors_nr static color entries
    315 **             if a static palette must be used, NULL otherwise
    316 */
    317 
    318 int gfxr_interpreter_needs_multicolored_pointers(int version);
    319 /* Determines whether support for pointers with more than two colors is required
    320 ** Parameters: (int) version: Interpreter version to test for
    321 ** Returns   : (int) 0 if no support for multi-colored pointers is required, non-0
    322 **                   otherwise
    323 */
    324 
    325276} // End of namespace Sci
    326277
    327278#endif // SCI_GFX_GFX_RSMGR_H
  • gfx/gfx_resource.cpp

     
    4040};
    4141
    4242
    43 static void gfxr_free_loop(gfx_driver_t *driver, gfxr_loop_t *loop) {
     43static void gfxr_free_loop(gfxr_loop_t *loop) {
    4444        int i;
    4545
    4646        if (loop->cels) {
    4747                for (i = 0; i < loop->cels_nr; i++)
    4848                        if (loop->cels[i])
    49                                 gfx_free_pixmap(driver, loop->cels[i]);
     49                                gfx_free_pixmap(loop->cels[i]);
    5050
    5151                free(loop->cels);
    5252        }
    5353}
    5454
    55 void gfxr_free_view(gfx_driver_t *driver, gfxr_view_t *view) {
     55void gfxr_free_view(gfxr_view_t *view) {
    5656        int i;
    5757
    5858        if (view->palette)
     
    6060
    6161        if (view->loops) {
    6262                for (i = 0; i < view->loops_nr; i++)
    63                         gfxr_free_loop(driver, view->loops + i);
     63                        gfxr_free_loop(view->loops + i);
    6464
    6565                free(view->loops);
    6666        }
     
    393393        }
    394394}
    395395
    396 void gfxr_free_pic(gfx_driver_t *driver, gfxr_pic_t *pic) {
    397         gfx_free_pixmap(driver, pic->visual_map);
    398         gfx_free_pixmap(driver, pic->priority_map);
    399         gfx_free_pixmap(driver, pic->control_map);
     396void gfxr_free_pic(gfxr_pic_t *pic) {
     397        gfx_free_pixmap(pic->visual_map);
     398        gfx_free_pixmap(pic->priority_map);
     399        gfx_free_pixmap(pic->control_map);
    400400        pic->visual_map = NULL;
    401401        pic->priority_map = NULL;
    402402        pic->control_map = NULL;
  • gfx/gfx_resource.h

     
    140140** This function allocates memory for use by resource drawer functions.
    141141*/
    142142
    143 void gfxr_free_pic(gfx_driver_t *driver, gfxr_pic_t *pic);
     143void gfxr_free_pic(gfxr_pic_t *pic);
    144144/* Uninitializes a pic resource
    145 ** Parameters: (gfx_driver_t *) driver: The driver the pic should be removed from
    146 **             (gfxr_pic_t *) pic: The pic to free
     145** Parameters: (gfxr_pic_t *) pic: The pic to free
    147146** Returns   : (void)
    148147*/
    149148
    150 void gfxr_free_view(gfx_driver_t *driver, gfxr_view_t *view);
     149void gfxr_free_view(gfxr_view_t *view);
    151150/* Frees all memory associated with a view
    152 ** Paremeters: (gfx_driver_t *) driver: The driver the view should be removed from
    153 **             (gfxr_view_t *) view: The view to free
     151** Paremeters: (gfxr_view_t *) view: The view to free
    154152** Returns   : (void)
    155153*/
    156154
  • gfx/gfx_tools.cpp

     
    8181        if (mode->palette)
    8282                mode->palette->free();
    8383        free(mode);
     84        mode = NULL;
    8485}
    8586
    8687void gfx_copy_pixmap_box_i(gfx_pixmap_t *dest, gfx_pixmap_t *src, rect_t box) {
     
    146147        return pxm;
    147148}
    148149
    149 void gfx_free_pixmap(gfx_driver_t *driver, gfx_pixmap_t *pxm) {
    150         if (driver) {
    151                 if (driver->mode->palette) {
    152                         if (pxm->palette)
    153                                 pxm->palette->free();
    154                 }
    155         }
     150void gfx_free_pixmap(gfx_pixmap_t *pxm) {
     151        if (pxm->palette)
     152                pxm->palette->free();
    156153
    157154        free(pxm->index_data);
    158155        free(pxm->alpha_map);
  • gfx/gfx_tools.h

     
    118118** Returns   : (gfx_pixmap_t *) pixmap
    119119*/
    120120
    121 void gfx_free_pixmap(gfx_driver_t *driver, gfx_pixmap_t *pxm);
     121void gfx_free_pixmap(gfx_pixmap_t *pxm);
    122122/* Frees all memory associated with a pixmap
    123 ** Parameters: (gfx_driver_t *) driver: The driver the pixmap is to be removed from
    124 **             (gfx_pixmap_t *) pxm: The pixmap to free
     123** Parameters: (gfx_pixmap_t *) pxm: The pixmap to free
    125124** Returns   : (void)
    126125*/
    127126
  • gfx/operations.cpp

     
    433433                return GFX_FATAL;
    434434        }
    435435
    436         int size;
    437         state->static_palette = gfxr_interpreter_get_static_palette(*(state->resstate->resManager), state->version, &size);
     436        state->static_palette = NULL;
    438437
     438        if (state->version < SCI_VERSION_01_VGA) {
     439                state->static_palette = gfx_sci0_pic_colors->getref();
     440        } else if (state->version == SCI_VERSION_1_1 || state->version == SCI_VERSION_32) {
     441                GFXDEBUG("Palettes are not yet supported in this SCI version\n");
     442        } else {
     443                Resource *res = state->resstate->resManager->findResource(kResourceTypePalette, 999, 0);
     444                if (res && res->data)
     445                        state->static_palette = gfxr_read_pal1(res->id, res->data, res->size);
     446        }
     447
    439448        state->visible_map = GFX_MASK_VISUAL;
    440449        state->fullscreen_override = NULL; // No magical override
    441450        gfxop_set_clip_zone(state, gfx_rect(0, 0, 320, 200));
     
    495504
    496505int gfxop_exit(gfx_state_t *state) {
    497506        BASIC_CHECKS(GFX_ERROR);
    498         gfxr_free_resource_manager(state->driver, state->resstate);
     507        gfxr_free_resource_manager(state->resstate);
    499508
    500509        if (state->control_map) {
    501                 gfx_free_pixmap(state->driver, state->control_map);
     510                gfx_free_pixmap(state->control_map);
    502511                state->control_map = NULL;
    503512        }
    504513
    505514        if (state->priority_map) {
    506                 gfx_free_pixmap(state->driver, state->priority_map);
     515                gfx_free_pixmap(state->priority_map);
    507516                state->priority_map = NULL;
    508517        }
    509518
    510519        if (state->static_priority_map) {
    511                 gfx_free_pixmap(state->driver, state->static_priority_map);
     520                gfx_free_pixmap(state->static_priority_map);
    512521                state->static_priority_map = NULL;
    513522        }
    514523
     
    11621171
    11631172        if (state->tag_mode) {
    11641173                // This usually happens after a pic and all resources have been drawn
    1165                 gfxr_free_tagged_resources(state->driver, state->resstate);
     1174                gfxr_free_tagged_resources(state->resstate);
    11661175                state->tag_mode = 0;
    11671176        }
    11681177
     
    12371246        if (nr == GFXOP_NO_POINTER)
    12381247                new_pointer = NULL;
    12391248        else {
    1240                 new_pointer = gfxr_get_cursor(state->resstate, nr);
     1249                // FIXME: the initialization of the GFX resource manager should
     1250                // be pushed up, and it shouldn't occur here
     1251                GfxResManager *_gfx = new GfxResManager(state->resstate);
     1252                new_pointer = _gfx->getCursor(nr);
     1253                delete _gfx;
    12411254
    12421255                if (!new_pointer) {
    12431256                        GFXWARN("Attempt to set invalid pointer #%d\n", nr);
     
    18481861int gfxop_new_pic(gfx_state_t *state, int nr, int flags, int default_palette) {
    18491862        BASIC_CHECKS(GFX_FATAL);
    18501863
    1851         gfxr_tag_resources(state->resstate);
     1864        // FIXME: the initialization of the GFX resource manager should
     1865        // be pushed up, and it shouldn't occur here
     1866        GfxResManager *_gfx = new GfxResManager(state->resstate);
     1867        _gfx->tagResources();
    18521868        state->tag_mode = 1;
    18531869        state->palette_nr = default_palette;
     1870        state->pic = _gfx->getPic(nr, GFX_MASK_VISUAL, flags, default_palette, true);
     1871        delete _gfx;
    18541872
    1855         state->pic = gfxr_get_pic(state->resstate, nr, GFX_MASK_VISUAL, flags, default_palette, 1);
    1856 
    1857         if (state->driver->mode->xfact == 1 && state->driver->mode->yfact == 1)
     1873        if (state->driver->mode->xfact == 1 && state->driver->mode->yfact == 1) {
    18581874                state->pic_unscaled = state->pic;
    1859         else
    1860                 state->pic_unscaled = gfxr_get_pic(state->resstate, nr, GFX_MASK_VISUAL, flags, default_palette, 0);
     1875        } else {
     1876                // FIXME: the initialization of the GFX resource manager should
     1877                // be pushed up, and it shouldn't occur here
     1878                GfxResManager *_gfx = new GfxResManager(state->resstate);
     1879                state->pic = _gfx->getPic(nr, GFX_MASK_VISUAL, flags, default_palette, false);
     1880                delete _gfx;
     1881        }
    18611882
    18621883        if (!state->pic || !state->pic_unscaled) {
    18631884                GFXERROR("Could not retrieve background pic %d!\n", nr);
     
    19041925        gfx_bitmap_font_t *font;
    19051926        BASIC_CHECKS(GFX_FATAL);
    19061927
    1907         font = gfxr_get_font(*(state->resstate->resManager), state->resstate, font_nr, 0);
     1928        // FIXME: the initialization of the GFX resource manager should
     1929        // be pushed up, and it shouldn't occur here
     1930        GfxResManager *_gfx = new GfxResManager(state->resstate);
     1931        font = _gfx->getFont(font_nr);
     1932        delete _gfx;
     1933
    19081934        if (!font)
    19091935                return GFX_ERROR;
    19101936
     
    19181944
    19191945        BASIC_CHECKS(GFX_FATAL);
    19201946
    1921         font = gfxr_get_font(*(state->resstate->resManager), state->resstate, font_nr, 0);
     1947        // FIXME: the initialization of the GFX resource manager should
     1948        // be pushed up, and it shouldn't occur here
     1949        GfxResManager *_gfx = new GfxResManager(state->resstate);
     1950        font = _gfx->getFont(font_nr);
     1951        delete _gfx;
    19221952
    19231953        if (!font) {
    19241954                GFXERROR("Attempt to calculate text size with invalid font #%d\n", font_nr);
     
    19561986                return NULL;
    19571987        }
    19581988
    1959         font = gfxr_get_font(*(state->resstate->resManager), state->resstate, font_nr, 0);
     1989        // FIXME: the initialization of the GFX resource manager should
     1990        // be pushed up, and it shouldn't occur here
     1991        GfxResManager *_gfx = new GfxResManager(state->resstate);
     1992        font = _gfx->getFont(font_nr);
     1993        delete _gfx;
    19601994
    19611995        if (!font) {
    19621996                GFXERROR("Attempt to draw text with invalid font #%d\n", font_nr);
     
    20012035                        int j;
    20022036
    20032037                        for (j = 0; j < i; j++)
    2004                                 gfx_free_pixmap(state->driver, handle->text_pixmaps[j]);
     2038                                gfx_free_pixmap(handle->text_pixmaps[j]);
    20052039
    20062040                        free(handle->text_pixmaps);
    20072041                        free(handle->text);
     
    20272061
    20282062        if (handle->text_pixmaps) {
    20292063                for (j = 0; j < handle->lines_nr; j++)
    2030                         gfx_free_pixmap(state->driver, handle->text_pixmaps[j]);
     2064                        gfx_free_pixmap(handle->text_pixmaps[j]);
    20312065                free(handle->text_pixmaps);
    20322066        }
    20332067
     
    21672201
    21682202int gfxop_free_pixmap(gfx_state_t *state, gfx_pixmap_t *pxm) {
    21692203        BASIC_CHECKS(GFX_ERROR);
    2170         gfx_free_pixmap(state->driver, pxm);
     2204        gfx_free_pixmap(pxm);
    21712205        return GFX_OK;
    21722206}
    21732207
  • gfx/resmgr.cpp

     
    4040
    4141namespace Sci {
    4242
    43 #undef TIME_PICDRAWING
    44 
    4543// Invalid hash mode: Used to invalidate modified pics
    4644#define MODE_INVALID -1
    4745
     
    6664
    6765#define FREEALL(freecmd, type) \
    6866        if (resource->scaled_data.type) \
    69                 freecmd(driver, resource->scaled_data.type); \
    70         resource->scaled_data.type = NULL; \
    71         if (resource->unscaled_data.type) \
    72                 freecmd(driver, resource->unscaled_data.type); \
    73         resource->unscaled_data.type = NULL;
    74 
    75 #define FREEALL_SIMPLE(freecmd, type) \
    76         if (resource->scaled_data.type) \
    7767                freecmd(resource->scaled_data.type); \
    7868        resource->scaled_data.type = NULL; \
    7969        if (resource->unscaled_data.type) \
    8070                freecmd(resource->unscaled_data.type); \
    8171        resource->unscaled_data.type = NULL;
    8272
    83 void gfxr_free_resource(gfx_driver_t *driver, gfx_resource_t *resource, int type) {
     73void gfxr_free_resource(gfx_resource_t *resource, int type) {
    8474        if (!resource)
    8575                return;
    8676
     
    9585                break;
    9686
    9787        case GFX_RESOURCE_TYPE_FONT:
    98                 FREEALL_SIMPLE(gfxr_free_font, font);
     88                FREEALL(gfxr_free_font, font);
    9989                break;
    10090
    10191        case GFX_RESOURCE_TYPE_CURSOR:
     
    10999        free(resource);
    110100}
    111101
    112 void gfxr_free_all_resources(gfx_driver_t *driver, gfx_resstate_t *state) {
     102void gfxr_free_all_resources(gfx_resstate_t *state) {
    113103        for (int type = 0; type < GFX_RESOURCE_TYPES_NR; ++type) {
    114104                for (IntResMap::iterator iter = state->_resourceMaps[type].begin(); iter != state->_resourceMaps[type].end(); ++iter) {
    115                         gfxr_free_resource(driver, iter->_value, type);
     105                        gfxr_free_resource(iter->_value, type);
    116106                        iter->_value = 0;
    117107                }
    118108        }
    119109}
    120110
    121 void gfxr_free_resource_manager(gfx_driver_t *driver, gfx_resstate_t *state) {
    122         gfxr_free_all_resources(driver, state);
     111void gfxr_free_resource_manager(gfx_resstate_t *state) {
     112        gfxr_free_all_resources(state);
    123113        delete state;
    124114}
    125115
    126 void gfxr_tag_resources(gfx_resstate_t *state) {
    127         (state->tag_lock_counter)++;
    128 }
    129 
    130 void gfxr_free_tagged_resources(gfx_driver_t *driver, gfx_resstate_t *state) {
     116void gfxr_free_tagged_resources(gfx_resstate_t *state) {
    131117        // Current heuristics: free tagged views and old pics
    132118
    133119        IntResMap::iterator iter;
     
    140126
    141127                if (resource) {
    142128                        if (resource->lock_sequence_nr < tmp) {
    143                                 gfxr_free_resource(driver, resource, type);
     129                                gfxr_free_resource(resource, type);
    144130                                iter->_value = 0;
    145131                        } else {
    146132                                resource->lock_sequence_nr = 0;
     
    154140
    155141                if (resource) {
    156142                        if (resource->lock_sequence_nr < 0) {
    157                                 gfxr_free_resource(driver, resource, type);
     143                                gfxr_free_resource(resource, type);
    158144                                iter->_value = 0;
    159145                        } else {
    160146                                resource->lock_sequence_nr--;
     
    191177}
    192178#undef XLATE_AS_APPROPRIATE
    193179
    194 gfxr_pic_t *gfxr_get_pic(gfx_resstate_t *state, int nr, int maps, int flags, int default_palette, int scaled) {
     180gfxr_pic_t *GfxResManager::getPic(int num, int maps, int flags, int default_palette, bool scaled) {
    195181        gfxr_pic_t *npic = NULL;
    196182        gfx_resource_type_t restype = GFX_RESOURCE_TYPE_PIC;
    197         IntResMap &resMap = state->_resourceMaps[restype];
     183        IntResMap &resMap = _state->_resourceMaps[restype];
    198184        gfx_resource_t *res = NULL;
    199         int hash = gfxr_interpreter_options_hash(restype, state->version, state->options, 0);
     185        int hash = gfxr_interpreter_options_hash(restype, _state->version, _state->options, 0);
    200186        int must_post_process_pic = 0;
    201         int need_unscaled = (state->driver->mode->xfact != 1 || state->driver->mode->yfact != 1);
     187        int need_unscaled = (_state->driver->mode->xfact != 1 || _state->driver->mode->yfact != 1);
    202188
    203189        hash |= (flags << 20) | ((default_palette & 0x7) << 28);
    204190
    205         res = resMap.contains(nr) ? resMap[nr] : NULL;
     191        res = resMap.contains(num) ? resMap[num] : NULL;
    206192
    207193        if (!res || res->mode != hash) {
    208194                gfxr_pic_t *pic;
    209195                gfxr_pic_t *unscaled_pic = NULL;
    210196
    211                 if (state->options->pic0_unscaled) {
     197                if (_state->options->pic0_unscaled) {
    212198                        need_unscaled = 0;
    213                         pic = gfxr_interpreter_init_pic(state->version, &mode_1x1_color_index, GFXR_RES_ID(restype, nr));
     199                        pic = gfxr_init_pic(&mode_1x1_color_index, GFXR_RES_ID(restype, num), _state->version >= SCI_VERSION_01_VGA);
    214200                } else
    215                         pic = gfxr_interpreter_init_pic(state->version, state->driver->mode, GFXR_RES_ID(restype, nr));
    216 
     201                        pic = gfxr_init_pic(_state->driver->mode, GFXR_RES_ID(restype, num), _state->version >= SCI_VERSION_01_VGA);
    217202                if (!pic) {
    218203                        GFXERROR("Failed to allocate scaled pic!\n");
    219204                        return NULL;
    220205                }
    221206
    222                 gfxr_interpreter_clear_pic(state->version, pic);
     207                gfxr_clear_pic0(pic, SCI_TITLEBAR_SIZE);
    223208
    224209                if (need_unscaled) {
    225                         unscaled_pic = gfxr_interpreter_init_pic(state->version, &mode_1x1_color_index, GFXR_RES_ID(restype, nr));
     210                        unscaled_pic = gfxr_init_pic(&mode_1x1_color_index, GFXR_RES_ID(restype, num), _state->version >= SCI_VERSION_01_VGA);
    226211                        if (!unscaled_pic) {
    227212                                GFXERROR("Failed to allocate unscaled pic!\n");
    228213                                return NULL;
    229214                        }
    230                         gfxr_interpreter_clear_pic(state->version, unscaled_pic);
     215                        gfxr_clear_pic0(pic, SCI_TITLEBAR_SIZE);
    231216                }
    232 #ifdef TIME_PICDRAWING
    233                 {
    234                         uint32 start_msec, end_msec;
    235                         start_msec = g_system->getMillis();
    236 #endif
    237                         if (gfxr_interpreter_calculate_pic(state, pic, unscaled_pic, flags, default_palette, nr)) {
    238                                 gfxr_free_pic(state->driver, pic);
    239                                 if (unscaled_pic)
    240                                         gfxr_free_pic(state->driver, unscaled_pic);
    241 
    242                                 return NULL;
    243                         }
    244 #ifdef TIME_PICDRAWING
    245                         end_msec = g_system->getMillis();
    246                         printf("\nTIME: %d      ms for drawing pic.%03d\n", end_msec - start_msec, nr);
     217                if (gfxr_interpreter_calculate_pic(_state, pic, unscaled_pic, flags, default_palette, num)) {
     218                        gfxr_free_pic(pic);
     219                        if (unscaled_pic)
     220                                gfxr_free_pic(unscaled_pic);
     221                        return NULL;
    247222                }
    248 #endif
    249 
    250223                if (!res) {
    251224                        res = (gfx_resource_t *)sci_malloc(sizeof(gfx_resource_t));
    252                         res->ID = GFXR_RES_ID(restype, nr);
    253                         res->lock_sequence_nr = state->options->buffer_pics_nr;
    254                         resMap[nr] = res;
     225                        res->ID = GFXR_RES_ID(restype, num);
     226                        res->lock_sequence_nr = _state->options->buffer_pics_nr;
     227                        resMap[num] = res;
    255228                } else {
    256                         gfxr_free_pic(state->driver, res->scaled_data.pic);
     229                        gfxr_free_pic(res->scaled_data.pic);
    257230                        if (res->unscaled_data.pic)
    258                                 gfxr_free_pic(state->driver, res->unscaled_data.pic);
     231                                gfxr_free_pic(res->unscaled_data.pic);
    259232                }
    260233
    261234                res->mode = hash;
    262235                res->scaled_data.pic = pic;
    263236                res->unscaled_data.pic = unscaled_pic;
    264237        } else {
    265                 res->lock_sequence_nr = state->options->buffer_pics_nr; // Update lock counter
     238                res->lock_sequence_nr = _state->options->buffer_pics_nr; // Update lock counter
    266239        }
    267240
    268241        must_post_process_pic = res->scaled_data.pic->visual_map->data == NULL;
    269242        // If the pic was only just drawn, we'll have to endianness-adjust it now
    270243
    271         npic = gfxr_pic_xlate_common(res, maps, scaled || state->options->pic0_unscaled, 0, state->driver->mode,
    272                                      state->options->pic_xlate_filter, 0, state->options);
     244        npic = gfxr_pic_xlate_common(res, maps, scaled || _state->options->pic0_unscaled, 0, _state->driver->mode,
     245                                     _state->options->pic_xlate_filter, 0, _state->options);
    273246
    274247
    275248        if (must_post_process_pic) {
    276                 gfxr_endianness_adjust(npic->visual_map, state->driver->mode);
     249                gfxr_endianness_adjust(npic->visual_map, _state->driver->mode);
    277250        }
    278251
    279252        return npic;
     
    338311        res = resMap.contains(old_nr) ? resMap[old_nr] : NULL;
    339312
    340313        if (!res || (res->mode != MODE_INVALID && res->mode != hash)) {
    341                 gfxr_get_pic(state, old_nr, 0, flags, old_default_palette, scaled);
     314                // FIXME: the initialization of the GFX resource manager should
     315                // be pushed up, and it shouldn't occur here
     316                GfxResManager *_gfx = new GfxResManager(state);
     317                _gfx->getPic(old_nr, 0, flags, old_default_palette, scaled);
     318                delete _gfx;
    342319
    343320                res = resMap.contains(old_nr) ? resMap[old_nr] : NULL;
    344321
     
    398375                        res->mode = hash;
    399376                        resMap[nr] = res;
    400377                } else {
    401                         gfxr_free_view(state->driver, res->unscaled_data.view);
     378                        gfxr_free_view(res->unscaled_data.view);
    402379                }
    403380
    404381                res->mode = hash;
     
    453430        return view;
    454431}
    455432
    456 gfx_bitmap_font_t *gfxr_get_font(ResourceManager& resourceManager, gfx_resstate_t *state, int nr, int scaled) {
     433gfx_bitmap_font_t *GfxResManager::getFont(int num, bool scaled) {
    457434        gfx_resource_type_t restype = GFX_RESOURCE_TYPE_FONT;
    458         IntResMap &resMap = state->_resourceMaps[restype];
     435        IntResMap &resMap = _state->_resourceMaps[restype];
    459436        gfx_resource_t *res = NULL;
    460437        int hash;
    461438
    462         hash = gfxr_interpreter_options_hash(restype, state->version, state->options, 0);
     439        hash = gfxr_interpreter_options_hash(restype, _state->version, _state->options, 0);
    463440
    464         res = resMap.contains(nr) ? resMap[nr] : NULL;
     441        res = resMap.contains(num) ? resMap[num] : NULL;
    465442
    466443        if (!res || res->mode != hash) {
    467                 gfx_bitmap_font_t *font = gfxr_interpreter_get_font(resourceManager, nr);
    468 
    469                 if (!font)
     444                Resource *fontRes = _state->resManager->findResource(kResourceTypeFont, num, 0);
     445                if (!fontRes || !fontRes->data)
    470446                        return NULL;
    471447
     448                gfx_bitmap_font_t *font = gfxr_read_font(fontRes->id, fontRes->data, fontRes->size);
     449
    472450                if (!res) {
    473451                        res = (gfx_resource_t *)sci_malloc(sizeof(gfx_resource_t));
    474452                        res->scaled_data.font = NULL;
    475                         res->ID = GFXR_RES_ID(restype, nr);
    476                         res->lock_sequence_nr = state->tag_lock_counter;
     453                        res->ID = GFXR_RES_ID(restype, num);
     454                        res->lock_sequence_nr = _state->tag_lock_counter;
    477455                        res->mode = hash;
    478                         resMap[nr] = res;
     456                        resMap[num] = res;
    479457                } else {
    480458                        gfxr_free_font(res->unscaled_data.font);
    481459                }
     
    484462
    485463                return font;
    486464        } else {
    487                 res->lock_sequence_nr = state->tag_lock_counter; // Update lock counter
     465                res->lock_sequence_nr = _state->tag_lock_counter; // Update lock counter
    488466                if (res->unscaled_data.pointer)
    489467                        return res->unscaled_data.font;
    490468                else
     
    492470        }
    493471}
    494472
    495 gfx_pixmap_t *gfxr_get_cursor(gfx_resstate_t *state, int nr) {
     473gfx_pixmap_t *GfxResManager::getCursor(int num) {
    496474        gfx_resource_type_t restype = GFX_RESOURCE_TYPE_CURSOR;
    497         IntResMap &resMap = state->_resourceMaps[restype];
     475        IntResMap &resMap = _state->_resourceMaps[restype];
    498476        gfx_resource_t *res = NULL;
    499         int hash = gfxr_interpreter_options_hash(restype, state->version, state->options, 0);
     477        int hash = gfxr_interpreter_options_hash(restype, _state->version, _state->options, 0);
    500478
    501         res = resMap.contains(nr) ? resMap[nr] : NULL;
     479        res = resMap.contains(num) ? resMap[num] : NULL;
    502480
    503481        if (!res || res->mode != hash) {
    504                 gfx_pixmap_t *cursor = gfxr_interpreter_get_cursor(*(state->resManager), nr, state->version);
     482                Resource *cursorRes = _state->resManager->findResource(kResourceTypeCursor, num, 0);
     483                if (!cursorRes || !cursorRes->data)
     484                        return NULL;
    505485
     486                if (_state->version >= SCI_VERSION_1_1) {
     487                        GFXWARN("Attempt to retrieve cursor in SCI1.1 or later\n");
     488                        return NULL;
     489                }
     490
     491                gfx_pixmap_t *cursor = gfxr_draw_cursor(GFXR_RES_ID(GFX_RESOURCE_TYPE_CURSOR, num),
     492                                                                                cursorRes->data, cursorRes->size, _state->version != SCI_VERSION_0);
     493
    506494                if (!cursor)
    507495                        return NULL;
    508496
    509497                if (!res) {
    510498                        res = (gfx_resource_t *)sci_malloc(sizeof(gfx_resource_t));
    511499                        res->scaled_data.pointer = NULL;
    512                         res->ID = GFXR_RES_ID(restype, nr);
    513                         res->lock_sequence_nr = state->tag_lock_counter;
     500                        res->ID = GFXR_RES_ID(restype, num);
     501                        res->lock_sequence_nr = _state->tag_lock_counter;
    514502                        res->mode = hash;
    515                         resMap[nr] = res;
     503                        resMap[num] = res;
    516504                } else {
    517                         gfx_free_pixmap(state->driver, res->unscaled_data.pointer);
     505                        gfx_free_pixmap(res->unscaled_data.pointer);
    518506                }
    519                 gfx_get_res_config(state->options, cursor);
    520                 gfx_xlate_pixmap(cursor, state->driver->mode, state->options->cursor_xlate_filter);
    521                 gfxr_endianness_adjust(cursor, state->driver->mode);
     507                gfx_get_res_config(_state->options, cursor);
     508                gfx_xlate_pixmap(cursor, _state->driver->mode, _state->options->cursor_xlate_filter);
     509                gfxr_endianness_adjust(cursor, _state->driver->mode);
    522510
    523511                res->unscaled_data.pointer = cursor;
    524512
    525513                return cursor;
    526514        } else {
    527                 res->lock_sequence_nr = state->tag_lock_counter; // Update lock counter
     515                res->lock_sequence_nr = _state->tag_lock_counter; // Update lock counter
    528516                return res->unscaled_data.pointer;
    529517        }
    530518}
  • gfx/resource/res_manager.cpp

     
    4949                               | (options->pic0_dither_pattern << 8) | (options->pic0_brush_mode << 4) | (options->pic0_line_mode);
    5050
    5151        case GFX_RESOURCE_TYPE_FONT:
    52                 return 0;
    53 
    5452        case GFX_RESOURCE_TYPE_CURSOR:
    5553                return 0;
    5654
     
    6159        }
    6260}
    6361
    64 gfxr_pic_t *gfxr_interpreter_init_pic(int version, gfx_mode_t *mode, int ID) {
    65         return gfxr_init_pic(mode, ID, version >= SCI_VERSION_01_VGA);
    66 }
    67 
    68 void gfxr_interpreter_clear_pic(int version, gfxr_pic_t *pic) {
    69         gfxr_clear_pic0(pic, SCI_TITLEBAR_SIZE);
    70 }
    71 
    7262int gfxr_interpreter_calculate_pic(gfx_resstate_t *state, gfxr_pic_t *scaled_pic, gfxr_pic_t *unscaled_pic,
    7363        int flags, int default_palette, int nr) {
    7464        ResourceManager& resourceManager = *(state->resManager);
     
    152142
    153143        if (version < SCI_VERSION_01) palette = -1;
    154144
    155         switch (version) {
    156         case SCI_VERSION_0:
    157         case SCI_VERSION_01:
     145        if (version <= SCI_VERSION_01)
    158146                result = gfxr_draw_view0(resid, res->data, res->size, palette);
    159                 break;
    160         case SCI_VERSION_01_VGA:
    161         case SCI_VERSION_01_VGA_ODD:
    162         case SCI_VERSION_1_EARLY:
    163         case SCI_VERSION_1_LATE:
     147        else if (version >= SCI_VERSION_01_VGA && version <= SCI_VERSION_1_LATE)
    164148                result = gfxr_draw_view1(resid, res->data, res->size, staticPalette);
    165                 break;
    166         case SCI_VERSION_1_1:
    167         case SCI_VERSION_32:
     149        else if (version >= SCI_VERSION_1_1)
    168150                result = gfxr_draw_view11(resid, res->data, res->size);
    169                 break;
    170         }
    171151
    172152        if (version >= SCI_VERSION_01_VGA) {
    173153                if (!result->palette) {
     
    179159        return result;
    180160}
    181161
    182 gfx_bitmap_font_t *gfxr_interpreter_get_font(ResourceManager& resourceManager, int nr) {
    183         Resource *res = resourceManager.findResource(kResourceTypeFont, nr, 0);
    184         if (!res || !res->data)
    185                 return NULL;
    186 
    187         return gfxr_read_font(res->id, res->data, res->size);
    188 }
    189 
    190 gfx_pixmap_t *gfxr_interpreter_get_cursor(ResourceManager& resourceManager, int nr, int version) {
    191         Resource *res = resourceManager.findResource(kResourceTypeCursor, nr, 0);
    192         int resid = GFXR_RES_ID(GFX_RESOURCE_TYPE_CURSOR, nr);
    193 
    194         if (!res || !res->data)
    195                 return NULL;
    196 
    197         if (version >= SCI_VERSION_1_1) {
    198                 GFXWARN("Attempt to retrieve cursor in SCI1.1 or later\n");
    199                 return NULL;
    200         }
    201 
    202         return gfxr_draw_cursor(resid, res->data, res->size, version != SCI_VERSION_0);
    203 }
    204 
    205 Palette *gfxr_interpreter_get_static_palette(ResourceManager& resourceManager, int version, int *colors_nr) {
    206         if (version >= SCI_VERSION_01_VGA)
    207                 return gfxr_interpreter_get_palette(resourceManager, version, colors_nr, 999);
    208 
    209         *colors_nr = GFX_SCI0_PIC_COLORS_NR;
    210         return gfx_sci0_pic_colors->getref();
    211 }
    212 
    213 Palette *gfxr_interpreter_get_palette(ResourceManager& resourceManager, int version, int *colors_nr, int nr) {
    214         Resource *res;
    215 
    216         if (version < SCI_VERSION_01_VGA)
    217                 return NULL;
    218 
    219         res = resourceManager.findResource(kResourceTypePalette, nr, 0);
    220         if (!res || !res->data)
    221                 return NULL;
    222 
    223         switch (version) {
    224         case SCI_VERSION_01_VGA :
    225         case SCI_VERSION_01_VGA_ODD :
    226         case SCI_VERSION_1_EARLY :
    227         case SCI_VERSION_1_LATE :
    228                 return gfxr_read_pal1(res->id, res->data, res->size);
    229         case SCI_VERSION_1_1 :
    230         case SCI_VERSION_32 :
    231                 GFXDEBUG("Palettes are not yet supported in this SCI version\n");
    232                 return NULL;
    233 
    234         default:
    235                 BREAKPOINT();
    236                 return NULL;
    237         }
    238 }
    239 
    240 int gfxr_interpreter_needs_multicolored_pointers(int version) {
    241         return (version > SCI_VERSION_1);
    242 }
    243 
    244162} // End of namespace Sci
  • gfx/resource/res_pic.cpp

     
    16951695                                // Set up mode structure for resizing the view
    16961696                                Graphics::PixelFormat format = { 1, 0, 0, 0, 0, 0, 0, 0, 0 }; // 1byte/p, which handles masks and the rest for us
    16971697                                gfx_mode_t *mode = gfx_new_mode(pic->visual_map->index_width / 320,
    1698                                            pic->visual_map->index_height / 200, format, view->palette, 0);
     1698                                           pic->visual_map->index_height / 200, format, view->palette->getref(), 0);
    16991699
    17001700                                gfx_xlate_pixmap(view, mode, GFX_XLATE_FILTER_NONE);
    17011701                                gfx_free_mode(mode);
     
    17081708                                                      view->index_data, pic->visual_map->index_width, view->index_width,
    17091709                                                      view->index_width, view->index_height, 1);
    17101710
    1711                                 gfx_free_pixmap(NULL, view);
     1711                                gfx_free_pixmap(view);
     1712                                view = NULL;
    17121713                        }
    17131714                        goto end_op_loop;
    17141715
     
    17951796
    17961797                // Set up mode structure for resizing the view
    17971798                Graphics::PixelFormat format = { 1, 0, 0, 0, 0, 0, 0, 0, 0 }; // 1 byte/p, which handles masks and the rest for us
    1798                 gfx_mode_t *mode = gfx_new_mode(pic->visual_map->index_width / 320, pic->visual_map->index_height / 200, format, view->palette, 0);
     1799                gfx_mode_t *mode = gfx_new_mode(pic->visual_map->index_width / 320, pic->visual_map->index_height / 200, format, view->palette->getref(), 0);
    17991800
    18001801                gfx_xlate_pixmap(view, mode, GFX_XLATE_FILTER_NONE);
    18011802                gfx_free_mode(mode);
  • gfx/resource/res_view0.cpp

     
    5757        }
    5858
    5959        if (xl <= 0 || yl <= 0) {
    60                 gfx_free_pixmap(NULL, retval);
     60                gfx_free_pixmap(retval);
    6161                GFXERROR("View %02x:(%d/%d) has invalid xl=%d or yl=%d\n", id, loop, cel, xl, yl);
    6262                return NULL;
    6363        }
     
    218218                if (error_token || gfxr_draw_loop0(view->loops + i, id, i, resource, loop_offset, size, view, mirrored)) {
    219219                        // An error occured
    220220                        view->loops_nr = i;
    221                         gfxr_free_view(NULL, view);
     221                        gfxr_free_view(view);
    222222                        return NULL;
    223223                }
    224224        }
  • gfx/resource/res_view1.cpp

     
    246246
    247247        if (view)
    248248                retval->palette = view->palette->getref();
     249        else
     250                retval->palette = NULL;
    249251
    250252        if (xl <= 0 || yl <= 0) {
    251                 gfx_free_pixmap(NULL, retval);
     253                gfx_free_pixmap(retval);
    252254                GFXERROR("View %02x:(%d/%d) has invalid xl=%d or yl=%d\n", id, loop, cel, xl, yl);
    253255                return NULL;
    254256        }
     
    261263                                                        pos, xl, yl, retval->color_key);
    262264
    263265        if (decompress_failed) {
    264                 gfx_free_pixmap(NULL, retval);
     266                gfx_free_pixmap(retval);
    265267                return NULL;
    266268        }
    267269
     
    381383                if (error_token || gfxr_draw_loop1(view->loops + i, id, i, mirror_mask & (1 << i), resource, loop_offset, size, view, amiga_game)) {
    382384                        // An error occured
    383385                        view->loops_nr = i;
    384                         gfxr_free_view(NULL, view);
     386                        gfxr_free_view(view);
    385387                        return NULL;
    386388                }
    387389        }
     
    429431                retval->palette = view->palette->getref();
    430432
    431433        if (xl <= 0 || yl <= 0) {
    432                 gfx_free_pixmap(NULL, retval);
     434                gfx_free_pixmap(retval);
    433435                GFXERROR("View %02x:(%d/%d) has invalid xl=%d or yl=%d\n", id, loop, cel, xl, yl);
    434436                return NULL;
    435437        }
     
    438440                                                runlength_offset, literal_offset, xl, yl, retval->color_key);
    439441
    440442        if (decompress_failed) {
    441                 gfx_free_pixmap(NULL, retval);
     443                gfx_free_pixmap(retval);
    442444                return NULL;
    443445        }
    444446