| 253 | } |
| 254 | |
| 255 | void TextureCache::loadImage() |
| 256 | { |
| 257 | AsyncStruct* asyncStruct = nullptr; |
| 258 | while (!_needQuit) |
| 259 | { |
| 260 | std::unique_lock<std::mutex> ul(_requestMutex); |
| 261 | // pop an AsyncStruct from request queue |
| 262 | if (_requestQueue.empty()) |
| 263 | { |
| 264 | asyncStruct = nullptr; |
| 265 | } |
| 266 | else |
| 267 | { |
| 268 | asyncStruct = _requestQueue.front(); |
| 269 | _requestQueue.pop_front(); |
| 270 | } |
| 271 | |
| 272 | if (nullptr == asyncStruct) |
| 273 | { |
| 274 | if (_needQuit) |
| 275 | { |
| 276 | break; |
| 277 | } |
| 278 | _sleepCondition.wait(ul); |
| 279 | continue; |
| 280 | } |
| 281 | ul.unlock(); |
| 282 | |
| 283 | // load image |
| 284 | asyncStruct->loadSuccess = asyncStruct->image.initWithImageFileThreadSafe(asyncStruct->filename); |
| 285 | |
| 286 | // ETC1 ALPHA supports. |
| 287 | if (asyncStruct->loadSuccess && asyncStruct->image.getFileType() == Image::Format::ETC1 && |
| 288 | !s_etc1AlphaFileSuffix.empty()) |
| 289 | { // check whether alpha texture exists & load it |
| 290 | auto alphaFile = asyncStruct->filename + s_etc1AlphaFileSuffix; |
| 291 | if (FileUtils::getInstance()->isFileExist(alphaFile)) |
| 292 | asyncStruct->imageAlpha.initWithImageFileThreadSafe(alphaFile); |
| 293 | } |
| 294 | // push the asyncStruct to response queue |
| 295 | _responseMutex.lock(); |
| 296 | _responseQueue.emplace_back(asyncStruct); |
| 297 | _responseMutex.unlock(); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | void TextureCache::addImageAsyncCallBack(float /*dt*/) |
| 302 | { |
nothing calls this directly
no test coverage detected