diff --git a/src/common/FrameBufferSDL2.cxx b/src/common/FrameBufferSDL2.cxx index ab35f68d0..ac7fdf0aa 100644 --- a/src/common/FrameBufferSDL2.cxx +++ b/src/common/FrameBufferSDL2.cxx @@ -342,10 +342,10 @@ void FrameBufferSDL2::setWindowIcon() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -FBSurface* FrameBufferSDL2::createSurface(uInt32 w, uInt32 h, +unique_ptr FrameBufferSDL2::createSurface(uInt32 w, uInt32 h, const uInt32* data) const { - return new FBSurfaceSDL2((FrameBufferSDL2&)*this, w, h, data); + return make_ptr((FrameBufferSDL2&)*this, w, h, data); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/FrameBufferSDL2.hxx b/src/common/FrameBufferSDL2.hxx index 556ac106d..edf71a6ee 100644 --- a/src/common/FrameBufferSDL2.hxx +++ b/src/common/FrameBufferSDL2.hxx @@ -151,7 +151,7 @@ class FrameBufferSDL2 : public FrameBuffer @param h The requested height of the new surface. @param data If non-null, use the given data values as a static surface */ - FBSurface* createSurface(uInt32 w, uInt32 h, const uInt32* data) const; + unique_ptr createSurface(uInt32 w, uInt32 h, const uInt32* data) const; /** Grabs or ungrabs the mouse based on the given boolean value. diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index a942bff8d..75cba2ff4 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -58,12 +58,6 @@ FrameBuffer::FrameBuffer(OSystem& osystem) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FrameBuffer::~FrameBuffer() { - // Free all allocated surfaces - while(!mySurfaceList.empty()) - { - delete (*mySurfaceList.begin()).second; - mySurfaceList.erase(mySurfaceList.begin()); - } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -234,19 +228,14 @@ FBInitStatus FrameBuffer::createDisplay(const string& title, myStatsMsg.w = infoFont().getMaxCharWidth() * 24 + 2; myStatsMsg.h = (infoFont().getFontHeight() + 2) * 2; - if(myStatsMsg.surface == nullptr) - { - uInt32 surfaceID = allocateSurface(myStatsMsg.w, myStatsMsg.h); - myStatsMsg.surface = surface(surfaceID); - } - if(myMsg.surface == nullptr) - { - uInt32 surfaceID = allocateSurface((uInt32)kFBMinW, font().getFontHeight()+10); - myMsg.surface = surface(surfaceID); - } + if(!myStatsMsg.surface) + myStatsMsg.surface = allocateSurface(myStatsMsg.w, myStatsMsg.h); + + if(!myMsg.surface) + myMsg.surface = allocateSurface((uInt32)kFBMinW, font().getFontHeight()+10); // Print initial usage message, but only print it later if the status has changed - if (myInitializedCount == 1) + if(myInitializedCount == 1) { myOSystem.logMessage(about(), 1); } @@ -567,23 +556,13 @@ void FrameBuffer::refresh() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt32 FrameBuffer::allocateSurface(int w, int h, const uInt32* data) +FBSurface* FrameBuffer::allocateSurface(int w, int h, const uInt32* data) { - // Create a new surface - FBSurface* surface = createSurface(w, h, data); + // Add new surface to the list + mySurfaceList.push_back(createSurface(w, h, data)); - // Add it to the list - mySurfaceList.insert(make_pair((uInt32)mySurfaceList.size(), surface)); - - // Return a reference to it - return (uInt32)mySurfaceList.size() - 1; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -FBSurface* FrameBuffer::surface(uInt32 id) const -{ - const auto& iter = mySurfaceList.find(id); - return iter != mySurfaceList.end() ? iter->second : nullptr; + // And return a pointer to it (pointer should be treated read-only) + return mySurfaceList.at(mySurfaceList.size() - 1).get(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -596,9 +575,9 @@ void FrameBuffer::resetSurfaces() // aware of these restrictions, and act accordingly for(auto& s: mySurfaceList) - s.second->free(); + s->free(); for(auto& s: mySurfaceList) - s.second->reload(); + s->reload(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/FrameBuffer.hxx b/src/emucore/FrameBuffer.hxx index 3a275235a..32ed03fa6 100644 --- a/src/emucore/FrameBuffer.hxx +++ b/src/emucore/FrameBuffer.hxx @@ -197,25 +197,16 @@ class FrameBuffer void enableMessages(bool enable); /** - Allocate a new surface with a unique ID. The FrameBuffer class takes - all responsibility for freeing this surface (ie, other classes must not - delete it directly). + Allocate a new surface. The FrameBuffer class takes all responsibility + for freeing this surface (ie, other classes must not delete it directly). @param w The requested width of the new surface. @param h The requested height of the new surface. @param data If non-null, use the given data values as a static surface - @return A unique ID used to identify this surface + @return A pointer to a valid surface object, or nullptr. */ - uInt32 allocateSurface(int w, int h, const uInt32* data = 0); - - /** - Retrieve the surface associated with the given ID. - - @param id The ID for the surface to retrieve. - @return A pointer to a valid surface object, or nullptr. - */ - FBSurface* surface(uInt32 id) const; + FBSurface* allocateSurface(int w, int h, const uInt32* data = 0); /** Returns the current dimensions of the framebuffer image. @@ -401,7 +392,8 @@ class FrameBuffer @param h The requested height of the new surface. @param data If non-null, use the given data values as a static surface */ - virtual FBSurface* createSurface(uInt32 w, uInt32 h, const uInt32* data) const = 0; + virtual unique_ptr createSurface(uInt32 w, uInt32 h, + const uInt32* data) const = 0; /** Grabs or ungrabs the mouse based on the given boolean value. @@ -569,7 +561,7 @@ class FrameBuffer VariantList myTIAZoomLevels; // Holds a reference to all the surfaces that have been created - map mySurfaceList; + vector> mySurfaceList; // Holds UI palette data (standard and classic colours) static uInt32 ourGUIColors[2][kNumColors-256]; diff --git a/src/emucore/TIASurface.cxx b/src/emucore/TIASurface.cxx index 9c2c3cbb7..5244c8030 100644 --- a/src/emucore/TIASurface.cxx +++ b/src/emucore/TIASurface.cxx @@ -45,8 +45,7 @@ TIASurface::TIASurface(OSystem& system) myNTSCFilter.loadConfig(myOSystem.settings()); // Create a surface for the TIA image and scanlines; we'll need them eventually - uInt32 tiaID = myFB.allocateSurface(ATARI_NTSC_OUT_WIDTH(kTIAW), kTIAH); - myTiaSurface = myFB.surface(tiaID); + myTiaSurface = myFB.allocateSurface(ATARI_NTSC_OUT_WIDTH(kTIAW), kTIAH); // Generate scanline data, and a pre-defined scanline surface uInt32 scanData[kScanH]; @@ -55,12 +54,10 @@ TIASurface::TIASurface(OSystem& system) scanData[i] = 0x00000000; scanData[i+1] = 0xff000000; } - uInt32 scanID = myFB.allocateSurface(1, kScanH, scanData); - mySLineSurface = myFB.surface(scanID); + mySLineSurface = myFB.allocateSurface(1, kScanH, scanData); // Base TIA surface for use in taking snapshots in 1x mode - uInt32 baseID = myFB.allocateSurface(kTIAW*2, kTIAH); - myBaseTiaSurface = myFB.surface(baseID); + myBaseTiaSurface = myFB.allocateSurface(kTIAW*2, kTIAH); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index 9be465215..6d0042cf6 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -40,14 +40,14 @@ Dialog::Dialog(OSystem& instance, DialogContainer& parent, int x, int y, int w, int h) : GuiObject(instance, parent, *this, x, y, w, h), - _mouseWidget(0), - _focusedWidget(0), - _dragWidget(0), - _okWidget(0), - _cancelWidget(0), + _mouseWidget(nullptr), + _focusedWidget(nullptr), + _dragWidget(nullptr), + _okWidget(nullptr), + _cancelWidget(nullptr), _visible(false), _processCancel(false), - _surface(0), + _surface(nullptr), _tabID(0) { } @@ -71,10 +71,7 @@ void Dialog::open(bool refresh) // Technically, this shouldn't be needed until drawDialog(), but some // dialogs cause drawing to occur within loadConfig() if(_surface == nullptr) - { - uInt32 surfaceID = instance().frameBuffer().allocateSurface(_w, _h); - _surface = instance().frameBuffer().surface(surfaceID); - } + _surface = instance().frameBuffer().allocateSurface(_w, _h); parent().addDialog(this); center(); diff --git a/src/gui/RomInfoWidget.cxx b/src/gui/RomInfoWidget.cxx index 237b6b8c1..ea0a4dd16 100644 --- a/src/gui/RomInfoWidget.cxx +++ b/src/gui/RomInfoWidget.cxx @@ -92,8 +92,7 @@ void RomInfoWidget::parseProperties() // only draw certain parts of it if(mySurface == nullptr) { - uInt32 ID = instance().frameBuffer().allocateSurface(320*2, 256*2); - mySurface = instance().frameBuffer().surface(ID); + mySurface = instance().frameBuffer().allocateSurface(320*2, 256*2); mySurface->attributes().smoothing = true; mySurface->applyAttributes();