2012-07-11 00:48:30 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2012 by Mailson Menezes <mailson@gmail.com> *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2012-11-08 11:50:33 +00:00
|
|
|
#ifndef _OKULAR_TILES_MANAGER_P_H_
|
|
|
|
#define _OKULAR_TILES_MANAGER_P_H_
|
2012-07-07 17:40:52 +00:00
|
|
|
|
|
|
|
#include "area.h"
|
2014-10-27 21:35:06 +00:00
|
|
|
#include "okularcore_export.h"
|
2012-07-07 17:40:52 +00:00
|
|
|
|
|
|
|
class QPixmap;
|
|
|
|
|
|
|
|
namespace Okular
|
|
|
|
{
|
2012-11-08 20:29:09 +00:00
|
|
|
class Tile;
|
2012-11-08 15:41:00 +00:00
|
|
|
|
2012-11-09 18:24:29 +00:00
|
|
|
/**
|
|
|
|
* Node in the quadtree structure used by the tiles manager to store tiles.
|
|
|
|
*
|
|
|
|
* Except for the first level, the tiles manager stores tiles in a quadtree
|
|
|
|
* structure.
|
|
|
|
* Each node stores the pixmap of a tile and its location on the page.
|
|
|
|
* There's a limit on the size of the pixmaps (TILES_MAXSIZE, defined in
|
|
|
|
* tilesmanager.cpp), and tiles that are bigger than that value are split into
|
|
|
|
* four children tiles, which are stored as children of the original tile.
|
|
|
|
* If children tiles are still too big, they are recursively split again.
|
|
|
|
* If the zoom level changes and a big tile goes below the limit, it is merged
|
|
|
|
* back into a leaf tile.
|
|
|
|
*/
|
2012-11-08 15:41:00 +00:00
|
|
|
class TileNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TileNode();
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-11-08 15:41:00 +00:00
|
|
|
bool isValid() const;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-11-09 18:24:29 +00:00
|
|
|
/**
|
|
|
|
* Location on the page in normalized coords
|
|
|
|
*/
|
2012-11-08 15:41:00 +00:00
|
|
|
NormalizedRect rect;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-11-09 18:24:29 +00:00
|
|
|
/**
|
|
|
|
* Associated pixmap or NULL if not present
|
|
|
|
*
|
|
|
|
* For each node, it is guaranteed that there's no more than one pixmap
|
|
|
|
* along the path from the root to the node itself.
|
|
|
|
* In fact, it is very frequent that a leaf node has no pixmap and one
|
|
|
|
* of its ancestors has. Such a situation shows, for example, when the
|
|
|
|
* parent tile still has a dirty tile from a previous lower zoom level.
|
|
|
|
*/
|
2012-07-11 05:14:50 +00:00
|
|
|
QPixmap *pixmap;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-11-10 17:50:58 +00:00
|
|
|
/**
|
|
|
|
* Rotation of this individual tile.
|
|
|
|
*
|
|
|
|
* A rotation to the page does not immediately rotates the pixmaps in
|
|
|
|
* cache. This operation happens when pixmaps are going to be used.
|
|
|
|
*/
|
|
|
|
Rotation rotation;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-08-19 21:54:47 +00:00
|
|
|
/**
|
|
|
|
* Whether the tile needs to be repainted (after a zoom or rotation)
|
|
|
|
* If a tile doesn't have a pixmap but all its children are updated
|
|
|
|
* (dirty = false), the parent tile is also considered updated.
|
|
|
|
*/
|
2012-11-08 11:50:33 +00:00
|
|
|
bool dirty;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-11-08 13:58:08 +00:00
|
|
|
/**
|
|
|
|
* Distance between the tile and the viewport.
|
|
|
|
* This is used by the evicting algorithm.
|
|
|
|
*/
|
|
|
|
double distance;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-08-19 21:54:47 +00:00
|
|
|
/**
|
|
|
|
* Children tiles
|
2012-11-09 18:24:29 +00:00
|
|
|
* When a tile is split into multiple tiles, they're added as children.
|
|
|
|
* nTiles can be either 0 (in leaf tiles) or 4 (in split tiles).
|
2012-08-19 21:54:47 +00:00
|
|
|
*/
|
2012-11-08 15:41:00 +00:00
|
|
|
TileNode *tiles;
|
2012-08-04 21:00:19 +00:00
|
|
|
int nTiles;
|
2012-11-08 15:41:00 +00:00
|
|
|
TileNode *parent;
|
2012-07-11 05:14:50 +00:00
|
|
|
};
|
2012-07-07 17:40:52 +00:00
|
|
|
|
2012-08-19 21:54:47 +00:00
|
|
|
/**
|
|
|
|
* @short Tiles management
|
|
|
|
*
|
2012-11-09 18:24:29 +00:00
|
|
|
* This class has direct access to all tiles and handles how they should be
|
2012-11-08 11:50:33 +00:00
|
|
|
* stored, deleted and retrieved. Each tiles manager only handles one page.
|
2012-08-19 21:54:47 +00:00
|
|
|
*
|
2012-11-09 18:24:29 +00:00
|
|
|
* The tiles manager is a tree of tiles. At first the page is divided in a 4x4
|
|
|
|
* grid of 16 tiles. Then each of these tiles can be recursively split in 4
|
|
|
|
* subtiles so that we keep the size of each pixmap inside a safe interval.
|
2012-08-19 21:54:47 +00:00
|
|
|
*/
|
2012-11-09 18:10:01 +00:00
|
|
|
class TilesManager
|
2012-07-07 17:40:52 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-11-12 14:55:13 +00:00
|
|
|
enum TileLeaf {
|
|
|
|
TerminalTile, ///< Return tiles without children
|
|
|
|
PixmapTile ///< Return only tiles with pixmap
|
|
|
|
};
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-11-08 13:58:08 +00:00
|
|
|
TilesManager(int pageNumber, int width, int height, Rotation rotation = Rotation0);
|
2012-11-09 18:10:01 +00:00
|
|
|
~TilesManager();
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2019-01-09 23:28:49 +00:00
|
|
|
TilesManager(const TilesManager &) = delete;
|
|
|
|
TilesManager &operator=(const TilesManager &) = delete;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-08-19 21:54:47 +00:00
|
|
|
/**
|
2012-11-08 11:50:33 +00:00
|
|
|
* Sets the pixmap of the tiles covered by @p rect (which represents
|
|
|
|
* the location of @p pixmap on the page).
|
|
|
|
* @p pixmap may cover an area which contains multiple tiles. So each
|
|
|
|
* tile we get a cropped part of the @p pixmap.
|
|
|
|
*
|
|
|
|
* Also it checks the dimensions of the given parameters against the
|
|
|
|
* current request as to avoid setting pixmaps of late requests.
|
2012-08-19 21:54:47 +00:00
|
|
|
*/
|
2018-02-01 18:42:37 +00:00
|
|
|
void setPixmap(const QPixmap *pixmap, const NormalizedRect &rect, bool isPartialPixmap);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-08-19 21:54:47 +00:00
|
|
|
/**
|
|
|
|
* Checks whether all tiles intersecting with @p rect are available.
|
|
|
|
* Returns false if at least one tile needs to be repainted (the tile
|
|
|
|
* is dirty).
|
|
|
|
*/
|
2012-07-07 17:40:52 +00:00
|
|
|
bool hasPixmap(const NormalizedRect &rect);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-08-19 21:54:47 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of all tiles intersecting with @p rect.
|
|
|
|
*
|
2012-11-08 11:50:33 +00:00
|
|
|
* As to avoid requests of big areas, each traversed tile is checked
|
|
|
|
* for its size and split if necessary.
|
|
|
|
*
|
2018-10-19 06:00:06 +00:00
|
|
|
* @param rect The normalized rectangular area
|
2012-11-12 14:55:13 +00:00
|
|
|
* @param tileLeaf Indicate the type of tile to return
|
2012-08-19 21:54:47 +00:00
|
|
|
*/
|
2012-11-12 14:55:13 +00:00
|
|
|
QList<Tile> tilesAt(const NormalizedRect &rect, TileLeaf tileLeaf);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-08-19 21:54:47 +00:00
|
|
|
/**
|
|
|
|
* The total memory consumed by the tiles manager
|
|
|
|
*/
|
2012-11-08 18:31:53 +00:00
|
|
|
qulonglong totalMemory() const;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-08-19 21:54:47 +00:00
|
|
|
/**
|
2012-11-08 11:50:33 +00:00
|
|
|
* Removes at least @p numberOfBytes bytes worth of tiles (least ranked
|
|
|
|
* tiles are removed first).
|
2012-11-08 13:58:08 +00:00
|
|
|
* Set @p visibleRect to the visible region of the page. Set a
|
|
|
|
* @p visiblePageNumber if the current page is not visible.
|
2012-11-08 11:50:33 +00:00
|
|
|
* Visible tiles are not discarded.
|
2012-08-19 21:54:47 +00:00
|
|
|
*/
|
2012-11-08 13:58:08 +00:00
|
|
|
void cleanupPixmapMemory(qulonglong numberOfBytes, const NormalizedRect &visibleRect, int visiblePageNumber);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-09-25 01:01:47 +00:00
|
|
|
/**
|
|
|
|
* Checks whether a given region has already been requested
|
|
|
|
*/
|
|
|
|
bool isRequesting(const NormalizedRect &rect, int pageWidth, int pageHeight) const;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-09-25 01:01:47 +00:00
|
|
|
/**
|
|
|
|
* Sets a region to be requested so the tiles manager knows which
|
|
|
|
* pixmaps to expect and discard those not useful anymore (late pixmaps)
|
|
|
|
*/
|
|
|
|
void setRequest(const NormalizedRect &rect, int pageWidth, int pageHeight);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-08-19 21:54:47 +00:00
|
|
|
/**
|
2012-11-11 19:56:39 +00:00
|
|
|
* Inform the new size of the page and mark all tiles to repaint
|
2012-08-19 21:54:47 +00:00
|
|
|
*/
|
2012-11-11 19:56:39 +00:00
|
|
|
void setSize(int width, int height);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-11-08 11:50:33 +00:00
|
|
|
/**
|
|
|
|
* Gets the width of the page in tiles manager
|
|
|
|
*/
|
2012-08-19 21:54:47 +00:00
|
|
|
int width() const;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-11-08 11:50:33 +00:00
|
|
|
/**
|
|
|
|
* Gets the height of the page in tiles manager
|
|
|
|
*/
|
2012-08-19 21:54:47 +00:00
|
|
|
int height() const;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-08-19 21:54:47 +00:00
|
|
|
/**
|
2012-11-10 17:50:58 +00:00
|
|
|
* Inform the new rotation of the page
|
2012-08-19 21:54:47 +00:00
|
|
|
*/
|
2012-08-17 17:25:58 +00:00
|
|
|
void setRotation(Rotation rotation);
|
2012-08-19 21:54:47 +00:00
|
|
|
Rotation rotation() const;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-10-25 12:16:17 +00:00
|
|
|
/**
|
|
|
|
* Mark all tiles as dirty
|
|
|
|
*/
|
|
|
|
void markDirty();
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-08-19 21:54:47 +00:00
|
|
|
/**
|
|
|
|
* Returns a rotated NormalizedRect given a @p rotation
|
|
|
|
*/
|
2012-08-17 17:25:58 +00:00
|
|
|
static NormalizedRect toRotatedRect(const NormalizedRect &rect, Rotation rotation);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-08-19 21:54:47 +00:00
|
|
|
/**
|
|
|
|
* Returns a non rotated version of @p rect, which is rotated by @p rotation
|
|
|
|
*/
|
2012-08-17 17:25:58 +00:00
|
|
|
static NormalizedRect fromRotatedRect(const NormalizedRect &rect, Rotation rotation);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-07-07 17:40:52 +00:00
|
|
|
private:
|
2012-08-04 21:00:19 +00:00
|
|
|
class Private;
|
|
|
|
Private *const d;
|
|
|
|
friend class Private;
|
2012-07-07 17:40:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-08 11:50:33 +00:00
|
|
|
#endif // _OKULAR_TILES_MANAGER_P_H_
|