diff options
author | Filippos Karapetis | 2009-10-06 12:26:13 +0000 |
---|---|---|
committer | Filippos Karapetis | 2009-10-06 12:26:13 +0000 |
commit | df29b0067e100e97f29d286178685257816f0972 (patch) | |
tree | fcd50174daca7557431c8cb01c0233950bef4f1d /engines/sci/gfx | |
parent | 8e108cc0a0c76814ac533c51b361737ba5e8c867 (diff) | |
download | scummvm-rg350-df29b0067e100e97f29d286178685257816f0972.tar.gz scummvm-rg350-df29b0067e100e97f29d286178685257816f0972.tar.bz2 scummvm-rg350-df29b0067e100e97f29d286178685257816f0972.zip |
- Unified the screen buffers that are used by the current and the new GUI
- Replaced the FreeSCI line drawing code (which is actually Bresenham) with Graphics::drawLine(), after discussing with waltervn. This shouldn't bring any regressions, as we're no longer offering the option to scale the background at a vector level. After playing through some of the games, I haven't noticed any regressions
- Some cleanup
svn-id: r44692
Diffstat (limited to 'engines/sci/gfx')
-rw-r--r-- | engines/sci/gfx/gfx_driver.cpp | 100 | ||||
-rw-r--r-- | engines/sci/gfx/gfx_driver.h | 9 | ||||
-rw-r--r-- | engines/sci/gfx/gfx_resmgr.cpp | 1 | ||||
-rw-r--r-- | engines/sci/gfx/gfx_resource.h | 1 | ||||
-rw-r--r-- | engines/sci/gfx/gfx_support.cpp | 75 | ||||
-rw-r--r-- | engines/sci/gfx/gfx_tools.cpp | 7 | ||||
-rw-r--r-- | engines/sci/gfx/gfx_tools.h | 5 | ||||
-rw-r--r-- | engines/sci/gfx/operations.cpp | 4 | ||||
-rw-r--r-- | engines/sci/gfx/operations.h | 5 | ||||
-rw-r--r-- | engines/sci/gfx/res_pic.cpp | 5 |
10 files changed, 67 insertions, 145 deletions
diff --git a/engines/sci/gfx/gfx_driver.cpp b/engines/sci/gfx/gfx_driver.cpp index ccf15f3e30..1d8eb6f01f 100644 --- a/engines/sci/gfx/gfx_driver.cpp +++ b/engines/sci/gfx/gfx_driver.cpp @@ -30,50 +30,23 @@ #include "graphics/surface.h" #include "sci/sci.h" +#include "sci/gui/gui_screen.h" #include "sci/gfx/gfx_driver.h" #include "sci/gfx/gfx_tools.h" +#include "sci/gui/gui_screen.h" namespace Sci { -GfxDriver::GfxDriver(int xfact, int yfact) { - int i; - - _mode = gfx_new_mode(xfact, yfact, new Palette(256)); - _mode->xsize = xfact * 320; - _mode->ysize = yfact * 200; - for (i = 0; i < 2; i++) { - _priority[i] = gfx_pixmap_alloc_index_data(gfx_new_pixmap(_mode->xsize, _mode->ysize, GFX_RESID_NONE, -i, -777)); - if (!_priority[i]) { - error("Out of memory: Could not allocate priority maps! (%dx%d)\n", _mode->xsize, _mode->ysize); - } - } - // create the visual buffers - for (i = 0; i < 2; i++) { - _visual[i] = NULL; - _visual[i] = new byte[_mode->xsize * _mode->ysize]; - if (!_visual[i]) { - error("Out of memory: Could not allocate visual buffers! (%dx%d)\n", _mode->xsize, _mode->ysize); - } - memset(_visual[i], 0, _mode->xsize * _mode->ysize); - } +GfxDriver::GfxDriver(SciGuiScreen *screen, int scaleFactor) : _screen(screen) { + _mode = gfx_new_mode(scaleFactor, new Palette(256)); if (_mode->palette) _mode->palette->name = "global"; } GfxDriver::~GfxDriver() { - int i; - for (i = 0; i < 2; i++) { - gfx_free_pixmap(_priority[i]); - _priority[i] = NULL; - } - - for (i = 0; i < 2; i++) { - delete[] _visual[i]; - _visual[i] = NULL; - } } @@ -81,9 +54,16 @@ GfxDriver::~GfxDriver() { static void drawProc(int x, int y, int c, void *data) { GfxDriver *drv = (GfxDriver *)data; - byte *p = drv->getVisual0(); + byte *p = drv->_screen->_displayScreen; uint8 col = c; - memcpy(p + (y * 320* drv->getMode()->scaleFactor + x), &col, 1); + memcpy(p + (y * drv->_screen->_width * drv->getMode()->scaleFactor + x), &col, 1); +} + +static void drawProcPriority(int x, int y, int c, void *data) { + GfxDriver *drv = (GfxDriver *)data; + byte *p = drv->_screen->_priorityScreen; + uint8 col = c; + memcpy(p + (y * drv->_screen->_width + x), &col, 1); } void GfxDriver::drawLine(Common::Point start, Common::Point end, gfx_color_t color, @@ -107,7 +87,7 @@ void GfxDriver::drawLine(Common::Point start, Common::Point end, gfx_color_t col Graphics::drawLine(nstart.x, nstart.y, nend.x, nend.y, scolor, drawProc, this); if (color.mask & GFX_MASK_PRIORITY) { - gfx_draw_line_pixmap_i(_priority[0], nstart, nend, color.priority); + Graphics::drawLine(nstart.x, nstart.y, nend.x, nend.y, color.priority, drawProcPriority, this); } } } @@ -118,29 +98,31 @@ void GfxDriver::drawFilledRect(rect_t rect, gfx_color_t color1, gfx_color_t colo gfx_rectangle_fill_t shade_mode) { if (color1.mask & GFX_MASK_VISUAL) { for (int i = rect.y; i < rect.y + rect.height; i++) { - memset(_visual[0] + (i * _mode->xsize + rect.x), + memset(_screen->_displayScreen + (i * _mode->xsize + rect.x), color1.visual.getParentIndex(), rect.width); } } - if (color1.mask & GFX_MASK_PRIORITY) - gfx_draw_box_pixmap_i(_priority[0], rect, color1.priority); + if (color1.mask & GFX_MASK_PRIORITY) { + gfx_clip_box_basic(&rect, _screen->_width - 1, _screen->_height - 1); + gfx_draw_box_buffer(_screen->_priorityScreen, _screen->_width, rect, color1.priority); + } } // Pixmap operations void GfxDriver::drawPixmap(gfx_pixmap_t *pxm, int priority, rect_t src, rect_t dest, gfx_buffer_t buffer) { - int bufnr = (buffer == GFX_BUFFER_STATIC) ? 1 : 0; - + byte *destBuffer = (buffer == GFX_BUFFER_STATIC) ? _screen->_visualScreen : _screen->_displayScreen; + byte *destPriority = (buffer == GFX_BUFFER_STATIC) ? _screen->_controlScreen : _screen->_priorityScreen; if (dest.width != src.width || dest.height != src.height) { warning("Attempt to scale pixmap (%dx%d)->(%dx%d): Not supported\n", src.width, src.height, dest.width, dest.height); return; } - gfx_crossblit_pixmap(_mode, pxm, priority, src, dest, _visual[bufnr], + gfx_crossblit_pixmap(_mode, pxm, priority, src, dest, destBuffer, _mode->xsize, - _priority[bufnr]->index_data, - _priority[bufnr]->index_width, 1, 0); + destPriority, + _screen->_width, 1, 0); } void GfxDriver::grabPixmap(rect_t src, gfx_pixmap_t *pxm, gfx_map_mask_t map) { @@ -157,7 +139,7 @@ void GfxDriver::grabPixmap(rect_t src, gfx_pixmap_t *pxm, gfx_map_mask_t map) { pxm->height = src.height; for (int i = 0; i < src.height; i++) { memcpy(pxm->data + i * src.width, - _visual[0] + ((i + src.y) * _mode->xsize + src.x), + _screen->_displayScreen + ((i + src.y) * _mode->xsize + src.x), src.width); } break; @@ -174,28 +156,26 @@ void GfxDriver::grabPixmap(rect_t src, gfx_pixmap_t *pxm, gfx_map_mask_t map) { // Buffer operations void GfxDriver::update(rect_t src, Common::Point dest, gfx_buffer_t buffer) { - //TODO - - /* - if (src.x != dest.x || src.y != dest.y) { - printf("Updating %d (%d,%d)(%dx%d) to (%d,%d) on %d\n", buffer, src.x, src.y, src.width, src.height, dest.x, dest.y, data_dest); - } else { - printf("Updating %d (%d,%d)(%dx%d) to %d\n", buffer, src.x, src.y, src.width, src.height, data_dest); - } - */ - switch (buffer) { case GFX_BUFFER_BACK: for (int i = 0; i < src.height; i++) { - memcpy(_visual[0] + ( (dest.y + i) * _mode->xsize + dest.x), - _visual[1] + ( (src.y + i) * _mode->xsize + src.x), src.width ); + memcpy(_screen->_displayScreen + ( (dest.y + i) * _mode->xsize + dest.x), + _screen->_visualScreen + ( (src.y + i) * _mode->xsize + src.x), src.width ); } - if ((src.x == dest.x) && (src.y == dest.y)) - gfx_copy_pixmap_box_i(_priority[0], _priority[1], src); + if ((src.x == dest.x) && (src.y == dest.y)) { + int offset = src.x + (src.y * _screen->_width); + + gfx_clip_box_basic(&src, _screen->_width, _screen->_height); + + while (src.height--) { + memcpy(_screen->_priorityScreen + offset, _screen->_controlScreen + offset, _screen->_width); + offset += _screen->_width; + } + } break; case GFX_BUFFER_FRONT: { - g_system->copyRectToScreen(_visual[0] + (src.x + src.y * _mode->xsize), _mode->xsize, dest.x, dest.y, src.width, src.height); + g_system->copyRectToScreen(_screen->_displayScreen + (src.x + src.y * _mode->xsize), _mode->xsize, dest.x, dest.y, src.width, src.height); g_system->updateScreen(); break; } @@ -205,8 +185,8 @@ void GfxDriver::update(rect_t src, Common::Point dest, gfx_buffer_t buffer) { } void GfxDriver::setStaticBuffer(gfx_pixmap_t *pic, gfx_pixmap_t *priority) { - memcpy(_visual[1], pic->data, _mode->xsize * _mode->ysize); - gfx_copy_pixmap_box_i(_priority[1], priority, gfx_rect(0, 0, _mode->xsize, _mode->ysize)); + memcpy(_screen->_visualScreen, pic->data, _mode->xsize * _mode->ysize); + memcpy(_screen->_controlScreen, priority->index_data, _mode->xsize * _mode->ysize); } // Mouse pointer operations diff --git a/engines/sci/gfx/gfx_driver.h b/engines/sci/gfx/gfx_driver.h index 1143d8e66d..19cd2f314f 100644 --- a/engines/sci/gfx/gfx_driver.h +++ b/engines/sci/gfx/gfx_driver.h @@ -29,8 +29,6 @@ #include "sci/gfx/gfx_system.h" #include "sci/uinput.h" -#include "graphics/pixelformat.h" - namespace Sci { enum gfx_buffer_t { @@ -85,7 +83,7 @@ public: * not be set, or GFX_FATAL if the graphics target * is unuseable. */ - GfxDriver(int xfact, int yfact); + GfxDriver(SciGuiScreen *screen, int scaleFactor); /** * Uninitializes the current graphics mode. @@ -226,16 +224,15 @@ public: /** @} */ gfx_mode_t *getMode() { return _mode; } - byte *getVisual0() { return _visual[0]; } /** * Animates palette */ void animatePalette(int fromColor, int toColor, int stepCount); +public: // temporary hack + SciGuiScreen *_screen; private: - gfx_pixmap_t *_priority[2]; - byte *_visual[2]; gfx_mode_t *_mode; /**< Currently active mode, NULL if no mode is active */ }; diff --git a/engines/sci/gfx/gfx_resmgr.cpp b/engines/sci/gfx/gfx_resmgr.cpp index f81f9e0dc1..ad1172fefc 100644 --- a/engines/sci/gfx/gfx_resmgr.cpp +++ b/engines/sci/gfx/gfx_resmgr.cpp @@ -32,6 +32,7 @@ #include "sci/sci.h" #include "sci/gfx/gfx_resource.h" #include "sci/gfx/gfx_tools.h" +#include "sci/gui/gui_screen.h" #include "sci/gfx/gfx_driver.h" #include "sci/gfx/gfx_resmgr.h" #include "sci/gfx/gfx_state_internal.h" diff --git a/engines/sci/gfx/gfx_resource.h b/engines/sci/gfx/gfx_resource.h index 753e966dd6..0bb5265bdf 100644 --- a/engines/sci/gfx/gfx_resource.h +++ b/engines/sci/gfx/gfx_resource.h @@ -31,6 +31,7 @@ #define SCI_GFX_GFX_RESOURCE_H #include "sci/gfx/gfx_system.h" +#include "sci/gui/gui_screen.h" #include "sci/gfx/gfx_driver.h" #include "common/rect.h" diff --git a/engines/sci/gfx/gfx_support.cpp b/engines/sci/gfx/gfx_support.cpp index fa3b94835a..2529fde35b 100644 --- a/engines/sci/gfx/gfx_support.cpp +++ b/engines/sci/gfx/gfx_support.cpp @@ -30,78 +30,19 @@ #include "sci/gfx/gfx_system.h" #include "sci/gfx/gfx_tools.h" -namespace Sci { - -#define LINEMACRO(startx, starty, deltalinear, deltanonlinear, linearvar, nonlinearvar, \ - linearend, nonlinearstart, linearmod, nonlinearmod) \ - incrNE = ((deltalinear) > 0) ? (deltalinear) : -(deltalinear); \ - incrNE <<= 1; \ - deltanonlinear <<= 1; \ - incrE = ((deltanonlinear) > 0) ? -(deltanonlinear) : (deltanonlinear); \ - d = nonlinearstart - 1; \ - while (linearvar != (linearend)) { \ - memcpy(buffer + linewidth * (starty) + (startx), &color, PIXELWIDTH); \ - linearvar += linearmod; \ - if ((d += incrE) < 0) { \ - d += incrNE; \ - nonlinearvar += nonlinearmod; \ - }; \ - }; \ - memcpy(buffer + linewidth * (starty) + (startx), &color, PIXELWIDTH); - - -template <int PIXELWIDTH> -void _gfx_draw_line_buffer(byte *buffer, int linewidth, Common::Point start, Common::Point end, unsigned int color) { - int incrE, incrNE, d; - int dx = ABS(end.x - start.x); - int dy = ABS(end.y - start.y); -#ifdef SCUMM_BIG_ENDIAN - color = SWAP_BYTES_32(color); -#endif +#include "graphics/primitives.h" - if (dx > dy) { - int sign1 = (end.x < start.x) ? -1 : 1; - int sign2 = (end.y < start.y) ? -1 : 1; - LINEMACRO(start.x, start.y, dx, dy, start.x, start.y, end.x, dx, sign1 * PIXELWIDTH, sign2); - } else { // dx <= dy - int sign1 = (end.y < start.y) ? -1 : 1; - int sign2 = (end.x < start.x) ? -1 : 1; - LINEMACRO(start.x, start.y, dy, dx, start.y, start.x, end.y, dy, sign1, sign2 * PIXELWIDTH); - } -} - -#undef LINEMACRO - - -static void gfx_draw_line_buffer(byte *buffer, int linewidth, int pixelwidth, - Common::Point start, Common::Point end, unsigned int color) { - switch (pixelwidth) { - - case 1: - _gfx_draw_line_buffer<1>(buffer, linewidth, start, end, color); - return; - - case 2: - _gfx_draw_line_buffer<2>(buffer, linewidth, start, end, color); - return; - - case 3: - _gfx_draw_line_buffer<3>(buffer, linewidth, start, end, color); - return; - - case 4: - _gfx_draw_line_buffer<4>(buffer, linewidth, start, end, color); - return; - - default: - error("pixelwidth=%d not supported", pixelwidth); - return; +namespace Sci { - } +static void drawProc(int x, int y, int c, void *data) { + gfx_pixmap_t *pxm = (gfx_pixmap_t *)data; + byte *p = pxm->index_data; + uint8 col = c; + memcpy(p + (y * pxm->index_width + x), &col, 1); } void gfx_draw_line_pixmap_i(gfx_pixmap_t *pxm, Common::Point start, Common::Point end, int color) { - gfx_draw_line_buffer(pxm->index_data, pxm->index_width, 1, start, end, color); + Graphics::drawLine(start.x, start.y, end.x, end.y, color, drawProc, pxm); } void gfx_draw_box_buffer(byte *buffer, int linewidth, rect_t zone, int color) { diff --git a/engines/sci/gfx/gfx_tools.cpp b/engines/sci/gfx/gfx_tools.cpp index 5df8f4a97c..290759374b 100644 --- a/engines/sci/gfx/gfx_tools.cpp +++ b/engines/sci/gfx/gfx_tools.cpp @@ -43,11 +43,12 @@ void gfx_clip_box_basic(rect_t *box, int maxx, int maxy) { box->height = maxy - box->y + 1; } -gfx_mode_t *gfx_new_mode(int xfact, int yfact, Palette *palette) { +gfx_mode_t *gfx_new_mode(int scaleFactor, Palette *palette) { gfx_mode_t *mode = (gfx_mode_t *)malloc(sizeof(gfx_mode_t)); - mode->scaleFactor = xfact; - mode->scaleFactor = yfact; + mode->scaleFactor = scaleFactor; + mode->xsize = scaleFactor * 320; + mode->ysize = scaleFactor * 200; mode->palette = palette; return mode; diff --git a/engines/sci/gfx/gfx_tools.h b/engines/sci/gfx/gfx_tools.h index 0abf5e26e7..6de6b81afc 100644 --- a/engines/sci/gfx/gfx_tools.h +++ b/engines/sci/gfx/gfx_tools.h @@ -29,6 +29,7 @@ #include "graphics/pixelformat.h" #include "sci/gfx/gfx_system.h" +#include "sci/gui/gui_screen.h" #include "sci/gfx/gfx_driver.h" namespace Sci { @@ -44,7 +45,7 @@ namespace Sci { * @param[in] palette Number of palette colors, 0 if we're not in palette mode * @return A newly allocated gfx_mode_t structure */ -gfx_mode_t *gfx_new_mode(int xfact, int yfact, Palette *palette); +gfx_mode_t *gfx_new_mode(int scaleFactor, Palette *palette); /** * Clips a rect_t @@ -154,6 +155,8 @@ void gfx_draw_line_pixmap_i(gfx_pixmap_t *pxm, Common::Point start, */ void gfx_draw_box_pixmap_i(gfx_pixmap_t *pxm, rect_t box, int color); +void gfx_draw_box_buffer(byte *buffer, int linewidth, rect_t zone, int color); + /** * Copies part of a pixmap to another pixmap, with clipping * diff --git a/engines/sci/gfx/operations.cpp b/engines/sci/gfx/operations.cpp index 65fdfc1de7..8e6db7895a 100644 --- a/engines/sci/gfx/operations.cpp +++ b/engines/sci/gfx/operations.cpp @@ -386,7 +386,7 @@ static void init_aux_pixmap(gfx_pixmap_t **pixmap) { void gfxop_init(GfxState *state, gfx_options_t *options, ResourceManager *resMan, - int xfact, int yfact) { + SciGuiScreen *screen, int scaleFactor) { state->options = options; state->visible_map = GFX_MASK_VISUAL; state->fullscreen_override = NULL; // No magical override @@ -399,7 +399,7 @@ void gfxop_init(GfxState *state, state->pic_port_bounds = gfx_rect(0, 10, 320, 190); state->_dirtyRects.clear(); - state->driver = new GfxDriver(xfact, yfact); + state->driver = new GfxDriver(screen, scaleFactor); state->gfxResMan = new GfxResManager(state->options, state->driver, resMan); diff --git a/engines/sci/gfx/operations.h b/engines/sci/gfx/operations.h index f20bbf176a..84dace4394 100644 --- a/engines/sci/gfx/operations.h +++ b/engines/sci/gfx/operations.h @@ -136,15 +136,14 @@ struct GfxState { * Initializes a graphics mode. * * @param[in] state The state to initialize - * @param[in] xfact Horizontal scale factor - * @param[in] yfact Vertical scale factors + * @param[in] scaleFactor Scale factor * @param[in] mode Graphics mode to use * @param[in] options Rendering options * @param[in] resMan Resource manager to use */ void gfxop_init(GfxState *state, gfx_options_t *options, ResourceManager *resMan, - int xfact = 1, int yfact = 1); + SciGuiScreen *screen, int scaleFactor = 1); /** * Deinitializes a currently active driver. diff --git a/engines/sci/gfx/res_pic.cpp b/engines/sci/gfx/res_pic.cpp index cb628b94ef..0196ad57a4 100644 --- a/engines/sci/gfx/res_pic.cpp +++ b/engines/sci/gfx/res_pic.cpp @@ -1485,8 +1485,7 @@ void gfxr_draw_pic01(gfxr_pic_t *pic, int flags, int default_palette, int size, view->index_height = CLIP<int>(view->index_height, 0, portBounds.height()); // Set up mode structure for resizing the view - gfx_mode_t *mode = gfx_new_mode(pic->visual_map->index_width / 320, - pic->visual_map->index_height / 200, view->palette); + gfx_mode_t *mode = gfx_new_mode(pic->visual_map->index_width / 320, view->palette); gfx_xlate_pixmap(view, mode); gfx_free_mode(mode); @@ -1590,7 +1589,7 @@ void gfxr_draw_pic11(gfxr_pic_t *pic, int flags, int default_palette, int size, view->palette = pic->visual_map->palette->getref(); // Set up mode structure for resizing the view - gfx_mode_t *mode = gfx_new_mode(pic->visual_map->index_width / 320, pic->visual_map->index_height / 200, view->palette); + gfx_mode_t *mode = gfx_new_mode(pic->visual_map->index_width / 320, view->palette); gfx_xlate_pixmap(view, mode); gfx_free_mode(mode); |