Bug 1699224 - Part 1. Ensure we map/unmap surfaces used by DrawTargetSkia. r=jrmuizel draft
authorAndrew Osmond <aosmond@mozilla.com>
Tue, 23 Mar 2021 14:18:20 +0000
changeset 3622636 567e715124e6e107730f0cc455b8e7be182ae830
parent 3619876 729eaf579f2827239182db122d59e42730ea540f
child 3622637 959d05eb903ede4af9d0a7bbcb0ae290abde3cc7
push id671972
push userreviewbot
push dateTue, 23 Mar 2021 14:19:00 +0000
treeherdertry@1e89320a485e [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-5tnmicfmpxt6rixbj7qe
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;