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:34:24 +0000
changeset 3622706 104f8347b50862f975303ddb323aaccc86f66f93
parent 3619876 729eaf579f2827239182db122d59e42730ea540f
child 3622707 7cd1bfb2fa02d47d5dd30e4c69f6e2e3ac0e03c6
push id671988
push userreviewbot
push dateTue, 23 Mar 2021 14:35:53 +0000
treeherdertry@4a3e4c289ec3 [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-eiq7uoje7vlko4pvzz6j
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;