| 1352 | } |
| 1353 | |
| 1354 | void DocumentPrivate::sendGeneratorPixmapRequest() |
| 1355 | { |
| 1356 | /* If the pixmap cache will have to be cleaned in order to make room for the |
| 1357 | * next request, get the distance from the current viewport of the page |
| 1358 | * whose pixmap will be removed. We will ignore preload requests for pages |
| 1359 | * that are at the same distance or farther */ |
| 1360 | const qulonglong memoryToFree = calculateMemoryToFree(); |
| 1361 | const int currentViewportPage = (*m_viewportIterator).pageNumber; |
| 1362 | int maxDistance = INT_MAX; // Default: No maximum |
| 1363 | if (memoryToFree) { |
| 1364 | const AllocatedPixmap *pixmapToReplace = searchLowestPriorityPixmap(true); |
| 1365 | if (pixmapToReplace) { |
| 1366 | maxDistance = qAbs(pixmapToReplace->page - currentViewportPage); |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | // find a request |
| 1371 | PixmapRequest *request = nullptr; |
| 1372 | m_pixmapRequestsMutex.lock(); |
| 1373 | while (!m_pixmapRequestsStack.empty() && !request) { |
| 1374 | PixmapRequest *r = m_pixmapRequestsStack.back(); |
| 1375 | if (!r) { |
| 1376 | m_pixmapRequestsStack.pop_back(); |
| 1377 | continue; |
| 1378 | } |
| 1379 | |
| 1380 | QRect requestRect = r->isTile() ? r->normalizedRect().geometry(r->width(), r->height()) : QRect(0, 0, r->width(), r->height()); |
| 1381 | TilesManager *tilesManager = r->d->tilesManager(); |
| 1382 | const double normalizedArea = r->normalizedRect().width() * r->normalizedRect().height(); |
| 1383 | const QScreen *screen = nullptr; |
| 1384 | if (m_widget) { |
| 1385 | const QWindow *window = m_widget->window()->windowHandle(); |
| 1386 | if (window) { |
| 1387 | screen = window->screen(); |
| 1388 | } |
| 1389 | } |
| 1390 | if (!screen) { |
| 1391 | screen = QGuiApplication::primaryScreen(); |
| 1392 | } |
| 1393 | const long screenSize = screen->devicePixelRatio() * screen->size().width() * screen->devicePixelRatio() * screen->size().height(); |
| 1394 | |
| 1395 | // Make sure the page is the right size to receive the pixmap |
| 1396 | r->page()->setPageSize(r->observer(), r->width(), r->height()); |
| 1397 | |
| 1398 | // If it's a preload but the generator is not threaded no point in trying to preload |
| 1399 | if (r->preload() && !m_generator->hasFeature(Generator::Threaded)) { |
| 1400 | m_pixmapRequestsStack.pop_back(); |
| 1401 | delete r; |
| 1402 | } |
| 1403 | // request only if page isn't already present and request has valid id |
| 1404 | else if ((!r->d->mForce && r->page()->hasPixmap(r->observer(), r->width(), r->height(), r->normalizedRect())) || !m_observers.contains(r->observer())) { |
| 1405 | m_pixmapRequestsStack.pop_back(); |
| 1406 | delete r; |
| 1407 | } else if (!r->d->mForce && r->preload() && qAbs(r->pageNumber() - currentViewportPage) >= maxDistance) { |
| 1408 | m_pixmapRequestsStack.pop_back(); |
| 1409 | // qCDebug(OkularCoreDebug) << "Ignoring request that doesn't fit in cache"; |
| 1410 | delete r; |
| 1411 | } |
no test coverage detected