Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/graphics/TextureConverter.h
/* Copyright (C) 2012 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* 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