File indexing completed on 2025-02-23 04:08:58

0001 /*
0002  *  SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kis_canvas_updates_compressor.h"
0008 
0009 bool KisCanvasUpdatesCompressor::putUpdateInfo(KisUpdateInfoSP info)
0010 {
0011     const int levelOfDetail = info->levelOfDetail();
0012     const QRect newUpdateRect = info->dirtyImageRect();
0013     if (newUpdateRect.isEmpty()) return false;
0014 
0015     QMutexLocker l(&m_mutex);
0016 
0017     if (info->canBeCompressed()) {
0018         KisUpdateInfoList::iterator it = m_updatesList.begin();
0019         while (it != m_updatesList.end()) {
0020             if ((*it)->canBeCompressed() &&
0021                 levelOfDetail == (*it)->levelOfDetail() &&
0022                 newUpdateRect.contains((*it)->dirtyImageRect())) {
0023 
0024                 /**
0025                  * We should always remove the overridden update and put 'info' to the end
0026                  * of the queue. Otherwise, the updates will become reordered and the canvas
0027                  * may have tiles artifacts with "outdated" data
0028                  */
0029                 it = m_updatesList.erase(it);
0030             } else {
0031                 ++it;
0032             }
0033         }
0034     }
0035 
0036     m_updatesList.append(info);
0037 
0038     return m_updatesList.size() <= 1;
0039 }
0040 
0041 void KisCanvasUpdatesCompressor::takeUpdateInfo(KisUpdateInfoList &list)
0042 {
0043     KIS_SAFE_ASSERT_RECOVER(list.isEmpty()) { list.clear(); }
0044 
0045     QMutexLocker l(&m_mutex);
0046     m_updatesList.swap(list);
0047 }