Bug 1540581 - P5. Add ColorSpace info to MacIOSurface. r=mattwoodrow
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 11 Apr 2019 12:36:31 +0000
changeset 469133 c8d5854c0ef078fe1f725530c8fc4479abe65b1c
parent 469132 9a4305ff9a2dd501279f98c01ea0609952c4b72c
child 469134 884f5dc55873c9345ee945cd6d5427e8ab398071
push id35856
push usercsabou@mozilla.com
push dateFri, 12 Apr 2019 03:19:48 +0000
treeherdermozilla-central@940684cd1065 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1540581
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 1540581 - P5. Add ColorSpace info to MacIOSurface. r=mattwoodrow It would have been nicer and more logical to use a MacIOSurfaceImage to store the colorspace information, however the data passed around is a IOSurface Id via a SurfaceDescriptorMacIOSurface; the original data structure isn't kept; so we must transit the data at the same time as the IOSurface Id. Also remove unnecessary test (new operator is infallible). Differential Revision: https://phabricator.services.mozilla.com/D26058
gfx/2d/MacIOSurface.cpp
gfx/2d/MacIOSurface.h
gfx/2d/Types.h
gfx/gl/SharedSurfaceIO.cpp
gfx/ipc/GfxMessageUtils.h
gfx/layers/basic/MacIOSurfaceTextureHostBasic.cpp
gfx/layers/ipc/LayersSurfaces.ipdlh
gfx/layers/opengl/CompositorOGL.cpp
gfx/layers/opengl/MacIOSurfaceTextureClientOGL.cpp
gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp
gfx/layers/opengl/MacIOSurfaceTextureHostOGL.h
gfx/vr/VRDisplayLocal.cpp
--- a/gfx/2d/MacIOSurface.cpp
+++ b/gfx/2d/MacIOSurface.cpp
@@ -275,20 +275,22 @@ void MacIOSurfaceLib::CloseLibrary() {
     dlclose(sCoreVideoFramework);
   }
   sIOSurfaceFramework = nullptr;
   sOpenGLFramework = nullptr;
   sCoreVideoFramework = nullptr;
 }
 
 MacIOSurface::MacIOSurface(IOSurfacePtr aIOSurfacePtr,
-                           double aContentsScaleFactor, bool aHasAlpha)
+                           double aContentsScaleFactor, bool aHasAlpha,
+                           gfx::YUVColorSpace aColorSpace)
     : mIOSurfacePtr(aIOSurfacePtr),
       mContentsScaleFactor(aContentsScaleFactor),
-      mHasAlpha(aHasAlpha) {
+      mHasAlpha(aHasAlpha),
+      mColorSpace(aColorSpace) {
   CFRetain(mIOSurfacePtr);
   IncrementUseCount();
 }
 
 MacIOSurface::~MacIOSurface() {
   DecrementUseCount();
   CFRelease(mIOSurfacePtr);
 }
@@ -325,40 +327,33 @@ already_AddRefed<MacIOSurface> MacIOSurf
 
   IOSurfacePtr surfaceRef = MacIOSurfaceLib::IOSurfaceCreate(props);
   ::CFRelease(props);
 
   if (!surfaceRef) return nullptr;
 
   RefPtr<MacIOSurface> ioSurface =
       new MacIOSurface(surfaceRef, aContentsScaleFactor, aHasAlpha);
-  if (!ioSurface) {
-    ::CFRelease(surfaceRef);
-    return nullptr;
-  }
 
   // Release the IOSurface because MacIOSurface retained it
   CFRelease(surfaceRef);
 
   return ioSurface.forget();
 }
 
 already_AddRefed<MacIOSurface> MacIOSurface::LookupSurface(
-    IOSurfaceID aIOSurfaceID, double aContentsScaleFactor, bool aHasAlpha) {
+    IOSurfaceID aIOSurfaceID, double aContentsScaleFactor, bool aHasAlpha,
+    gfx::YUVColorSpace aColorSpace) {
   if (!MacIOSurfaceLib::isInit() || aContentsScaleFactor <= 0) return nullptr;
 
   IOSurfacePtr surfaceRef = MacIOSurfaceLib::IOSurfaceLookup(aIOSurfaceID);
   if (!surfaceRef) return nullptr;
 
-  RefPtr<MacIOSurface> ioSurface =
-      new MacIOSurface(surfaceRef, aContentsScaleFactor, aHasAlpha);
-  if (!ioSurface) {
-    ::CFRelease(surfaceRef);
-    return nullptr;
-  }
+  RefPtr<MacIOSurface> ioSurface = new MacIOSurface(
+      surfaceRef, aContentsScaleFactor, aHasAlpha, aColorSpace);
 
   // Release the IOSurface because MacIOSurface retained it
   CFRelease(surfaceRef);
 
   return ioSurface.forget();
 }
 
 IOSurfaceID MacIOSurface::GetIOSurfaceID() {
@@ -604,20 +599,16 @@ already_AddRefed<MacIOSurface> MacIOSurf
   if (!MacIOSurfaceLib::isInit() || aContentsScaleFactor <= 0) return nullptr;
 
   IOSurfacePtr surfaceRef =
       MacIOSurfaceLib::IOSurfaceContextGetSurface(aContext);
   if (!surfaceRef) return nullptr;
 
   RefPtr<MacIOSurface> ioSurface =
       new MacIOSurface(surfaceRef, aContentsScaleFactor, aHasAlpha);
-  if (!ioSurface) {
-    ::CFRelease(surfaceRef);
-    return nullptr;
-  }
   return ioSurface.forget();
 }
 
 CGContextType GetContextType(CGContextRef ref) {
   if (!MacIOSurfaceLib::isInit() || !MacIOSurfaceLib::sCGContextGetTypePtr)
     return CG_CONTEXT_TYPE_UNKNOWN;
 
   unsigned int type = MacIOSurfaceLib::sCGContextGetTypePtr(ref);
--- a/gfx/2d/MacIOSurface.h
+++ b/gfx/2d/MacIOSurface.h
@@ -6,16 +6,18 @@
 
 #ifndef MacIOSurface_h__
 #define MacIOSurface_h__
 #ifdef XP_DARWIN
 #  include <QuartzCore/QuartzCore.h>
 #  include <CoreVideo/CoreVideo.h>
 #  include <dlfcn.h>
 
+#  include "mozilla/gfx/Types.h"
+
 namespace mozilla {
 namespace gl {
 class GLContext;
 }
 }  // namespace mozilla
 
 struct _CGLContextObject;
 
@@ -91,21 +93,25 @@ class MacIOSurface final
   // MacIOSurface holds a reference to the corresponding IOSurface.
 
   static already_AddRefed<MacIOSurface> CreateIOSurface(
       int aWidth, int aHeight, double aContentsScaleFactor = 1.0,
       bool aHasAlpha = true);
   static void ReleaseIOSurface(MacIOSurface* aIOSurface);
   static already_AddRefed<MacIOSurface> LookupSurface(
       IOSurfaceID aSurfaceID, double aContentsScaleFactor = 1.0,
-      bool aHasAlpha = true);
+      bool aHasAlpha = true,
+      mozilla::gfx::YUVColorSpace aColorSpace =
+          mozilla::gfx::YUVColorSpace::UNKNOWN);
 
   explicit MacIOSurface(IOSurfacePtr aIOSurfacePtr,
                         double aContentsScaleFactor = 1.0,
-                        bool aHasAlpha = true);
+                        bool aHasAlpha = true,
+                        mozilla::gfx::YUVColorSpace aColorSpace =
+                            mozilla::gfx::YUVColorSpace::UNKNOWN);
   ~MacIOSurface();
   IOSurfaceID GetIOSurfaceID();
   void* GetBaseAddress();
   void* GetBaseAddressOfPlane(size_t planeIndex);
   size_t GetPlaneCount();
   OSType GetPixelFormat();
   // GetWidth() and GetHeight() return values in "display pixels".  A
   // "display pixel" is the smallest fully addressable part of a display.
@@ -119,16 +125,23 @@ class MacIOSurface final
   size_t GetBytesPerRow(size_t plane = 0);
   void Lock(bool aReadOnly = true);
   void Unlock(bool aReadOnly = true);
   void IncrementUseCount();
   void DecrementUseCount();
   bool HasAlpha() { return mHasAlpha; }
   mozilla::gfx::SurfaceFormat GetFormat();
   mozilla::gfx::SurfaceFormat GetReadFormat();
+  // This would be better suited on MacIOSurfaceImage type, however due to the
+  // current data structure, this is not possible as only the IOSurfacePtr is
+  // being used across.
+  void SetYUVColorSpace(mozilla::gfx::YUVColorSpace aColorSpace) {
+    mColorSpace = aColorSpace;
+  }
+  mozilla::gfx::YUVColorSpace GetYUVColorSpace() const { return mColorSpace; }
 
   // We would like to forward declare NSOpenGLContext, but it is an @interface
   // and this file is also used from c++, so we use a void *.
   CGLError CGLTexImageIOSurface2D(
       mozilla::gl::GLContext* aGL, CGLContextObj ctxt, size_t plane,
       mozilla::gfx::SurfaceFormat* aOutReadFormat = nullptr);
   CGLError CGLTexImageIOSurface2D(CGLContextObj ctxt, GLenum target,
                                   GLenum internalFormat, GLsizei width,
@@ -146,16 +159,18 @@ class MacIOSurface final
   static size_t GetMaxHeight();
   const void* GetIOSurfacePtr() { return mIOSurfacePtr; }
 
  private:
   friend class nsCARenderer;
   const IOSurfacePtr mIOSurfacePtr;
   double mContentsScaleFactor;
   bool mHasAlpha;
+  mozilla::gfx::YUVColorSpace mColorSpace =
+      mozilla::gfx::YUVColorSpace::UNKNOWN;
 };
 
 class MacIOSurfaceLib {
  public:
   MacIOSurfaceLib() = delete;
   static void* sIOSurfaceFramework;
   static void* sOpenGLFramework;
   static void* sCoreGraphicsFramework;
--- a/gfx/2d/Types.h
+++ b/gfx/2d/Types.h
@@ -137,18 +137,19 @@ inline bool IsOpaque(SurfaceFormat aForm
       return false;
   }
 }
 
 enum class YUVColorSpace : uint8_t {
   BT601,
   BT709,
   BT2020,
-  // This represents the unknown format.
+  // This represents the unknown format and is a valid value.
   UNKNOWN,
+  _NUM_COLORSPACE
 };
 
 enum class ColorDepth : uint8_t {
   COLOR_8,
   COLOR_10,
   COLOR_12,
   COLOR_16,
   UNKNOWN
--- a/gfx/gl/SharedSurfaceIO.cpp
+++ b/gfx/gl/SharedSurfaceIO.cpp
@@ -151,17 +151,18 @@ SharedSurface_IOSurface::~SharedSurface_
 
   mGL->fDeleteTextures(1, &mProdTex);
 }
 
 bool SharedSurface_IOSurface::ToSurfaceDescriptor(
     layers::SurfaceDescriptor* const out_descriptor) {
   bool isOpaque = !mHasAlpha;
   *out_descriptor = layers::SurfaceDescriptorMacIOSurface(
-      mIOSurf->GetIOSurfaceID(), mIOSurf->GetContentsScaleFactor(), isOpaque);
+      mIOSurf->GetIOSurfaceID(), mIOSurf->GetContentsScaleFactor(), isOpaque,
+      mIOSurf->GetYUVColorSpace());
   return true;
 }
 
 bool SharedSurface_IOSurface::ReadbackBySharedHandle(
     gfx::DataSourceSurface* out_surface) {
   MOZ_ASSERT(out_surface);
   mIOSurf->Lock();
   size_t bytesPerRow = mIOSurf->GetBytesPerRow();
--- a/gfx/ipc/GfxMessageUtils.h
+++ b/gfx/ipc/GfxMessageUtils.h
@@ -646,22 +646,22 @@ struct ParamTraits<mozilla::gfx::Surface
                                       mozilla::gfx::SurfaceFormat::UNKNOWN> {};
 
 template <>
 struct ParamTraits<mozilla::gfx::ColorDepth>
     : public ContiguousEnumSerializer<mozilla::gfx::ColorDepth,
                                       mozilla::gfx::ColorDepth::COLOR_8,
                                       mozilla::gfx::ColorDepth::UNKNOWN> {};
 
-
 template <>
 struct ParamTraits<mozilla::gfx::YUVColorSpace>
-    : public ContiguousEnumSerializer<mozilla::gfx::YUVColorSpace,
-                                      mozilla::gfx::YUVColorSpace::BT601,
-                                      mozilla::gfx::YUVColorSpace::UNKNOWN> {};
+    : public ContiguousEnumSerializer<
+          mozilla::gfx::YUVColorSpace, mozilla::gfx::YUVColorSpace::BT601,
+          mozilla::gfx::YUVColorSpace::_NUM_COLORSPACE> {};
+
 template <>
 struct ParamTraits<mozilla::StereoMode>
     : public ContiguousEnumSerializer<mozilla::StereoMode,
                                       mozilla::StereoMode::MONO,
                                       mozilla::StereoMode::MAX> {};
 
 template <>
 struct ParamTraits<mozilla::gfx::ImplicitlyCopyableFloatArray>
--- a/gfx/layers/basic/MacIOSurfaceTextureHostBasic.cpp
+++ b/gfx/layers/basic/MacIOSurfaceTextureHostBasic.cpp
@@ -31,19 +31,19 @@ gfx::SurfaceFormat MacIOSurfaceTextureSo
   return mSurface->GetFormat() == gfx::SurfaceFormat::NV12
              ? gfx::SurfaceFormat::B8G8R8X8
              : gfx::SurfaceFormat::B8G8R8A8;
 }
 
 MacIOSurfaceTextureHostBasic::MacIOSurfaceTextureHostBasic(
     TextureFlags aFlags, const SurfaceDescriptorMacIOSurface& aDescriptor)
     : TextureHost(aFlags) {
-  mSurface = MacIOSurface::LookupSurface(aDescriptor.surfaceId(),
-                                         aDescriptor.scaleFactor(),
-                                         !aDescriptor.isOpaque());
+  mSurface = MacIOSurface::LookupSurface(
+      aDescriptor.surfaceId(), aDescriptor.scaleFactor(),
+      !aDescriptor.isOpaque(), aDescriptor.yUVColorSpace());
 }
 
 gfx::SourceSurface* MacIOSurfaceTextureSourceBasic::GetSurface(
     gfx::DrawTarget* aTarget) {
   if (!mSourceSurface) {
     mSourceSurface = CreateSourceSurfaceFromMacIOSurface(mSurface);
   }
   return mSourceSurface;
--- a/gfx/layers/ipc/LayersSurfaces.ipdlh
+++ b/gfx/layers/ipc/LayersSurfaces.ipdlh
@@ -46,16 +46,17 @@ struct SurfaceDescriptorDXGIYCbCr {
   ColorDepth colorDepth;
   YUVColorSpace yUVColorSpace;
 };
 
 struct SurfaceDescriptorMacIOSurface {
   uint32_t surfaceId;
   double scaleFactor;
   bool isOpaque;
+  YUVColorSpace yUVColorSpace;
 };
 
 struct SurfaceTextureDescriptor {
   uint64_t handle;
   IntSize size;
   SurfaceFormat format;
   bool continuous;
   bool ignoreTransform;
--- a/gfx/layers/opengl/CompositorOGL.cpp
+++ b/gfx/layers/opengl/CompositorOGL.cpp
@@ -1489,17 +1489,17 @@ void CompositorOGL::DrawGeometry(const G
         // This is used by IOSurface that use 0,0...w,h coordinate rather then
         // 0,0..1,1.
         program->SetCbCrTexCoordMultiplier(sourceCbCr->GetSize().width,
                                            sourceCbCr->GetSize().height);
       }
 
       program->SetNV12TextureUnits(Y, CbCr);
       program->SetTextureTransform(Matrix4x4());
-      program->SetYUVColorSpace(gfx::YUVColorSpace::BT601);
+      program->SetYUVColorSpace(effectNV12->mYUVColorSpace);
 
       if (maskType != MaskType::MaskNone) {
         BindMaskForProgram(program, sourceMask, LOCAL_GL_TEXTURE2,
                            maskQuadTransform);
       }
       if (mixBlendBackdrop) {
         BindBackdrop(program, mixBlendBackdrop, LOCAL_GL_TEXTURE3);
       }
--- a/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.cpp
+++ b/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.cpp
@@ -47,17 +47,17 @@ MacIOSurfaceTextureData* MacIOSurfaceTex
   }
 
   return Create(surf, aBackend);
 }
 
 bool MacIOSurfaceTextureData::Serialize(SurfaceDescriptor& aOutDescriptor) {
   aOutDescriptor = SurfaceDescriptorMacIOSurface(
       mSurface->GetIOSurfaceID(), mSurface->GetContentsScaleFactor(),
-      !mSurface->HasAlpha());
+      !mSurface->HasAlpha(), mSurface->GetYUVColorSpace());
   return true;
 }
 
 void MacIOSurfaceTextureData::FillInfo(TextureData::Info& aInfo) const {
   aInfo.size = gfx::IntSize(mSurface->GetDevicePixelWidth(),
                             mSurface->GetDevicePixelHeight());
   aInfo.format =
       mSurface->HasAlpha() ? SurfaceFormat::B8G8R8A8 : SurfaceFormat::B8G8R8X8;
--- a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp
+++ b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp
@@ -13,19 +13,19 @@
 
 namespace mozilla {
 namespace layers {
 
 MacIOSurfaceTextureHostOGL::MacIOSurfaceTextureHostOGL(
     TextureFlags aFlags, const SurfaceDescriptorMacIOSurface& aDescriptor)
     : TextureHost(aFlags) {
   MOZ_COUNT_CTOR(MacIOSurfaceTextureHostOGL);
-  mSurface = MacIOSurface::LookupSurface(aDescriptor.surfaceId(),
-                                         aDescriptor.scaleFactor(),
-                                         !aDescriptor.isOpaque());
+  mSurface = MacIOSurface::LookupSurface(
+      aDescriptor.surfaceId(), aDescriptor.scaleFactor(),
+      !aDescriptor.isOpaque(), aDescriptor.yUVColorSpace());
 }
 
 MacIOSurfaceTextureHostOGL::~MacIOSurfaceTextureHostOGL() {
   MOZ_COUNT_DTOR(MacIOSurfaceTextureHostOGL);
 }
 
 GLTextureSource* MacIOSurfaceTextureHostOGL::CreateTextureSourceForPlane(
     size_t aPlane) {
@@ -110,16 +110,23 @@ gfx::IntSize MacIOSurfaceTextureHostOGL:
   return gfx::IntSize(mSurface->GetDevicePixelWidth(),
                       mSurface->GetDevicePixelHeight());
 }
 
 gl::GLContext* MacIOSurfaceTextureHostOGL::gl() const {
   return mProvider ? mProvider->GetGLContext() : nullptr;
 }
 
+gfx::YUVColorSpace MacIOSurfaceTextureHostOGL::GetYUVColorSpace() const {
+  if (!mSurface) {
+    return gfx::YUVColorSpace::UNKNOWN;
+  }
+  return mSurface->GetYUVColorSpace();
+}
+
 void MacIOSurfaceTextureHostOGL::CreateRenderTexture(
     const wr::ExternalImageId& aExternalImageId) {
   RefPtr<wr::RenderTextureHost> texture =
       new wr::RenderMacIOSurfaceTextureHostOGL(GetMacIOSurface());
 
   wr::RenderThread::Get()->RegisterExternalImage(wr::AsUint64(aExternalImageId),
                                                  texture.forget());
 }
@@ -216,27 +223,27 @@ void MacIOSurfaceTextureHostOGL::PushDis
     }
     case gfx::SurfaceFormat::YUV422: {
       MOZ_ASSERT(aImageKeys.length() == 1);
       MOZ_ASSERT(mSurface->GetPlaneCount() == 0);
       // Those images can only be generated at present by the Apple H264 decoder
       // which only supports 8 bits color depth.
       aBuilder.PushYCbCrInterleavedImage(
           aBounds, aClip, true, aImageKeys[0], wr::ColorDepth::Color8,
-          wr::ToWrYuvColorSpace(gfx::YUVColorSpace::BT601), aFilter);
+          wr::ToWrYuvColorSpace(GetYUVColorSpace()), aFilter);
       break;
     }
     case gfx::SurfaceFormat::NV12: {
       MOZ_ASSERT(aImageKeys.length() == 2);
       MOZ_ASSERT(mSurface->GetPlaneCount() == 2);
       // Those images can only be generated at present by the Apple H264 decoder
       // which only supports 8 bits color depth.
       aBuilder.PushNV12Image(aBounds, aClip, true, aImageKeys[0], aImageKeys[1],
                              wr::ColorDepth::Color8,
-                             wr::ToWrYuvColorSpace(gfx::YUVColorSpace::BT601),
+                             wr::ToWrYuvColorSpace(GetYUVColorSpace()),
                              aFilter);
       break;
     }
     default: {
       MOZ_ASSERT_UNREACHABLE("unexpected to be called");
     }
   }
 }
--- a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.h
+++ b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.h
@@ -76,16 +76,18 @@ class MacIOSurfaceTextureHostOGL : publi
                                    const wr::ExternalImageId& aExtID) override;
 
   virtual void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
                                 const wr::LayoutRect& aBounds,
                                 const wr::LayoutRect& aClip,
                                 wr::ImageRendering aFilter,
                                 const Range<wr::ImageKey>& aImageKeys) override;
 
+  gfx::YUVColorSpace GetYUVColorSpace() const override;
+
  protected:
   GLTextureSource* CreateTextureSourceForPlane(size_t aPlane);
 
   RefPtr<GLTextureSource> mTextureSource;
   RefPtr<MacIOSurface> mSurface;
 };
 
 }  // namespace layers
--- a/gfx/vr/VRDisplayLocal.cpp
+++ b/gfx/vr/VRDisplayLocal.cpp
@@ -1,126 +1,127 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "VRDisplayLocal.h"
-#include "gfxPrefs.h"
-#include "gfxVR.h"
-#include "ipc/VRLayerParent.h"
-#include "mozilla/layers/TextureHost.h"
-#include "mozilla/dom/GamepadBinding.h"  // For GamepadMappingType
-#include "VRThread.h"
-
-#if defined(XP_WIN)
-
-#  include <d3d11.h>
-#  include "gfxWindowsPlatform.h"
-#  include "../layers/d3d11/CompositorD3D11.h"
-#  include "mozilla/gfx/DeviceManagerDx.h"
-#  include "mozilla/layers/TextureD3D11.h"
-
-#elif defined(XP_MACOSX)
-
-#  include "mozilla/gfx/MacIOSurface.h"
-
-#endif
-
-#if defined(MOZ_WIDGET_ANDROID)
-#  include "mozilla/layers/CompositorThread.h"
-#endif  // defined(MOZ_WIDGET_ANDROID)
-
-using namespace mozilla;
-using namespace mozilla::gfx;
-using namespace mozilla::layers;
-
-VRDisplayLocal::VRDisplayLocal(VRDeviceType aType) : VRDisplayHost(aType) {
-  MOZ_COUNT_CTOR_INHERITED(VRDisplayLocal, VRDisplayHost);
-}
-
-VRDisplayLocal::~VRDisplayLocal() {
-  MOZ_COUNT_DTOR_INHERITED(VRDisplayLocal, VRDisplayHost);
-}
-
-bool VRDisplayLocal::SubmitFrame(const layers::SurfaceDescriptor& aTexture,
-                                 uint64_t aFrameId,
-                                 const gfx::Rect& aLeftEyeRect,
-                                 const gfx::Rect& aRightEyeRect) {
-#if !defined(MOZ_WIDGET_ANDROID)
-  MOZ_ASSERT(mSubmitThread->GetThread() == NS_GetCurrentThread());
-#endif  // !defined(MOZ_WIDGET_ANDROID)
-
-  switch (aTexture.type()) {
-#if defined(XP_WIN)
-    case SurfaceDescriptor::TSurfaceDescriptorD3D10: {
-      if (!CreateD3DObjects()) {
-        return false;
-      }
-      const SurfaceDescriptorD3D10& surf =
-          aTexture.get_SurfaceDescriptorD3D10();
-      RefPtr<ID3D11Texture2D> dxTexture;
-      HRESULT hr = mDevice->OpenSharedResource(
-          (HANDLE)surf.handle(), __uuidof(ID3D11Texture2D),
-          (void**)(ID3D11Texture2D**)getter_AddRefs(dxTexture));
-      if (FAILED(hr) || !dxTexture) {
-        NS_WARNING("Failed to open shared texture");
-        return false;
-      }
-
-      // Similar to LockD3DTexture in TextureD3D11.cpp
-      RefPtr<IDXGIKeyedMutex> mutex;
-      dxTexture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mutex));
-      if (mutex) {
-        HRESULT hr = mutex->AcquireSync(0, 1000);
-        if (hr == WAIT_TIMEOUT) {
-          gfxDevCrash(LogReason::D3DLockTimeout) << "D3D lock mutex timeout";
-        } else if (hr == WAIT_ABANDONED) {
-          gfxCriticalNote << "GFX: D3D11 lock mutex abandoned";
-        }
-        if (FAILED(hr)) {
-          NS_WARNING("Failed to lock the texture");
-          return false;
-        }
-      }
-      bool success =
-          SubmitFrame(dxTexture, surf.size(), aLeftEyeRect, aRightEyeRect);
-      if (mutex) {
-        HRESULT hr = mutex->ReleaseSync(0);
-        if (FAILED(hr)) {
-          NS_WARNING("Failed to unlock the texture");
-        }
-      }
-      return success;
-    }
-#elif defined(XP_MACOSX)
-    case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface: {
-      const auto& desc = aTexture.get_SurfaceDescriptorMacIOSurface();
-      RefPtr<MacIOSurface> surf = MacIOSurface::LookupSurface(
-          desc.surfaceId(), desc.scaleFactor(), !desc.isOpaque());
-      if (!surf) {
-        NS_WARNING("VRDisplayHost::SubmitFrame failed to get a MacIOSurface");
-        return false;
-      }
-      IntSize texSize = gfx::IntSize(surf->GetDevicePixelWidth(),
-                                     surf->GetDevicePixelHeight());
-      if (!SubmitFrame(surf, texSize, aLeftEyeRect, aRightEyeRect)) {
-        return false;
-      }
-      return true;
-    }
-#elif defined(MOZ_WIDGET_ANDROID)
-    case SurfaceDescriptor::TSurfaceTextureDescriptor: {
-      const SurfaceTextureDescriptor& desc =
-          aTexture.get_SurfaceTextureDescriptor();
-      if (!SubmitFrame(desc, aLeftEyeRect, aRightEyeRect)) {
-        return false;
-      }
-      return true;
-    }
-#endif
-    default: {
-      NS_WARNING("Unsupported SurfaceDescriptor type for VR layer texture");
-      return false;
-    }
-  }
-}
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "VRDisplayLocal.h"
+#include "VRThread.h"
+#include "gfxPrefs.h"
+#include "gfxVR.h"
+#include "ipc/VRLayerParent.h"
+#include "mozilla/dom/GamepadBinding.h"  // For GamepadMappingType
+#include "mozilla/layers/TextureHost.h"
+
+#if defined(XP_WIN)
+
+#  include <d3d11.h>
+#  include "../layers/d3d11/CompositorD3D11.h"
+#  include "gfxWindowsPlatform.h"
+#  include "mozilla/gfx/DeviceManagerDx.h"
+#  include "mozilla/layers/TextureD3D11.h"
+
+#elif defined(XP_MACOSX)
+
+#  include "mozilla/gfx/MacIOSurface.h"
+
+#endif
+
+#if defined(MOZ_WIDGET_ANDROID)
+#  include "mozilla/layers/CompositorThread.h"
+#endif  // defined(MOZ_WIDGET_ANDROID)
+
+using namespace mozilla;
+using namespace mozilla::gfx;
+using namespace mozilla::layers;
+
+VRDisplayLocal::VRDisplayLocal(VRDeviceType aType) : VRDisplayHost(aType) {
+  MOZ_COUNT_CTOR_INHERITED(VRDisplayLocal, VRDisplayHost);
+}
+
+VRDisplayLocal::~VRDisplayLocal() {
+  MOZ_COUNT_DTOR_INHERITED(VRDisplayLocal, VRDisplayHost);
+}
+
+bool VRDisplayLocal::SubmitFrame(const layers::SurfaceDescriptor& aTexture,
+                                 uint64_t aFrameId,
+                                 const gfx::Rect& aLeftEyeRect,
+                                 const gfx::Rect& aRightEyeRect) {
+#if !defined(MOZ_WIDGET_ANDROID)
+  MOZ_ASSERT(mSubmitThread->GetThread() == NS_GetCurrentThread());
+#endif  // !defined(MOZ_WIDGET_ANDROID)
+
+  switch (aTexture.type()) {
+#if defined(XP_WIN)
+    case SurfaceDescriptor::TSurfaceDescriptorD3D10: {
+      if (!CreateD3DObjects()) {
+        return false;
+      }
+      const SurfaceDescriptorD3D10& surf =
+          aTexture.get_SurfaceDescriptorD3D10();
+      RefPtr<ID3D11Texture2D> dxTexture;
+      HRESULT hr = mDevice->OpenSharedResource(
+          (HANDLE)surf.handle(), __uuidof(ID3D11Texture2D),
+          (void**)(ID3D11Texture2D**)getter_AddRefs(dxTexture));
+      if (FAILED(hr) || !dxTexture) {
+        NS_WARNING("Failed to open shared texture");
+        return false;
+      }
+
+      // Similar to LockD3DTexture in TextureD3D11.cpp
+      RefPtr<IDXGIKeyedMutex> mutex;
+      dxTexture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mutex));
+      if (mutex) {
+        HRESULT hr = mutex->AcquireSync(0, 1000);
+        if (hr == WAIT_TIMEOUT) {
+          gfxDevCrash(LogReason::D3DLockTimeout) << "D3D lock mutex timeout";
+        } else if (hr == WAIT_ABANDONED) {
+          gfxCriticalNote << "GFX: D3D11 lock mutex abandoned";
+        }
+        if (FAILED(hr)) {
+          NS_WARNING("Failed to lock the texture");
+          return false;
+        }
+      }
+      bool success =
+          SubmitFrame(dxTexture, surf.size(), aLeftEyeRect, aRightEyeRect);
+      if (mutex) {
+        HRESULT hr = mutex->ReleaseSync(0);
+        if (FAILED(hr)) {
+          NS_WARNING("Failed to unlock the texture");
+        }
+      }
+      return success;
+    }
+#elif defined(XP_MACOSX)
+    case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface: {
+      const auto& desc = aTexture.get_SurfaceDescriptorMacIOSurface();
+      RefPtr<MacIOSurface> surf =
+          MacIOSurface::LookupSurface(desc.surfaceId(), desc.scaleFactor(),
+                                      !desc.isOpaque(), desc.yUVColorSpace());
+      if (!surf) {
+        NS_WARNING("VRDisplayHost::SubmitFrame failed to get a MacIOSurface");
+        return false;
+      }
+      IntSize texSize = gfx::IntSize(surf->GetDevicePixelWidth(),
+                                     surf->GetDevicePixelHeight());
+      if (!SubmitFrame(surf, texSize, aLeftEyeRect, aRightEyeRect)) {
+        return false;
+      }
+      return true;
+    }
+#elif defined(MOZ_WIDGET_ANDROID)
+    case SurfaceDescriptor::TSurfaceTextureDescriptor: {
+      const SurfaceTextureDescriptor& desc =
+          aTexture.get_SurfaceTextureDescriptor();
+      if (!SubmitFrame(desc, aLeftEyeRect, aRightEyeRect)) {
+        return false;
+      }
+      return true;
+    }
+#endif
+    default: {
+      NS_WARNING("Unsupported SurfaceDescriptor type for VR layer texture");
+      return false;
+    }
+  }
+}