Bug 1544478 - Respect SharedRGBImage's stride during YUV->RGBA conversion. r=mattwoodrow
authorMarkus Stange <mstange@themasta.com>
Tue, 16 Apr 2019 17:02:59 +0000
changeset 469713 cf3fbdaa46b9
parent 469712 c503fc359408
child 469714 d5ac9681d3ce
push id35879
push usernerli@mozilla.com
push dateTue, 16 Apr 2019 22:01:48 +0000
treeherdermozilla-central@12a60898fdc1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1544478
milestone68.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
Bug 1544478 - Respect SharedRGBImage's stride during YUV->RGBA conversion. r=mattwoodrow Differential Revision: https://phabricator.services.mozilla.com/D27600
dom/media/MediaData.cpp
--- a/dom/media/MediaData.cpp
+++ b/dom/media/MediaData.cpp
@@ -409,25 +409,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,