Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/TextureConverter.h
Show All 13 Lines | |||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#ifndef INCLUDED_TEXTURECONVERTER | #ifndef INCLUDED_TEXTURECONVERTER | ||||
#define INCLUDED_TEXTURECONVERTER | #define INCLUDED_TEXTURECONVERTER | ||||
#include "lib/file/vfs/vfs.h" | #include "lib/file/vfs/vfs.h" | ||||
#include "lib/posix/posix_pthread.h" | |||||
#include "lib/external_libraries/libsdl.h" | #include "lib/external_libraries/libsdl.h" | ||||
#include "TextureManager.h" | #include "TextureManager.h" | ||||
#include <thread> | |||||
class MD5; | class MD5; | ||||
/** | /** | ||||
* Texture conversion helper class. | * Texture conversion helper class. | ||||
* Provides an asynchronous API to convert input image files into compressed DDS, | * Provides an asynchronous API to convert input image files into compressed DDS, | ||||
* given various conversion settings. | * given various conversion settings. | ||||
* (The (potentially very slow) compression is a performed in a background thread, | * (The (potentially very slow) compression is a performed in a background thread, | ||||
* so the game can remain responsive). | * so the game can remain responsive). | ||||
▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | public: | ||||
/** | /** | ||||
* Returns whether there is currently a queued request from ConvertTexture(). | * Returns whether there is currently a queued request from ConvertTexture(). | ||||
* (Note this may return false while the worker thread is still converting the last texture.) | * (Note this may return false while the worker thread is still converting the last texture.) | ||||
*/ | */ | ||||
bool IsBusy(); | bool IsBusy(); | ||||
private: | private: | ||||
static void* RunThread(void* data); | static void RunThread(CTextureConverter* data); | ||||
PIVFS m_VFS; | PIVFS m_VFS; | ||||
bool m_HighQuality; | bool m_HighQuality; | ||||
pthread_t m_WorkerThread; | std::thread m_WorkerThread; | ||||
pthread_mutex_t m_WorkerMutex; | std::mutex m_WorkerMutex; | ||||
SDL_sem* m_WorkerSem; | SDL_sem* m_WorkerSem; | ||||
struct ConversionRequest; | struct ConversionRequest; | ||||
struct ConversionResult; | struct ConversionResult; | ||||
std::deque<shared_ptr<ConversionRequest> > m_RequestQueue; // protected by m_WorkerMutex | std::deque<shared_ptr<ConversionRequest> > m_RequestQueue; // protected by m_WorkerMutex | ||||
std::deque<shared_ptr<ConversionResult> > m_ResultQueue; // protected by m_WorkerMutex | std::deque<shared_ptr<ConversionResult> > m_ResultQueue; // protected by m_WorkerMutex | ||||
bool m_Shutdown; // protected by m_WorkerMutex | bool m_Shutdown; // protected by m_WorkerMutex | ||||
}; | }; | ||||
#endif // INCLUDED_TEXTURECONVERTER | #endif // INCLUDED_TEXTURECONVERTER |
Wildfire Games · Phabricator