Bug 1699224 - Part 1. Ensure we map/unmap surfaces used by DrawTargetSkia. r=jrmuizel draft
authorAndrew Osmond <aosmond@mozilla.com>
Mon, 22 Mar 2021 23:24:44 +0000
changeset 3621147 68fb4e2605845586269d3dcddafa713d68132c11
parent 3619876 729eaf579f2827239182db122d59e42730ea540f
child 3621148 dd3c6ecb4f81375d6cf326eafa2879c2397c98ba
push id671686
push userreviewbot
push dateMon, 22 Mar 2021 23:25:20 +0000
treeherdertry@8d6ee275f877 [default view] [failures only]
reviewersjrmuizel
bugs1699224
milestone88.0a1
Bug 1699224 - Part 1. Ensure we map/unmap surfaces used by DrawTargetSkia. r=jrmuizel Since we want to be able to unmap shared surfaces which are not in use, we need to be able to map the data in as required. Blob images can access shared surfaces via recordings which are used by DrawTargetSkia. This patch makes it call Map/Unmap for data surfaces that require a data pointer in Skia. Differential Revision: https://phabricator.services.mozilla.com/D109437 Differential Diff: PHID-DIFF-kfqjf4dbvb7z3qloqh4s
gfx/2d/DrawTargetSkia.cpp
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -93,16 +93,17 @@ class GradientStopsSkia : public Gradien
  * When constructing a temporary SkImage via GetSkImageForSurface, we may also
  * have to construct a temporary DataSourceSurface, which must live as long as
  * the SkImage. We attach this temporary surface to the image's pixelref, so
  * that it can be released once the pixelref is freed.
  */
 static void ReleaseTemporarySurface(const void* aPixels, void* aContext) {
   DataSourceSurface* surf = static_cast<DataSourceSurface*>(aContext);
   if (surf) {
+    surf->Unmap();
     surf->Release();
   }
 }
 
 static void WriteRGBXFormat(uint8_t* aData, const IntSize& aSize,
                             const int32_t aStride, SurfaceFormat aFormat) {
   if (aFormat != SurfaceFormat::B8G8R8X8 || aSize.IsEmpty()) {
     return;
@@ -236,29 +237,37 @@ static sk_sp<SkImage> GetSkImageForSurfa
     MOZ_ASSERT(resolved->GetType() != SurfaceType::CAPTURE);
     return GetSkImageForSurface(resolved, aLock, aBounds, aMatrix);
   }
 
   if (aSurface->GetType() == SurfaceType::SKIA) {
     return static_cast<SourceSurfaceSkia*>(aSurface)->GetImage(aLock);
   }
 
-  DataSourceSurface* surf = aSurface->GetDataSurface().take();
-  if (!surf) {
+  RefPtr<DataSourceSurface> dataSurface = aSurface->GetDataSurface();
+  if (!dataSurface) {
     gfxWarning() << "Failed getting DataSourceSurface for Skia image";
     return nullptr;
   }
 
+  DataSourceSurface::MappedSurface map;
+  if (!dataSurface->Map(DataSourceSurface::MapType::READ, &map)) {
+    gfxWarning() << "Failed mapping DataSourceSurface for Skia image";
+    return nullptr;
+  }
+
+  DataSourceSurface* surf = aSurface->GetDataSurface().take();
+
   // Skia doesn't support RGBX surfaces so ensure that the alpha value is opaque
   // white.
-  MOZ_ASSERT(VerifyRGBXCorners(surf->GetData(), surf->GetSize(), surf->Stride(),
+  MOZ_ASSERT(VerifyRGBXCorners(map.mData, surf->GetSize(), map.mStride,
                                surf->GetFormat(), aBounds, aMatrix));
 
   SkPixmap pixmap(MakeSkiaImageInfo(surf->GetSize(), surf->GetFormat()),
-                  surf->GetData(), surf->Stride());
+                  map.mData, map.mStride);
   sk_sp<SkImage> image =
       SkImage::MakeFromRaster(pixmap, ReleaseTemporarySurface, surf);
   if (!image) {
     ReleaseTemporarySurface(nullptr, surf);
     gfxDebug() << "Failed making Skia raster image for temporary surface";
   }
 
   return image;