Bug 1565717 - Remove dynamic lookup of the kIOSurface constants. r=mattwoodrow
authorMarkus Stange <mstange@themasta.com>
Wed, 14 Aug 2019 11:05:47 +0000
changeset 488098 35ae2dc9438e211637779380ef36de19a5b2ef39
parent 488097 8dfadc1af721cda996fe297e090a0d5426ade763
child 488099 6c4665fb2c103b1a0253791f66d7f9ec6ff691f6
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 - Remove dynamic lookup of the kIOSurface constants. r=mattwoodrow Differential Revision: https://phabricator.services.mozilla.com/D41812
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
@@ -2,16 +2,18 @@
 /* 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 <IOSurface/IOSurface.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"
@@ -553,17 +555,17 @@ CFDictionaryRef AppleVTDecoder::CreateOu
   // Output format type:
   SInt32 PixelFormatTypeValue =
       mColorRange == gfx::ColorRange::FULL
           ? kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
           : kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
   AutoCFRelease<CFNumberRef> PixelFormatTypeNumber = CFNumberCreate(
       kCFAllocatorDefault, kCFNumberSInt32Type, &PixelFormatTypeValue);
   // Construct IOSurface Properties
-  const void* IOSurfaceKeys[] = {MacIOSurfaceLib::kPropIsGlobal};
+  const void* IOSurfaceKeys[] = {kIOSurfaceIsGlobal};
   const void* IOSurfaceValues[] = {kCFBooleanTrue};
   static_assert(ArrayLength(IOSurfaceKeys) == ArrayLength(IOSurfaceValues),
                 "Non matching keys/values array size");
 
   // Contruct output configuration.
   AutoCFRelease<CFDictionaryRef> IOSurfaceProperties = CFDictionaryCreate(
       kCFAllocatorDefault, IOSurfaceKeys, IOSurfaceValues,
       ArrayLength(IOSurfaceKeys), &kCFTypeDictionaryKeyCallBacks,
--- a/gfx/2d/MacIOSurface.cpp
+++ b/gfx/2d/MacIOSurface.cpp
@@ -1,31 +1,30 @@
 /* -*- 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 <dlfcn.h>
 #include "GLConsts.h"
 #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 GET_CONST(const_name) \
-  ((CFStringRef*)dlsym(sIOSurfaceFramework, const_name))
 #define GET_IOSYM(dest, sym_name) \
   (typeof(dest)) dlsym(sIOSurfaceFramework, sym_name)
 
 MacIOSurfaceLib::LibraryUnloader MacIOSurfaceLib::sLibraryUnloader;
 bool MacIOSurfaceLib::isLoaded = false;
 void* MacIOSurfaceLib::sIOSurfaceFramework;
 IOSurfaceCreateFunc MacIOSurfaceLib::sCreate;
 IOSurfaceGetIDFunc MacIOSurfaceLib::sGetID;
@@ -38,22 +37,16 @@ IOSurfaceSizeTFunc MacIOSurfaceLib::sPla
 IOSurfaceSizePlaneTFunc MacIOSurfaceLib::sBytesPerRow;
 IOSurfaceGetPropertyMaximumFunc MacIOSurfaceLib::sGetPropertyMaximum;
 IOSurfaceVoidFunc MacIOSurfaceLib::sIncrementUseCount;
 IOSurfaceVoidFunc MacIOSurfaceLib::sDecrementUseCount;
 IOSurfaceLockFunc MacIOSurfaceLib::sLock;
 IOSurfaceUnlockFunc MacIOSurfaceLib::sUnlock;
 IOSurfacePixelFormatFunc MacIOSurfaceLib::sPixelFormat;
 
-CFStringRef MacIOSurfaceLib::kPropWidth;
-CFStringRef MacIOSurfaceLib::kPropHeight;
-CFStringRef MacIOSurfaceLib::kPropBytesPerElem;
-CFStringRef MacIOSurfaceLib::kPropBytesPerRow;
-CFStringRef MacIOSurfaceLib::kPropIsGlobal;
-
 bool MacIOSurfaceLib::isInit() {
   // Guard against trying to reload the library
   // if it is not available.
   if (!isLoaded) LoadLibrary();
   MOZ_ASSERT(sIOSurfaceFramework);
   return sIOSurfaceFramework;
 }
 
@@ -118,40 +111,28 @@ IOReturn MacIOSurfaceLib::IOSurfaceUnloc
 void MacIOSurfaceLib::IOSurfaceIncrementUseCount(IOSurfacePtr aIOSurfacePtr) {
   sIncrementUseCount(aIOSurfacePtr);
 }
 
 void MacIOSurfaceLib::IOSurfaceDecrementUseCount(IOSurfacePtr aIOSurfacePtr) {
   sDecrementUseCount(aIOSurfacePtr);
 }
 
-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);
 
   if (!sIOSurfaceFramework) {
     return;
   }
 
-  kPropWidth = GetIOConst("kIOSurfaceWidth");
-  kPropHeight = GetIOConst("kIOSurfaceHeight");
-  kPropBytesPerElem = GetIOConst("kIOSurfaceBytesPerElement");
-  kPropBytesPerRow = GetIOConst("kIOSurfaceBytesPerRow");
-  kPropIsGlobal = GetIOConst("kIOSurfaceIsGlobal");
   sCreate = GET_IOSYM(sCreate, "IOSurfaceCreate");
   sGetID = GET_IOSYM(sGetID, "IOSurfaceGetID");
   sWidth = GET_IOSYM(sWidth, "IOSurfaceGetWidthOfPlane");
   sHeight = GET_IOSYM(sHeight, "IOSurfaceGetHeightOfPlane");
   sBytesPerRow = GET_IOSYM(sBytesPerRow, "IOSurfaceGetBytesPerRowOfPlane");
   sGetPropertyMaximum =
       GET_IOSYM(sGetPropertyMaximum, "IOSurfaceGetPropertyMaximum");
   sLookup = GET_IOSYM(sLookup, "IOSurfaceLookup");
@@ -163,20 +144,19 @@ void MacIOSurfaceLib::LoadLibrary() {
       GET_IOSYM(sDecrementUseCount, "IOSurfaceDecrementUseCount");
   sGetBaseAddress = GET_IOSYM(sGetBaseAddress, "IOSurfaceGetBaseAddress");
   sGetBaseAddressOfPlane =
       GET_IOSYM(sGetBaseAddressOfPlane, "IOSurfaceGetBaseAddressOfPlane");
   sPlaneCount = GET_IOSYM(sPlaneCount, "IOSurfaceGetPlaneCount");
   sPixelFormat = GET_IOSYM(sPixelFormat, "IOSurfaceGetPixelFormat");
 
   if (!sCreate || !sGetID || !sLookup || !sGetBaseAddress ||
-      !sGetBaseAddressOfPlane || !sPlaneCount || !kPropWidth || !kPropHeight ||
-      !kPropBytesPerElem || !kPropIsGlobal || !sLock || !sUnlock ||
+      !sGetBaseAddressOfPlane || !sPlaneCount || !sLock || !sUnlock ||
       !sIncrementUseCount || !sDecrementUseCount || !sWidth || !sHeight ||
-      !kPropBytesPerRow || !sBytesPerRow || !sGetPropertyMaximum) {
+      !sBytesPerRow || !sGetPropertyMaximum) {
     CloseLibrary();
   }
 }
 
 void MacIOSurfaceLib::CloseLibrary() {
   if (sIOSurfaceFramework) {
     dlclose(sIOSurfaceFramework);
   }
@@ -216,24 +196,23 @@ already_AddRefed<MacIOSurface> MacIOSurf
   size_t intScaleFactor = ceil(aContentsScaleFactor);
   aWidth *= intScaleFactor;
   aHeight *= intScaleFactor;
   CFNumberRef cfWidth = ::CFNumberCreate(nullptr, kCFNumberSInt32Type, &aWidth);
   CFNumberRef cfHeight =
       ::CFNumberCreate(nullptr, kCFNumberSInt32Type, &aHeight);
   CFNumberRef cfBytesPerElem =
       ::CFNumberCreate(nullptr, kCFNumberSInt32Type, &bytesPerElem);
-  ::CFDictionaryAddValue(props, MacIOSurfaceLib::kPropWidth, cfWidth);
+  ::CFDictionaryAddValue(props, kIOSurfaceWidth, cfWidth);
   ::CFRelease(cfWidth);
-  ::CFDictionaryAddValue(props, MacIOSurfaceLib::kPropHeight, cfHeight);
+  ::CFDictionaryAddValue(props, kIOSurfaceHeight, cfHeight);
   ::CFRelease(cfHeight);
-  ::CFDictionaryAddValue(props, MacIOSurfaceLib::kPropBytesPerElem,
-                         cfBytesPerElem);
+  ::CFDictionaryAddValue(props, kIOSurfaceBytesPerElement, cfBytesPerElem);
   ::CFRelease(cfBytesPerElem);
-  ::CFDictionaryAddValue(props, MacIOSurfaceLib::kPropIsGlobal, kCFBooleanTrue);
+  ::CFDictionaryAddValue(props, kIOSurfaceIsGlobal, kCFBooleanTrue);
 
   IOSurfacePtr surfaceRef = MacIOSurfaceLib::IOSurfaceCreate(props);
   ::CFRelease(props);
 
   if (!surfaceRef) return nullptr;
 
   RefPtr<MacIOSurface> ioSurface =
       new MacIOSurface(surfaceRef, aContentsScaleFactor, aHasAlpha);
@@ -287,25 +266,23 @@ size_t MacIOSurface::GetHeight(size_t pl
 
 size_t MacIOSurface::GetPlaneCount() const {
   return MacIOSurfaceLib::IOSurfaceGetPlaneCount(mIOSurfacePtr);
 }
 
 /*static*/
 size_t MacIOSurface::GetMaxWidth() {
   if (!MacIOSurfaceLib::isInit()) return -1;
-  return MacIOSurfaceLib::IOSurfaceGetPropertyMaximum(
-      MacIOSurfaceLib::kPropWidth);
+  return MacIOSurfaceLib::IOSurfaceGetPropertyMaximum(kIOSurfaceWidth);
 }
 
 /*static*/
 size_t MacIOSurface::GetMaxHeight() {
   if (!MacIOSurfaceLib::isInit()) return -1;
-  return MacIOSurfaceLib::IOSurfaceGetPropertyMaximum(
-      MacIOSurfaceLib::kPropHeight);
+  return MacIOSurfaceLib::IOSurfaceGetPropertyMaximum(kIOSurfaceHeight);
 }
 
 size_t MacIOSurface::GetDevicePixelWidth(size_t plane) const {
   return MacIOSurfaceLib::IOSurfaceGetWidth(mIOSurfacePtr, plane);
 }
 
 size_t MacIOSurface::GetDevicePixelHeight(size_t plane) const {
   return MacIOSurfaceLib::IOSurfaceGetHeight(mIOSurfacePtr, plane);
--- a/gfx/2d/MacIOSurface.h
+++ b/gfx/2d/MacIOSurface.h
@@ -156,24 +156,18 @@ class MacIOSurfaceLib {
   static IOSurfaceUnlockFunc sUnlock;
   static IOSurfaceVoidFunc sIncrementUseCount;
   static IOSurfaceVoidFunc sDecrementUseCount;
   static IOSurfaceSizePlaneTFunc sWidth;
   static IOSurfaceSizePlaneTFunc sHeight;
   static IOSurfaceSizePlaneTFunc sBytesPerRow;
   static IOSurfaceGetPropertyMaximumFunc sGetPropertyMaximum;
   static IOSurfacePixelFormatFunc sPixelFormat;
-  static CFStringRef kPropWidth;
-  static CFStringRef kPropHeight;
-  static CFStringRef kPropBytesPerElem;
-  static CFStringRef kPropBytesPerRow;
-  static CFStringRef kPropIsGlobal;
 
   static bool isInit();
-  static CFStringRef GetIOConst(const char* symbole);
   static IOSurfacePtr IOSurfaceCreate(CFDictionaryRef properties);
   static IOSurfacePtr IOSurfaceLookup(IOSurfaceID aIOSurfaceID);
   static IOSurfaceID IOSurfaceGetID(IOSurfacePtr aIOSurfacePtr);
   static void* IOSurfaceGetBaseAddress(IOSurfacePtr aIOSurfacePtr);
   static void* IOSurfaceGetBaseAddressOfPlane(IOSurfacePtr aIOSurfacePtr,
                                               size_t aPlaneIndex);
   static size_t IOSurfaceGetPlaneCount(IOSurfacePtr aIOSurfacePtr);
   static size_t IOSurfaceGetWidth(IOSurfacePtr aIOSurfacePtr, size_t plane);