diff options
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/surface.cpp | 5 | ||||
-rw-r--r-- | graphics/surface.h | 19 |
2 files changed, 23 insertions, 1 deletions
diff --git a/graphics/surface.cpp b/graphics/surface.cpp index a9f3e75886..263a4fd23b 100644 --- a/graphics/surface.cpp +++ b/graphics/surface.cpp @@ -66,6 +66,11 @@ void Surface::free() { bytesPerPixel = 0; } +void Surface::copyFrom(const Surface &surf) { + create(surf.w, surf.h, surf.bytesPerPixel); + memcpy(pixels, surf.pixels, h * pitch); +} + void Surface::hLine(int x, int y, int x2, uint32 color) { // Clipping if (y < 0 || y >= h) diff --git a/graphics/surface.h b/graphics/surface.h index ff1ddda695..747bda9a26 100644 --- a/graphics/surface.h +++ b/graphics/surface.h @@ -30,7 +30,6 @@ namespace Graphics { - /** * An arbitrary graphics surface, which can be the target (or source) of blit * operations, font rendering, etc. @@ -67,6 +66,12 @@ struct Surface { */ void free(); + /** + * Copies data from another Surface, this calls *free* on the current surface, to assure + * it being clean. + */ + void copyFrom(const Surface &surf); + void drawLine(int x0, int y0, int x1, int y1, uint32 color); void hLine(int x, int y, int x2, uint32 color); void vLine(int x, int y, int y2, uint32 color); @@ -76,6 +81,18 @@ struct Surface { void move(int dx, int dy, int height); }; +/** + * For safe deletion of surface with SharedPtr. + * The deleter assures Surface::free is called on + * deletion. + */ +struct SharedPtrSurfaceDeleter { + void operator()(Surface *ptr) { + ptr->free(); + delete ptr; + } +}; + } // End of namespace Graphics |