PassRefPtr<BitmapTexture> BitmapTexturePool::acquireTexture(const IntSize& size, TextureMapper* textureMapper) { BitmapTexturePoolEntry* selectedEntry = 0; for (size_t i = 0; i < m_textures.size(); ++i) { BitmapTexturePoolEntry* entry = &m_textures[i]; // If the surface has only one reference (the one in m_textures), we can safely reuse it. if (entry->m_texture->refCount() > 1) continue; if (entry->m_texture->canReuseWith(size)) { selectedEntry = entry; break; } } if (!selectedEntry) { m_textures.append(BitmapTexturePoolEntry(textureMapper->createTexture())); selectedEntry = &m_textures.last(); } scheduleReleaseUnusedTextures(); selectedEntry->markUsed(); return selectedEntry->m_texture; }
void BitmapTexturePool::releaseUnusedTexturesTimerFired() { // Delete entries, which have been unused in s_releaseUnusedSecondsTolerance. double minUsedTime = monotonicallyIncreasingTime() - s_releaseUnusedSecondsTolerance; if (!m_textures.isEmpty()) { std::sort(m_textures.begin(), m_textures.end(), [](const Entry& a, const Entry& b) { return a.m_lastUsedTime > b.m_lastUsedTime; }); for (size_t i = 0; i < m_textures.size(); ++i) { if (m_textures[i].m_lastUsedTime < minUsedTime) { m_textures.remove(i, m_textures.size() - i); break; } } } if (!m_attachmentTextures.isEmpty()) { std::sort(m_attachmentTextures.begin(), m_attachmentTextures.end(), [](const Entry& a, const Entry& b) { return a.m_lastUsedTime > b.m_lastUsedTime; }); for (size_t i = 0; i < m_attachmentTextures.size(); ++i) { if (m_attachmentTextures[i].m_lastUsedTime < minUsedTime) { m_attachmentTextures.remove(i, m_attachmentTextures.size() - i); break; } } } if (!m_textures.isEmpty() || !m_attachmentTextures.isEmpty()) scheduleReleaseUnusedTextures(); }
RefPtr<BitmapTexture> BitmapTexturePool::acquireTexture(const IntSize& size, const BitmapTexture::Flags flags) { Vector<Entry>& list = flags & BitmapTexture::FBOAttachment ? m_attachmentTextures : m_textures; Entry* selectedEntry = std::find_if(list.begin(), list.end(), [&size](Entry& entry) { return entry.m_texture->refCount() == 1 && entry.m_texture->size() == size; }); if (selectedEntry == list.end()) { list.append(Entry(createTexture(flags))); selectedEntry = &list.last(); } scheduleReleaseUnusedTextures(); selectedEntry->markIsInUse(); return selectedEntry->m_texture.copyRef(); }
PassRefPtr<BitmapTexture> BitmapTexturePool::acquireTexture(const IntSize& size) { BitmapTexturePoolEntry* selectedEntry = 0; for (auto& entry : m_textures) { // If the surface has only one reference (the one in m_textures), we can safely reuse it. if (entry.m_texture->refCount() > 1) continue; if (entry.m_texture->size() == size) { selectedEntry = &entry; break; } } if (!selectedEntry) { m_textures.append(BitmapTexturePoolEntry(createTexture())); selectedEntry = &m_textures.last(); } scheduleReleaseUnusedTextures(); selectedEntry->markUsed(); return selectedEntry->m_texture; }