Bug 1544478 - Respect SharedRGBImage's stride during YUV->RGBA conversion. r=mattwoodrow a=pascalc
authorMarkus Stange <mstange@themasta.com>
Tue, 16 Apr 2019 17:02:59 +0000
changeset 523249 1cf183a8be97f72bc3d61a866ba76a41ffcd4289
parent 523248 d2668e1efcfd00856dd3c49eec1aa52b6ed7c095
child 523250 9b2635dc41a478fa26dd8cf2bd428e1974e4d880
push id11115
push useraiakab@mozilla.com
push dateFri, 19 Apr 2019 16:14:22 +0000
treeherdermozilla-beta@86f6ec90b34b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow, pascalc
bugs1544478
milestone67.0
Bug 1544478 - Respect SharedRGBImage's stride during YUV->RGBA conversion. r=mattwoodrow a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D27600
dom/media/MediaData.cpp
--- a/dom/media/MediaData.cpp
+++ b/dom/media/MediaData.cpp
@@ -412,25 +412,44 @@ already_AddRefed<VideoData> VideoData::C
   if (!v->mImage) {
     return nullptr;
   }
   if (!videoImage->Allocate(
           IntSize(aBuffer.mPlanes[0].mWidth, aBuffer.mPlanes[0].mHeight),
           SurfaceFormat::B8G8R8A8)) {
     return nullptr;
   }
-  uint8_t* argb_buffer = videoImage->GetBuffer();
-  IntSize size = videoImage->GetSize();
+
+  RefPtr<layers::TextureClient> texture =
+      videoImage->GetTextureClient(/* aForwarder */ nullptr);
+  if (!texture) {
+    NS_WARNING("Failed to allocate TextureClient");
+    return nullptr;
+  }
+
+  layers::TextureClientAutoLock autoLock(texture,
+                                         layers::OpenMode::OPEN_WRITE_ONLY);
+  if (!autoLock.Succeeded()) {
+    NS_WARNING("Failed to lock TextureClient");
+    return nullptr;
+  }
+
+  layers::MappedTextureData buffer;
+  if (!texture->BorrowMappedData(buffer)) {
+    NS_WARNING("Failed to borrow mapped data");
+    return nullptr;
+  }
 
   // The naming convention for libyuv and associated utils is word-order.
   // The naming convention in the gfx stack is byte-order.
   ConvertYCbCrAToARGB(aBuffer.mPlanes[0].mData, aBuffer.mPlanes[1].mData,
                       aBuffer.mPlanes[2].mData, aAlphaPlane.mData,
                       aBuffer.mPlanes[0].mStride, aBuffer.mPlanes[1].mStride,
-                      argb_buffer, size.width * 4, size.width, size.height);
+                      buffer.data, buffer.stride, buffer.size.width,
+                      buffer.size.height);
 
   return v.forget();
 }
 
 /* static */
 already_AddRefed<VideoData> VideoData::CreateFromImage(
     const IntSize& aDisplay, int64_t aOffset, const TimeUnit& aTime,
     const TimeUnit& aDuration, const RefPtr<Image>& aImage, bool aKeyframe,