aboutsummaryrefslogtreecommitdiff
path: root/graphics/managed_surface.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2016-03-17 18:35:17 -0400
committerPaul Gilbert2016-03-17 18:35:17 -0400
commit390487aa43e5507d4d0fb4ae57e7cf726a94f4c1 (patch)
tree3a1c9d748a99f139a712f62a75005ad7eb6a93b1 /graphics/managed_surface.cpp
parentc05a09d33717d1b2c41b258013be589fa63a7097 (diff)
downloadscummvm-rg350-390487aa43e5507d4d0fb4ae57e7cf726a94f4c1.tar.gz
scummvm-rg350-390487aa43e5507d4d0fb4ae57e7cf726a94f4c1.tar.bz2
scummvm-rg350-390487aa43e5507d4d0fb4ae57e7cf726a94f4c1.zip
GRAPHICS: Cleanup of ManagedSurface and Screen classes
Diffstat (limited to 'graphics/managed_surface.cpp')
-rw-r--r--graphics/managed_surface.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/graphics/managed_surface.cpp b/graphics/managed_surface.cpp
index 45db0bc52e..e493ab9f4e 100644
--- a/graphics/managed_surface.cpp
+++ b/graphics/managed_surface.cpp
@@ -30,30 +30,30 @@ const int SCALE_THRESHOLD = 0x100;
ManagedSurface::ManagedSurface() :
w(_innerSurface.w), h(_innerSurface.h), pitch(_innerSurface.pitch), format(_innerSurface.format),
- _isManaged(false), _owner(nullptr) {
+ _disposeAfterUse(DisposeAfterUse::NO), _owner(nullptr) {
}
ManagedSurface::ManagedSurface(const ManagedSurface &surf) :
w(_innerSurface.w), h(_innerSurface.h), pitch(_innerSurface.pitch), format(_innerSurface.format),
- _isManaged(false), _owner(nullptr) {
+ _disposeAfterUse(DisposeAfterUse::NO), _owner(nullptr) {
*this = surf;
}
ManagedSurface::ManagedSurface(int width, int height) :
w(_innerSurface.w), h(_innerSurface.h), pitch(_innerSurface.pitch), format(_innerSurface.format),
- _isManaged(false), _owner(nullptr) {
+ _disposeAfterUse(DisposeAfterUse::NO), _owner(nullptr) {
create(width, height);
}
ManagedSurface::ManagedSurface(int width, int height, const Graphics::PixelFormat &pixelFormat) :
w(_innerSurface.w), h(_innerSurface.h), pitch(_innerSurface.pitch), format(_innerSurface.format),
- _isManaged(false), _owner(nullptr) {
+ _disposeAfterUse(DisposeAfterUse::NO), _owner(nullptr) {
create(width, height, format);
}
ManagedSurface::ManagedSurface(ManagedSurface &surf, const Common::Rect &bounds) :
w(_innerSurface.w), h(_innerSurface.h), pitch(_innerSurface.pitch), format(_innerSurface.format),
- _isManaged(false), _owner(nullptr) {
+ _disposeAfterUse(DisposeAfterUse::NO), _owner(nullptr) {
create(surf, bounds);
}
@@ -62,17 +62,18 @@ ManagedSurface::~ManagedSurface() {
}
ManagedSurface &ManagedSurface::operator=(const ManagedSurface &surf) {
- if (surf._isManaged) {
+ // Free any current surface
+ free();
+
+ if (surf._disposeAfterUse == DisposeAfterUse::YES) {
// Create a new surface and copy the pixels from the source surface
create(surf.w, surf.h, surf.format);
Common::copy((const byte *)surf.getPixels(), (const byte *)surf.getPixels() +
surf.w * surf.h * surf.format.bytesPerPixel, (byte *)this->getPixels());
} else {
- // Source isn't managed, so simply copy it's fields
- _isManaged = false;
+ // Source isn't managed, so simply copy its fields
_owner = surf._owner;
_offsetFromOwner = surf._offsetFromOwner;
-
void *srcPixels = (void *)surf._innerSurface.getPixels();
_innerSurface.setPixels(srcPixels);
_innerSurface.w = surf.w;
@@ -97,7 +98,7 @@ void ManagedSurface::create(uint16 width, uint16 height, const PixelFormat &pixe
free();
_innerSurface.create(width, height, pixelFormat);
- _isManaged = true;
+ _disposeAfterUse = DisposeAfterUse::YES;
markAllDirty();
}
@@ -111,14 +112,14 @@ void ManagedSurface::create(ManagedSurface &surf, const Common::Rect &bounds) {
_innerSurface.w = bounds.width();
_innerSurface.h = bounds.height();
_owner = &surf;
- _isManaged = false;
+ _disposeAfterUse = DisposeAfterUse::NO;
}
void ManagedSurface::free() {
- if (_isManaged)
+ if (_disposeAfterUse == DisposeAfterUse::YES)
_innerSurface.free();
- _isManaged = false;
+ _disposeAfterUse = DisposeAfterUse::NO;
_owner = nullptr;
_offsetFromOwner = Common::Point(0, 0);
}
@@ -246,6 +247,7 @@ void ManagedSurface::markAllDirty() {
void ManagedSurface::addDirtyRect(const Common::Rect &r) {
if (_owner) {
Common::Rect bounds = r;
+ bounds.clip(Common::Rect(0, 0, this->w, this->h));
bounds.translate(_offsetFromOwner.x, _offsetFromOwner.y);
_owner->addDirtyRect(bounds);
}