Remove trivial calls to DataSourceSurface::Stride. (bug 1405390 part 3, r=bas)
authorDavid Anderson <danderson@mozilla.com>
Thu, 09 Nov 2017 00:43:30 -0800
changeset 391065 b804f968bd3260a45982e4a3d59d7976d31df1b5
parent 391064 3ae8914a63408662ab4fc26f93e14b8976e33d71
child 391066 074d85a019df6bf4014f16351629a7975f8a6cf9
push id32860
push userebalazs@mozilla.com
push dateFri, 10 Nov 2017 09:56:38 +0000
treeherdermozilla-central@864174ac0707 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas
bugs1405390
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Remove trivial calls to DataSourceSurface::Stride. (bug 1405390 part 3, r=bas)
dom/canvas/ImageBitmap.cpp
gfx/2d/DrawTargetSkia.cpp
gfx/2d/FilterProcessingSIMD-inl.h
gfx/2d/RecordedEventImpl.h
gfx/2d/SVGTurbulenceRenderer-inl.h
gfx/2d/unittest/TestBugs.cpp
gfx/gl/GLReadTexImageHelper.cpp
gfx/gl/GLReadTexImageHelper.h
gfx/layers/AsyncCanvasRenderer.cpp
gfx/layers/LayerScope.cpp
gfx/layers/d3d11/TextureD3D11.cpp
gfx/tests/gtest/TestCompositor.cpp
gfx/tests/gtest/TestTextures.cpp
gfx/thebes/gfxImageSurface.cpp
gfx/thebes/gfxUtils.cpp
image/test/gtest/Common.cpp
--- a/dom/canvas/ImageBitmap.cpp
+++ b/dom/canvas/ImageBitmap.cpp
@@ -218,27 +218,29 @@ CreateImageFromRawData(const gfx::IntSiz
                              aBuffer, aBufferLength,
                              aCropRect);
 
   if (NS_WARN_IF(!rgbaSurface)) {
     return nullptr;
   }
 
   // Convert RGBA to BGRA
+  DataSourceSurface::MappedSurface rgbaMap;
   RefPtr<DataSourceSurface> rgbaDataSurface = rgbaSurface->GetDataSurface();
+  if (NS_WARN_IF(!rgbaDataSurface->Map(DataSourceSurface::MapType::READ, &rgbaMap))) {
+    return nullptr;
+  }
+
   RefPtr<DataSourceSurface> bgraDataSurface =
     Factory::CreateDataSourceSurfaceWithStride(rgbaDataSurface->GetSize(),
                                                SurfaceFormat::B8G8R8A8,
-                                               rgbaDataSurface->Stride());
+                                               rgbaMap.mStride);
 
-  DataSourceSurface::MappedSurface rgbaMap;
   DataSourceSurface::MappedSurface bgraMap;
-
-  if (NS_WARN_IF(!rgbaDataSurface->Map(DataSourceSurface::MapType::READ, &rgbaMap)) ||
-      NS_WARN_IF(!bgraDataSurface->Map(DataSourceSurface::MapType::WRITE, &bgraMap))) {
+  if (NS_WARN_IF(!bgraDataSurface->Map(DataSourceSurface::MapType::WRITE, &bgraMap))) {
     return nullptr;
   }
 
   SwizzleData(rgbaMap.mData, rgbaMap.mStride, SurfaceFormat::R8G8B8A8,
               bgraMap.mData, bgraMap.mStride, SurfaceFormat::B8G8R8A8,
               bgraDataSurface->GetSize());
 
   rgbaDataSurface->Unmap();
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -1575,17 +1575,17 @@ DrawTarget::Draw3DTransformedSurface(Sou
   }
 
   DataSourceSurface::ScopedMap map(dstSurf, DataSourceSurface::READ_WRITE);
   std::unique_ptr<SkCanvas> dstCanvas(
     SkCanvas::MakeRasterDirect(
                         SkImageInfo::Make(xformBounds.Width(), xformBounds.Height(),
                         GfxFormatToSkiaColorType(dstSurf->GetFormat()),
                         kPremul_SkAlphaType),
-      map.GetData(), dstSurf->Stride()));
+      map.GetData(), map.GetStride()));
   if (!dstCanvas) {
     return false;
   }
 
   // Do the transform.
   SkPaint paint;
   paint.setAntiAlias(true);
   paint.setFilterQuality(kLow_SkFilterQuality);
@@ -1750,17 +1750,17 @@ DrawTargetSkia::OptimizeSourceSurfaceFor
   RefPtr<DataSourceSurface> dataSurface = aSurface->GetDataSurface();
   DataSourceSurface::ScopedMap map(dataSurface, DataSourceSurface::READ_WRITE);
 
   // For plugins, GDI can sometimes just write 0 to the alpha channel
   // even for RGBX formats. In this case, we have to manually write
   // the alpha channel to make Skia happy with RGBX and in case GDI
   // writes some bad data. Luckily, this only happens on plugins.
   WriteRGBXFormat(map.GetData(), dataSurface->GetSize(),
-                  dataSurface->Stride(), dataSurface->GetFormat());
+                  map.GetStride(), dataSurface->GetFormat());
   return dataSurface.forget();
 }
 
 already_AddRefed<SourceSurface>
 DrawTargetSkia::OptimizeSourceSurface(SourceSurface *aSurface) const
 {
 #ifdef USE_SKIA_GPU
   if (UsingSkiaGPU()) {
@@ -1776,17 +1776,17 @@ DrawTargetSkia::OptimizeSourceSurface(So
   // If we're not using skia-gl then drawing doesn't require any
   // uploading, so any data surface is fine. Call GetDataSurface
   // to trigger any required readback so that it only happens
   // once.
   RefPtr<DataSourceSurface> dataSurface = aSurface->GetDataSurface();
 #ifdef DEBUG
   DataSourceSurface::ScopedMap map(dataSurface, DataSourceSurface::READ);
   MOZ_ASSERT(VerifyRGBXFormat(map.GetData(), dataSurface->GetSize(),
-                              dataSurface->Stride(), dataSurface->GetFormat()));
+                              map.GetStride(), dataSurface->GetFormat()));
 #endif
   return dataSurface.forget();
 }
 
 already_AddRefed<SourceSurface>
 DrawTargetSkia::CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const
 {
 #ifdef USE_SKIA_GPU
--- a/gfx/2d/FilterProcessingSIMD-inl.h
+++ b/gfx/2d/FilterProcessingSIMD-inl.h
@@ -19,18 +19,18 @@ ConvertToB8G8R8A8_SIMD(SourceSurface* aS
   IntSize size = aSurface->GetSize();
   RefPtr<DataSourceSurface> input = aSurface->GetDataSurface();
   RefPtr<DataSourceSurface> output =
     Factory::CreateDataSourceSurface(size, SurfaceFormat::B8G8R8A8);
   DataSourceSurface::ScopedMap inputMap(input, DataSourceSurface::READ);
   DataSourceSurface::ScopedMap outputMap(output, DataSourceSurface::READ_WRITE);
   uint8_t *inputData = inputMap.GetData();
   uint8_t *outputData = outputMap.GetData();
-  int32_t inputStride = input->Stride();
-  int32_t outputStride = output->Stride();
+  int32_t inputStride = inputMap.GetStride();
+  int32_t outputStride = outputMap.GetStride();
   switch (input->GetFormat()) {
     case SurfaceFormat::B8G8R8A8:
       output = input;
       break;
     case SurfaceFormat::B8G8R8X8:
       for (int32_t y = 0; y < size.height; y++) {
         for (int32_t x = 0; x < size.width; x++) {
           int32_t inputIndex = y * inputStride + 4 * x;
@@ -299,19 +299,19 @@ ApplyBlending_SIMD(DataSourceSurface* aI
 
   DataSourceSurface::ScopedMap inputMap1(aInput1, DataSourceSurface::READ);
   DataSourceSurface::ScopedMap inputMap2(aInput2, DataSourceSurface::READ);
   DataSourceSurface::ScopedMap outputMap(target, DataSourceSurface::READ_WRITE);
 
   uint8_t* source1Data = inputMap1.GetData();
   uint8_t* source2Data = inputMap2.GetData();
   uint8_t* targetData = outputMap.GetData();
-  int32_t targetStride = target->Stride();
-  int32_t source1Stride = aInput1->Stride();
-  int32_t source2Stride = aInput2->Stride();
+  int32_t targetStride = outputMap.GetStride();
+  int32_t source1Stride = inputMap1.GetStride();
+  int32_t source2Stride = inputMap2.GetStride();
 
   for (int32_t y = 0; y < size.height; y++) {
     for (int32_t x = 0; x < size.width; x += 4) {
       int32_t targetIndex = y * targetStride + 4 * x;
       int32_t source1Index = y * source1Stride + 4 * x;
       int32_t source2Index = y * source2Stride + 4 * x;
 
       u8x16_t s1234 = simd::Load8<u8x16_t>(&source2Data[source2Index]);
@@ -526,18 +526,18 @@ ApplyColorMatrix_SIMD(DataSourceSurface*
     return nullptr;
   }
 
   DataSourceSurface::ScopedMap inputMap(aInput, DataSourceSurface::READ);
   DataSourceSurface::ScopedMap outputMap(target, DataSourceSurface::READ_WRITE);
 
   uint8_t* sourceData = inputMap.GetData();
   uint8_t* targetData = outputMap.GetData();
-  int32_t sourceStride = aInput->Stride();
-  int32_t targetStride = target->Stride();
+  int32_t sourceStride = inputMap.GetStride();
+  int32_t targetStride = outputMap.GetStride();
 
   const int16_t factor = 128;
   const Float floatElementMax = INT16_MAX / factor; // 255
   MOZ_ASSERT((floatElementMax * factor) <= INT16_MAX, "badly chosen float-to-int scale");
 
   const Float *floats = &aMatrix._11;
 
   ptrdiff_t componentOffsets[4] = {
@@ -711,18 +711,18 @@ ApplyComposition(DataSourceSurface* aSou
 {
   IntSize size = aDest->GetSize();
 
   DataSourceSurface::ScopedMap input(aSource, DataSourceSurface::READ);
   DataSourceSurface::ScopedMap output(aDest, DataSourceSurface::READ_WRITE);
 
   uint8_t* sourceData = input.GetData();
   uint8_t* destData = output.GetData();
-  uint32_t sourceStride = aSource->Stride();
-  uint32_t destStride = aDest->Stride();
+  uint32_t sourceStride = input.GetStride();
+  uint32_t destStride = output.GetStride();
 
   for (int32_t y = 0; y < size.height; y++) {
     for (int32_t x = 0; x < size.width; x += 4) {
       uint32_t sourceIndex = y * sourceStride + 4 * x;
       uint32_t destIndex = y * destStride + 4 * x;
 
       u8x16_t s1234 = simd::Load8<u8x16_t>(&sourceData[sourceIndex]);
       u8x16_t d1234 = simd::Load8<u8x16_t>(&destData[destIndex]);
@@ -1039,19 +1039,19 @@ ApplyArithmeticCombine_SIMD(DataSourceSu
 
   DataSourceSurface::ScopedMap inputMap1(aInput1, DataSourceSurface::READ);
   DataSourceSurface::ScopedMap inputMap2(aInput2, DataSourceSurface::READ);
   DataSourceSurface::ScopedMap outputMap(target, DataSourceSurface::READ_WRITE);
 
   uint8_t* source1Data = inputMap1.GetData();
   uint8_t* source2Data = inputMap2.GetData();
   uint8_t* targetData = outputMap.GetData();
-  uint32_t source1Stride = aInput1->Stride();
-  uint32_t source2Stride = aInput2->Stride();
-  uint32_t targetStride = target->Stride();
+  uint32_t source1Stride = inputMap1.GetStride();
+  uint32_t source2Stride = inputMap2.GetStride();
+  uint32_t targetStride = outputMap.GetStride();
 
   // The arithmetic combine filter does the following calculation:
   // result = k1 * in1 * in2 + k2 * in1 + k3 * in2 + k4
   //
   // Or, with in1/2 integers between 0 and 255:
   // result = (k1 * in1 * in2) / 255 + k2 * in1 + k3 * in2 + k4 * 255
   //
   // We want the whole calculation to happen in integer, with 16-bit factors.
--- a/gfx/2d/RecordedEventImpl.h
+++ b/gfx/2d/RecordedEventImpl.h
@@ -1531,17 +1531,17 @@ RecordedDrawTargetCreation::Record(S &aS
 
   if (mHasExistingData) {
     MOZ_ASSERT(mExistingData);
     MOZ_ASSERT(mExistingData->GetSize() == mSize);
     RefPtr<DataSourceSurface> dataSurf = mExistingData->GetDataSurface();
 
     DataSourceSurface::ScopedMap map(dataSurf, DataSourceSurface::READ);
     for (int y = 0; y < mSize.height; y++) {
-      aStream.write((const char*)map.GetData() + y * dataSurf->Stride(),
+      aStream.write((const char*)map.GetData() + y * map.GetStride(),
                     BytesPerPixel(mFormat) * mSize.width);
     }
   }
 }
 
 template<class S>
 RecordedDrawTargetCreation::RecordedDrawTargetCreation(S &aStream)
   : RecordedEventDerived(DRAWTARGETCREATION)
@@ -1558,17 +1558,17 @@ RecordedDrawTargetCreation::RecordedDraw
     if (!dataSurf) {
       gfxWarning() << "RecordedDrawTargetCreation had to reset mHasExistingData";
       mHasExistingData = false;
       return;
     }
 
     DataSourceSurface::ScopedMap map(dataSurf, DataSourceSurface::READ);
     for (int y = 0; y < mSize.height; y++) {
-      aStream.read((char*)map.GetData() + y * dataSurf->Stride(),
+      aStream.read((char*)map.GetData() + y * map.GetStride(),
                     BytesPerPixel(mFormat) * mSize.width);
     }
     mExistingData = dataSurf;
   }
 }
 
 inline void
 RecordedDrawTargetCreation::OutputSimpleEventInfo(std::stringstream &aStringStream) const
--- a/gfx/2d/SVGTurbulenceRenderer-inl.h
+++ b/gfx/2d/SVGTurbulenceRenderer-inl.h
@@ -326,17 +326,17 @@ SVGTurbulenceRenderer<Type,Stitch,f32x4_
   RefPtr<DataSourceSurface> target =
     Factory::CreateDataSourceSurface(aSize, SurfaceFormat::B8G8R8A8);
   if (!target) {
     return nullptr;
   }
 
   DataSourceSurface::ScopedMap map(target, DataSourceSurface::READ_WRITE);
   uint8_t* targetData = map.GetData();
-  uint32_t stride = target->Stride();
+  uint32_t stride = map.GetStride();
 
   Point startOffset = EquivalentNonNegativeOffset(aOffset);
 
   for (int32_t y = 0; y < aSize.height; y++) {
     for (int32_t x = 0; x < aSize.width; x += 4) {
       int32_t targIndex = y * stride + x * 4;
       i32x4_t a = Turbulence(startOffset + Point(x, y));
       i32x4_t b = Turbulence(startOffset + Point(x + 1, y));
--- a/gfx/2d/unittest/TestBugs.cpp
+++ b/gfx/2d/unittest/TestBugs.cpp
@@ -59,18 +59,18 @@ TestBugs::CairoClip918671()
   RefPtr<SourceSurface> surf2 = ref->Snapshot();
 
   RefPtr<DataSourceSurface> dataSurf1 = surf1->GetDataSurface();
   RefPtr<DataSourceSurface> dataSurf2 = surf2->GetDataSurface();
 
   DataSourceSurface::ScopedMap map1(dataSurf1, DataSourceSurface::READ);
   DataSourceSurface::ScopedMap map2(dataSurf2, DataSourceSurface::READ);
   for (int y = 0; y < dt->GetSize().height; y++) {
-    VERIFY(memcmp(map1.GetData() + y * dataSurf1->Stride(),
-                  map2.GetData() + y * dataSurf2->Stride(),
+    VERIFY(memcmp(map1.GetData() + y * map1.GetStride(),
+                  map2.GetData() + y * map2.GetStride(),
                   dataSurf1->GetSize().width * 4) == 0);
   }
 
 }
 
 void
 TestBugs::PushPopClip950550()
 {
--- a/gfx/gl/GLReadTexImageHelper.cpp
+++ b/gfx/gl/GLReadTexImageHelper.cpp
@@ -411,22 +411,22 @@ ReadPixelsIntoDataSurface(GLContext* gl,
     if (readSurf != dest) {
         MOZ_ASSERT(readFormat == LOCAL_GL_RGBA);
         MOZ_ASSERT(readType == LOCAL_GL_UNSIGNED_BYTE);
         gfx::Factory::CopyDataSourceSurface(readSurf, dest);
     }
 }
 
 already_AddRefed<gfx::DataSourceSurface>
-YInvertImageSurface(gfx::DataSourceSurface* aSurf)
+YInvertImageSurface(gfx::DataSourceSurface* aSurf, uint32_t aStride)
 {
     RefPtr<DataSourceSurface> temp =
       Factory::CreateDataSourceSurfaceWithStride(aSurf->GetSize(),
                                                  aSurf->GetFormat(),
-                                                 aSurf->Stride());
+                                                 aStride);
     if (NS_WARN_IF(!temp)) {
         return nullptr;
     }
 
     DataSourceSurface::MappedSurface map;
     if (!temp->Map(DataSourceSurface::MapType::WRITE, &map)) {
         return nullptr;
     }
@@ -484,17 +484,17 @@ ReadBackSurface(GLContext* gl, GLuint aT
         gl->fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, currentPackAlignment);
     }
 
     if (aFormat == SurfaceFormat::R8G8B8A8 || aFormat == SurfaceFormat::R8G8B8X8) {
         SwapRAndBComponents(surf);
     }
 
     if (aYInvert) {
-        surf = YInvertImageSurface(surf);
+        surf = YInvertImageSurface(surf, map.GetStride());
     }
 
     return surf.forget();
 }
 
 #define CLEANUP_IF_GLERROR_OCCURRED(x)                                      \
     if (DidGLErrorOccur(x)) {                                               \
         return false;                                                       \
--- a/gfx/gl/GLReadTexImageHelper.h
+++ b/gfx/gl/GLReadTexImageHelper.h
@@ -29,17 +29,17 @@ bool GetActualReadFormats(GLContext* gl,
 
 void ReadPixelsIntoDataSurface(GLContext* aGL,
                                gfx::DataSourceSurface* aSurface);
 
 already_AddRefed<gfx::DataSourceSurface>
 ReadBackSurface(GLContext* gl, GLuint aTexture, bool aYInvert, gfx::SurfaceFormat aFormat);
 
 already_AddRefed<gfx::DataSourceSurface>
-YInvertImageSurface(gfx::DataSourceSurface* aSurf);
+YInvertImageSurface(gfx::DataSourceSurface* aSurf, uint32_t aStride);
 
 void
 SwapRAndBComponents(gfx::DataSourceSurface* surf);
 
 class GLReadTexImageHelper final
 {
     // The GLContext is the sole owner of the GLBlitHelper.
     GLContext* mGL;
--- a/gfx/layers/AsyncCanvasRenderer.cpp
+++ b/gfx/layers/AsyncCanvasRenderer.cpp
@@ -267,16 +267,18 @@ AsyncCanvasRenderer::GetInputStream(cons
                                     nsIInputStream **aStream)
 {
   MOZ_ASSERT(NS_IsMainThread());
   RefPtr<gfx::DataSourceSurface> surface = GetSurface();
   if (!surface) {
     return NS_ERROR_FAILURE;
   }
 
+  gfx::DataSourceSurface::ScopedMap map(surface, gfx::DataSourceSurface::READ);
+
   // Handle y flip.
-  RefPtr<gfx::DataSourceSurface> dataSurf = gl::YInvertImageSurface(surface);
+  RefPtr<gfx::DataSourceSurface> dataSurf = gl::YInvertImageSurface(surface, map.GetStride());
 
   return gfxUtils::GetInputStream(dataSurf, false, aMimeType, aEncoderOptions, aStream);
 }
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/LayerScope.cpp
+++ b/gfx/layers/LayerScope.cpp
@@ -501,19 +501,19 @@ private:
         tp->set_dataformat(LOCAL_GL_RGBA);
         tp->set_glcontext(static_cast<uint64_t>(mContextAddress));
         tp->set_ismask(mIsMask);
 
         if (aImage) {
             DataSourceSurface::ScopedMap map(aImage, DataSourceSurface::READ);
             tp->set_width(aImage->GetSize().width);
             tp->set_height(aImage->GetSize().height);
-            tp->set_stride(aImage->Stride());
+            tp->set_stride(map.GetStride());
 
-            mDatasize = aImage->GetSize().height * aImage->Stride();
+            mDatasize = aImage->GetSize().height * map.GetStride();
 
             auto compresseddata = MakeUnique<char[]>(LZ4::maxCompressedSize(mDatasize));
             if (compresseddata) {
                 int ndatasize = LZ4::compress((char*)map.GetData(),
                                               mDatasize,
                                               compresseddata.get());
                 if (ndatasize > 0) {
                     mDatasize = ndatasize;
--- a/gfx/layers/d3d11/TextureD3D11.cpp
+++ b/gfx/layers/d3d11/TextureD3D11.cpp
@@ -1444,17 +1444,17 @@ DataTextureSourceD3D11::Update(DataSourc
         box.bottom = rect.YMost();
 
         void* data = map.mData + map.mStride * rect.y + BytesPerPixel(aSurface->GetFormat()) * rect.x;
 
         context->UpdateSubresource(mTexture, 0, &box, data, map.mStride, map.mStride * rect.Height());
       }
     } else {
       context->UpdateSubresource(mTexture, 0, nullptr, map.mData,
-                                 aSurface->Stride(), aSurface->Stride() * mSize.height);
+                                 map.mStride, map.mStride * mSize.height);
     }
 
     aSurface->Unmap();
   } else {
     mIsTiled = true;
     uint32_t tileCount = GetRequiredTilesD3D11(mSize.width, maxSize) *
                          GetRequiredTilesD3D11(mSize.height, maxSize);
 
@@ -1473,19 +1473,19 @@ DataTextureSourceD3D11::Update(DataSourc
       IntRect tileRect = GetTileRect(i);
 
       desc.Width = tileRect.Width();
       desc.Height = tileRect.Height();
       desc.Usage = D3D11_USAGE_IMMUTABLE;
 
       D3D11_SUBRESOURCE_DATA initData;
       initData.pSysMem = map.GetData() +
-                         tileRect.y * aSurface->Stride() +
+                         tileRect.y * map.GetStride() +
                          tileRect.x * bpp;
-      initData.SysMemPitch = aSurface->Stride();
+      initData.SysMemPitch = map.GetStride();
 
       hr = mDevice->CreateTexture2D(&desc, &initData, getter_AddRefs(mTileTextures[i]));
       if (FAILED(hr) || !mTileTextures[i]) {
         Reset();
         return false;
       }
     }
   }
--- a/gfx/tests/gtest/TestCompositor.cpp
+++ b/gfx/tests/gtest/TestCompositor.cpp
@@ -136,18 +136,18 @@ static bool CompositeAndCompare(RefPtr<L
   RefPtr<SourceSurface> ssRef = refDT->Snapshot();
   RefPtr<DataSourceSurface> dssRef = ssRef->GetDataSurface();
   DataSourceSurface::ScopedMap dssRefMap(dssRef, DataSourceSurface::READ);
   uint8_t* bitmapRef = dssRefMap.GetData();
 
   for (int y = 0; y < gCompHeight; y++) {
     for (int x = 0; x < gCompWidth; x++) {
       for (size_t channel = 0; channel < 4; channel++) {
-        uint8_t bit = bitmap[y * dss->Stride() + x * 4 + channel];
-        uint8_t bitRef = bitmapRef[y * dss->Stride() + x * 4 + channel];
+        uint8_t bit = bitmap[y * dssMap.GetStride() + x * 4 + channel];
+        uint8_t bitRef = bitmapRef[y * dssRefMap.GetStride() + x * 4 + channel];
         if (bit != bitRef) {
           printf("Layer Tree:\n");
           layerManager->Dump();
           printf("Original:\n");
           gfxUtils::DumpAsDataURI(drawTarget);
           printf("\n\n");
 
           printf("Reference:\n");
--- a/gfx/tests/gtest/TestTextures.cpp
+++ b/gfx/tests/gtest/TestTextures.cpp
@@ -162,17 +162,17 @@ void TestTextureClientSurface(TextureCli
   // but the latter needs a widget...
   if (host->Lock()) {
     RefPtr<mozilla::gfx::DataSourceSurface> hostDataSurface = host->GetAsSurface();
 
     DataSourceSurface::ScopedMap map(hostDataSurface, DataSourceSurface::READ);
     RefPtr<gfxImageSurface> hostSurface =
       new gfxImageSurface(map.GetData(),
                           hostDataSurface->GetSize(),
-                          hostDataSurface->Stride(),
+                          map.GetStride(),
                           SurfaceFormatToImageFormat(hostDataSurface->GetFormat()));
     AssertSurfacesEqual(surface, hostSurface.get());
     host->Unlock();
   }
 }
 
 // Same as above, for YCbCr surfaces
 void TestTextureClientYCbCr(TextureClient* client, PlanarYCbCrData& ycbcrData) {
--- a/gfx/thebes/gfxImageSurface.cpp
+++ b/gfx/thebes/gfxImageSurface.cpp
@@ -275,17 +275,17 @@ gfxImageSurface::CopyFrom (SourceSurface
     }
 
     if (!FormatsAreCompatible(SurfaceFormatToImageFormat(aSurface->GetFormat()),
                               mFormat)) {
         return false;
     }
 
     DataSourceSurface::ScopedMap map(data, DataSourceSurface::READ);
-    CopyForStride(mData, map.GetData(), size, mStride, data->Stride());
+    CopyForStride(mData, map.GetData(), size, mStride, map.GetStride());
 
     return true;
 }
 
 
 bool
 gfxImageSurface::CopyFrom(gfxImageSurface *other)
 {
@@ -316,17 +316,17 @@ gfxImageSurface::CopyTo(SourceSurface *a
     }
 
     if (!FormatsAreCompatible(SurfaceFormatToImageFormat(aSurface->GetFormat()),
                               mFormat)) {
         return false;
     }
 
     DataSourceSurface::ScopedMap map(data, DataSourceSurface::READ_WRITE);
-    CopyForStride(map.GetData(), mData, size, data->Stride(), mStride);
+    CopyForStride(map.GetData(), mData, size, map.GetStride(), mStride);
 
     return true;
 }
 
 already_AddRefed<DataSourceSurface>
 gfxImageSurface::CopyToB8G8R8A8DataSourceSurface()
 {
   RefPtr<DataSourceSurface> dataSurface =
--- a/gfx/thebes/gfxUtils.cpp
+++ b/gfx/thebes/gfxUtils.cpp
@@ -1293,31 +1293,31 @@ gfxUtils::DumpAsDataURI(DrawTarget* aDT,
   } else {
     NS_WARNING("Failed to get surface!");
   }
 }
 
 /* static */ nsCString
 gfxUtils::GetAsLZ4Base64Str(DataSourceSurface* aSourceSurface)
 {
-  int32_t dataSize = aSourceSurface->GetSize().height * aSourceSurface->Stride();
+  DataSourceSurface::ScopedMap map(aSourceSurface, DataSourceSurface::READ);
+  int32_t dataSize = aSourceSurface->GetSize().height * map.GetStride();
   auto compressedData = MakeUnique<char[]>(LZ4::maxCompressedSize(dataSize));
   if (compressedData) {
-    DataSourceSurface::ScopedMap map(aSourceSurface, DataSourceSurface::READ);
     int nDataSize = LZ4::compress((char*)map.GetData(),
                                   dataSize,
                                   compressedData.get());
     if (nDataSize > 0) {
       nsCString encodedImg;
       nsresult rv = Base64Encode(Substring(compressedData.get(), nDataSize), encodedImg);
       if (rv == NS_OK) {
         nsCString string("");
         string.AppendPrintf("data:image/lz4bgra;base64,%i,%i,%i,",
                              aSourceSurface->GetSize().width,
-                             aSourceSurface->Stride(),
+                             map.GetStride(),
                              aSourceSurface->GetSize().height);
         string.Append(encodedImg);
         return string;
       }
     }
   }
   return nsCString("");
 }
--- a/image/test/gtest/Common.cpp
+++ b/image/test/gtest/Common.cpp
@@ -182,26 +182,25 @@ RectIsSolidColor(SourceSurface* aSurface
 {
   IntSize surfaceSize = aSurface->GetSize();
   IntRect rect =
     aRect.Intersect(IntRect(0, 0, surfaceSize.width, surfaceSize.height));
 
   RefPtr<DataSourceSurface> dataSurface = aSurface->GetDataSurface();
   ASSERT_TRUE_OR_RETURN(dataSurface != nullptr, false);
 
-  ASSERT_EQ_OR_RETURN(dataSurface->Stride(), surfaceSize.width * 4, false);
-
   DataSourceSurface::ScopedMap mapping(dataSurface,
                                        DataSourceSurface::MapType::READ);
   ASSERT_TRUE_OR_RETURN(mapping.IsMapped(), false);
+  ASSERT_EQ_OR_RETURN(mapping.GetStride(), surfaceSize.width * 4, false);
 
   uint8_t* data = mapping.GetData();
   ASSERT_TRUE_OR_RETURN(data != nullptr, false);
 
-  int32_t rowLength = dataSurface->Stride();
+  int32_t rowLength = mapping.GetStride();
   for (int32_t row = rect.y; row < rect.YMost(); ++row) {
     for (int32_t col = rect.x; col < rect.XMost(); ++col) {
       int32_t i = row * rowLength + col * 4;
       if (aFuzz != 0) {
         ASSERT_LE_OR_RETURN(abs(aColor.mBlue - data[i + 0]), aFuzz, false);
         ASSERT_LE_OR_RETURN(abs(aColor.mGreen - data[i + 1]), aFuzz, false);
         ASSERT_LE_OR_RETURN(abs(aColor.mRed - data[i + 2]), aFuzz, false);
         ASSERT_LE_OR_RETURN(abs(aColor.mAlpha - data[i + 3]), aFuzz, false);
@@ -263,26 +262,25 @@ RowHasPixels(SourceSurface* aSurface,
 
   IntSize surfaceSize = aSurface->GetSize();
   ASSERT_EQ_OR_RETURN(aPixels.size(), size_t(surfaceSize.width), false);
   ASSERT_LT_OR_RETURN(aRow, surfaceSize.height, false);
 
   RefPtr<DataSourceSurface> dataSurface = aSurface->GetDataSurface();
   ASSERT_TRUE_OR_RETURN(dataSurface, false);
 
-  ASSERT_EQ_OR_RETURN(dataSurface->Stride(), surfaceSize.width * 4, false);
-
   DataSourceSurface::ScopedMap mapping(dataSurface,
                                        DataSourceSurface::MapType::READ);
   ASSERT_TRUE_OR_RETURN(mapping.IsMapped(), false);
+  ASSERT_EQ_OR_RETURN(mapping.GetStride(), surfaceSize.width * 4, false);
 
   uint8_t* data = mapping.GetData();
   ASSERT_TRUE_OR_RETURN(data != nullptr, false);
 
-  int32_t rowLength = dataSurface->Stride();
+  int32_t rowLength = mapping.GetStride();
   for (int32_t col = 0; col < surfaceSize.width; ++col) {
     int32_t i = aRow * rowLength + col * 4;
     ASSERT_EQ_OR_RETURN(aPixels[col].mBlue,  data[i + 0], false);
     ASSERT_EQ_OR_RETURN(aPixels[col].mGreen, data[i + 1], false);
     ASSERT_EQ_OR_RETURN(aPixels[col].mRed,   data[i + 2], false);
     ASSERT_EQ_OR_RETURN(aPixels[col].mAlpha, data[i + 3], false);
   }