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:36:41 +0000
changeset 3621180 f557e31fb5be90e25a97d3b9ca1f0fa5471be7e9
parent 3619876 729eaf579f2827239182db122d59e42730ea540f
child 3621181 2aa01ec5e7ec9c2fb065dc04ee1f60f5bbbedc59
push id671694
push userreviewbot
push dateMon, 22 Mar 2021 23:37:25 +0000
treeherdertry@12fdeb589e69 [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-esodjucqynbvcus4lw7a
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;