// When bliting, if the item from the transfer queue is mismatching b/t the // BaseTile and the content, then the item is considered as obsolete, and // the content is discarded. bool TransferQueue::checkObsolete(int index) { BaseTile* baseTilePtr = m_transferQueue[index].savedBaseTilePtr; if (!baseTilePtr) { XLOG("Invalid savedBaseTilePtr , such that the tile is obsolete"); return true; } BaseTileTexture* baseTileTexture = baseTilePtr->backTexture(); if (!baseTileTexture) { XLOG("Invalid baseTileTexture , such that the tile is obsolete"); return true; } const TextureTileInfo* tileInfo = &m_transferQueue[index].tileInfo; if (tileInfo->m_x != baseTilePtr->x() || tileInfo->m_y != baseTilePtr->y() || tileInfo->m_scale != baseTilePtr->scale() || tileInfo->m_painter != baseTilePtr->painter()) { XLOG("Mismatching x, y, scale or painter , such that the tile is obsolete"); return true; } return false; }
void TiledPage::prepareRow(bool goingLeft, int tilesInRow, int firstTileX, int y, const SkIRect& tileBounds) { for (int i = 0; i < tilesInRow; i++) { int x = firstTileX; // If we are goingLeft, we want to schedule the tiles starting from the // right (and to the left if not). This is because tiles are appended to // the list and the texture uploader goes through the set front to back. if (goingLeft) x += (tilesInRow - 1) - i; else x += i; BaseTile* currentTile = 0; BaseTile* availableTile = 0; for (int j = 0; j < m_baseTileSize; j++) { BaseTile& tile = m_baseTiles[j]; if (tile.x() == x && tile.y() == y) { currentTile = &tile; break; } if (!availableTile || (tile.drawCount() < availableTile->drawCount())) availableTile = &tile; } if (!currentTile && availableTile) { XLOG("STEALING tile %d, %d (draw count %llu) for tile %d, %d", availableTile->x(), availableTile->y(), availableTile->drawCount(), x, y); availableTile->discardTextures(); // don't wait for textures to be stolen currentTile = availableTile; } if (!currentTile) { XLOG("ERROR: No tile available for tile %d %d", x, y); } if (currentTile) { currentTile->setGLWebViewState(m_glWebViewState); currentTile->setPage(this); currentTile->setContents(this, x, y, m_scale); // TODO: move below (which is largely the same for layers / tiled // page) into prepare() function // ensure there is a texture associated with the tile and then check to // see if the texture is dirty and in need of repainting if (currentTile->isDirty() || !currentTile->frontTexture()) currentTile->reserveTexture(); if (currentTile->backTexture() && currentTile->isDirty() && !currentTile->isRepaintPending()) { PaintTileOperation *operation = new PaintTileOperation(currentTile); TilesManager::instance()->scheduleOperation(operation); } } } }
void TilesManager::printTextures() { #ifdef DEBUG XLOG("++++++"); for (unsigned int i = 0; i < m_textures.size(); i++) { BaseTileTexture* texture = m_textures[i]; BaseTile* o = 0; if (texture->owner()) o = (BaseTile*) texture->owner(); int x = -1; int y = -1; if (o) { x = o->x(); y = o->y(); } XLOG("[%d] texture %x busy: %d owner: %x (%d, %d) page: %x scale: %.2f", i, texture, texture->busy(), o, x, y, o ? o->page() : 0, o ? o->scale() : 0); } XLOG("------"); #endif // DEBUG }
void TilesProfiler::nextTile(BaseTile& tile, float scale, bool inView) { if (!m_enabled || (m_records.size() > MAX_PROF_FRAMES) || (m_records.size() == 0)) return; bool isReady = tile.isTileReady(); int left = tile.x() * TilesManager::tileWidth(); int top = tile.y() * TilesManager::tileWidth(); int right = left + TilesManager::tileWidth(); int bottom = top + TilesManager::tileWidth(); if (inView) { if (isReady) m_goodTiles++; else m_badTiles++; } m_records.last().append(TileProfileRecord( left, top, right, bottom, scale, isReady, (int)tile.drawCount())); XLOG("adding tile %d %d %d %d, scale %f", left, top, right, bottom, scale); }
BaseTileTexture* TilesManager::getAvailableTexture(BaseTile* owner) { android::Mutex::Autolock lock(m_texturesLock); // Sanity check that the tile does not already own a texture if (owner->backTexture() && owner->backTexture()->owner() == owner) { XLOG("same owner (%d, %d), getAvailableBackTexture(%x) => texture %x", owner->x(), owner->y(), owner, owner->backTexture()); if (owner->isLayerTile()) m_availableTilesTextures.remove(m_availableTilesTextures.find(owner->backTexture())); else m_availableTextures.remove(m_availableTextures.find(owner->backTexture())); return owner->backTexture(); } WTF::Vector<BaseTileTexture*>* availableTexturePool; if (owner->isLayerTile()) { availableTexturePool = &m_availableTilesTextures; } else { availableTexturePool = &m_availableTextures; } // The heuristic for selecting a texture is as follows: // 1. Skip textures currently being painted, they can't be painted while // busy anyway // 2. If a tile isn't owned, break with that one // 3. Don't let tiles acquire their front textures // 4. If we find a tile in the same page with a different scale, // it's old and not visible. Break with that one // 5. Otherwise, use the least recently prepared tile, but ignoring tiles // drawn in the last frame to avoid flickering BaseTileTexture* farthestTexture = 0; unsigned long long oldestDrawCount = getDrawGLCount() - 1; const unsigned int max = availableTexturePool->size(); for (unsigned int i = 0; i < max; i++) { BaseTileTexture* texture = (*availableTexturePool)[i]; BaseTile* currentOwner = static_cast<BaseTile*>(texture->owner()); if (texture->busy()) { // don't bother, since the acquire() will likely fail continue; } if (!currentOwner) { // unused texture! take it! farthestTexture = texture; break; } if (currentOwner == owner) { // Don't let a tile acquire its own front texture, as the // acquisition logic doesn't handle that continue; } if (currentOwner->painter() == owner->painter() && texture->scale() != owner->scale()) { // if we render the back page with one scale, then another while // still zooming, we recycle the tiles with the old scale instead of // taking ones from the front page farthestTexture = texture; break; } unsigned long long textureDrawCount = currentOwner->drawCount(); if (oldestDrawCount > textureDrawCount) { farthestTexture = texture; oldestDrawCount = textureDrawCount; } } if (farthestTexture) { BaseTile* previousOwner = static_cast<BaseTile*>(farthestTexture->owner()); if (farthestTexture->acquire(owner)) { if (previousOwner) { previousOwner->removeTexture(farthestTexture); XLOG("%s texture %p stolen from tile %d, %d for %d, %d, drawCount was %llu (now %llu)", owner->isLayerTile() ? "LAYER" : "BASE", farthestTexture, previousOwner->x(), previousOwner->y(), owner->x(), owner->y(), oldestDrawCount, getDrawGLCount()); } availableTexturePool->remove(availableTexturePool->find(farthestTexture)); return farthestTexture; } } else { if (owner->isLayerTile()) { // couldn't find a tile for a layer, layers shouldn't request redraw // TODO: once we do layer prefetching, don't set this for those // tiles m_layerTexturesRemain = false; } } XLOG("Couldn't find an available texture for %s tile %x (%d, %d) out of %d available", owner->isLayerTile() ? "LAYER" : "BASE", owner, owner->x(), owner->y(), max); #ifdef DEBUG printTextures(); #endif // DEBUG return 0; }