|
@@ -19,16 +19,16 @@
|
|
|
|
|
|
/**
|
|
|
* The base factory, keeping track of all blitters.
|
|
|
*/
|
|
|
class BlitterFactory {
|
|
|
private:
|
|
|
const char *name; ///< The name of the blitter factory.
|
|
|
const char *description; ///< The description of the blitter.
|
|
|
const std::string name; ///< The name of the blitter factory.
|
|
|
const std::string description; ///< The description of the blitter.
|
|
|
|
|
|
typedef std::map<const char *, BlitterFactory *, StringCompare> Blitters; ///< Map of blitter factories.
|
|
|
typedef std::map<std::string, BlitterFactory *> Blitters; ///< Map of blitter factories.
|
|
|
|
|
|
/**
|
|
|
* Get the map with currently known blitters.
|
|
|
* @return The known blitters.
|
|
|
*/
|
|
|
static Blitters &GetBlitters()
|
|
@@ -55,13 +55,13 @@ protected:
|
|
|
* @param usable Whether the blitter is usable (on the current computer). For example for disabling SSE blitters when the CPU can't handle them.
|
|
|
* @pre name != nullptr.
|
|
|
* @pre description != nullptr.
|
|
|
* @pre There is no blitter registered with this name.
|
|
|
*/
|
|
|
BlitterFactory(const char *name, const char *description, bool usable = true) :
|
|
|
name(stredup(name)), description(stredup(description))
|
|
|
name(name), description(description)
|
|
|
{
|
|
|
if (usable) {
|
|
|
/*
|
|
|
* Only add when the blitter is usable. Do not bail out or
|
|
|
* do more special things since the blitters are always
|
|
|
* instantiated upon start anyhow and freed upon shutdown.
|
|
@@ -75,56 +75,53 @@ protected:
|
|
|
|
|
|
public:
|
|
|
virtual ~BlitterFactory()
|
|
|
{
|
|
|
GetBlitters().erase(this->name);
|
|
|
if (GetBlitters().empty()) delete &GetBlitters();
|
|
|
|
|
|
free(this->name);
|
|
|
free(this->description);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Find the requested blitter and return his class.
|
|
|
* @param name the blitter to select.
|
|
|
* @post Sets the blitter so GetCurrentBlitter() returns it too.
|
|
|
*/
|
|
|
static Blitter *SelectBlitter(const char *name)
|
|
|
static Blitter *SelectBlitter(const std::string &name)
|
|
|
{
|
|
|
BlitterFactory *b = GetBlitterFactory(name);
|
|
|
if (b == nullptr) return nullptr;
|
|
|
|
|
|
Blitter *newb = b->CreateInstance();
|
|
|
delete *GetActiveBlitter();
|
|
|
*GetActiveBlitter() = newb;
|
|
|
|
|
|
DEBUG(driver, 1, "Successfully %s blitter '%s'", StrEmpty(name) ? "probed" : "loaded", newb->GetName());
|
|
|
DEBUG(driver, 1, "Successfully %s blitter '%s'", name.empty() ? "probed" : "loaded", newb->GetName());
|
|
|
return newb;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Get the blitter factory with the given name.
|
|
|
* @param name the blitter factory to select.
|
|
|
* @return The blitter factory, or nullptr when there isn't one with the wanted name.
|
|
|
*/
|
|
|
static BlitterFactory *GetBlitterFactory(const char *name)
|
|
|
static BlitterFactory *GetBlitterFactory(const std::string &name)
|
|
|
{
|
|
|
#if defined(DEDICATED)
|
|
|
const char *default_blitter = "null";
|
|
|
#elif defined(WITH_COCOA)
|
|
|
const char *default_blitter = "32bpp-anim";
|
|
|
#else
|
|
|
const char *default_blitter = "8bpp-optimized";
|
|
|
#endif
|
|
|
if (GetBlitters().size() == 0) return nullptr;
|
|
|
const char *bname = (StrEmpty(name)) ? default_blitter : name;
|
|
|
const char *bname = name.empty() ? default_blitter : name.c_str();
|
|
|
|
|
|
Blitters::iterator it = GetBlitters().begin();
|
|
|
for (; it != GetBlitters().end(); it++) {
|
|
|
BlitterFactory *b = (*it).second;
|
|
|
if (strcasecmp(bname, b->name) == 0) {
|
|
|
if (strcasecmp(bname, b->name.c_str()) == 0) {
|
|
|
return b;
|
|
|
}
|
|
|
}
|
|
|
return nullptr;
|
|
|
}
|
|
|
|
|
@@ -145,39 +142,39 @@ public:
|
|
|
static char *GetBlittersInfo(char *p, const char *last)
|
|
|
{
|
|
|
p += seprintf(p, last, "List of blitters:\n");
|
|
|
Blitters::iterator it = GetBlitters().begin();
|
|
|
for (; it != GetBlitters().end(); it++) {
|
|
|
BlitterFactory *b = (*it).second;
|
|
|
p += seprintf(p, last, "%18s: %s\n", b->name, b->GetDescription());
|
|
|
p += seprintf(p, last, "%18s: %s\n", b->name.c_str(), b->GetDescription().c_str());
|
|
|
}
|
|
|
p += seprintf(p, last, "\n");
|
|
|
|
|
|
return p;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Get the long, human readable, name for the Blitter-class.
|
|
|
*/
|
|
|
const char *GetName() const
|
|
|
const std::string &GetName() const
|
|
|
{
|
|
|
return this->name;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Get a nice description of the blitter-class.
|
|
|
*/
|
|
|
const char *GetDescription() const
|
|
|
const std::string &GetDescription() const
|
|
|
{
|
|
|
return this->description;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Create an instance of this Blitter-class.
|
|
|
*/
|
|
|
virtual Blitter *CreateInstance() = 0;
|
|
|
};
|
|
|
|
|
|
extern char *_ini_blitter;
|
|
|
extern std::string _ini_blitter;
|
|
|
extern bool _blitter_autodetected;
|
|
|
|
|
|
#endif /* BLITTER_FACTORY_HPP */
|