Bug 1565717 - Don't use dynamic symbol lookup for CVPixelBufferGetIOSurface. r=mattwoodrow
authorMarkus Stange <mstange@themasta.com>
Wed, 14 Aug 2019 11:05:24 +0000
changeset 488097 8dfadc1af721cda996fe297e090a0d5426ade763
parent 488096 9072a9f04ddd8999c1b6260fca8145776364fc45
child 488098 35ae2dc9438e211637779380ef36de19a5b2ef39
push id113900
push usercbrindusan@mozilla.com
push dateThu, 15 Aug 2019 09:53:50 +0000
treeherdermozilla-inbound@0db07ff50ab5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1565717
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 1565717 - Don't use dynamic symbol lookup for CVPixelBufferGetIOSurface. r=mattwoodrow Differential Revision: https://phabricator.services.mozilla.com/D41811
dom/media/platforms/apple/AppleVTDecoder.cpp
gfx/2d/MacIOSurface.cpp
gfx/2d/MacIOSurface.h
--- a/dom/media/platforms/apple/AppleVTDecoder.cpp
+++ b/dom/media/platforms/apple/AppleVTDecoder.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* 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 "AppleVTDecoder.h"
 
+#include <CoreVideo/CVPixelBufferIOSurface.h>
 #include "AppleDecoderModule.h"
 #include "AppleUtils.h"
 #include "MacIOSurfaceImage.h"
 #include "MediaData.h"
 #include "mozilla/ArrayUtils.h"
 #include "H264.h"
 #include "nsAutoPtr.h"
 #include "nsThreadUtils.h"
@@ -386,17 +387,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 = MacIOSurfaceLib::CVPixelBufferGetIOSurface(aImage);
+    IOSurfacePtr surface = (IOSurfacePtr)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
@@ -13,46 +13,39 @@
 #include "GLContextCGL.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/RefPtr.h"
 
 using namespace mozilla;
 // IOSurface signatures
 #define IOSURFACE_FRAMEWORK_PATH \
   "/System/Library/Frameworks/IOSurface.framework/IOSurface"
-#define COREVIDEO_FRAMEWORK_PATH                                         \
-  "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/" \
-  "CoreVideo.framework/CoreVideo"
 
 #define GET_CONST(const_name) \
   ((CFStringRef*)dlsym(sIOSurfaceFramework, const_name))
 #define GET_IOSYM(dest, sym_name) \
   (typeof(dest)) dlsym(sIOSurfaceFramework, sym_name)
-#define GET_CVSYM(dest, sym_name) \
-  (typeof(dest)) dlsym(sCoreVideoFramework, sym_name)
 
 MacIOSurfaceLib::LibraryUnloader MacIOSurfaceLib::sLibraryUnloader;
 bool MacIOSurfaceLib::isLoaded = false;
 void* MacIOSurfaceLib::sIOSurfaceFramework;
-void* MacIOSurfaceLib::sCoreVideoFramework;
 IOSurfaceCreateFunc MacIOSurfaceLib::sCreate;
 IOSurfaceGetIDFunc MacIOSurfaceLib::sGetID;
 IOSurfaceLookupFunc MacIOSurfaceLib::sLookup;
 IOSurfaceGetBaseAddressFunc MacIOSurfaceLib::sGetBaseAddress;
 IOSurfaceGetBaseAddressOfPlaneFunc MacIOSurfaceLib::sGetBaseAddressOfPlane;
 IOSurfaceSizePlaneTFunc MacIOSurfaceLib::sWidth;
 IOSurfaceSizePlaneTFunc MacIOSurfaceLib::sHeight;
 IOSurfaceSizeTFunc MacIOSurfaceLib::sPlaneCount;
 IOSurfaceSizePlaneTFunc MacIOSurfaceLib::sBytesPerRow;
 IOSurfaceGetPropertyMaximumFunc MacIOSurfaceLib::sGetPropertyMaximum;
 IOSurfaceVoidFunc MacIOSurfaceLib::sIncrementUseCount;
 IOSurfaceVoidFunc MacIOSurfaceLib::sDecrementUseCount;
 IOSurfaceLockFunc MacIOSurfaceLib::sLock;
 IOSurfaceUnlockFunc MacIOSurfaceLib::sUnlock;
-CVPixelBufferGetIOSurfaceFunc MacIOSurfaceLib::sCVPixelBufferGetIOSurface;
 IOSurfacePixelFormatFunc MacIOSurfaceLib::sPixelFormat;
 
 CFStringRef MacIOSurfaceLib::kPropWidth;
 CFStringRef MacIOSurfaceLib::kPropHeight;
 CFStringRef MacIOSurfaceLib::kPropBytesPerElem;
 CFStringRef MacIOSurfaceLib::kPropBytesPerRow;
 CFStringRef MacIOSurfaceLib::kPropIsGlobal;
 
@@ -125,44 +118,32 @@ IOReturn MacIOSurfaceLib::IOSurfaceUnloc
 void MacIOSurfaceLib::IOSurfaceIncrementUseCount(IOSurfacePtr aIOSurfacePtr) {
   sIncrementUseCount(aIOSurfacePtr);
 }
 
 void MacIOSurfaceLib::IOSurfaceDecrementUseCount(IOSurfacePtr aIOSurfacePtr) {
   sDecrementUseCount(aIOSurfacePtr);
 }
 
-IOSurfacePtr MacIOSurfaceLib::CVPixelBufferGetIOSurface(
-    CVPixelBufferRef aPixelBuffer) {
-  return sCVPixelBufferGetIOSurface(aPixelBuffer);
-}
-
 CFStringRef MacIOSurfaceLib::GetIOConst(const char* symbole) {
   CFStringRef* address = (CFStringRef*)dlsym(sIOSurfaceFramework, symbole);
   if (!address) return nullptr;
 
   return *address;
 }
 
 void MacIOSurfaceLib::LoadLibrary() {
   if (isLoaded) {
     return;
   }
   isLoaded = true;
   sIOSurfaceFramework =
       dlopen(IOSURFACE_FRAMEWORK_PATH, RTLD_LAZY | RTLD_LOCAL);
 
-  sCoreVideoFramework =
-      dlopen(COREVIDEO_FRAMEWORK_PATH, RTLD_LAZY | RTLD_LOCAL);
-
-  if (!sIOSurfaceFramework || !sCoreVideoFramework) {
-    if (sIOSurfaceFramework) dlclose(sIOSurfaceFramework);
-    if (sCoreVideoFramework) dlclose(sCoreVideoFramework);
-    sIOSurfaceFramework = nullptr;
-    sCoreVideoFramework = nullptr;
+  if (!sIOSurfaceFramework) {
     return;
   }
 
   kPropWidth = GetIOConst("kIOSurfaceWidth");
   kPropHeight = GetIOConst("kIOSurfaceHeight");
   kPropBytesPerElem = GetIOConst("kIOSurfaceBytesPerElement");
   kPropBytesPerRow = GetIOConst("kIOSurfaceBytesPerRow");
   kPropIsGlobal = GetIOConst("kIOSurfaceIsGlobal");
@@ -181,38 +162,30 @@ void MacIOSurfaceLib::LoadLibrary() {
   sDecrementUseCount =
       GET_IOSYM(sDecrementUseCount, "IOSurfaceDecrementUseCount");
   sGetBaseAddress = GET_IOSYM(sGetBaseAddress, "IOSurfaceGetBaseAddress");
   sGetBaseAddressOfPlane =
       GET_IOSYM(sGetBaseAddressOfPlane, "IOSurfaceGetBaseAddressOfPlane");
   sPlaneCount = GET_IOSYM(sPlaneCount, "IOSurfaceGetPlaneCount");
   sPixelFormat = GET_IOSYM(sPixelFormat, "IOSurfaceGetPixelFormat");
 
-  sCVPixelBufferGetIOSurface =
-      GET_CVSYM(sCVPixelBufferGetIOSurface, "CVPixelBufferGetIOSurface");
-
   if (!sCreate || !sGetID || !sLookup || !sGetBaseAddress ||
       !sGetBaseAddressOfPlane || !sPlaneCount || !kPropWidth || !kPropHeight ||
       !kPropBytesPerElem || !kPropIsGlobal || !sLock || !sUnlock ||
       !sIncrementUseCount || !sDecrementUseCount || !sWidth || !sHeight ||
-      !kPropBytesPerRow || !sBytesPerRow || !sGetPropertyMaximum ||
-      !sCVPixelBufferGetIOSurface) {
+      !kPropBytesPerRow || !sBytesPerRow || !sGetPropertyMaximum) {
     CloseLibrary();
   }
 }
 
 void MacIOSurfaceLib::CloseLibrary() {
   if (sIOSurfaceFramework) {
     dlclose(sIOSurfaceFramework);
   }
-  if (sCoreVideoFramework) {
-    dlclose(sCoreVideoFramework);
-  }
   sIOSurfaceFramework = nullptr;
-  sCoreVideoFramework = nullptr;
 }
 
 MacIOSurface::MacIOSurface(IOSurfacePtr aIOSurfacePtr,
                            double aContentsScaleFactor, bool aHasAlpha,
                            gfx::YUVColorSpace aColorSpace)
     : mIOSurfacePtr(aIOSurfacePtr),
       mContentsScaleFactor(aContentsScaleFactor),
       mHasAlpha(aHasAlpha),
--- a/gfx/2d/MacIOSurface.h
+++ b/gfx/2d/MacIOSurface.h
@@ -40,18 +40,16 @@ typedef IOReturn (*IOSurfaceUnlockFunc)(
                                         uint32_t options, uint32_t* seed);
 typedef void* (*IOSurfaceGetBaseAddressFunc)(IOSurfacePtr io_surface);
 typedef void* (*IOSurfaceGetBaseAddressOfPlaneFunc)(IOSurfacePtr io_surface,
                                                     size_t planeIndex);
 typedef size_t (*IOSurfaceSizeTFunc)(IOSurfacePtr io_surface);
 typedef size_t (*IOSurfaceSizePlaneTFunc)(IOSurfacePtr io_surface,
                                           size_t plane);
 typedef size_t (*IOSurfaceGetPropertyMaximumFunc)(CFStringRef property);
-typedef IOSurfacePtr (*CVPixelBufferGetIOSurfaceFunc)(
-    CVPixelBufferRef pixelBuffer);
 
 typedef OSType (*IOSurfacePixelFormatFunc)(IOSurfacePtr io_surface);
 
 #  ifdef XP_MACOSX
 #    import <OpenGL/OpenGL.h>
 #  else
 #    import <OpenGLES/ES2/gl.h>
 #  endif
@@ -142,33 +140,31 @@ class MacIOSurface final
   mozilla::gfx::YUVColorSpace mColorSpace =
       mozilla::gfx::YUVColorSpace::UNKNOWN;
 };
 
 class MacIOSurfaceLib {
  public:
   MacIOSurfaceLib() = delete;
   static void* sIOSurfaceFramework;
-  static void* sCoreVideoFramework;
   static bool isLoaded;
   static IOSurfaceCreateFunc sCreate;
   static IOSurfaceGetIDFunc sGetID;
   static IOSurfaceLookupFunc sLookup;
   static IOSurfaceGetBaseAddressFunc sGetBaseAddress;
   static IOSurfaceGetBaseAddressOfPlaneFunc sGetBaseAddressOfPlane;
   static IOSurfaceSizeTFunc sPlaneCount;
   static IOSurfaceLockFunc sLock;
   static IOSurfaceUnlockFunc sUnlock;
   static IOSurfaceVoidFunc sIncrementUseCount;
   static IOSurfaceVoidFunc sDecrementUseCount;
   static IOSurfaceSizePlaneTFunc sWidth;
   static IOSurfaceSizePlaneTFunc sHeight;
   static IOSurfaceSizePlaneTFunc sBytesPerRow;
   static IOSurfaceGetPropertyMaximumFunc sGetPropertyMaximum;
-  static CVPixelBufferGetIOSurfaceFunc sCVPixelBufferGetIOSurface;
   static IOSurfacePixelFormatFunc sPixelFormat;
   static CFStringRef kPropWidth;
   static CFStringRef kPropHeight;
   static CFStringRef kPropBytesPerElem;
   static CFStringRef kPropBytesPerRow;
   static CFStringRef kPropIsGlobal;
 
   static bool isInit();
@@ -186,17 +182,16 @@ class MacIOSurfaceLib {
                                         size_t plane);
   static size_t IOSurfaceGetPropertyMaximum(CFStringRef property);
   static IOReturn IOSurfaceLock(IOSurfacePtr aIOSurfacePtr, uint32_t options,
                                 uint32_t* seed);
   static IOReturn IOSurfaceUnlock(IOSurfacePtr aIOSurfacePtr, uint32_t options,
                                   uint32_t* seed);
   static void IOSurfaceIncrementUseCount(IOSurfacePtr aIOSurfacePtr);
   static void IOSurfaceDecrementUseCount(IOSurfacePtr aIOSurfacePtr);
-  static IOSurfacePtr CVPixelBufferGetIOSurface(CVPixelBufferRef apixelBuffer);
   static OSType IOSurfaceGetPixelFormat(IOSurfacePtr aIOSurfacePtr);
   static void LoadLibrary();
   static void CloseLibrary();
 
   // Static deconstructor
   static class LibraryUnloader {
    public:
     ~LibraryUnloader() { CloseLibrary(); }