| 299 | } |
| 300 | |
| 301 | void TextureCache::addImageAsyncCallBack(float /*dt*/) |
| 302 | { |
| 303 | Texture2D* texture = nullptr; |
| 304 | AsyncStruct* asyncStruct = nullptr; |
| 305 | while (true) |
| 306 | { |
| 307 | // pop an AsyncStruct from response queue |
| 308 | _responseMutex.lock(); |
| 309 | if (_responseQueue.empty()) |
| 310 | { |
| 311 | asyncStruct = nullptr; |
| 312 | } |
| 313 | else |
| 314 | { |
| 315 | asyncStruct = _responseQueue.front(); |
| 316 | _responseQueue.pop_front(); |
| 317 | |
| 318 | // the asyncStruct's sequence order in _asyncStructQueue must equal to the order in _responseQueue |
| 319 | AX_ASSERT(asyncStruct == _asyncStructQueue.front()); |
| 320 | _asyncStructQueue.pop_front(); |
| 321 | } |
| 322 | _responseMutex.unlock(); |
| 323 | |
| 324 | if (nullptr == asyncStruct) |
| 325 | { |
| 326 | break; |
| 327 | } |
| 328 | |
| 329 | // check the image has been convert to texture or not |
| 330 | auto it = _textures.find(asyncStruct->filename); |
| 331 | if (it != _textures.end()) |
| 332 | { |
| 333 | texture = it->second; |
| 334 | } |
| 335 | else |
| 336 | { |
| 337 | // convert image to texture |
| 338 | if (asyncStruct->loadSuccess) |
| 339 | { |
| 340 | Image* image = &(asyncStruct->image); |
| 341 | // generate texture in render thread |
| 342 | texture = new Texture2D(); |
| 343 | |
| 344 | texture->initWithImage(image, asyncStruct->pixelFormat); |
| 345 | // parse 9-patch info |
| 346 | this->parseNinePatchImage(image, texture, asyncStruct->filename); |
| 347 | #if AX_ENABLE_CACHE_TEXTURE_DATA |
| 348 | // cache the texture file name |
| 349 | VolatileTextureMgr::addImageTexture(texture, asyncStruct->filename); |
| 350 | #endif |
| 351 | // cache the texture. retain it, since it is added in the map |
| 352 | _textures.emplace(asyncStruct->filename, texture); |
| 353 | texture->retain(); |
| 354 | |
| 355 | texture->autorelease(); |
| 356 | // ETC1 ALPHA supports. |
| 357 | if (asyncStruct->imageAlpha.getFileType() == Image::Format::ETC1) |
| 358 | { |
nothing calls this directly
no test coverage detected