Bug 1500805 Part 6 - Add middleman call hooks for some graphics APIs, r=mccr8.
authorBrian Hackett <bhackett1024@gmail.com>
Sun, 21 Oct 2018 15:09:13 -0600
changeset 491291 0b8359215f5b0e02a2ee693615a34c218662e7df
parent 491290 22e55baef1fc05c63ad96694f1b8c5915fd16e0d
child 491292 31b1aec1f478396b13afd5adb7bae220ca1b5d44
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersmccr8
bugs1500805
milestone65.0a1
Bug 1500805 Part 6 - Add middleman call hooks for some graphics APIs, r=mccr8.
toolkit/recordreplay/MiddlemanCall.h
toolkit/recordreplay/ProcessRedirectDarwin.cpp
--- a/toolkit/recordreplay/MiddlemanCall.h
+++ b/toolkit/recordreplay/MiddlemanCall.h
@@ -349,17 +349,17 @@ void ProcessMiddlemanCall(const char* aI
 // In the middleman process, reset all call state.
 void ResetMiddlemanCalls();
 
 ///////////////////////////////////////////////////////////////////////////////
 // Middleman Call Helpers
 ///////////////////////////////////////////////////////////////////////////////
 
 // Capture the contents of an input buffer at BufferArg with element count at CountArg.
-template <size_t BufferArg, size_t CountArg, typename ElemType>
+template <size_t BufferArg, size_t CountArg, typename ElemType = char>
 static inline void
 Middleman_Buffer(MiddlemanCallContext& aCx)
 {
   if (aCx.AccessPreface()) {
     auto& buffer = aCx.mArguments->Arg<BufferArg, void*>();
     auto byteSize = aCx.mArguments->Arg<CountArg, size_t>() * sizeof(ElemType);
     aCx.ReadOrWritePrefaceBuffer(&buffer, byteSize);
   }
--- a/toolkit/recordreplay/ProcessRedirectDarwin.cpp
+++ b/toolkit/recordreplay/ProcessRedirectDarwin.cpp
@@ -324,19 +324,19 @@ namespace recordreplay {
   MACRO(CFStringTokenizerCreate, RR_ScalarRval)                  \
   MACRO(CFStringTokenizerGetCurrentTokenRange, RR_ComplexScalarRval) \
   MACRO(CFURLCreateFromFileSystemRepresentation, RR_ScalarRval)  \
   MACRO(CFURLCreateFromFSRef, RR_ScalarRval)                     \
   MACRO(CFURLCreateWithFileSystemPath, RR_ScalarRval)            \
   MACRO(CFURLCreateWithString, RR_ScalarRval)                    \
   MACRO(CFURLGetFileSystemRepresentation, RR_Compose<RR_ScalarRval, RR_WriteBuffer<2, 3>>) \
   MACRO(CFURLGetFSRef, RR_Compose<RR_ScalarRval, RR_WriteBufferFixedSize<1, sizeof(FSRef)>>) \
-  MACRO(CFUUIDCreate, RR_ScalarRval)                             \
+  MACRO(CFUUIDCreate, RR_ScalarRval, nullptr, Middleman_CreateCFTypeRval) \
   MACRO(CFUUIDCreateString, RR_ScalarRval)                       \
-  MACRO(CFUUIDGetUUIDBytes, RR_ComplexScalarRval)                \
+  MACRO(CFUUIDGetUUIDBytes, RR_ComplexScalarRval, nullptr, Middleman_CFTypeArg<0>) \
   MACRO(CGAffineTransformConcat, RR_OversizeRval<sizeof(CGAffineTransform)>) \
   MACRO(CGBitmapContextCreateImage, RR_ScalarRval)               \
   MACRO(CGBitmapContextCreateWithData,                           \
         RR_Compose<RR_ScalarRval, RR_CGBitmapContextCreateWithData>, nullptr, \
         Middleman_CGBitmapContextCreateWithData)                 \
   MACRO(CGBitmapContextGetBytesPerRow, RR_ScalarRval)            \
   MACRO(CGBitmapContextGetHeight, RR_ScalarRval)                 \
   MACRO(CGBitmapContextGetWidth, RR_ScalarRval)                  \
@@ -382,29 +382,31 @@ namespace recordreplay {
   MACRO(CGContextSetShouldSubpixelPositionFonts, nullptr, nullptr, Middleman_UpdateCFTypeArg<0>) \
   MACRO(CGContextSetShouldSubpixelQuantizeFonts, nullptr, nullptr, Middleman_UpdateCFTypeArg<0>) \
   MACRO(CGContextSetTextDrawingMode, nullptr, nullptr, Middleman_UpdateCFTypeArg<0>) \
   MACRO(CGContextSetTextMatrix, nullptr, nullptr,                \
         Middleman_Compose<Middleman_UpdateCFTypeArg<0>,          \
                           Middleman_StackArgumentData<sizeof(CGAffineTransform)>>) \
   MACRO(CGContextScaleCTM, nullptr, nullptr, Middleman_UpdateCFTypeArg<0>) \
   MACRO(CGContextTranslateCTM, nullptr, nullptr, Middleman_UpdateCFTypeArg<0>) \
-  MACRO(CGDataProviderCreateWithData, RR_Compose<RR_ScalarRval, RR_CGDataProviderCreateWithData>) \
-  MACRO(CGDataProviderRelease)                                   \
+  MACRO(CGDataProviderCreateWithData, RR_Compose<RR_ScalarRval, RR_CGDataProviderCreateWithData>, \
+        nullptr, Middleman_CGDataProviderCreateWithData)         \
+  MACRO(CGDataProviderRelease, nullptr, nullptr, nullptr, Preamble_Veto<0>) \
   MACRO(CGDisplayCopyColorSpace, RR_ScalarRval)                  \
   MACRO(CGDisplayIOServicePort, RR_ScalarRval)                   \
   MACRO(CGEventSourceCounterForEventType, RR_ScalarRval)         \
   MACRO(CGFontCopyTableForTag, RR_ScalarRval, nullptr,           \
         Middleman_Compose<Middleman_CFTypeArg<0>, Middleman_CreateCFTypeRval>) \
   MACRO(CGFontCopyTableTags, RR_ScalarRval, nullptr,             \
         Middleman_Compose<Middleman_CFTypeArg<0>, Middleman_CreateCFTypeRval>) \
   MACRO(CGFontCopyVariations, RR_ScalarRval, nullptr,            \
         Middleman_Compose<Middleman_CFTypeArg<0>, Middleman_CreateCFTypeRval>) \
   MACRO(CGFontCreateCopyWithVariations, RR_ScalarRval)           \
-  MACRO(CGFontCreateWithDataProvider, RR_ScalarRval)             \
+  MACRO(CGFontCreateWithDataProvider, RR_ScalarRval, nullptr,    \
+        Middleman_Compose<Middleman_CFTypeArg<0>, Middleman_CreateCFTypeRval>) \
   MACRO(CGFontCreateWithFontName, RR_ScalarRval, nullptr,        \
         Middleman_Compose<Middleman_CFTypeArg<0>, Middleman_CreateCFTypeRval>) \
   MACRO(CGFontCreateWithPlatformFont, RR_ScalarRval)             \
   MACRO(CGFontGetAscent, RR_ScalarRval, nullptr, Middleman_CFTypeArg<0>) \
   MACRO(CGFontGetCapHeight, RR_ScalarRval, nullptr, Middleman_CFTypeArg<0>) \
   MACRO(CGFontGetDescent, RR_ScalarRval, nullptr, Middleman_CFTypeArg<0>) \
   MACRO(CGFontGetFontBBox, RR_OversizeRval<sizeof(CGRect)>, nullptr, \
         Middleman_Compose<Middleman_CFTypeArg<1>, Middleman_OversizeRval<sizeof(CGRect)>>) \
@@ -438,20 +440,24 @@ namespace recordreplay {
   MACRO(CTFontCopyFeatures, RR_ScalarRval, nullptr,              \
         Middleman_Compose<Middleman_CFTypeArg<0>, Middleman_CreateCFTypeRval>) \
   MACRO(CTFontCopyFontDescriptor, RR_ScalarRval, nullptr,        \
         Middleman_Compose<Middleman_CFTypeArg<0>, Middleman_CreateCFTypeRval>) \
   MACRO(CTFontCopyGraphicsFont, RR_ScalarRval, nullptr,          \
         Middleman_Compose<Middleman_CFTypeArg<0>, Middleman_CreateCFTypeRval>) \
   MACRO(CTFontCopyTable, RR_ScalarRval, nullptr,                 \
         Middleman_Compose<Middleman_CFTypeArg<0>, Middleman_CreateCFTypeRval>) \
-  MACRO(CTFontCopyVariationAxes, RR_ScalarRval)                  \
+  MACRO(CTFontCopyVariationAxes, RR_ScalarRval, nullptr,         \
+        Middleman_Compose<Middleman_CFTypeArg<0>, Middleman_CreateCFTypeRval>) \
   MACRO(CTFontCreateForString, RR_ScalarRval, nullptr,           \
         Middleman_Compose<Middleman_CFTypeArg<0>, Middleman_CFTypeArg<1>, Middleman_CreateCFTypeRval>) \
-  MACRO(CTFontCreatePathForGlyph, RR_ScalarRval)                 \
+  MACRO(CTFontCreatePathForGlyph, RR_ScalarRval, nullptr,        \
+        Middleman_Compose<Middleman_CFTypeArg<0>,                \
+                          Middleman_BufferFixedSize<2, sizeof(CGAffineTransform)>, \
+                          Middleman_CreateCFTypeRval>)           \
   MACRO(CTFontCreateWithFontDescriptor, RR_ScalarRval, nullptr,  \
         Middleman_Compose<Middleman_CFTypeArg<0>,                \
                           Middleman_BufferFixedSize<1, sizeof(CGAffineTransform)>, \
                           Middleman_CreateCFTypeRval>)                 \
   MACRO(CTFontCreateWithGraphicsFont, RR_ScalarRval, nullptr,    \
         Middleman_Compose<Middleman_CFTypeArg<0>,                \
                           Middleman_BufferFixedSize<1, sizeof(CGAffineTransform)>, \
                           Middleman_CFTypeArg<2>,                \
@@ -1754,16 +1760,17 @@ Middleman_CFArrayGetValueAtIndex(Middlem
 
   // We can't probe the array to see what callbacks it uses, so look at where
   // it came from to see whether its elements should be treated as CFTypes.
   MiddlemanCall* call = LookupMiddlemanCall(array);
   bool isCFTypeRval = false;
   if (call) {
     switch (call->mCallId) {
     case CallEvent_CTLineGetGlyphRuns:
+    case CallEvent_CTFontCopyVariationAxes:
     case CallEvent_CTFontDescriptorCreateMatchingFontDescriptors:
       isCFTypeRval = true;
       break;
     default:
       break;
     }
   }
 
@@ -2050,16 +2057,49 @@ RR_CGDataProviderCreateWithData(Stream& 
   auto& releaseData = aArguments->Arg<3, CGDataProviderReleaseDataCallback>();
 
   if (IsReplaying()) {
     // Immediately release the data, since there is no data provider to do it for us.
     releaseData(info, data, size);
   }
 }
 
+static void
+ReleaseDataCallback(void*, const void* aData, size_t)
+{
+  free((void*) aData);
+}
+
+static void
+Middleman_CGDataProviderCreateWithData(MiddlemanCallContext& aCx)
+{
+  Middleman_Buffer<1, 2>(aCx);
+  Middleman_CreateCFTypeRval(aCx);
+
+  auto& info = aCx.mArguments->Arg<0, void*>();
+  auto& data = aCx.mArguments->Arg<1, const void*>();
+  auto& size = aCx.mArguments->Arg<2, size_t>();
+  auto& releaseData = aCx.mArguments->Arg<3, CGDataProviderReleaseDataCallback>();
+
+  // Make a copy of the data that won't be released the next time middleman
+  // calls are reset, in case CoreGraphics decides to hang onto the data
+  // provider after that point.
+  if (aCx.mPhase == MiddlemanCallPhase::MiddlemanInput) {
+    void* newData = malloc(size);
+    memcpy(newData, data, size);
+    data = newData;
+    releaseData = ReleaseDataCallback;
+  }
+
+  // Immediately release the data in the replaying process.
+  if (aCx.mPhase == MiddlemanCallPhase::ReplayInput) {
+    releaseData(info, data, size);
+  }
+}
+
 static PreambleResult
 Preamble_CGPathApply(CallArguments* aArguments)
 {
   if (AreThreadEventsPassedThrough()) {
     return PreambleResult::Redirect;
   }
 
   auto& path = aArguments->Arg<0, CGPathRef>();