mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-02-19 13:25:38 +00:00
Removed the deprecated SVG scaleDuringLoad functionality.
This commit is contained in:
parent
a6f72ff934
commit
0dc6f1e17a
es-core/src/resources
|
@ -15,6 +15,7 @@
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "renderers/Renderer.h"
|
#include "renderers/Renderer.h"
|
||||||
#include "resources/ResourceManager.h"
|
#include "resources/ResourceManager.h"
|
||||||
|
#include "utils/StringUtil.h"
|
||||||
|
|
||||||
#include "nanosvg.h"
|
#include "nanosvg.h"
|
||||||
#include "nanosvgrast.h"
|
#include "nanosvgrast.h"
|
||||||
|
@ -31,7 +32,6 @@ TextureData::TextureData(bool tile)
|
||||||
, mHeight{0}
|
, mHeight{0}
|
||||||
, mSourceWidth{0.0f}
|
, mSourceWidth{0.0f}
|
||||||
, mSourceHeight{0.0f}
|
, mSourceHeight{0.0f}
|
||||||
, mScaleDuringLoad{1.0f}
|
|
||||||
, mScalable{false}
|
, mScalable{false}
|
||||||
, mLinearMagnify{false}
|
, mLinearMagnify{false}
|
||||||
, mForceRasterization{false}
|
, mForceRasterization{false}
|
||||||
|
@ -71,7 +71,7 @@ bool TextureData::initSVGFromMemory(const std::string& fileData)
|
||||||
bool rasterize{true};
|
bool rasterize{true};
|
||||||
|
|
||||||
// If there is no image size defined yet, then don't rasterize unless mForceRasterization has
|
// If there is no image size defined yet, then don't rasterize unless mForceRasterization has
|
||||||
// been set (this is only used by NinePatchComponent to avoid flickering menus).
|
// been set.
|
||||||
if (mSourceWidth == 0.0f && mSourceHeight == 0.0f) {
|
if (mSourceWidth == 0.0f && mSourceHeight == 0.0f) {
|
||||||
if (!mForceRasterization)
|
if (!mForceRasterization)
|
||||||
rasterize = false;
|
rasterize = false;
|
||||||
|
@ -80,8 +80,8 @@ bool TextureData::initSVGFromMemory(const std::string& fileData)
|
||||||
mSourceHeight = 64.0f * (svgImage->height / svgImage->width);
|
mSourceHeight = 64.0f * (svgImage->height / svgImage->width);
|
||||||
}
|
}
|
||||||
|
|
||||||
mWidth = static_cast<int>(std::round(mSourceWidth * mScaleDuringLoad));
|
mWidth = static_cast<int>(std::round(mSourceWidth));
|
||||||
mHeight = static_cast<int>(std::round(mSourceHeight * mScaleDuringLoad));
|
mHeight = static_cast<int>(std::round(mSourceHeight));
|
||||||
|
|
||||||
if (mWidth == 0) {
|
if (mWidth == 0) {
|
||||||
// Auto scale width to keep aspect ratio.
|
// Auto scale width to keep aspect ratio.
|
||||||
|
@ -176,7 +176,7 @@ bool TextureData::load()
|
||||||
std::shared_ptr<ResourceManager>& rm = ResourceManager::getInstance();
|
std::shared_ptr<ResourceManager>& rm = ResourceManager::getInstance();
|
||||||
const ResourceData& data = rm->getFileData(mPath);
|
const ResourceData& data = rm->getFileData(mPath);
|
||||||
// Is it an SVG?
|
// Is it an SVG?
|
||||||
if (mPath.substr(mPath.size() - 4, std::string::npos) == ".svg") {
|
if (Utils::String::toLower(mPath.substr(mPath.size() - 4, std::string::npos)) == ".svg") {
|
||||||
mScalable = true;
|
mScalable = true;
|
||||||
std::string dataString;
|
std::string dataString;
|
||||||
dataString.assign(std::string(reinterpret_cast<char*>(data.ptr.get()), data.length));
|
dataString.assign(std::string(reinterpret_cast<char*>(data.ptr.get()), data.length));
|
||||||
|
@ -243,22 +243,14 @@ size_t TextureData::width()
|
||||||
{
|
{
|
||||||
if (mWidth == 0)
|
if (mWidth == 0)
|
||||||
load();
|
load();
|
||||||
// If it's an SVG image, the size was correctly set to the scaled-up values during the
|
return static_cast<size_t>(mWidth);
|
||||||
// rasterization, so only multiply by the scale factor if it's a raster file.
|
|
||||||
if (!mScalable)
|
|
||||||
return static_cast<size_t>(mWidth * mScaleDuringLoad);
|
|
||||||
else
|
|
||||||
return mWidth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t TextureData::height()
|
size_t TextureData::height()
|
||||||
{
|
{
|
||||||
if (mHeight == 0)
|
if (mHeight == 0)
|
||||||
load();
|
load();
|
||||||
if (!mScalable)
|
return static_cast<size_t>(mHeight);
|
||||||
return static_cast<size_t>(mHeight * mScaleDuringLoad);
|
|
||||||
else
|
|
||||||
return mHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float TextureData::sourceWidth()
|
float TextureData::sourceWidth()
|
||||||
|
|
|
@ -57,8 +57,6 @@ public:
|
||||||
void setSourceSize(float width, float height);
|
void setSourceSize(float width, float height);
|
||||||
glm::vec2 getSize() { return glm::vec2{mWidth, mHeight}; }
|
glm::vec2 getSize() { return glm::vec2{mWidth, mHeight}; }
|
||||||
|
|
||||||
// Define a factor for scaling the file when loading it (1.0f = no scaling).
|
|
||||||
void setScaleDuringLoad(float scale) { mScaleDuringLoad = scale; }
|
|
||||||
// Whether to use linear filtering when magnifying the texture.
|
// Whether to use linear filtering when magnifying the texture.
|
||||||
void setLinearMagnify(bool setting) { mLinearMagnify = setting; }
|
void setLinearMagnify(bool setting) { mLinearMagnify = setting; }
|
||||||
// Whether to rasterize the image even if a size has not been set yet.
|
// Whether to rasterize the image even if a size has not been set yet.
|
||||||
|
@ -81,7 +79,6 @@ private:
|
||||||
int mHeight;
|
int mHeight;
|
||||||
float mSourceWidth;
|
float mSourceWidth;
|
||||||
float mSourceHeight;
|
float mSourceHeight;
|
||||||
float mScaleDuringLoad;
|
|
||||||
bool mScalable;
|
bool mScalable;
|
||||||
bool mLinearMagnify;
|
bool mLinearMagnify;
|
||||||
bool mReloadable;
|
bool mReloadable;
|
||||||
|
|
|
@ -16,12 +16,8 @@ std::map<TextureResource::TextureKeyType, std::weak_ptr<TextureResource>>
|
||||||
TextureResource::sTextureMap;
|
TextureResource::sTextureMap;
|
||||||
std::set<TextureResource*> TextureResource::sAllTextures;
|
std::set<TextureResource*> TextureResource::sAllTextures;
|
||||||
|
|
||||||
TextureResource::TextureResource(const std::string& path,
|
TextureResource::TextureResource(
|
||||||
bool tile,
|
const std::string& path, bool tile, bool dynamic, bool linearMagnify, bool forceRasterization)
|
||||||
bool dynamic,
|
|
||||||
bool linearMagnify,
|
|
||||||
bool forceRasterization,
|
|
||||||
float scaleDuringLoad)
|
|
||||||
: mTextureData(nullptr)
|
: mTextureData(nullptr)
|
||||||
, mForceLoad(false)
|
, mForceLoad(false)
|
||||||
{
|
{
|
||||||
|
@ -33,8 +29,6 @@ TextureResource::TextureResource(const std::string& path,
|
||||||
if (dynamic) {
|
if (dynamic) {
|
||||||
data = sTextureDataManager.add(this, tile);
|
data = sTextureDataManager.add(this, tile);
|
||||||
data->initFromPath(path);
|
data->initFromPath(path);
|
||||||
if (scaleDuringLoad != 1.0f)
|
|
||||||
data->setScaleDuringLoad(scaleDuringLoad);
|
|
||||||
data->setLinearMagnify(linearMagnify);
|
data->setLinearMagnify(linearMagnify);
|
||||||
data->setForceRasterization(forceRasterization);
|
data->setForceRasterization(forceRasterization);
|
||||||
// Force the texture manager to load it using a blocking load.
|
// Force the texture manager to load it using a blocking load.
|
||||||
|
@ -44,8 +38,6 @@ TextureResource::TextureResource(const std::string& path,
|
||||||
mTextureData = std::shared_ptr<TextureData>(new TextureData(tile));
|
mTextureData = std::shared_ptr<TextureData>(new TextureData(tile));
|
||||||
data = mTextureData;
|
data = mTextureData;
|
||||||
data->initFromPath(path);
|
data->initFromPath(path);
|
||||||
if (scaleDuringLoad != 1.0f)
|
|
||||||
data->setScaleDuringLoad(scaleDuringLoad);
|
|
||||||
data->setLinearMagnify(linearMagnify);
|
data->setLinearMagnify(linearMagnify);
|
||||||
data->setForceRasterization(forceRasterization);
|
data->setForceRasterization(forceRasterization);
|
||||||
// Load it so we can read the width/height.
|
// Load it so we can read the width/height.
|
||||||
|
@ -154,15 +146,14 @@ std::shared_ptr<TextureResource> TextureResource::get(const std::string& path,
|
||||||
bool forceLoad,
|
bool forceLoad,
|
||||||
bool dynamic,
|
bool dynamic,
|
||||||
bool linearMagnify,
|
bool linearMagnify,
|
||||||
bool forceRasterization,
|
bool forceRasterization)
|
||||||
float scaleDuringLoad)
|
|
||||||
{
|
{
|
||||||
std::shared_ptr<ResourceManager>& rm = ResourceManager::getInstance();
|
std::shared_ptr<ResourceManager>& rm = ResourceManager::getInstance();
|
||||||
|
|
||||||
const std::string canonicalPath = Utils::FileSystem::getCanonicalPath(path);
|
const std::string canonicalPath = Utils::FileSystem::getCanonicalPath(path);
|
||||||
if (canonicalPath.empty()) {
|
if (canonicalPath.empty()) {
|
||||||
std::shared_ptr<TextureResource> tex(new TextureResource(
|
std::shared_ptr<TextureResource> tex(
|
||||||
"", tile, false, linearMagnify, forceRasterization, scaleDuringLoad));
|
new TextureResource("", tile, false, linearMagnify, forceRasterization));
|
||||||
// Make sure we get properly deinitialized even though we do nothing on reinitialization.
|
// Make sure we get properly deinitialized even though we do nothing on reinitialization.
|
||||||
rm->addReloadable(tex);
|
rm->addReloadable(tex);
|
||||||
return tex;
|
return tex;
|
||||||
|
@ -178,8 +169,8 @@ std::shared_ptr<TextureResource> TextureResource::get(const std::string& path,
|
||||||
|
|
||||||
// Need to create it.
|
// Need to create it.
|
||||||
std::shared_ptr<TextureResource> tex;
|
std::shared_ptr<TextureResource> tex;
|
||||||
tex = std::shared_ptr<TextureResource>(new TextureResource(
|
tex = std::shared_ptr<TextureResource>(
|
||||||
key.first, tile, dynamic, linearMagnify, forceRasterization, scaleDuringLoad));
|
new TextureResource(key.first, tile, dynamic, linearMagnify, forceRasterization));
|
||||||
std::shared_ptr<TextureData> data = sTextureDataManager.get(tex.get());
|
std::shared_ptr<TextureData> data = sTextureDataManager.get(tex.get());
|
||||||
|
|
||||||
// Is it an SVG?
|
// Is it an SVG?
|
||||||
|
@ -219,6 +210,9 @@ void TextureResource::rasterizeAt(float width, float height)
|
||||||
data->setSourceSize(static_cast<float>(width), static_cast<float>(height));
|
data->setSourceSize(static_cast<float>(width), static_cast<float>(height));
|
||||||
if (mForceLoad || mTextureData != nullptr)
|
if (mForceLoad || mTextureData != nullptr)
|
||||||
data->load();
|
data->load();
|
||||||
|
|
||||||
|
mSize.x = width;
|
||||||
|
mSize.y = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t TextureResource::getTotalMemUsage()
|
size_t TextureResource::getTotalMemUsage()
|
||||||
|
|
|
@ -31,8 +31,7 @@ public:
|
||||||
bool forceLoad = false,
|
bool forceLoad = false,
|
||||||
bool dynamic = true,
|
bool dynamic = true,
|
||||||
bool linearMagnify = false,
|
bool linearMagnify = false,
|
||||||
bool forceRasterization = false,
|
bool forceRasterization = false);
|
||||||
float scaleDuringLoad = 1.0f);
|
|
||||||
void initFromPixels(const unsigned char* dataRGBA, size_t width, size_t height);
|
void initFromPixels(const unsigned char* dataRGBA, size_t width, size_t height);
|
||||||
virtual void initFromMemory(const char* data, size_t length);
|
virtual void initFromMemory(const char* data, size_t length);
|
||||||
static void manualUnload(std::string path, bool tile);
|
static void manualUnload(std::string path, bool tile);
|
||||||
|
@ -48,10 +47,6 @@ public:
|
||||||
|
|
||||||
std::string getTextureFilePath();
|
std::string getTextureFilePath();
|
||||||
|
|
||||||
// For SVG graphics this function effectively rescales the image to the defined size.
|
|
||||||
// It does unload and re-rasterize the texture though which may cause flickering in some
|
|
||||||
// situations. An alternative is to set a scaling factor directly when loading the texture
|
|
||||||
// using get(), by using the scaleDuringLoad parameter (which also works for raster graphics).
|
|
||||||
void rasterizeAt(float width, float height);
|
void rasterizeAt(float width, float height);
|
||||||
glm::vec2 getSourceImageSize() const { return mSourceSize; }
|
glm::vec2 getSourceImageSize() const { return mSourceSize; }
|
||||||
|
|
||||||
|
@ -72,8 +67,7 @@ protected:
|
||||||
bool tile,
|
bool tile,
|
||||||
bool dynamic,
|
bool dynamic,
|
||||||
bool linearMagnify,
|
bool linearMagnify,
|
||||||
bool forceRasterization,
|
bool forceRasterization);
|
||||||
float scaleDuringLoad);
|
|
||||||
virtual void unload(std::shared_ptr<ResourceManager>& rm);
|
virtual void unload(std::shared_ptr<ResourceManager>& rm);
|
||||||
virtual void reload(std::shared_ptr<ResourceManager>& rm);
|
virtual void reload(std::shared_ptr<ResourceManager>& rm);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue