mirror of https://github.com/stella-emu/stella.git
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:
parent
17c60192dd
commit
cf34707e27
|
@ -28,8 +28,7 @@ FBSurfaceSDL2::FBSurfaceSDL2(FrameBufferSDL2& buffer,
|
||||||
myTexAccess(SDL_TEXTUREACCESS_STREAMING),
|
myTexAccess(SDL_TEXTUREACCESS_STREAMING),
|
||||||
myInterpolate(false),
|
myInterpolate(false),
|
||||||
myBlendEnabled(false),
|
myBlendEnabled(false),
|
||||||
myBlendAlpha(255),
|
myBlendAlpha(255)
|
||||||
myStaticData(nullptr)
|
|
||||||
{
|
{
|
||||||
createSurface(width, height, data);
|
createSurface(width, height, data);
|
||||||
}
|
}
|
||||||
|
@ -41,12 +40,6 @@ FBSurfaceSDL2::~FBSurfaceSDL2()
|
||||||
SDL_FreeSurface(mySurface);
|
SDL_FreeSurface(mySurface);
|
||||||
|
|
||||||
free();
|
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 the data is static, we only upload it once
|
||||||
if(myTexAccess == SDL_TEXTUREACCESS_STATIC)
|
if(myTexAccess == SDL_TEXTUREACCESS_STATIC)
|
||||||
SDL_UpdateTexture(myTexture, nullptr, myStaticData, myStaticPitch);
|
SDL_UpdateTexture(myTexture, nullptr, myStaticData.get(), myStaticPitch);
|
||||||
|
|
||||||
// Blending enabled?
|
// Blending enabled?
|
||||||
if(myBlendEnabled)
|
if(myBlendEnabled)
|
||||||
|
@ -225,8 +218,8 @@ void FBSurfaceSDL2::createSurface(uInt32 width, uInt32 height,
|
||||||
{
|
{
|
||||||
myTexAccess = SDL_TEXTUREACCESS_STATIC;
|
myTexAccess = SDL_TEXTUREACCESS_STATIC;
|
||||||
myStaticPitch = mySurface->w * 4; // we need pitch in 'bytes'
|
myStaticPitch = mySurface->w * 4; // we need pitch in 'bytes'
|
||||||
myStaticData = new uInt32[mySurface->w * mySurface->h];
|
myStaticData = make_unique<uInt32[]>(mySurface->w * mySurface->h);
|
||||||
SDL_memcpy(myStaticData, data, mySurface->w * mySurface->h * 4);
|
SDL_memcpy(myStaticData.get(), data, mySurface->w * mySurface->h * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
applyAttributes(false);
|
applyAttributes(false);
|
||||||
|
|
|
@ -88,7 +88,7 @@ class FBSurfaceSDL2 : public FBSurface
|
||||||
bool myBlendEnabled; // Blending is enabled
|
bool myBlendEnabled; // Blending is enabled
|
||||||
uInt8 myBlendAlpha; // Alpha to use in blending mode
|
uInt8 myBlendAlpha; // Alpha to use in blending mode
|
||||||
|
|
||||||
uInt32* myStaticData; // The data to use when the buffer contents are static
|
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
|
uInt32 myStaticPitch; // The number of bytes in a row of static data
|
||||||
|
|
||||||
GUI::Rect mySrcGUIR, myDstGUIR;
|
GUI::Rect mySrcGUIR, myDstGUIR;
|
||||||
|
|
|
@ -317,8 +317,8 @@ void FrameBufferSDL2::setWindowIcon()
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
unique_ptr<FBSurface> FrameBufferSDL2::createSurface(uInt32 w, uInt32 h,
|
unique_ptr<FBSurface>
|
||||||
const uInt32* data) const
|
FrameBufferSDL2::createSurface(uInt32 w, uInt32 h, const uInt32* data) const
|
||||||
{
|
{
|
||||||
return make_unique<FBSurfaceSDL2>(const_cast<FrameBufferSDL2&>(*this), w, h, data);
|
return make_unique<FBSurfaceSDL2>(const_cast<FrameBufferSDL2&>(*this), w, h, data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,8 +145,8 @@ class FrameBufferSDL2 : public FrameBuffer
|
||||||
@param h The requested height 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
|
@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)
|
unique_ptr<FBSurface>
|
||||||
const override;
|
createSurface(uInt32 w, uInt32 h, const uInt32* data) const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Grabs or ungrabs the mouse based on the given boolean value.
|
Grabs or ungrabs the mouse based on the given boolean value.
|
||||||
|
|
|
@ -349,8 +349,8 @@ class FrameBuffer
|
||||||
@param h The requested height 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
|
@param data If non-null, use the given data values as a static surface
|
||||||
*/
|
*/
|
||||||
virtual unique_ptr<FBSurface> createSurface(uInt32 w, uInt32 h,
|
virtual unique_ptr<FBSurface>
|
||||||
const uInt32* data) const = 0;
|
createSurface(uInt32 w, uInt32 h, const uInt32* data) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Grabs or ungrabs the mouse based on the given boolean value.
|
Grabs or ungrabs the mouse based on the given boolean value.
|
||||||
|
|
Loading…
Reference in New Issue