Changeset View
Changeset View
Standalone View
Standalone View
core/document.cpp
Show First 20 Lines • Show All 1276 Lines • ▼ Show 20 Line(s) | |||||
1277 | { | 1277 | { | ||
1278 | /* If the pixmap cache will have to be cleaned in order to make room for the | 1278 | /* If the pixmap cache will have to be cleaned in order to make room for the | ||
1279 | * next request, get the distance from the current viewport of the page | 1279 | * next request, get the distance from the current viewport of the page | ||
1280 | * whose pixmap will be removed. We will ignore preload requests for pages | 1280 | * whose pixmap will be removed. We will ignore preload requests for pages | ||
1281 | * that are at the same distance or farther */ | 1281 | * that are at the same distance or farther */ | ||
1282 | const qulonglong memoryToFree = calculateMemoryToFree(); | 1282 | const qulonglong memoryToFree = calculateMemoryToFree(); | ||
1283 | const int currentViewportPage = (*m_viewportIterator).pageNumber; | 1283 | const int currentViewportPage = (*m_viewportIterator).pageNumber; | ||
1284 | int maxDistance = INT_MAX; // Default: No maximum | 1284 | int maxDistance = INT_MAX; // Default: No maximum | ||
1285 | qCDebug(OkularCoreDebug) << "sendGeneratorPixmapRequest entry for " << currentViewportPage; | ||||
1285 | if ( memoryToFree ) | 1286 | if ( memoryToFree ) | ||
1286 | { | 1287 | { | ||
1287 | AllocatedPixmap *pixmapToReplace = searchLowestPriorityPixmap( true ); | 1288 | AllocatedPixmap *pixmapToReplace = searchLowestPriorityPixmap( true ); | ||
1288 | if ( pixmapToReplace ) | 1289 | if ( pixmapToReplace ) | ||
1289 | maxDistance = qAbs( pixmapToReplace->page - currentViewportPage ); | 1290 | maxDistance = qAbs( pixmapToReplace->page - currentViewportPage ); | ||
1290 | } | 1291 | } | ||
1291 | 1292 | | |||
1292 | // find a request | 1293 | // find a request | ||
1293 | PixmapRequest * request = nullptr; | 1294 | PixmapRequest * request = nullptr; | ||
1294 | m_pixmapRequestsMutex.lock(); | 1295 | m_pixmapRequestsMutex.lock(); | ||
1295 | while ( !m_pixmapRequestsStack.isEmpty() && !request ) | 1296 | while ( !m_pixmapRequestsStack.isEmpty() && !request ) | ||
1296 | { | 1297 | { | ||
1297 | PixmapRequest * r = m_pixmapRequestsStack.last(); | 1298 | PixmapRequest * r = m_pixmapRequestsStack.last(); | ||
1298 | if (!r) | 1299 | if (!r) | ||
1299 | { | 1300 | { | ||
1300 | m_pixmapRequestsStack.pop_back(); | 1301 | m_pixmapRequestsStack.pop_back(); | ||
1301 | continue; | 1302 | continue; | ||
1302 | } | 1303 | } | ||
1303 | 1304 | | |||
1304 | QRect requestRect = r->isTile() ? r->normalizedRect().geometry( r->width(), r->height() ) : QRect( 0, 0, r->width(), r->height() ); | 1305 | QRect requestRect = r->isTile() ? r->normalizedRect().geometry( r->width(), r->height() ) : QRect( 0, 0, r->width(), r->height() ); | ||
1305 | TilesManager *tilesManager = r->d->tilesManager(); | 1306 | TilesManager *tilesManager = r->d->tilesManager(); | ||
1307 | double normalizedArea = r->normalizedRect().width() * r->normalizedRect().height(); | ||||
aacid: make this const | |||||
1306 | 1308 | | |||
1309 | qCDebug(OkularCoreDebug) << "sendGeneratorPixmapRequest loop (tile): for " << currentViewportPage << " isTile: " << r->isTile() | ||||
1310 | << " preload: " << r->preload() | ||||
1311 | << " normalizedRect" << r->normalizedRect() | ||||
1312 | << " requestRect=" << requestRect << " wxh=" << r->width() << " x " << r->height(); | ||||
1307 | // If it's a preload but the generator is not threaded no point in trying to preload | 1313 | // If it's a preload but the generator is not threaded no point in trying to preload | ||
1308 | if ( r->preload() && !m_generator->hasFeature( Generator::Threaded ) ) | 1314 | if ( r->preload() && !m_generator->hasFeature( Generator::Threaded ) ) | ||
1309 | { | 1315 | { | ||
1310 | m_pixmapRequestsStack.pop_back(); | 1316 | m_pixmapRequestsStack.pop_back(); | ||
1311 | delete r; | 1317 | delete r; | ||
1312 | } | 1318 | } | ||
1313 | // request only if page isn't already present and request has valid id | 1319 | // request only if page isn't already present and request has valid id | ||
1314 | else if ( ( !r->d->mForce && r->page()->hasPixmap( r->observer(), r->width(), r->height(), r->normalizedRect() ) ) || !m_observers.contains(r->observer()) ) | 1320 | else if ( ( !r->d->mForce && r->page()->hasPixmap( r->observer(), r->width(), r->height(), r->normalizedRect() ) ) || !m_observers.contains(r->observer()) ) | ||
1315 | { | 1321 | { | ||
1316 | m_pixmapRequestsStack.pop_back(); | 1322 | m_pixmapRequestsStack.pop_back(); | ||
1317 | delete r; | 1323 | delete r; | ||
1318 | } | 1324 | } | ||
1319 | else if ( !r->d->mForce && r->preload() && qAbs( r->pageNumber() - currentViewportPage ) >= maxDistance ) | 1325 | else if ( !r->d->mForce && r->preload() && qAbs( r->pageNumber() - currentViewportPage ) >= maxDistance ) | ||
1320 | { | 1326 | { | ||
1321 | m_pixmapRequestsStack.pop_back(); | 1327 | m_pixmapRequestsStack.pop_back(); | ||
1322 | //qCDebug(OkularCoreDebug) << "Ignoring request that doesn't fit in cache"; | 1328 | qCDebug(OkularCoreDebug) << "Ignoring request that doesn't fit in cache"; | ||
1323 | delete r; | 1329 | delete r; | ||
1324 | } | 1330 | } | ||
1325 | // Ignore requests for pixmaps that are already being generated | 1331 | // Ignore requests for pixmaps that are already being generated | ||
1326 | else if ( tilesManager && tilesManager->isRequesting( r->normalizedRect(), r->width(), r->height() ) ) | 1332 | else if ( tilesManager && tilesManager->isRequesting( r->normalizedRect(), r->width(), r->height() ) ) | ||
1327 | { | 1333 | { | ||
1334 | qCDebug(OkularCoreDebug).nospace() << "ignore already gen req for " << r->pageNumber(); | ||||
1328 | m_pixmapRequestsStack.pop_back(); | 1335 | m_pixmapRequestsStack.pop_back(); | ||
1329 | delete r; | 1336 | delete r; | ||
1330 | } | 1337 | } | ||
1331 | // If the requested area is above 8000000 pixels, switch on the tile manager | 1338 | // If the requested area is above 8000000 pixels, and we're not rendering most of the page, switch on the tile manager | ||
1332 | else if ( !tilesManager && m_generator->hasFeature( Generator::TiledRendering ) && (long)r->width() * (long)r->height() > 8000000L ) | 1339 | else if ( !tilesManager && m_generator->hasFeature( Generator::TiledRendering ) && | ||
1340 | (long)r->width() * (long)r->height() > 8000000L && | ||||
1341 | normalizedArea < 0.75 && normalizedArea != 0 ) | ||||
1333 | { | 1342 | { | ||
1334 | // if the image is too big. start using tiles | 1343 | // if the image is too big. start using tiles | ||
1335 | qCDebug(OkularCoreDebug).nospace() << "Start using tiles on page " << r->pageNumber() | 1344 | qCDebug(OkularCoreDebug).nospace() << "Start using tiles on page " << r->pageNumber() | ||
1336 | << " (" << r->width() << "x" << r->height() << " px);"; | 1345 | << " (" << r->width() << "x" << r->height() << " px);"; | ||
1337 | 1346 | | |||
1338 | // fill the tiles manager with the last rendered pixmap | 1347 | // fill the tiles manager with the last rendered pixmap | ||
1339 | const QPixmap *pixmap = r->page()->_o_nearestPixmap( r->observer(), r->width(), r->height() ); | 1348 | const QPixmap *pixmap = r->page()->_o_nearestPixmap( r->observer(), r->width(), r->height() ); | ||
1340 | if ( pixmap ) | 1349 | if ( pixmap ) | ||
Show All 27 Lines | 1373 | { | |||
1368 | else | 1377 | else | ||
1369 | tilesRect |= tile.rect(); | 1378 | tilesRect |= tile.rect(); | ||
1370 | 1379 | | |||
1371 | ++tIt; | 1380 | ++tIt; | ||
1372 | } | 1381 | } | ||
1373 | 1382 | | |||
1374 | r->setNormalizedRect( tilesRect ); | 1383 | r->setNormalizedRect( tilesRect ); | ||
1375 | request = r; | 1384 | request = r; | ||
1385 | qCDebug(OkularCoreDebug).nospace() << "large case request set:" << r; | ||||
1376 | } | 1386 | } | ||
1377 | else | 1387 | else | ||
1378 | { | 1388 | { | ||
1379 | // Discard request if normalizedRect is null. This happens in | 1389 | // Discard request if normalizedRect is null. This happens in | ||
1380 | // preload requests issued by PageView if the requested page is | 1390 | // preload requests issued by PageView if the requested page is | ||
1381 | // not visible and the user has just switched from a non-tiled | 1391 | // not visible and the user has just switched from a non-tiled | ||
1382 | // zoom level to a tiled one | 1392 | // zoom level to a tiled one | ||
1383 | m_pixmapRequestsStack.pop_back(); | 1393 | m_pixmapRequestsStack.pop_back(); | ||
1384 | delete r; | 1394 | delete r; | ||
1395 | qCDebug(OkularCoreDebug).nospace() << "large case request discard"; | ||||
1385 | } | 1396 | } | ||
1386 | } | 1397 | } | ||
1387 | // If the requested area is below 6000000 pixels, switch off the tile manager | 1398 | // If the requested area is below 6000000 pixels, switch off the tile manager | ||
1388 | else if ( tilesManager && (long)r->width() * (long)r->height() < 6000000L ) | 1399 | else if ( tilesManager && (long)r->width() * (long)r->height() < 6000000L ) | ||
1389 | { | 1400 | { | ||
1390 | qCDebug(OkularCoreDebug).nospace() << "Stop using tiles on page " << r->pageNumber() | 1401 | qCDebug(OkularCoreDebug).nospace() << "Stop using tiles on page " << r->pageNumber() | ||
1391 | << " (" << r->width() << "x" << r->height() << " px);"; | 1402 | << " (" << r->width() << "x" << r->height() << " px);"; | ||
1392 | 1403 | | |||
Show All 20 Lines | 1423 | { | |||
1413 | request = r; | 1424 | request = r; | ||
1414 | } | 1425 | } | ||
1415 | } | 1426 | } | ||
1416 | 1427 | | |||
1417 | // if no request found (or already generated), return | 1428 | // if no request found (or already generated), return | ||
1418 | if ( !request ) | 1429 | if ( !request ) | ||
1419 | { | 1430 | { | ||
1420 | m_pixmapRequestsMutex.unlock(); | 1431 | m_pixmapRequestsMutex.unlock(); | ||
1432 | qCDebug(OkularCoreDebug) << "sendGeneratorPixmapRequest exit !request for " << currentViewportPage; | ||||
1421 | return; | 1433 | return; | ||
1422 | } | 1434 | } | ||
1423 | 1435 | | |||
1424 | // [MEM] preventive memory freeing | 1436 | // [MEM] preventive memory freeing | ||
1425 | qulonglong pixmapBytes = 0; | 1437 | qulonglong pixmapBytes = 0; | ||
1426 | TilesManager * tm = request->d->tilesManager(); | 1438 | TilesManager * tm = request->d->tilesManager(); | ||
1427 | if ( tm ) | 1439 | if ( tm ) | ||
1428 | pixmapBytes = tm->totalMemory(); | 1440 | pixmapBytes = tm->totalMemory(); | ||
Show All 34 Lines | 1449 | { | |||
1463 | m_generator->generatePixmap( request ); | 1475 | m_generator->generatePixmap( request ); | ||
1464 | } | 1476 | } | ||
1465 | else | 1477 | else | ||
1466 | { | 1478 | { | ||
1467 | m_pixmapRequestsMutex.unlock(); | 1479 | m_pixmapRequestsMutex.unlock(); | ||
1468 | // pino (7/4/2006): set the polling interval from 10 to 30 | 1480 | // pino (7/4/2006): set the polling interval from 10 to 30 | ||
1469 | QTimer::singleShot( 30, m_parent, SLOT(sendGeneratorPixmapRequest()) ); | 1481 | QTimer::singleShot( 30, m_parent, SLOT(sendGeneratorPixmapRequest()) ); | ||
1470 | } | 1482 | } | ||
1483 | qCDebug(OkularCoreDebug) << "sendGeneratorPixmapRequest exit bottom for " << currentViewportPage; | ||||
1471 | } | 1484 | } | ||
1472 | 1485 | | |||
1473 | void DocumentPrivate::rotationFinished( int page, Okular::Page *okularPage ) | 1486 | void DocumentPrivate::rotationFinished( int page, Okular::Page *okularPage ) | ||
1474 | { | 1487 | { | ||
1475 | Okular::Page *wantedPage = m_pagesVector.value( page, 0 ); | 1488 | Okular::Page *wantedPage = m_pagesVector.value( page, 0 ); | ||
1476 | if ( !wantedPage || wantedPage != okularPage ) | 1489 | if ( !wantedPage || wantedPage != okularPage ) | ||
1477 | return; | 1490 | return; | ||
1478 | 1491 | | |||
▲ Show 20 Lines • Show All 4193 Lines • Show Last 20 Lines |
make this const