void BasicShadowCanvasLayer::Swap(const CanvasSurface& aNewFront, bool needYFlip, CanvasSurface* aNewBack) { AutoOpenSurface autoSurface(OPEN_READ_ONLY, aNewFront); // Destroy mFrontBuffer if size different gfxIntSize sz = autoSurface.Size(); bool surfaceConfigChanged = sz != gfxIntSize(mBounds.width, mBounds.height); if (IsSurfaceDescriptorValid(mFrontSurface)) { AutoOpenSurface autoFront(OPEN_READ_ONLY, mFrontSurface); surfaceConfigChanged = surfaceConfigChanged || autoSurface.ContentType() != autoFront.ContentType(); } if (surfaceConfigChanged) { DestroyFrontBuffer(); mBounds.SetRect(0, 0, sz.width, sz.height); } mNeedsYFlip = needYFlip; // If mFrontBuffer if (IsSurfaceDescriptorValid(mFrontSurface)) { *aNewBack = mFrontSurface; } else { *aNewBack = null_t(); } mFrontSurface = aNewFront; }
void TileClient::ValidateBackBufferFromFront(const nsIntRegion& aDirtyRegion, bool aCanRerasterizeValidRegion) { if (mBackBuffer && mFrontBuffer) { const nsIntRect tileRect = nsIntRect(0, 0, TILEDLAYERBUFFER_TILE_SIZE, TILEDLAYERBUFFER_TILE_SIZE); if (aDirtyRegion.Contains(tileRect)) { // The dirty region means that we no longer need the front buffer, so // discard it. DiscardFrontBuffer(); } else { // Region that needs copying. nsIntRegion regionToCopy = mInvalidBack; regionToCopy.Sub(regionToCopy, aDirtyRegion); if (regionToCopy.IsEmpty() || (aCanRerasterizeValidRegion && regionToCopy.Area() < MINIMUM_TILE_COPY_AREA)) { // Just redraw it all. return; } if (!mFrontBuffer->Lock(OPEN_READ)) { NS_WARNING("Failed to lock the tile's front buffer"); return; } TextureClientAutoUnlock autoFront(mFrontBuffer); if (!mBackBuffer->Lock(OPEN_WRITE)) { NS_WARNING("Failed to lock the tile's back buffer"); return; } TextureClientAutoUnlock autoBack(mBackBuffer); // Copy the bounding rect of regionToCopy. As tiles are quite small, it // is unlikely that we'd save much by copying each individual rect of the // region, but we can reevaluate this if it becomes an issue. const nsIntRect rectToCopy = regionToCopy.GetBounds(); gfx::IntRect gfxRectToCopy(rectToCopy.x, rectToCopy.y, rectToCopy.width, rectToCopy.height); gfx::IntPoint gfxRectToCopyTopLeft = gfxRectToCopy.TopLeft(); mFrontBuffer->CopyToTextureClient(mBackBuffer, &gfxRectToCopy, &gfxRectToCopyTopLeft); mInvalidBack.SetEmpty(); } } }