MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenImageIO / read_tile

Method read_tile

src/libtexture/imagecache.cpp:611–694  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

609
610
611bool
612ImageCacheFile::read_tile (ImageCachePerThreadInfo *thread_info,
613 int subimage, int miplevel, int x, int y, int z,
614 TypeDesc format, void *data)
615{
616 recursive_lock_guard guard (m_input_mutex);
617
618 if (! m_input && !m_broken) {
619 // The file is already in the file cache, but the handle is
620 // closed. We will need to re-open, so we must make sure there
621 // will be enough file handles.
622 // But wait, it's possible that somebody else is waiting on our
623 // m_input_mutex, which we locked above. To avoid deadlock, we
624 // need to release m_input_mutex while we close files.
625 m_input_mutex.unlock ();
626 imagecache().check_max_files (thread_info);
627 // Now we're back, whew! Grab the lock again.
628 m_input_mutex.lock ();
629 }
630
631 bool ok = open (thread_info);
632 if (! ok)
633 return false;
634
635 // Mark if we ever use a mip level that's not the first
636 if (miplevel > 0)
637 m_mipused = true;
638
639 // count how many times this mipmap level was read
640 m_mipreadcount[miplevel]++;
641
642 SubimageInfo &subinfo (subimageinfo(subimage));
643
644 // Special case for un-MIP-mapped
645 if (subinfo.unmipped && miplevel != 0) {
646 // For a non-base mip level of an unmipped file, release the
647 // mutex on the ImageInput since upper levels don't need to
648 // directly perform I/O. This prevents the deadlock that could
649 // occur if another thread has one of the lower-level tiles and
650 // itself blocks on the mutex (it's waiting for our mutex, we're
651 // waiting on its tile to get filled with pixels).
652 unlock_input_mutex ();
653 bool ok = read_unmipped (thread_info, subimage, miplevel,
654 x, y, z, format, data);
655 // The lock_guard at the very top will try to unlock upon
656 // destruction, to to make things right, we need to re-lock.
657 lock_input_mutex ();
658 return ok;
659 }
660
661 // Special case for untiled images -- need to do tile emulation
662 if (subinfo.untiled)
663 return read_untiled (thread_info, subimage, miplevel,
664 x, y, z, format, data);
665
666 // Ordinary tiled
667 ImageSpec tmp;
668 if (m_input->current_subimage() != subimage ||

Callers 1

readMethod · 0.45

Calls 14

openFunction · 0.85
unlock_input_mutexFunction · 0.85
lock_input_mutexFunction · 0.85
check_max_filesMethod · 0.80
failure_retriesMethod · 0.80
tile_bytesMethod · 0.80
unlockMethod · 0.45
lockMethod · 0.45
current_subimageMethod · 0.45
current_miplevelMethod · 0.45
seek_subimageMethod · 0.45
geterrorMethod · 0.45

Tested by

no test coverage detected