Use smart pointer to store static scanline data in FBSurface.

- in working on the OpenBSD crashing issue, I noticed that we can use a unique_ptr here
This commit is contained in:
Stephen Anthony 2018-06-06 17:57:15 -02:30
parent 17c60192dd
commit cf34707e27
5 changed files with 12 additions and 19 deletions

View File

@ -28,8 +28,7 @@ FBSurfaceSDL2::FBSurfaceSDL2(FrameBufferSDL2& buffer,
myTexAccess(SDL_TEXTUREACCESS_STREAMING),
myInterpolate(false),
myBlendEnabled(false),
myBlendAlpha(255),
myStaticData(nullptr)
myBlendAlpha(255)
{
createSurface(width, height, data);
}
@ -41,12 +40,6 @@ FBSurfaceSDL2::~FBSurfaceSDL2()
SDL_FreeSurface(mySurface);
free();
if(myStaticData)
{
delete[] myStaticData;
myStaticData = nullptr;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -173,7 +166,7 @@ void FBSurfaceSDL2::reload()
// If the data is static, we only upload it once
if(myTexAccess == SDL_TEXTUREACCESS_STATIC)
SDL_UpdateTexture(myTexture, nullptr, myStaticData, myStaticPitch);
SDL_UpdateTexture(myTexture, nullptr, myStaticData.get(), myStaticPitch);
// Blending enabled?
if(myBlendEnabled)
@ -225,8 +218,8 @@ void FBSurfaceSDL2::createSurface(uInt32 width, uInt32 height,
{
myTexAccess = SDL_TEXTUREACCESS_STATIC;
myStaticPitch = mySurface->w * 4; // we need pitch in 'bytes'
myStaticData = new uInt32[mySurface->w * mySurface->h];
SDL_memcpy(myStaticData, data, mySurface->w * mySurface->h * 4);
myStaticData = make_unique<uInt32[]>(mySurface->w * mySurface->h);
SDL_memcpy(myStaticData.get(), data, mySurface->w * mySurface->h * 4);
}
applyAttributes(false);

View File

@ -88,8 +88,8 @@ class FBSurfaceSDL2 : public FBSurface
bool myBlendEnabled; // Blending is enabled
uInt8 myBlendAlpha; // Alpha to use in blending mode
uInt32* myStaticData; // The data to use when the buffer contents are static
uInt32 myStaticPitch; // The number of bytes in a row of static data
unique_ptr<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;
};

View File

@ -317,8 +317,8 @@ void FrameBufferSDL2::setWindowIcon()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
unique_ptr<FBSurface> FrameBufferSDL2::createSurface(uInt32 w, uInt32 h,
const uInt32* data) const
unique_ptr<FBSurface>
FrameBufferSDL2::createSurface(uInt32 w, uInt32 h, const uInt32* data) const
{
return make_unique<FBSurfaceSDL2>(const_cast<FrameBufferSDL2&>(*this), w, h, data);
}

View File

@ -145,8 +145,8 @@ 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
*/
unique_ptr<FBSurface> createSurface(uInt32 w, uInt32 h, const uInt32* data)
const override;
unique_ptr<FBSurface>
createSurface(uInt32 w, uInt32 h, const uInt32* data) const override;
/**
Grabs or ungrabs the mouse based on the given boolean value.

View File

@ -349,8 +349,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 unique_ptr<FBSurface> createSurface(uInt32 w, uInt32 h,
const uInt32* data) const = 0;
virtual unique_ptr<FBSurface>
createSurface(uInt32 w, uInt32 h, const uInt32* data) const = 0;
/**
Grabs or ungrabs the mouse based on the given boolean value.