From e31274c753fa7364bcf91e933a2200e56b2aaec9 Mon Sep 17 00:00:00 2001 From: stephena Date: Wed, 7 May 2014 20:21:07 +0000 Subject: [PATCH] When obtaining FBSurface bounding rects, use references instead of constantly creating new instances of GUI::Rect. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2887 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- src/common/FBSurfaceSDL2.cxx | 10 ++++++---- src/common/FBSurfaceSDL2.hxx | 6 ++++-- src/common/FBSurfaceTIA.hxx | 4 ++-- src/emucore/FBSurface.hxx | 4 ++-- src/gui/Rect.hxx | 9 ++++++++- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/common/FBSurfaceSDL2.cxx b/src/common/FBSurfaceSDL2.cxx index 4cf940e0b..19cd83b31 100644 --- a/src/common/FBSurfaceSDL2.cxx +++ b/src/common/FBSurfaceSDL2.cxx @@ -131,15 +131,17 @@ void FBSurfaceSDL2::setInterpolationAndBlending( } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -GUI::Rect FBSurfaceSDL2::srcRect() +const GUI::Rect& FBSurfaceSDL2::srcRect() { - return GUI::Rect(mySrcR.x, mySrcR.y, mySrcR.x+mySrcR.w, mySrcR.y+mySrcR.h); + mySrcGUIR.setBounds(mySrcR.x, mySrcR.y, mySrcR.x+mySrcR.w, mySrcR.y+mySrcR.h); + return mySrcGUIR; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -GUI::Rect FBSurfaceSDL2::dstRect() +const GUI::Rect& FBSurfaceSDL2::dstRect() { - return GUI::Rect(myDstR.x, myDstR.y, myDstR.x+myDstR.w, myDstR.y+myDstR.h); + myDstGUIR.setBounds(myDstR.x, myDstR.y, myDstR.x+myDstR.w, myDstR.y+myDstR.h); + return myDstGUIR; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/FBSurfaceSDL2.hxx b/src/common/FBSurfaceSDL2.hxx index 84ba163b1..68f85ccdb 100644 --- a/src/common/FBSurfaceSDL2.hxx +++ b/src/common/FBSurfaceSDL2.hxx @@ -47,8 +47,8 @@ class FBSurfaceSDL2 : public FBSurface void setInterpolationAndBlending(bool smoothScale, bool useBlend, uInt32 blendAlpha); - GUI::Rect srcRect(); - GUI::Rect dstRect(); + const GUI::Rect& srcRect(); + const GUI::Rect& dstRect(); void setSrcPos(uInt32 x, uInt32 y); void setSrcSize(uInt32 w, uInt32 h); void setDstPos(uInt32 x, uInt32 y); @@ -76,6 +76,8 @@ class FBSurfaceSDL2 : public FBSurface uInt32* myStaticData; // The data to use when the buffer contents are static uInt32 myStaticPitch; // The number of bytes in a row of static data + + GUI::Rect mySrcGUIR, myDstGUIR; }; #endif diff --git a/src/common/FBSurfaceTIA.hxx b/src/common/FBSurfaceTIA.hxx index 3c018f4c6..8c58e5c73 100644 --- a/src/common/FBSurfaceTIA.hxx +++ b/src/common/FBSurfaceTIA.hxx @@ -52,8 +52,8 @@ class FBSurfaceTIA : public FBSurface void setInterpolationAndBlending(bool smoothScale, bool useBlend, uInt32 blendAlpha) { } - GUI::Rect srcRect() { return GUI::Rect(); } - GUI::Rect dstRect() { return GUI::Rect(); } + const GUI::Rect& srcRect() { return GUI::Rect(); } + const GUI::Rect& dstRect() { return GUI::Rect(); } /////////////////////////////////////////////////////// void getPos(uInt32& x, uInt32& y) const; uInt32 getWidth() const { return myDstR.w; } diff --git a/src/emucore/FBSurface.hxx b/src/emucore/FBSurface.hxx index 9fac81818..c41914b47 100644 --- a/src/emucore/FBSurface.hxx +++ b/src/emucore/FBSurface.hxx @@ -225,8 +225,8 @@ class FBSurface /** These methods answer the current dimensions of the specified surface. */ - virtual GUI::Rect srcRect() = 0; - virtual GUI::Rect dstRect() = 0; + virtual const GUI::Rect& srcRect() = 0; + virtual const GUI::Rect& dstRect() = 0; /** These methods set the origin point and width/height for the diff --git a/src/gui/Rect.hxx b/src/gui/Rect.hxx index b81ed0133..dffa7a0c0 100644 --- a/src/gui/Rect.hxx +++ b/src/gui/Rect.hxx @@ -126,6 +126,13 @@ struct Rect void setHeight(int aHeight) { bottom = top + aHeight; } void setSize(const Size& size) { setWidth(size.w); setHeight(size.h); } + void setBounds(int x1, int y1, int x2, int y2) { + top = y1; + left = x1; + bottom = y2; + right = x2; + } + /* @param x the horizontal position to check @param y the vertical position to check @@ -206,7 +213,7 @@ struct Rect left = x; } - void moveTo(const Point & p) { + void moveTo(const Point& p) { moveTo(p.x, p.y); }