Bug 1573668 - Use the real IOSurfaceRef type in MacIOSurface. r=mattwoodrow
authorMarkus Stange <mstange@themasta.com>
Wed, 14 Aug 2019 14:50:25 +0000
changeset 488373 90f8b1145bd781d210aa9a7e1ebc06f583b7be29
parent 488372 691f28f0517fd094c983038165cd6fb6683bc852
child 488374 4e96530fe5c4d04fa462b55ac29d2d15224f618d
push id113906
push userncsoregi@mozilla.com
push dateFri, 16 Aug 2019 04:07:24 +0000
treeherdermozilla-inbound@d887276421d3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1573668
milestone70.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 1573668 - Use the real IOSurfaceRef type in MacIOSurface. r=mattwoodrow Differential Revision: https://phabricator.services.mozilla.com/D41841
dom/media/platforms/apple/AppleVTDecoder.cpp
gfx/2d/MacIOSurface.cpp
gfx/2d/MacIOSurface.h
gfx/2d/QuartzSupport.mm
gfx/vr/service/OpenVRSession.cpp
--- a/dom/media/platforms/apple/AppleVTDecoder.cpp
+++ b/dom/media/platforms/apple/AppleVTDecoder.cpp
@@ -389,17 +389,17 @@ void AppleVTDecoder::OutputFrame(CVPixel
     data = VideoData::CreateAndCopyData(
         info, mImageContainer, aFrameRef.byte_offset,
         aFrameRef.composition_timestamp, aFrameRef.duration, buffer,
         aFrameRef.is_sync_point, aFrameRef.decode_timestamp, visible);
     // Unlock the returned image data.
     CVPixelBufferUnlockBaseAddress(aImage, kCVPixelBufferLock_ReadOnly);
   } else {
 #ifndef MOZ_WIDGET_UIKIT
-    IOSurfacePtr surface = (IOSurfacePtr)CVPixelBufferGetIOSurface(aImage);
+    IOSurfaceRef surface = CVPixelBufferGetIOSurface(aImage);
     MOZ_ASSERT(surface, "Decoder didn't return an IOSurface backed buffer");
 
     RefPtr<MacIOSurface> macSurface = new MacIOSurface(surface);
     macSurface->SetYUVColorSpace(mColorSpace);
 
     RefPtr<layers::Image> image = new layers::MacIOSurfaceImage(macSurface);
 
     data = VideoData::CreateFromImage(
--- a/gfx/2d/MacIOSurface.cpp
+++ b/gfx/2d/MacIOSurface.cpp
@@ -1,40 +1,39 @@
 /* -*- 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 "MacIOSurface.h"
-#include <IOSurface/IOSurface.h>
 #include <OpenGL/gl.h>
 #include <OpenGL/CGLIOSurface.h>
 #include <QuartzCore/QuartzCore.h>
 #include "GLConsts.h"
 #include "GLContextCGL.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/RefPtr.h"
 
 using namespace mozilla;
 
-MacIOSurface::MacIOSurface(IOSurfacePtr aIOSurfacePtr,
+MacIOSurface::MacIOSurface(IOSurfaceRef aIOSurfaceRef,
                            double aContentsScaleFactor, bool aHasAlpha,
                            gfx::YUVColorSpace aColorSpace)
-    : mIOSurfacePtr(aIOSurfacePtr),
+    : mIOSurfaceRef(aIOSurfaceRef),
       mContentsScaleFactor(aContentsScaleFactor),
       mHasAlpha(aHasAlpha),
       mColorSpace(aColorSpace) {
-  CFRetain(mIOSurfacePtr);
+  CFRetain(mIOSurfaceRef);
   IncrementUseCount();
 }
 
 MacIOSurface::~MacIOSurface() {
   DecrementUseCount();
-  CFRelease(mIOSurfacePtr);
+  CFRelease(mIOSurfaceRef);
 }
 
 /* static */
 already_AddRefed<MacIOSurface> MacIOSurface::CreateIOSurface(
     int aWidth, int aHeight, double aContentsScaleFactor, bool aHasAlpha) {
   if (aContentsScaleFactor <= 0) return nullptr;
 
   CFMutableDictionaryRef props = ::CFDictionaryCreateMutable(
@@ -57,17 +56,17 @@ already_AddRefed<MacIOSurface> MacIOSurf
   ::CFDictionaryAddValue(props, kIOSurfaceWidth, cfWidth);
   ::CFRelease(cfWidth);
   ::CFDictionaryAddValue(props, kIOSurfaceHeight, cfHeight);
   ::CFRelease(cfHeight);
   ::CFDictionaryAddValue(props, kIOSurfaceBytesPerElement, cfBytesPerElem);
   ::CFRelease(cfBytesPerElem);
   ::CFDictionaryAddValue(props, kIOSurfaceIsGlobal, kCFBooleanTrue);
 
-  IOSurfacePtr surfaceRef = ::IOSurfaceCreate(props);
+  IOSurfaceRef surfaceRef = ::IOSurfaceCreate(props);
   ::CFRelease(props);
 
   if (!surfaceRef) return nullptr;
 
   RefPtr<MacIOSurface> ioSurface =
       new MacIOSurface(surfaceRef, aContentsScaleFactor, aHasAlpha);
 
   // Release the IOSurface because MacIOSurface retained it
@@ -77,97 +76,96 @@ already_AddRefed<MacIOSurface> MacIOSurf
 }
 
 /* static */
 already_AddRefed<MacIOSurface> MacIOSurface::LookupSurface(
     IOSurfaceID aIOSurfaceID, double aContentsScaleFactor, bool aHasAlpha,
     gfx::YUVColorSpace aColorSpace) {
   if (aContentsScaleFactor <= 0) return nullptr;
 
-  IOSurfacePtr surfaceRef = (IOSurfacePtr)::IOSurfaceLookup(aIOSurfaceID);
+  IOSurfaceRef surfaceRef = ::IOSurfaceLookup(aIOSurfaceID);
   if (!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() const {
-  return ::IOSurfaceGetID((IOSurfaceRef)mIOSurfacePtr);
+  return ::IOSurfaceGetID(mIOSurfaceRef);
 }
 
 void* MacIOSurface::GetBaseAddress() const {
-  return ::IOSurfaceGetBaseAddress((IOSurfaceRef)mIOSurfacePtr);
+  return ::IOSurfaceGetBaseAddress(mIOSurfaceRef);
 }
 
 void* MacIOSurface::GetBaseAddressOfPlane(size_t aPlaneIndex) const {
-  return ::IOSurfaceGetBaseAddressOfPlane((IOSurfaceRef)mIOSurfacePtr,
-                                          aPlaneIndex);
+  return ::IOSurfaceGetBaseAddressOfPlane(mIOSurfaceRef, aPlaneIndex);
 }
 
 size_t MacIOSurface::GetWidth(size_t plane) const {
   size_t intScaleFactor = ceil(mContentsScaleFactor);
   return GetDevicePixelWidth(plane) / intScaleFactor;
 }
 
 size_t MacIOSurface::GetHeight(size_t plane) const {
   size_t intScaleFactor = ceil(mContentsScaleFactor);
   return GetDevicePixelHeight(plane) / intScaleFactor;
 }
 
 size_t MacIOSurface::GetPlaneCount() const {
-  return ::IOSurfaceGetPlaneCount((IOSurfaceRef)mIOSurfacePtr);
+  return ::IOSurfaceGetPlaneCount(mIOSurfaceRef);
 }
 
 /*static*/
 size_t MacIOSurface::GetMaxWidth() {
   return ::IOSurfaceGetPropertyMaximum(kIOSurfaceWidth);
 }
 
 /*static*/
 size_t MacIOSurface::GetMaxHeight() {
   return ::IOSurfaceGetPropertyMaximum(kIOSurfaceHeight);
 }
 
 size_t MacIOSurface::GetDevicePixelWidth(size_t plane) const {
-  return ::IOSurfaceGetWidthOfPlane((IOSurfaceRef)mIOSurfacePtr, plane);
+  return ::IOSurfaceGetWidthOfPlane(mIOSurfaceRef, plane);
 }
 
 size_t MacIOSurface::GetDevicePixelHeight(size_t plane) const {
-  return ::IOSurfaceGetHeightOfPlane((IOSurfaceRef)mIOSurfacePtr, plane);
+  return ::IOSurfaceGetHeightOfPlane(mIOSurfaceRef, plane);
 }
 
 size_t MacIOSurface::GetBytesPerRow(size_t plane) const {
-  return ::IOSurfaceGetBytesPerRowOfPlane((IOSurfaceRef)mIOSurfacePtr, plane);
+  return ::IOSurfaceGetBytesPerRowOfPlane(mIOSurfaceRef, plane);
 }
 
 OSType MacIOSurface::GetPixelFormat() const {
-  return ::IOSurfaceGetPixelFormat((IOSurfaceRef)mIOSurfacePtr);
+  return ::IOSurfaceGetPixelFormat(mIOSurfaceRef);
 }
 
 void MacIOSurface::IncrementUseCount() {
-  ::IOSurfaceIncrementUseCount((IOSurfaceRef)mIOSurfacePtr);
+  ::IOSurfaceIncrementUseCount(mIOSurfaceRef);
 }
 
 void MacIOSurface::DecrementUseCount() {
-  ::IOSurfaceDecrementUseCount((IOSurfaceRef)mIOSurfacePtr);
+  ::IOSurfaceDecrementUseCount(mIOSurfaceRef);
 }
 
 void MacIOSurface::Lock(bool aReadOnly) {
-  ::IOSurfaceLock((IOSurfaceRef)mIOSurfacePtr,
-                  aReadOnly ? kIOSurfaceLockReadOnly : 0, nullptr);
+  ::IOSurfaceLock(mIOSurfaceRef, aReadOnly ? kIOSurfaceLockReadOnly : 0,
+                  nullptr);
 }
 
 void MacIOSurface::Unlock(bool aReadOnly) {
-  ::IOSurfaceUnlock((IOSurfaceRef)mIOSurfacePtr,
-                    aReadOnly ? kIOSurfaceLockReadOnly : 0, nullptr);
+  ::IOSurfaceUnlock(mIOSurfaceRef, aReadOnly ? kIOSurfaceLockReadOnly : 0,
+                    nullptr);
 }
 
 using mozilla::gfx::IntSize;
 using mozilla::gfx::SourceSurface;
 using mozilla::gfx::SurfaceFormat;
 
 static void MacIOSurfaceBufferDeallocator(void* aClosure) {
   MOZ_ASSERT(aClosure);
@@ -226,18 +224,17 @@ SurfaceFormat MacIOSurface::GetReadForma
 }
 
 CGLError MacIOSurface::CGLTexImageIOSurface2D(CGLContextObj ctx, GLenum target,
                                               GLenum internalFormat,
                                               GLsizei width, GLsizei height,
                                               GLenum format, GLenum type,
                                               GLuint plane) const {
   return ::CGLTexImageIOSurface2D(ctx, target, internalFormat, width, height,
-                                  format, type, (IOSurfaceRef)mIOSurfacePtr,
-                                  plane);
+                                  format, type, mIOSurfaceRef, plane);
 }
 
 CGLError MacIOSurface::CGLTexImageIOSurface2D(
     mozilla::gl::GLContext* aGL, CGLContextObj ctx, size_t plane,
     mozilla::gfx::SurfaceFormat* aOutReadFormat) {
   MOZ_ASSERT(plane >= 0);
   bool isCompatibilityProfile = aGL->IsCompatibilityProfile();
   OSType pixelFormat = GetPixelFormat();
--- a/gfx/2d/MacIOSurface.h
+++ b/gfx/2d/MacIOSurface.h
@@ -3,16 +3,17 @@
 /* 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/. */
 
 #ifndef MacIOSurface_h__
 #define MacIOSurface_h__
 #ifdef XP_DARWIN
 #  include <CoreVideo/CoreVideo.h>
+#  include <IOSurface/IOSurface.h>
 #  include <QuartzCore/QuartzCore.h>
 #  include <dlfcn.h>
 
 #  include "mozilla/gfx/Types.h"
 
 namespace mozilla {
 namespace gl {
 class GLContext;
@@ -24,18 +25,16 @@ struct _CGLContextObject;
 typedef _CGLContextObject* CGLContextObj;
 typedef uint32_t IOSurfaceID;
 
 #  ifdef XP_IOS
 typedef kern_return_t IOReturn;
 typedef int CGLError;
 #  endif
 
-typedef CFTypeRef IOSurfacePtr;
-
 #  ifdef XP_MACOSX
 #    import <OpenGL/OpenGL.h>
 #  else
 #    import <OpenGLES/ES2/gl.h>
 #  endif
 
 #  include "2D.h"
 #  include "mozilla/RefCounted.h"
@@ -56,17 +55,17 @@ class MacIOSurface final
       bool aHasAlpha = true);
   static void ReleaseIOSurface(MacIOSurface* aIOSurface);
   static already_AddRefed<MacIOSurface> LookupSurface(
       IOSurfaceID aSurfaceID, double aContentsScaleFactor = 1.0,
       bool aHasAlpha = true,
       mozilla::gfx::YUVColorSpace aColorSpace =
           mozilla::gfx::YUVColorSpace::UNKNOWN);
 
-  explicit MacIOSurface(IOSurfacePtr aIOSurfacePtr,
+  explicit MacIOSurface(IOSurfaceRef aIOSurfaceRef,
                         double aContentsScaleFactor = 1.0,
                         bool aHasAlpha = true,
                         mozilla::gfx::YUVColorSpace aColorSpace =
                             mozilla::gfx::YUVColorSpace::UNKNOWN);
   ~MacIOSurface();
   IOSurfaceID GetIOSurfaceID() const;
   void* GetBaseAddress() const;
   void* GetBaseAddressOfPlane(size_t planeIndex) const;
@@ -85,17 +84,17 @@ class MacIOSurface final
   void Lock(bool aReadOnly = true);
   void Unlock(bool aReadOnly = true);
   void IncrementUseCount();
   void DecrementUseCount();
   bool HasAlpha() const { return mHasAlpha; }
   mozilla::gfx::SurfaceFormat GetFormat() const;
   mozilla::gfx::SurfaceFormat GetReadFormat() const;
   // This would be better suited on MacIOSurfaceImage type, however due to the
-  // current data structure, this is not possible as only the IOSurfacePtr is
+  // current data structure, this is not possible as only the IOSurfaceRef is
   // being used across.
   void SetYUVColorSpace(mozilla::gfx::YUVColorSpace aColorSpace) {
     mColorSpace = aColorSpace;
   }
   mozilla::gfx::YUVColorSpace GetYUVColorSpace() const { return mColorSpace; }
   bool IsFullRange() const {
     return GetPixelFormat() == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange;
   }
@@ -108,21 +107,20 @@ class MacIOSurface final
   CGLError CGLTexImageIOSurface2D(CGLContextObj ctxt, GLenum target,
                                   GLenum internalFormat, GLsizei width,
                                   GLsizei height, GLenum format, GLenum type,
                                   GLuint plane) const;
   already_AddRefed<SourceSurface> GetAsSurface();
 
   static size_t GetMaxWidth();
   static size_t GetMaxHeight();
-  const void* GetIOSurfacePtr() { return mIOSurfacePtr; }
+  IOSurfaceRef GetIOSurfaceRef() { return mIOSurfaceRef; }
 
  private:
-  friend class nsCARenderer;
-  const IOSurfacePtr mIOSurfacePtr;
+  const IOSurfaceRef mIOSurfaceRef;
   double mContentsScaleFactor;
   bool mHasAlpha;
   mozilla::gfx::YUVColorSpace mColorSpace =
       mozilla::gfx::YUVColorSpace::UNKNOWN;
 };
 
 #endif
 #endif
--- a/gfx/2d/QuartzSupport.mm
+++ b/gfx/2d/QuartzSupport.mm
@@ -198,18 +198,17 @@ nsresult nsCARenderer::SetupRenderer(voi
   if (mIOSurface) {
     // Create the IOSurface mapped texture.
     ::glGenTextures(1, &mIOTexture);
     ::glBindTexture(GL_TEXTURE_RECTANGLE_ARB, mIOTexture);
     ::glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     ::glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     ::CGLTexImageIOSurface2D(mOpenGLContext, GL_TEXTURE_RECTANGLE_ARB, GL_RGBA,
                              aWidth * intScaleFactor, aHeight * intScaleFactor, GL_BGRA,
-                             GL_UNSIGNED_INT_8_8_8_8_REV, (IOSurfaceRef)mIOSurface->mIOSurfacePtr,
-                             0);
+                             GL_UNSIGNED_INT_8_8_8_8_REV, mIOSurface->GetIOSurfaceRef(), 0);
     ::glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
   } else {
     ::glGenTextures(1, &mFBOTexture);
     ::glBindTexture(GL_TEXTURE_RECTANGLE_ARB, mFBOTexture);
     ::glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     ::glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     ::glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
   }
@@ -330,18 +329,18 @@ void nsCARenderer::AttachIOSurface(MacIO
     int width = caRenderer.bounds.size.width / intScaleFactor;
     int height = caRenderer.bounds.size.height / intScaleFactor;
 
     CGLContextObj oldContext = ::CGLGetCurrentContext();
     ::CGLSetCurrentContext(mOpenGLContext);
     ::glBindTexture(GL_TEXTURE_RECTANGLE_ARB, mIOTexture);
     ::CGLTexImageIOSurface2D(mOpenGLContext, GL_TEXTURE_RECTANGLE_ARB, GL_RGBA,
                              mIOSurface->GetDevicePixelWidth(), mIOSurface->GetDevicePixelHeight(),
-                             GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
-                             (IOSurfaceRef)mIOSurface->mIOSurfacePtr, 0);
+                             GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, mIOSurface->GetIOSurfaceRef(),
+                             0);
     ::glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
 
     // Rebind the FBO to make it live
     ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFBO);
 
     if (static_cast<int>(mIOSurface->GetWidth()) != width ||
         static_cast<int>(mIOSurface->GetHeight()) != height) {
       width = mIOSurface->GetWidth();
--- a/gfx/vr/service/OpenVRSession.cpp
+++ b/gfx/vr/service/OpenVRSession.cpp
@@ -2121,17 +2121,17 @@ bool OpenVRSession::SubmitFrame(const VR
   // VRDisplayExternal. scaleFactor and opaque are skipped because they always
   // are 1.0 and false.
   RefPtr<MacIOSurface> surf = MacIOSurface::LookupSurface(aTextureHandle);
   if (!surf) {
     NS_WARNING("OpenVRSession::SubmitFrame failed to get a MacIOSurface");
     return false;
   }
 
-  const void* ioSurface = surf->GetIOSurfacePtr();
+  IOSurfaceRef ioSurface = surf->GetIOSurfaceRef();
   tex.handle = (void*)ioSurface;
 #else
   tex.handle = aTextureHandle;
 #endif
   tex.eType = aTextureType;
   tex.eColorSpace = ::vr::EColorSpace::ColorSpace_Auto;
 
   ::vr::VRTextureBounds_t bounds;