MCPcopy Create free account
hub / github.com/axmolengine/axmol / addImageAsyncCallBack

Method addImageAsyncCallBack

core/renderer/TextureCache.cpp:301–385  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

299}
300
301void 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 {

Callers

nothing calls this directly

Calls 15

parseNinePatchImageMethod · 0.95
getInstanceFunction · 0.85
initWithImageMethod · 0.80
autoreleaseMethod · 0.80
updateWithImageMethod · 0.80
lockMethod · 0.45
emptyMethod · 0.45
frontMethod · 0.45
pop_frontMethod · 0.45
unlockMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected