Skip to content

Commit

Permalink
WINTERMUTE: Prefer getBasePtr over direct Surface::pixels access.
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Schickel committed Aug 3, 2013
1 parent d26817a commit 19fa89b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions engines/wintermute/base/gfx/osystem/base_render_osystem.cpp
Expand Up @@ -187,9 +187,9 @@ bool BaseRenderOSystem::flip() {
}
if (_needsFlip || _disableDirtyRects || _tempDisableDirtyRects) {
if (_disableDirtyRects || _tempDisableDirtyRects) {
g_system->copyRectToScreen((byte *)_renderSurface->pixels, _renderSurface->pitch, 0, 0, _renderSurface->w, _renderSurface->h);
g_system->copyRectToScreen((byte *)_renderSurface->getBasePtr(0, 0), _renderSurface->pitch, 0, 0, _renderSurface->w, _renderSurface->h);
}
// g_system->copyRectToScreen((byte *)_renderSurface->pixels, _renderSurface->pitch, _dirtyRect->left, _dirtyRect->top, _dirtyRect->width(), _dirtyRect->height());
// g_system->copyRectToScreen((byte *)_renderSurface->getBasePtr(0, 0), _renderSurface->pitch, _dirtyRect->left, _dirtyRect->top, _dirtyRect->width(), _dirtyRect->height());
delete _dirtyRect;
_dirtyRect = nullptr;
g_system->updateScreen();
Expand Down Expand Up @@ -682,7 +682,7 @@ void BaseRenderOSystem::endSaveLoad() {
_drawNum = 1;

_renderSurface->fillRect(Common::Rect(0, 0, _renderSurface->h, _renderSurface->w), _renderSurface->format.ARGBToColor(255, 0, 0, 0));
g_system->copyRectToScreen((byte *)_renderSurface->pixels, _renderSurface->pitch, 0, 0, _renderSurface->w, _renderSurface->h);
g_system->copyRectToScreen((byte *)_renderSurface->getBasePtr(0, 0), _renderSurface->pitch, 0, 0, _renderSurface->w, _renderSurface->h);
g_system->updateScreen();
}

Expand Down
Expand Up @@ -234,7 +234,7 @@ uint32 BaseSurfaceOSystem::getPixelAt(Graphics::Surface *surface, int x, int y)
warning("BaseSurfaceOSystem::GetPixel - Not ported yet");
int bpp = surface->format.bytesPerPixel;
/* Here p is the address to the pixel we want to retrieve */
uint8 *p = (uint8 *)surface->pixels + y * surface->pitch + x * bpp;
uint8 *p = (uint8 *)surface->getBasePtr(x, y);

switch (bpp) {
case 1:
Expand Down
13 changes: 8 additions & 5 deletions engines/wintermute/graphics/transparent_surface.cpp
Expand Up @@ -158,7 +158,10 @@ TransparentSurface::TransparentSurface(const Surface &surf, bool copyData) : Sur
h = surf.h;
pitch = surf.pitch;
format = surf.format;
pixels = surf.pixels;
// We need to cast the const qualifier away here because 'pixels'
// always needs to be writable. 'surf' however is a constant Surface,
// thus getBasePtr will always return const pixel data.
pixels = const_cast<void *>(surf.getBasePtr(0, 0));
}
}

Expand Down Expand Up @@ -307,7 +310,7 @@ Common::Rect TransparentSurface::blit(Graphics::Surface &target, int posX, int p
}

if (pPartRect) {
srcImage.pixels = &((char *)pixels)[pPartRect->top * srcImage.pitch + pPartRect->left * 4];
srcImage.pixels = getBasePtr(pPartRect->top, pPartRect->left);
srcImage.w = pPartRect->width();
srcImage.h = pPartRect->height();

Expand Down Expand Up @@ -336,21 +339,21 @@ Common::Rect TransparentSurface::blit(Graphics::Surface &target, int posX, int p
if ((width != srcImage.w) || (height != srcImage.h)) {
// Scale the image
img = imgScaled = srcImage.scale(width, height);
savedPixels = (byte *)img->pixels;
savedPixels = (byte *)img->getBasePtr(0, 0);
} else {
img = &srcImage;
}

// Handle off-screen clipping
if (posY < 0) {
img->h = MAX(0, (int)img->h - -posY);
img->pixels = (byte *)img->pixels + img->pitch * -posY;
img->pixels = (byte *)img->getBasePtr(0, -posY);
posY = 0;
}

if (posX < 0) {
img->w = MAX(0, (int)img->w - -posX);
img->pixels = (byte *)img->pixels + (-posX * 4);
img->pixels = (byte *)img->getBasePtr(-posX, 0);
posX = 0;
}

Expand Down

0 comments on commit 19fa89b

Please sign in to comment.