diff --git a/gfx/layers/client/SimpleTiledContentClient.cpp b/gfx/layers/client/SimpleTiledContentClient.cpp index 59393333a421..1fb09032a6e8 100644 --- a/gfx/layers/client/SimpleTiledContentClient.cpp +++ b/gfx/layers/client/SimpleTiledContentClient.cpp @@ -90,19 +90,17 @@ SimpleTiledLayerBuffer::ValidateTile(SimpleTiledLayerTile aTile, return SimpleTiledLayerTile(); } - if (!textureClient->Lock(OPEN_WRITE)) { + if (!textureClient->Lock(OPEN_READ_WRITE)) { NS_WARNING("TextureClient lock failed"); return SimpleTiledLayerTile(); } - TextureClientSurface *textureClientSurf = textureClient->AsTextureClientSurface(); - if (!textureClientSurf) { + if (!textureClient->CanExposeDrawTarget()) { doBufferedDrawing = false; } RefPtr drawTarget; - nsRefPtr clientAsImageSurface; unsigned char *bufferData = nullptr; // these are set/updated differently based on doBufferedDrawing @@ -110,23 +108,25 @@ SimpleTiledLayerBuffer::ValidateTile(SimpleTiledLayerTile aTile, nsIntRegion drawRegion; nsIntRegion invalidateRegion; - if (doBufferedDrawing) { - // try to obtain the TextureClient as an ImageSurface, so that we can - // access the pixels directly - nsRefPtr asurf = textureClientSurf->GetAsSurface(); - clientAsImageSurface = asurf ? asurf->GetAsImageSurface() : nullptr; - if (clientAsImageSurface) { - int32_t bufferStride = clientAsImageSurface->Stride(); + RefPtr srcDT; + uint8_t* srcData = nullptr; + int32_t srcStride = 0; + gfx::IntSize srcSize; + gfx::SurfaceFormat srcFormat = gfx::SurfaceFormat::UNKNOWN; + if (doBufferedDrawing) { + // try to directly access the pixels of the TextureClient + srcDT = textureClient->GetAsDrawTarget(); + if (srcDT->LockBits(&srcData, &srcSize, &srcStride, &srcFormat)) { if (!aTile.mCachedBuffer) { - aTile.mCachedBuffer = SharedBuffer::Create(clientAsImageSurface->GetDataSize()); + aTile.mCachedBuffer = SharedBuffer::Create(srcStride * srcSize.height); fullPaint = true; } bufferData = (unsigned char*) aTile.mCachedBuffer->Data(); drawTarget = gfxPlatform::GetPlatform()->CreateDrawTargetForData(bufferData, kTileSize, - bufferStride, + srcStride, tileFormat); if (fullPaint) { @@ -170,14 +170,15 @@ SimpleTiledLayerBuffer::ValidateTile(SimpleTiledLayerTile aTile, mCallbackData); ctxt = nullptr; - drawTarget = nullptr; if (doBufferedDrawing) { - memcpy(clientAsImageSurface->Data(), bufferData, clientAsImageSurface->GetDataSize()); - clientAsImageSurface = nullptr; + memcpy(srcData, bufferData, srcSize.height * srcStride); bufferData = nullptr; + srcDT->ReleaseBits(srcData); + srcDT = nullptr; } + drawTarget = nullptr; textureClient->Unlock(); if (!mCompositableClient->AddTextureClient(textureClient)) {