Created
February 7, 2012 17:02
-
-
Save kenchris/1760745 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Source/WebCore/platform/graphics/TiledBackingStore.cpp b/Source/WebCore/platform/graphics/TiledBackingStore.cpp | |
index ceb489e..7f29813 100644 | |
--- a/Source/WebCore/platform/graphics/TiledBackingStore.cpp | |
+++ b/Source/WebCore/platform/graphics/TiledBackingStore.cpp | |
@@ -25,10 +25,11 @@ | |
#include "GraphicsContext.h" | |
#include "TiledBackingStoreClient.h" | |
+#include <QtDebug> | |
+ | |
namespace WebCore { | |
-static const int defaultTileWidth = 512; | |
-static const int defaultTileHeight = 512; | |
+static const int defaultTileDimension = 512; | |
static IntPoint innerBottomRight(const IntRect& rect) | |
{ | |
@@ -41,15 +42,13 @@ TiledBackingStore::TiledBackingStore(TiledBackingStoreClient* client, PassOwnPtr | |
, m_backend(backend) | |
, m_tileBufferUpdateTimer(new TileTimer(this, &TiledBackingStore::tileBufferUpdateTimerFired)) | |
, m_tileCreationTimer(new TileTimer(this, &TiledBackingStore::tileCreationTimerFired)) | |
- , m_tileSize(defaultTileWidth, defaultTileHeight) | |
+ , m_tileDimension(defaultTileDimension) | |
, m_tileCreationDelay(0.01) | |
- , m_keepAreaMultiplier(3.5f) | |
- , m_coverAreaMultiplier(2.5f) | |
+ , m_coverAreaMultiplier(2.0f) | |
, m_contentsScale(1.f) | |
, m_pendingScale(0) | |
, m_contentsFrozen(false) | |
{ | |
- ASSERT(m_coverAreaMultiplier <= m_keepAreaMultiplier); | |
} | |
TiledBackingStore::~TiledBackingStore() | |
@@ -60,7 +59,7 @@ TiledBackingStore::~TiledBackingStore() | |
void TiledBackingStore::setTileSize(const IntSize& size) | |
{ | |
- m_tileSize = size; | |
+ m_tileDimension = size.width(); | |
m_tiles.clear(); | |
startTileCreationTimer(); | |
} | |
@@ -70,14 +69,6 @@ void TiledBackingStore::setTileCreationDelay(double delay) | |
m_tileCreationDelay = delay; | |
} | |
-void TiledBackingStore::setKeepAndCoverAreaMultipliers(float keepMultiplier, float coverMultiplier) | |
-{ | |
- ASSERT(coverMultiplier <= keepMultiplier); | |
- m_keepAreaMultiplier = keepMultiplier; | |
- m_coverAreaMultiplier = coverMultiplier; | |
- startTileCreationTimer(); | |
-} | |
- | |
void TiledBackingStore::setVisibleRectTrajectoryVector(const FloatPoint& vector) | |
{ | |
if (m_visibleRectTrajectoryVector == vector) | |
@@ -256,18 +247,18 @@ void TiledBackingStore::createTiles() | |
// Resize tiles on edges in case the contents size has changed. | |
bool didResizeTiles = resizeEdgeTiles(); | |
- IntRect keepRect = computeKeepRect(visibleRect); | |
- | |
+ IntRect keepRect; | |
+ IntRect coverRect; | |
+ computeCoverAndKeepRect(visibleRect, coverRect, keepRect); | |
+ | |
dropTilesOutsideRect(keepRect); | |
- IntRect coverRect = computeCoverRect(visibleRect); | |
- ASSERT(keepRect.contains(coverRect)); | |
- | |
// Search for the tile position closest to the viewport center that does not yet contain a tile. | |
// Which position is considered the closest depends on the tileDistance function. | |
double shortestDistance = std::numeric_limits<double>::infinity(); | |
Vector<Tile::Coordinate> tilesToCreate; | |
unsigned requiredTileCount = 0; | |
+ | |
Tile::Coordinate topLeft = tileCoordinateForPoint(coverRect.location()); | |
Tile::Coordinate bottomRight = tileCoordinateForPoint(innerBottomRight(coverRect)); | |
for (unsigned yCoordinate = topLeft.y(); yCoordinate <= bottomRight.y(); ++yCoordinate) { | |
@@ -287,7 +278,7 @@ void TiledBackingStore::createTiles() | |
tilesToCreate.append(currentCoordinate); | |
} | |
} | |
- | |
+ | |
// Now construct the tile(s) | |
unsigned tilesToCreateCount = tilesToCreate.size(); | |
for (unsigned n = 0; n < tilesToCreateCount; ++n) { | |
@@ -305,17 +296,6 @@ void TiledBackingStore::createTiles() | |
m_tileCreationTimer->startOneShot(m_tileCreationDelay); | |
} | |
-IntRect TiledBackingStore::computeKeepRect(const IntRect& visibleRect) const | |
-{ | |
- IntRect result = visibleRect; | |
- // Inflates to both sides, so divide the inflate delta by 2. | |
- result.inflateX(visibleRect.width() * (m_keepAreaMultiplier - 1) / 2); | |
- result.inflateY(visibleRect.height() * (m_keepAreaMultiplier - 1) / 2); | |
- result.intersect(contentsRect()); | |
- | |
- return result; | |
-} | |
- | |
// A null trajectory vector means that tiles intersecting all the coverArea (i.e. visibleRect * coverMultiplier) will be created. | |
// A non-null trajectory vector will shrink the intersection rect to visibleRect plus its expansion from its | |
// center toward the cover area edges in the direction of the given vector. | |
@@ -323,24 +303,37 @@ IntRect TiledBackingStore::computeKeepRect(const IntRect& visibleRect) const | |
// a (0,0) trajectory vector will create tiles intersecting (5,5)15x15, | |
// a (1,0) trajectory vector will create tiles intersecting (10,10)10x5, | |
// and a (1,1) trajectory vector will create tiles intersecting (10,10)10x10. | |
-IntRect TiledBackingStore::computeCoverRect(const IntRect& visibleRect) const | |
+void TiledBackingStore::computeCoverAndKeepRect(const IntRect& visibleRect, IntRect& coverRect, IntRect& keepRect) const | |
{ | |
- IntRect result = visibleRect; | |
+ coverRect = visibleRect; | |
+ | |
float trajectoryVectorNorm = sqrt(pow(m_visibleRectTrajectoryVector.x(), 2) + pow(m_visibleRectTrajectoryVector.y(), 2)); | |
if (trajectoryVectorNorm > 0) { | |
// Multiply the vector by the distance to the edge of the cover area. | |
- float trajectoryVectorMultiplier = (m_coverAreaMultiplier - 1) / 2; | |
+ float trajectoryVectorMultiplier = (m_coverAreaMultiplier - 1); | |
// Unite the visible rect with a "ghost" of the visible rect moved in the direction of the trajectory vector. | |
- result.move(result.width() * m_visibleRectTrajectoryVector.x() / trajectoryVectorNorm * trajectoryVectorMultiplier, | |
- result.height() * m_visibleRectTrajectoryVector.y() / trajectoryVectorNorm * trajectoryVectorMultiplier); | |
- result.unite(visibleRect); | |
+ coverRect.move(coverRect.width() * m_visibleRectTrajectoryVector.x() / trajectoryVectorNorm * trajectoryVectorMultiplier, | |
+ coverRect.height() * m_visibleRectTrajectoryVector.y() / trajectoryVectorNorm * trajectoryVectorMultiplier); | |
+ coverRect.unite(visibleRect); | |
} else { | |
- result.inflateX(visibleRect.width() * (m_coverAreaMultiplier - 1) / 2); | |
- result.inflateY(visibleRect.height() * (m_coverAreaMultiplier - 1) / 2); | |
+ coverRect.inflateX(visibleRect.width() * (m_coverAreaMultiplier - 1) / 2); | |
+ coverRect.inflateY(visibleRect.height() * (m_coverAreaMultiplier - 1) / 2); | |
} | |
- result.intersect(contentsRect()); | |
- return result; | |
+ // The cover rect used as base for the keep rect has to be inflated to the non-optimized size used while not panning. | |
+ IntRect normalizedCoverRect = coverRect; | |
+ normalizedCoverRect.inflateX((visibleRect.width() * m_coverAreaMultiplier - coverRect.width()) / 2); | |
+ normalizedCoverRect.inflateY((visibleRect.height() * m_coverAreaMultiplier - coverRect.height()) / 2); | |
+ | |
+ // The keep rect is an inflated version of the cover rect, inflated in tile dimensions. | |
+ keepRect = normalizedCoverRect; | |
+ keepRect.inflateX(m_tileDimension / 3); | |
+ keepRect.inflateY(m_tileDimension / 3); | |
+ | |
+ qWarning() << "visible/cover/keep (needed/kept around)" << QRect(visibleRect).size() << QRect(coverRect).size() << QRect(keepRect).size() << (coverRect.width() / 512) * (coverRect.height() / 512) << (keepRect.width() / 512) * (keepRect.height() / 512); | |
+ | |
+ coverRect.intersect(contentsRect()); | |
+ keepRect.intersect(contentsRect()); | |
} | |
bool TiledBackingStore::resizeEdgeTiles() | |
@@ -421,10 +414,10 @@ IntRect TiledBackingStore::contentsRect() const | |
IntRect TiledBackingStore::tileRectForCoordinate(const Tile::Coordinate& coordinate) const | |
{ | |
- IntRect rect(coordinate.x() * m_tileSize.width(), | |
- coordinate.y() * m_tileSize.height(), | |
- m_tileSize.width(), | |
- m_tileSize.height()); | |
+ IntRect rect(coordinate.x() * m_tileDimension, | |
+ coordinate.y() * m_tileDimension, | |
+ m_tileDimension, | |
+ m_tileDimension); | |
rect.intersect(contentsRect()); | |
return rect; | |
@@ -432,8 +425,8 @@ IntRect TiledBackingStore::tileRectForCoordinate(const Tile::Coordinate& coordin | |
Tile::Coordinate TiledBackingStore::tileCoordinateForPoint(const IntPoint& point) const | |
{ | |
- int x = point.x() / m_tileSize.width(); | |
- int y = point.y() / m_tileSize.height(); | |
+ int x = point.x() / m_tileDimension; | |
+ int y = point.y() / m_tileDimension; | |
return Tile::Coordinate(std::max(x, 0), std::max(y, 0)); | |
} | |
diff --git a/Source/WebCore/platform/graphics/TiledBackingStore.h b/Source/WebCore/platform/graphics/TiledBackingStore.h | |
index 0a02ac5..1a10d27 100644 | |
--- a/Source/WebCore/platform/graphics/TiledBackingStore.h | |
+++ b/Source/WebCore/platform/graphics/TiledBackingStore.h | |
@@ -57,19 +57,12 @@ public: | |
void invalidate(const IntRect& dirtyRect); | |
void paint(GraphicsContext*, const IntRect&); | |
- IntSize tileSize() { return m_tileSize; } | |
+ IntSize tileSize() { return IntSize(m_tileDimension, m_tileDimension); } | |
void setTileSize(const IntSize&); | |
double tileCreationDelay() const { return m_tileCreationDelay; } | |
void setTileCreationDelay(double delay); | |
- // Tiled are dropped outside the keep area, and created for cover area. The values a relative to the viewport size. | |
- void getKeepAndCoverAreaMultipliers(float& keepMultiplier, float& coverMultiplier) | |
- { | |
- keepMultiplier = m_keepAreaMultiplier; | |
- coverMultiplier = m_coverAreaMultiplier; | |
- } | |
- void setKeepAndCoverAreaMultipliers(float keepMultiplier, float coverMultiplier); | |
void setVisibleRectTrajectoryVector(const FloatPoint&); | |
IntRect mapToContents(const IntRect&) const; | |
@@ -90,8 +83,7 @@ private: | |
void tileCreationTimerFired(TileTimer*); | |
void createTiles(); | |
- IntRect computeKeepRect(const IntRect& visibleRect) const; | |
- IntRect computeCoverRect(const IntRect& visibleRect) const; | |
+ void computeCoverAndKeepRect(const IntRect& visibleRect, IntRect& coverRect, IntRect& keepRect) const; | |
void commitScaleChange(); | |
@@ -117,7 +109,7 @@ private: | |
TileTimer* m_tileBufferUpdateTimer; | |
TileTimer* m_tileCreationTimer; | |
- IntSize m_tileSize; | |
+ int m_tileDimension; | |
double m_tileCreationDelay; | |
float m_keepAreaMultiplier; | |
float m_coverAreaMultiplier; | |
diff --git a/Source/WebKit/qt/Api/qwebpage.cpp b/Source/WebKit/qt/Api/qwebpage.cpp | |
index f94d445..daca8ed 100644 | |
--- a/Source/WebKit/qt/Api/qwebpage.cpp | |
+++ b/Source/WebKit/qt/Api/qwebpage.cpp | |
@@ -1212,28 +1212,6 @@ void QWebPagePrivate::dynamicPropertyChangeEvent(QDynamicPropertyChangeEvent* ev | |
return; | |
int tileCreationDelay = q->property("_q_TiledBackingStoreTileCreationDelay").toInt(); | |
frame->tiledBackingStore()->setTileCreationDelay(static_cast<double>(tileCreationDelay) / 1000.); | |
- } else if (event->propertyName() == "_q_TiledBackingStoreKeepAreaMultiplier") { | |
- WebCore::Frame* frame = QWebFramePrivate::core(q->mainFrame()); | |
- if (!frame->tiledBackingStore()) | |
- return; | |
- float keepMultiplier; | |
- float coverMultiplier; | |
- frame->tiledBackingStore()->getKeepAndCoverAreaMultipliers(keepMultiplier, coverMultiplier); | |
- QSizeF qSize = q->property("_q_TiledBackingStoreKeepAreaMultiplier").toSizeF(); | |
- // setKeepAndCoverAreaMultipliers do not use FloatSize anymore, keep only the height part. | |
- keepMultiplier = qSize.height(); | |
- frame->tiledBackingStore()->setKeepAndCoverAreaMultipliers(keepMultiplier, coverMultiplier); | |
- } else if (event->propertyName() == "_q_TiledBackingStoreCoverAreaMultiplier") { | |
- WebCore::Frame* frame = QWebFramePrivate::core(q->mainFrame()); | |
- if (!frame->tiledBackingStore()) | |
- return; | |
- float keepMultiplier; | |
- float coverMultiplier; | |
- frame->tiledBackingStore()->getKeepAndCoverAreaMultipliers(keepMultiplier, coverMultiplier); | |
- QSizeF qSize = q->property("_q_TiledBackingStoreCoverAreaMultiplier").toSizeF(); | |
- // setKeepAndCoverAreaMultipliers do not use FloatSize anymore, keep only the height part. | |
- coverMultiplier = qSize.height(); | |
- frame->tiledBackingStore()->setKeepAndCoverAreaMultipliers(keepMultiplier, coverMultiplier); | |
} | |
#endif | |
else if (event->propertyName() == "_q_webInspectorServerPort") { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment