Commit 06164dc27c310b7b8c05b98fd8ce9bafdb8e71f6
- Diff rendering mode:
- inline
- side by side
WebCore/platform/TileCache.h
(6 / 1)
|   | |||
| 77 | 77 | void setTile(const TileCoordinate& coordinate, PassRefPtr<Tile> tile); | |
| 78 | 78 | void removeTile(const TileCoordinate& coordinate); | |
| 79 | 79 | ||
| 80 | FloatRect tileRectForCoordinate(const TileCoordinate&) const; | ||
| 80 | IntRect rectToDocument(const IntRect&) const; | ||
| 81 | IntRect rectFromDocument(const IntRect&) const; | ||
| 82 | |||
| 83 | IntRect contentRect() const; | ||
| 84 | |||
| 85 | IntRect tileRectForCoordinate(const TileCoordinate&) const; | ||
| 81 | 86 | TileCache::TileCoordinate tileCoordinateForPoint(const IntPoint&) const; | |
| 82 | 87 | double tileDistance(const IntRect& viewport, const TileCache::TileCoordinate&); | |
| 83 | 88 |
WebCore/platform/qt/TileCacheQt.cpp
(88 / 42)
|   | |||
| 135 | 135 | ~Tile(); | |
| 136 | 136 | ||
| 137 | 137 | bool isDirty() const { return !m_dirtyRegion.isEmpty(); } | |
| 138 | const QRegion& dirtyRegion() const { return m_dirtyRegion; } | ||
| 138 | 139 | void invalidate(const IntRect&); | |
| 139 | 140 | void updateBuffer(); | |
| 140 | 141 | void swapBuffer(); | |
| … | … | ||
| 143 | 143 | void paint(QPainter* painter, const IntRect& rect); | |
| 144 | 144 | ||
| 145 | 145 | const TileCache::TileCoordinate coordinate() const { return m_tileCoordinate; } | |
| 146 | const FloatRect& rect() const { return m_tileRect; } | ||
| 147 | IntRect enclosingIntRect() const { return WebCore::enclosingIntRect(m_tileRect); } | ||
| 146 | const IntRect& rect() const { return m_tileRect; } | ||
| 147 | const IntRect rectToDocument() const { return m_cache->rectToDocument(m_tileRect); } | ||
| 148 | 148 | ||
| 149 | 149 | private: | |
| 150 | 150 | Tile(TileCache* cache, const TileCache::TileCoordinate& tileCoordinate); | |
| 151 | 151 | ||
| 152 | 152 | TileCache* m_cache; | |
| 153 | 153 | TileCache::TileCoordinate m_tileCoordinate; | |
| 154 | FloatRect m_tileRect; | ||
| 154 | IntRect m_tileRect; | ||
| 155 | 155 | QImage* m_buffer; | |
| 156 | 156 | QImage* m_backBuffer; | |
| 157 | 157 | QRegion m_dirtyRegion; | |
| … | … | ||
| 169 | 169 | , m_tileRect(m_cache->tileRectForCoordinate(tileCoordinate)) | |
| 170 | 170 | , m_buffer(0) | |
| 171 | 171 | , m_backBuffer(0) | |
| 172 | , m_dirtyRegion(enclosingIntRect()) | ||
| 172 | , m_dirtyRegion(m_tileRect) | ||
| 173 | 173 | , m_pixmapNeedsReset(false) | |
| 174 | 174 | { | |
| 175 | 175 | #if ENABLE(ENGINE_THREAD) | |
| … | … | ||
| 190 | 190 | ||
| 191 | 191 | void Tile::invalidate(const IntRect& dirtyRect) | |
| 192 | 192 | { | |
| 193 | IntRect tileDirtyRect = intersection(dirtyRect, enclosingIntRect()); | ||
| 193 | IntRect tileDirtyRect = intersection(dirtyRect, m_tileRect); | ||
| 194 | 194 | if (tileDirtyRect.isEmpty()) | |
| 195 | 195 | return; | |
| 196 | 196 | #if ENABLE(ENGINE_THREAD) | |
| … | … | ||
| 229 | 229 | // Paint to backbuffer, no locks held. | |
| 230 | 230 | QPainter painter(m_backBuffer); | |
| 231 | 231 | GraphicsContext context(&painter); | |
| 232 | context.scale(m_cache->tileScale()); | ||
| 233 | 232 | context.translate(-m_tileRect.x(), -m_tileRect.y()); | |
| 234 | 233 | ||
| 235 | 234 | int size = dirtyRects.size(); | |
| 236 | 235 | for (int n = 0; n < size; ++n) { | |
| 237 | 236 | context.save(); | |
| 238 | QRect rect = dirtyRects[n]; | ||
| 239 | context.clip(FloatRect(rect.x(), rect.y(), rect.width(), rect.height())); | ||
| 240 | m_cache->m_client->tileCachePaint(&context, rect); | ||
| 237 | IntRect rect = dirtyRects[n]; | ||
| 238 | context.clip(FloatRect(rect)); | ||
| 239 | context.scale(m_cache->tileScale()); | ||
| 240 | m_cache->m_client->tileCachePaint(&context, m_cache->rectToDocument(rect)); | ||
| 241 | 241 | context.restore(); | |
| 242 | 242 | } | |
| 243 | 243 | } | |
| … | … | ||
| 261 | 261 | // m_bufferPixmap = QPixmap::fromImage(*m_buffer); | |
| 262 | 262 | m_pixmapNeedsReset = false; | |
| 263 | 263 | ||
| 264 | FloatRect target = intersection(FloatRect(rect), m_tileRect); | ||
| 265 | FloatRect source((target.x() - m_tileRect.x()), | ||
| 264 | IntRect target = intersection(rect, m_tileRect); | ||
| 265 | IntRect source((target.x() - m_tileRect.x()), | ||
| 266 | 266 | (target.y() - m_tileRect.y()), | |
| 267 | 267 | target.width(), | |
| 268 | 268 | target.height()); | |
| 269 | |||
| 270 | FloatSize scale = m_cache->tileScale(); | ||
| 271 | source.scale(scale.width(), scale.height()); | ||
| 272 | 269 | ||
| 273 | 270 | #if ENABLE(ENGINE_THREAD) | |
| 274 | 271 | // qDebug() << (EngineThread::isCurrent() ? "EngineThread " : "MainThread ") << "painting tile " << QRectF(m_tileRect) << " source " << QRectF(source) << " target " << QRectF(target); | |
| … | … | ||
| 293 | 293 | m_tileCreationTimer = 0; | |
| 294 | 294 | } | |
| 295 | 295 | ||
| 296 | void TileCache::invalidate(const IntRect& dirtyRect) | ||
| 296 | void TileCache::invalidate(const IntRect& documentDirtyRect) | ||
| 297 | 297 | { | |
| 298 | IntRect dirtyRect(rectFromDocument(documentDirtyRect)); | ||
| 299 | |||
| 298 | 300 | TileCoordinate topLeft = tileCoordinateForPoint(dirtyRect.topLeft()); | |
| 299 | 301 | TileCoordinate bottomRight = tileCoordinateForPoint(dirtyRect.bottomRight()); | |
| 300 | 302 | ||
| … | … | ||
| 324 | 324 | if (!it->second->isDirty()) | |
| 325 | 325 | continue; | |
| 326 | 326 | m_dirtyTiles.append(it->second); | |
| 327 | fullDirtyRegion += it->second->enclosingIntRect(); | ||
| 327 | // FIXME: should not request system repaint for the full tile. | ||
| 328 | fullDirtyRegion += it->second->rect(); | ||
| 329 | //fullDirtyRegion += it->second->dirtyRegion(); | ||
| 328 | 330 | } | |
| 329 | 331 | ||
| 330 | 332 | if (m_dirtyTiles.isEmpty()) | |
| … | … | ||
| 351 | 351 | Vector<IntRect> paintedArea; | |
| 352 | 352 | unsigned rectCount = qrects.size(); | |
| 353 | 353 | for (unsigned n = 0; n < rectCount; ++n) | |
| 354 | paintedArea.append(qrects[n]); | ||
| 354 | paintedArea.append(rectToDocument(qrects[n])); | ||
| 355 | 355 | ||
| 356 | 356 | m_client->tileCachePaintEnd(paintedArea); | |
| 357 | 357 | } | |
| … | … | ||
| 392 | 392 | MutexLocker locker(m_paintMutex); | |
| 393 | 393 | #endif | |
| 394 | 394 | QPainter* painter = context->platformContext(); | |
| 395 | TileCoordinate topLeft = tileCoordinateForPoint(rect.topLeft()); | ||
| 396 | TileCoordinate bottomRight = tileCoordinateForPoint(rect.bottomRight()); | ||
| 397 | 395 | ||
| 396 | painter->save(); | ||
| 397 | |||
| 398 | if (m_state == StateNoTileCreation) { | ||
| 399 | painter->scale(1.f / m_scale.width(), 1.f / m_scale.height()); | ||
| 400 | } else { | ||
| 401 | QTransform t = painter->worldTransform(); | ||
| 402 | QTransform nt(1., t.m12(), t.m13(), | ||
| 403 | t.m21(), 1., t.m23(), | ||
| 404 | t.m31(), t.m32(), t.m33()); | ||
| 405 | painter->setWorldTransform(nt); | ||
| 406 | } | ||
| 407 | |||
| 408 | IntRect dirtyRect = rectFromDocument(rect); | ||
| 409 | |||
| 410 | TileCoordinate topLeft = tileCoordinateForPoint(dirtyRect.topLeft()); | ||
| 411 | TileCoordinate bottomRight = tileCoordinateForPoint(dirtyRect.bottomRight()); | ||
| 412 | |||
| 398 | 413 | for (unsigned yCoordinate = topLeft.y(); yCoordinate <= bottomRight.y(); ++yCoordinate) { | |
| 399 | 414 | for (unsigned xCoordinate = topLeft.x(); xCoordinate <= bottomRight.x(); ++xCoordinate) { | |
| 400 | 415 | TileCoordinate currentCoordinate(xCoordinate, yCoordinate); | |
| 401 | 416 | RefPtr<Tile> currentTile = tile(currentCoordinate); | |
| 402 | 417 | if (currentTile && currentTile->isReadyToPaint()) | |
| 403 | currentTile->paint(painter, rect); | ||
| 418 | currentTile->paint(painter, dirtyRect); | ||
| 404 | 419 | else | |
| 405 | paintCheckerPattern(painter, rect, currentCoordinate); | ||
| 420 | paintCheckerPattern(painter, dirtyRect, currentCoordinate); | ||
| 406 | 421 | } | |
| 407 | 422 | } | |
| 423 | painter->restore(); | ||
| 408 | 424 | } | |
| 409 | 425 | ||
| 410 | void TileCache::viewportChanged(const IntRect& viewport, const FloatSize& scale) | ||
| 426 | void TileCache::viewportChanged(const IntRect& docViewport, const FloatSize& scale) | ||
| 411 | 427 | { | |
| 412 | if (m_viewport == viewport && m_scale == scale) | ||
| 428 | bool scaleChanged = m_scale != scale; | ||
| 429 | m_scale = scale; | ||
| 430 | IntRect viewport = rectFromDocument(docViewport); | ||
| 431 | if (m_viewport == viewport && !scaleChanged) | ||
| 413 | 432 | return; | |
| 414 | 433 | ||
| 415 | if (m_viewport.size() != viewport.size() || m_scale != scale) | ||
| 416 | invalidate(m_client->tileCacheContentRect()); | ||
| 434 | bool needsInvalidate = m_viewport.size() != viewport.size() || scaleChanged; | ||
| 417 | 435 | ||
| 418 | 436 | m_viewport = viewport; | |
| 419 | if (m_scale != scale) | ||
| 437 | |||
| 438 | if (scaleChanged) | ||
| 420 | 439 | m_client->tileCacheViewportScaleChanged(); | |
| 421 | m_scale = scale; | ||
| 440 | |||
| 441 | if (needsInvalidate) | ||
| 442 | invalidate(m_client->tileCacheContentRect()); | ||
| 422 | 443 | ||
| 423 | 444 | startTileCreationTimer(); | |
| 424 | 445 | } | |
| … | … | ||
| 465 | 465 | if (m_viewport.isEmpty()) | |
| 466 | 466 | return; | |
| 467 | 467 | ||
| 468 | |||
| 469 | 468 | dropOverhangingTiles(); | |
| 470 | 469 | ||
| 471 | 470 | // FIXME: Make adapt to memory. | |
| 472 | 471 | IntRect keepRect = m_viewport; | |
| 473 | 472 | keepRect.inflateX(m_viewport.width()); | |
| 474 | 473 | keepRect.inflateY(2 * m_viewport.height()); | |
| 475 | keepRect.intersect(m_client->tileCacheContentRect()); | ||
| 474 | keepRect.intersect(contentRect()); | ||
| 476 | 475 | ||
| 477 | 476 | dropTilesOutsideRect(keepRect); | |
| 478 | 477 | ||
| 479 | 478 | IntRect coverRect = m_viewport; | |
| 480 | 479 | coverRect.inflateX(m_viewport.width() / 2); | |
| 481 | 480 | coverRect.inflateY(m_viewport.height()); | |
| 482 | coverRect.intersect(m_client->tileCacheContentRect()); | ||
| 481 | coverRect.intersect(contentRect()); | ||
| 483 | 482 | ||
| 484 | 483 | double shortestDistance = std::numeric_limits<double>::infinity(); | |
| 485 | 484 | Vector<TileCoordinate> tilesToCreate; | |
| … | … | ||
| 524 | 524 | ||
| 525 | 525 | void TileCache::dropOverhangingTiles() | |
| 526 | 526 | { | |
| 527 | FloatRect contentRect = m_client->tileCacheContentRect(); | ||
| 527 | IntRect contentRect = this->contentRect(); | ||
| 528 | 528 | ||
| 529 | 529 | Vector<TileCoordinate> tilesToRemove; | |
| 530 | 530 | TileMap::iterator end = m_tiles.end(); | |
| 531 | 531 | for (TileMap::iterator it = m_tiles.begin(); it != end; ++it) { | |
| 532 | 532 | TileCoordinate tileCoordinate = it->second->coordinate(); | |
| 533 | FloatRect tileRect = it->second->rect(); | ||
| 534 | FloatRect expectedTileRect = tileRectForCoordinate(tileCoordinate); | ||
| 533 | IntRect tileRect = it->second->rect(); | ||
| 534 | IntRect expectedTileRect = tileRectForCoordinate(tileCoordinate); | ||
| 535 | 535 | if (expectedTileRect != tileRect || !contentRect.contains(tileRect)) | |
| 536 | 536 | tilesToRemove.append(tileCoordinate); | |
| 537 | 537 | } | |
| … | … | ||
| 572 | 572 | m_tiles.remove(coordinate.hash()); | |
| 573 | 573 | } | |
| 574 | 574 | ||
| 575 | FloatRect TileCache::tileRectForCoordinate(const TileCoordinate& coordinate) const | ||
| 575 | IntRect TileCache::rectToDocument(const IntRect& rect) const | ||
| 576 | 576 | { | |
| 577 | 577 | float sx = m_scale.width(); | |
| 578 | 578 | float sy = m_scale.height(); | |
| 579 | |||
| 580 | return enclosingIntRect(FloatRect(rect.x() / sx, | ||
| 581 | rect.y() / sy, | ||
| 582 | rect.width() / sx, | ||
| 583 | rect.height() / sy)); | ||
| 584 | } | ||
| 579 | 585 | ||
| 580 | FloatRect rect(coordinate.x() * m_tileSize.width() / sx, | ||
| 581 | coordinate.y() * m_tileSize.height() / sy, | ||
| 582 | m_tileSize.width() / sx, | ||
| 583 | m_tileSize.height() / sy); | ||
| 586 | IntRect TileCache::rectFromDocument(const IntRect& rect) const | ||
| 587 | { | ||
| 588 | float sx = m_scale.width(); | ||
| 589 | float sy = m_scale.height(); | ||
| 590 | |||
| 591 | return enclosingIntRect(FloatRect(rect.x() * sx, | ||
| 592 | rect.y() * sy, | ||
| 593 | rect.width() * sx, | ||
| 594 | rect.height() * sy)); | ||
| 595 | } | ||
| 584 | 596 | ||
| 585 | rect.intersect(FloatRect(m_client->tileCacheContentRect())); | ||
| 586 | return rect; | ||
| 597 | IntRect TileCache::contentRect() const | ||
| 598 | { | ||
| 599 | return rectFromDocument(m_client->tileCacheContentRect()); | ||
| 587 | 600 | } | |
| 588 | 601 | ||
| 602 | IntRect TileCache::tileRectForCoordinate(const TileCoordinate& coordinate) const | ||
| 603 | { | ||
| 604 | IntRect rect(coordinate.x() * m_tileSize.width(), | ||
| 605 | coordinate.y() * m_tileSize.height(), | ||
| 606 | m_tileSize.width(), | ||
| 607 | m_tileSize.height()); | ||
| 608 | |||
| 609 | rect.intersect(contentRect()); | ||
| 610 | return rect; | ||
| 611 | } | ||
| 612 | |||
| 589 | 613 | TileCache::TileCoordinate TileCache::tileCoordinateForPoint(const IntPoint& point) const | |
| 590 | 614 | { | |
| 591 | int x = point.x() * m_scale.width() / m_tileSize.width(); | ||
| 592 | int y = point.y() * m_scale.height() / m_tileSize.height(); | ||
| 615 | int x = point.x() / m_tileSize.width(); | ||
| 616 | int y = point.y() / m_tileSize.height(); | ||
| 593 | 617 | return TileCoordinate(std::max(x, 0), std::max(y, 0)); | |
| 594 | 618 | } | |
| 595 | 619 |

