summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2016-12-15 20:10:36 +1100
committer Vas Crabb <vas@vastheman.com>2016-12-15 20:10:36 +1100
commit23df89c965cdf9422f2effbd33a87aeebc735d20 (patch)
treebf8496f51e9d4499a660d3cd9fe5862fedbe3b09 /src/lib/util
parent2a1643a82471428ab8ec0aefa5fd879aa488a332 (diff)
Make bitmaps movable, allowing them to be used in vectors and emplaced easily.
You're still responsible for ensuring you don't move a bitmap while a texture refers to it.
Diffstat (limited to 'src/lib/util')
-rw-r--r--src/lib/util/bitmap.cpp103
-rw-r--r--src/lib/util/bitmap.h86
-rw-r--r--src/lib/util/coretmpl.h1
3 files changed, 128 insertions, 62 deletions
diff --git a/src/lib/util/bitmap.cpp b/src/lib/util/bitmap.cpp
index 82f28e7755f..c8ceb5d3eab 100644
--- a/src/lib/util/bitmap.cpp
+++ b/src/lib/util/bitmap.cpp
@@ -37,7 +37,7 @@ inline int32_t bitmap_t::compute_rowpixels(int width, int xslop)
inline void bitmap_t::compute_base(int xslop, int yslop)
{
- m_base = m_alloc + (m_rowpixels * yslop + xslop) * (m_bpp / 8);
+ m_base = m_alloc.get() + (m_rowpixels * yslop + xslop) * (m_bpp / 8);
}
@@ -46,8 +46,24 @@ inline void bitmap_t::compute_base(int xslop, int yslop)
// BITMAP ALLOCATION/CONFIGURATION
//**************************************************************************
+bitmap_t::bitmap_t(bitmap_t &&that)
+ : m_alloc(std::move(that.m_alloc))
+ , m_allocbytes(that.m_allocbytes)
+ , m_base(that.m_base)
+ , m_rowpixels(that.m_rowpixels)
+ , m_width(that.m_width)
+ , m_height(that.m_height)
+ , m_format(that.m_format)
+ , m_bpp(that.m_bpp)
+ , m_palette(nullptr)
+ , m_cliprect(that.m_cliprect)
+{
+ set_palette(that.m_palette);
+ that.reset();
+}
+
/**
- * @fn bitmap_t::bitmap_t(bitmap_format format, int bpp, int width, int height, int xslop, int yslop)
+ * @fn bitmap_t::bitmap_t(bitmap_format format, uint8_t bpp, int width, int height, int xslop, int yslop)
*
* @brief -------------------------------------------------
* bitmap_t - basic constructor
@@ -61,19 +77,19 @@ inline void bitmap_t::compute_base(int xslop, int yslop)
* @param yslop The yslop.
*/
-bitmap_t::bitmap_t(bitmap_format format, int bpp, int width, int height, int xslop, int yslop)
- : m_alloc(nullptr),
- m_allocbytes(0),
- m_format(format),
- m_bpp(bpp),
- m_palette(nullptr)
+bitmap_t::bitmap_t(bitmap_format format, uint8_t bpp, int width, int height, int xslop, int yslop)
+ : m_alloc()
+ , m_allocbytes(0)
+ , m_format(format)
+ , m_bpp(bpp)
+ , m_palette(nullptr)
{
// allocate intializes all other fields
allocate(width, height, xslop, yslop);
}
/**
- * @fn bitmap_t::bitmap_t(bitmap_format format, int bpp, void *base, int width, int height, int rowpixels)
+ * @fn bitmap_t::bitmap_t(bitmap_format format, uint8_t bpp, void *base, int width, int height, int rowpixels)
*
* @brief Constructor.
*
@@ -85,22 +101,22 @@ bitmap_t::bitmap_t(bitmap_format format, int bpp, int width, int height, int xsl
* @param rowpixels The rowpixels.
*/
-bitmap_t::bitmap_t(bitmap_format format, int bpp, void *base, int width, int height, int rowpixels)
- : m_alloc(nullptr),
- m_allocbytes(0),
- m_base(base),
- m_rowpixels(rowpixels),
- m_width(width),
- m_height(height),
- m_format(format),
- m_bpp(bpp),
- m_palette(nullptr),
- m_cliprect(0, width - 1, 0, height - 1)
+bitmap_t::bitmap_t(bitmap_format format, uint8_t bpp, void *base, int width, int height, int rowpixels)
+ : m_alloc()
+ , m_allocbytes(0)
+ , m_base(base)
+ , m_rowpixels(rowpixels)
+ , m_width(width)
+ , m_height(height)
+ , m_format(format)
+ , m_bpp(bpp)
+ , m_palette(nullptr)
+ , m_cliprect(0, width - 1, 0, height - 1)
{
}
/**
- * @fn bitmap_t::bitmap_t(bitmap_format format, int bpp, bitmap_t &source, const rectangle &subrect)
+ * @fn bitmap_t::bitmap_t(bitmap_format format, uint8_t bpp, bitmap_t &source, const rectangle &subrect)
*
* @brief Constructor.
*
@@ -110,17 +126,17 @@ bitmap_t::bitmap_t(bitmap_format format, int bpp, void *base, int width, int hei
* @param subrect The subrect.
*/
-bitmap_t::bitmap_t(bitmap_format format, int bpp, bitmap_t &source, const rectangle &subrect)
- : m_alloc(nullptr),
- m_allocbytes(0),
- m_base(source.raw_pixptr(subrect.min_y, subrect.min_x)),
- m_rowpixels(source.m_rowpixels),
- m_width(subrect.width()),
- m_height(subrect.height()),
- m_format(format),
- m_bpp(bpp),
- m_palette(nullptr),
- m_cliprect(0, subrect.width() - 1, 0, subrect.height() - 1)
+bitmap_t::bitmap_t(bitmap_format format, uint8_t bpp, bitmap_t &source, const rectangle &subrect)
+ : m_alloc()
+ , m_allocbytes(0)
+ , m_base(source.raw_pixptr(subrect.min_y, subrect.min_x))
+ , m_rowpixels(source.m_rowpixels)
+ , m_width(subrect.width())
+ , m_height(subrect.height())
+ , m_format(format)
+ , m_bpp(bpp)
+ , m_palette(nullptr)
+ , m_cliprect(0, subrect.width() - 1, 0, subrect.height() - 1)
{
assert(format == source.m_format);
assert(bpp == source.m_bpp);
@@ -141,6 +157,22 @@ bitmap_t::~bitmap_t()
reset();
}
+bitmap_t &bitmap_t::operator=(bitmap_t &&that)
+{
+ m_alloc = std::move(that.m_alloc);
+ m_allocbytes = that.m_allocbytes;
+ m_base = that.m_base;
+ m_rowpixels = that.m_rowpixels;
+ m_width = that.m_width;
+ m_height = that.m_height;
+ m_format = that.m_format;
+ m_bpp = that.m_bpp;
+ set_palette(that.m_palette);
+ m_cliprect = that.m_cliprect;
+ that.reset();
+ return *this;
+}
+
/**
* @fn void bitmap_t::allocate(int width, int height, int xslop, int yslop)
*
@@ -175,10 +207,10 @@ void bitmap_t::allocate(int width, int height, int xslop, int yslop)
// allocate memory for the bitmap itself
m_allocbytes = m_rowpixels * (m_height + 2 * yslop) * m_bpp / 8;
- m_alloc = new uint8_t[m_allocbytes];
+ m_alloc.reset(new uint8_t[m_allocbytes]);
// clear to 0 by default
- memset(m_alloc, 0, m_allocbytes);
+ memset(m_alloc.get(), 0, m_allocbytes);
// compute the base
compute_base(xslop, yslop);
@@ -242,8 +274,7 @@ void bitmap_t::reset()
{
// delete any existing stuff
set_palette(nullptr);
- delete[] m_alloc;
- m_alloc = nullptr;
+ m_alloc.reset();
m_base = nullptr;
// reset all fields
diff --git a/src/lib/util/bitmap.h b/src/lib/util/bitmap.h
index 7d367bcb5cb..7b0fc34610f 100644
--- a/src/lib/util/bitmap.h
+++ b/src/lib/util/bitmap.h
@@ -8,10 +8,10 @@
***************************************************************************/
-#pragma once
+#ifndef MAME_UTIL_BITMAP_H
+#define MAME_UTIL_BITMAP_H
-#ifndef __BITMAP_H__
-#define __BITMAP_H__
+#pragma once
#include "osdcore.h"
#include "palette.h"
@@ -106,10 +106,10 @@ public:
void offsety(int32_t delta) { min_y += delta; max_y += delta; }
// internal state
- int32_t min_x; // minimum X, or left coordinate
- int32_t max_x; // maximum X, or right coordinate (inclusive)
- int32_t min_y; // minimum Y, or top coordinate
- int32_t max_y; // maximum Y, or bottom coordinate (inclusive)
+ int32_t min_x; // minimum X, or left coordinate
+ int32_t max_x; // maximum X, or right coordinate (inclusive)
+ int32_t min_y; // minimum Y, or top coordinate
+ int32_t max_y; // maximum Y, or bottom coordinate (inclusive)
};
@@ -118,18 +118,19 @@ public:
// bitmaps describe a rectangular array of pixels
class bitmap_t
{
-private:
- // prevent implicit copying
- bitmap_t(const bitmap_t &);
- bitmap_t &operator=(const bitmap_t &);
-
protected:
// construction/destruction -- subclasses only to ensure type correctness
- bitmap_t(bitmap_format format, int bpp, int width = 0, int height = 0, int xslop = 0, int yslop = 0);
- bitmap_t(bitmap_format format, int bpp, void *base, int width, int height, int rowpixels);
- bitmap_t(bitmap_format format, int bpp, bitmap_t &source, const rectangle &subrect);
+ bitmap_t(const bitmap_t &) = delete;
+ bitmap_t(bitmap_t &&that);
+ bitmap_t(bitmap_format format, uint8_t bpp, int width = 0, int height = 0, int xslop = 0, int yslop = 0);
+ bitmap_t(bitmap_format format, uint8_t bpp, void *base, int width, int height, int rowpixels);
+ bitmap_t(bitmap_format format, uint8_t bpp, bitmap_t &source, const rectangle &subrect);
virtual ~bitmap_t();
+ // prevent implicit copying
+ bitmap_t &operator=(const bitmap_t &) = delete;
+ bitmap_t &operator=(bitmap_t &&that);
+
public:
// allocation/deallocation
void reset();
@@ -175,16 +176,16 @@ private:
void compute_base(int xslop, int yslop);
// internal state
- uint8_t * m_alloc; // pointer to allocated pixel memory
- uint32_t m_allocbytes; // size of our allocation
- void * m_base; // pointer to pixel (0,0) (adjusted for padding)
- int32_t m_rowpixels; // pixels per row (including padding)
- int32_t m_width; // width of the bitmap
- int32_t m_height; // height of the bitmap
- bitmap_format m_format; // format of the bitmap
- uint8_t m_bpp; // bits per pixel
- palette_t * m_palette; // optional palette
- rectangle m_cliprect; // a clipping rectangle covering the full bitmap
+ std::unique_ptr<uint8_t []> m_alloc; // pointer to allocated pixel memory
+ uint32_t m_allocbytes; // size of our allocation
+ void * m_base; // pointer to pixel (0,0) (adjusted for padding)
+ int32_t m_rowpixels; // pixels per row (including padding)
+ int32_t m_width; // width of the bitmap
+ int32_t m_height; // height of the bitmap
+ bitmap_format m_format; // format of the bitmap
+ uint8_t m_bpp; // bits per pixel
+ palette_t * m_palette; // optional palette
+ rectangle m_cliprect; // a clipping rectangle covering the full bitmap
};
@@ -199,10 +200,13 @@ private:
protected:
// construction/destruction -- subclasses only
+ bitmap8_t(bitmap8_t &&) = default;
bitmap8_t(bitmap_format format, int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap_t(format, 8, width, height, xslop, yslop) { }
bitmap8_t(bitmap_format format, uint8_t *base, int width, int height, int rowpixels) : bitmap_t(format, 8, base, width, height, rowpixels) { assert(valid_format(format)); }
bitmap8_t(bitmap_format format, bitmap8_t &source, const rectangle &subrect) : bitmap_t(format, 8, source, subrect) { }
+ bitmap8_t &operator=(bitmap8_t &&) = default;
+
public:
// getters
uint8_t bpp() const { return 8; }
@@ -222,10 +226,13 @@ private:
protected:
// construction/destruction -- subclasses only
+ bitmap16_t(bitmap16_t &&) = default;
bitmap16_t(bitmap_format format, int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap_t(format, 16, width, height, xslop, yslop) { assert(valid_format(format)); }
bitmap16_t(bitmap_format format, uint16_t *base, int width, int height, int rowpixels) : bitmap_t(format, 16, base, width, height, rowpixels) { assert(valid_format(format)); }
bitmap16_t(bitmap_format format, bitmap16_t &source, const rectangle &subrect) : bitmap_t(format, 16, source, subrect) { }
+ bitmap16_t &operator=(bitmap16_t &&) = default;
+
public:
// getters
uint8_t bpp() const { return 16; }
@@ -245,10 +252,13 @@ private:
protected:
// construction/destruction -- subclasses only
+ bitmap32_t(bitmap32_t &&) = default;
bitmap32_t(bitmap_format format, int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap_t(format, 32, width, height, xslop, yslop) { assert(valid_format(format)); }
bitmap32_t(bitmap_format format, uint32_t *base, int width, int height, int rowpixels) : bitmap_t(format, 32, base, width, height, rowpixels) { assert(valid_format(format)); }
bitmap32_t(bitmap_format format, bitmap32_t &source, const rectangle &subrect) : bitmap_t(format, 32, source, subrect) { }
+ bitmap32_t &operator=(bitmap32_t &&) = default;
+
public:
// getters
uint8_t bpp() const { return 32; }
@@ -268,10 +278,13 @@ private:
protected:
// construction/destruction -- subclasses only
+ bitmap64_t(bitmap64_t &&) = default;
bitmap64_t(bitmap_format format, int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap_t(format, 64, width, height, xslop, yslop) { assert(valid_format(format)); }
bitmap64_t(bitmap_format format, uint64_t *base, int width, int height, int rowpixels) : bitmap_t(format, 64, base, width, height, rowpixels) { assert(valid_format(format)); }
bitmap64_t(bitmap_format format, bitmap64_t &source, const rectangle &subrect) : bitmap_t(format, 64, source, subrect) { }
+ bitmap64_t &operator=(bitmap64_t &&) = default;
+
public:
// getters
uint8_t bpp() const { return 64; }
@@ -292,6 +305,7 @@ class bitmap_ind8 : public bitmap8_t
public:
// construction/destruction
+ bitmap_ind8(bitmap_ind8 &&) = default;
bitmap_ind8(int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap8_t(k_bitmap_format, width, height, xslop, yslop) { }
bitmap_ind8(uint8_t *base, int width, int height, int rowpixels) : bitmap8_t(k_bitmap_format, base, width, height, rowpixels) { }
bitmap_ind8(bitmap_ind8 &source, const rectangle &subrect) : bitmap8_t(k_bitmap_format, source, subrect) { }
@@ -300,6 +314,8 @@ public:
// getters
bitmap_format format() const { return k_bitmap_format; }
+
+ bitmap_ind8 &operator=(bitmap_ind8 &&) = default;
};
// BITMAP_FORMAT_IND16 bitmaps
@@ -309,6 +325,7 @@ class bitmap_ind16 : public bitmap16_t
public:
// construction/destruction
+ bitmap_ind16(bitmap_ind16 &&) = default;
bitmap_ind16(int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap16_t(k_bitmap_format, width, height, xslop, yslop) { }
bitmap_ind16(uint16_t *base, int width, int height, int rowpixels) : bitmap16_t(k_bitmap_format, base, width, height, rowpixels) { }
bitmap_ind16(bitmap_ind16 &source, const rectangle &subrect) : bitmap16_t(k_bitmap_format, source, subrect) { }
@@ -317,6 +334,8 @@ public:
// getters
bitmap_format format() const { return k_bitmap_format; }
+
+ bitmap_ind16 &operator=(bitmap_ind16 &&) = default;
};
// BITMAP_FORMAT_IND32 bitmaps
@@ -326,6 +345,7 @@ class bitmap_ind32 : public bitmap32_t
public:
// construction/destruction
+ bitmap_ind32(bitmap_ind32 &&) = default;
bitmap_ind32(int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap32_t(k_bitmap_format, width, height, xslop, yslop) { }
bitmap_ind32(uint32_t *base, int width, int height, int rowpixels) : bitmap32_t(k_bitmap_format, base, width, height, rowpixels) { }
bitmap_ind32(bitmap_ind32 &source, const rectangle &subrect) : bitmap32_t(k_bitmap_format, source, subrect) { }
@@ -334,6 +354,8 @@ public:
// getters
bitmap_format format() const { return k_bitmap_format; }
+
+ bitmap_ind32 &operator=(bitmap_ind32 &&) = default;
};
// BITMAP_FORMAT_IND64 bitmaps
@@ -343,6 +365,7 @@ class bitmap_ind64 : public bitmap64_t
public:
// construction/destruction
+ bitmap_ind64(bitmap_ind64 &&) = default;
bitmap_ind64(int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap64_t(k_bitmap_format, width, height, xslop, yslop) { }
bitmap_ind64(uint64_t *base, int width, int height, int rowpixels) : bitmap64_t(k_bitmap_format, base, width, height, rowpixels) { }
bitmap_ind64(bitmap_ind64 &source, const rectangle &subrect) : bitmap64_t(k_bitmap_format, source, subrect) { }
@@ -351,6 +374,8 @@ public:
// getters
bitmap_format format() const { return k_bitmap_format; }
+
+ bitmap_ind64 &operator=(bitmap_ind64 &&) = default;
};
@@ -363,6 +388,7 @@ class bitmap_yuy16 : public bitmap16_t
public:
// construction/destruction
+ bitmap_yuy16(bitmap_yuy16 &&) = default;
bitmap_yuy16(int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap16_t(k_bitmap_format, width, height, xslop, yslop) { }
bitmap_yuy16(uint16_t *base, int width, int height, int rowpixels) : bitmap16_t(k_bitmap_format, base, width, height, rowpixels) { }
bitmap_yuy16(bitmap_yuy16 &source, const rectangle &subrect) : bitmap16_t(k_bitmap_format, source, subrect) { }
@@ -371,6 +397,8 @@ public:
// getters
bitmap_format format() const { return k_bitmap_format; }
+
+ bitmap_yuy16 &operator=(bitmap_yuy16 &&) = default;
};
// BITMAP_FORMAT_RGB32 bitmaps
@@ -380,6 +408,7 @@ class bitmap_rgb32 : public bitmap32_t
public:
// construction/destruction
+ bitmap_rgb32(bitmap_rgb32 &&) = default;
bitmap_rgb32(int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap32_t(k_bitmap_format, width, height, xslop, yslop) { }
bitmap_rgb32(uint32_t *base, int width, int height, int rowpixels) : bitmap32_t(k_bitmap_format, base, width, height, rowpixels) { }
bitmap_rgb32(bitmap_rgb32 &source, const rectangle &subrect) : bitmap32_t(k_bitmap_format, source, subrect) { }
@@ -388,6 +417,8 @@ public:
// getters
bitmap_format format() const { return k_bitmap_format; }
+
+ bitmap_rgb32 &operator=(bitmap_rgb32 &&) = default;
};
// BITMAP_FORMAT_ARGB32 bitmaps
@@ -397,6 +428,7 @@ class bitmap_argb32 : public bitmap32_t
public:
// construction/destruction
+ bitmap_argb32(bitmap_argb32 &&) = default;
bitmap_argb32(int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap32_t(k_bitmap_format, width, height, xslop, yslop) { }
bitmap_argb32(uint32_t *base, int width, int height, int rowpixels) : bitmap32_t(k_bitmap_format, base, width, height, rowpixels) { }
bitmap_argb32(bitmap_argb32 &source, const rectangle &subrect) : bitmap32_t(k_bitmap_format, source, subrect) { }
@@ -405,7 +437,9 @@ public:
// getters
bitmap_format format() const { return k_bitmap_format; }
+
+ bitmap_argb32 &operator=(bitmap_argb32 &&) = default;
};
-#endif // __BITMAP_H__
+#endif // MAME_UTIL_BITMAP_H
diff --git a/src/lib/util/coretmpl.h b/src/lib/util/coretmpl.h
index 4d17f3c0a4b..0633a10c06e 100644
--- a/src/lib/util/coretmpl.h
+++ b/src/lib/util/coretmpl.h
@@ -444,6 +444,7 @@ private:
// LRU cache that behaves like std::map with differences:
// * drops least-recently used items if necessary on insert to prevent size from exceeding max_size
+// * operator[], at, insert, emplace and find freshen existing entries
// * iterates from least- to most-recently used rather than in order by key
// * iterators to dropped items are invalidated
// * not all map interfaces implemented