void SurfaceBacking::prepareGL(GLWebViewState* state, float maxZoomScale,//4.2 Merge
                               const IntRect& prepareArea, const IntRect& fullContentArea,
                               TilePainter* painter, bool aggressiveRendering,
                               bool updateWithBlit)
{
// 4.2 Merge BEGIN <<
    // If the surface backing has ever zoomed beyond 1.0 scale, it's always
    // allowed to (so repaints aren't necessary when allowZoom toggles). If not,
    // and allowZoom is false, don't allow scale greater than 1.0
    m_maxZoomScale = std::max(m_maxZoomScale, maxZoomScale);
// 4.2 Merge END >>
    float scale = state->scale();
// 4.2 Merge BEGIN <<
    bool scaleOverridden = false;
    if (scale > m_maxZoomScale) {
        scale = m_maxZoomScale;
        scaleOverridden = true;
    }
// 4.2 Merge END >>

    if (m_scale == -1) {
        m_scale = scale;
        m_futureScale = scale;
    }

    if (m_futureScale != scale) {
        m_futureScale = scale;
// 4.2 Merge BEGIN <<
        if (scaleOverridden)
            m_zoomUpdateTime = 0; // start rendering immediately
        else
            m_zoomUpdateTime = WTF::currentTime() + SurfaceBacking::s_zoomUpdateDelay;
// 4.2 Merge END >>
        m_zooming = true;

        // release back TileGrid's TileTextures, so they can be reused immediately
        m_backTileGrid->discardTextures();
    }

    int prepareRegionFlags = TileGrid::StandardRegion;
    if (aggressiveRendering)
        prepareRegionFlags |= TileGrid::ExpandedRegion;

    ALOGV("Prepare SurfBack %p, scale %.2f, m_scale %.2f, futScale: %.2f, zooming: %d, f %p, b %p",
          this, scale, m_scale, m_futureScale, m_zooming,
          m_frontTileGrid, m_backTileGrid);

    if (m_zooming && (m_zoomUpdateTime < WTF::currentTime())) {
        // prepare the visible portions of the back tile grid at the futureScale
        m_backTileGrid->prepareGL(state, m_futureScale,
                                  prepareArea, fullContentArea, painter,
                                  TileGrid::StandardRegion, false);

        if (m_backTileGrid->isReady()) {
            // zooming completed, swap the TileGrids and new front tiles
            swapTileGrids();

            m_frontTileGrid->swapTiles();
            m_backTileGrid->discardTextures();
            m_lowResTileGrid->discardTextures();

            m_scale = m_futureScale;
            m_zooming = false;

            // clear the StandardRegion flag, to prevent preparing it twice -
            // the new frontTileGrid has already had its StandardRegion prepared
            prepareRegionFlags &= ~TileGrid::StandardRegion;
        }
    }

    if (!m_zooming) {
        if (prepareRegionFlags) {
            // if the front grid hasn't already prepared, or needs to prepare
            // expanded bounds do so now
            m_frontTileGrid->prepareGL(state, m_scale,
                                       prepareArea, fullContentArea, painter,
                                       prepareRegionFlags, false, updateWithBlit);
        }
        if (aggressiveRendering) {
            // prepare low res content
            float lowResPrefetchScale = m_scale * LOW_RES_PREFETCH_SCALE_MODIFIER;
            m_lowResTileGrid->prepareGL(state, lowResPrefetchScale,
                                       prepareArea, fullContentArea, painter,
                                       TileGrid::StandardRegion | TileGrid::ExpandedRegion, true);
            m_lowResTileGrid->swapTiles();
        }
    }
}
void SurfaceBacking::prepareGL(GLWebViewState* state, bool allowZoom,
                               const IntRect& prepareArea, const IntRect& fullContentArea,
                               TilePainter* painter, bool aggressiveRendering,
                               bool updateWithBlit)
{
    float scale = state->scale();
    if (scale > 1 && !allowZoom)
        scale = 1;

    if (m_scale == -1) {
        m_scale = scale;
        m_futureScale = scale;
    }

    if (m_futureScale != scale) {
        m_futureScale = scale;
        m_zoomUpdateTime = WTF::currentTime() + SurfaceBacking::s_zoomUpdateDelay;
        m_zooming = true;

        // release back TileGrid's TileTextures, so they can be reused immediately
        m_backTileGrid->discardTextures();
    }

    int prepareRegionFlags = TileGrid::StandardRegion;
    if (aggressiveRendering)
        prepareRegionFlags |= TileGrid::ExpandedRegion;

    ALOGV("Prepare SurfBack %p, scale %.2f, m_scale %.2f, futScale: %.2f, zooming: %d, f %p, b %p",
          this, scale, m_scale, m_futureScale, m_zooming,
          m_frontTileGrid, m_backTileGrid);

    if (m_zooming && (m_zoomUpdateTime < WTF::currentTime())) {
        // prepare the visible portions of the back tile grid at the futureScale
        m_backTileGrid->prepareGL(state, m_futureScale,
                                  prepareArea, fullContentArea, painter,
                                  TileGrid::StandardRegion, false);

        if (m_backTileGrid->isReady()) {
            // zooming completed, swap the TileGrids and new front tiles
            swapTileGrids();

            m_frontTileGrid->swapTiles();
            m_backTileGrid->discardTextures();
            m_lowResTileGrid->discardTextures();

            m_scale = m_futureScale;
            m_zooming = false;

            // clear the StandardRegion flag, to prevent preparing it twice -
            // the new frontTileGrid has already had its StandardRegion prepared
            prepareRegionFlags &= ~TileGrid::StandardRegion;
        }
    }

    if (!m_zooming) {
        if (prepareRegionFlags) {
            // if the front grid hasn't already prepared, or needs to prepare
            // expanded bounds do so now
            m_frontTileGrid->prepareGL(state, m_scale,
                                       prepareArea, fullContentArea, painter,
                                       prepareRegionFlags, false, updateWithBlit);
        }
        if (aggressiveRendering) {
            // prepare low res content
            float lowResPrefetchScale = m_scale * LOW_RES_PREFETCH_SCALE_MODIFIER;
            m_lowResTileGrid->prepareGL(state, lowResPrefetchScale,
                                       prepareArea, fullContentArea, painter,
                                       TileGrid::StandardRegion | TileGrid::ExpandedRegion, true);
            m_lowResTileGrid->swapTiles();
        }
    }
}