Bug 1499828 Part 3 - Redraw the overlay when required, r=mccr8.
authorBrian Hackett <bhackett1024@gmail.com>
Wed, 17 Oct 2018 13:32:19 -0600
changeset 490599 97475fb566eaefc467b4068a0579e779bd5e19d1
parent 490598 dc47411763c560e974c3f6d4842db72f75386ac6
child 490600 925e342d29d805f96f06ebd99a4679cd2fd72ecd
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersmccr8
bugs1499828
milestone64.0a1
Bug 1499828 Part 3 - Redraw the overlay when required, r=mccr8.
toolkit/recordreplay/ipc/ParentGraphics.cpp
toolkit/recordreplay/ipc/ParentIPC.cpp
toolkit/recordreplay/ipc/ParentInternal.h
--- a/toolkit/recordreplay/ipc/ParentGraphics.cpp
+++ b/toolkit/recordreplay/ipc/ParentGraphics.cpp
@@ -148,19 +148,16 @@ UpdateGraphicsInUIProcess(const PaintMes
   gLastExplicitPaint = nullptr;
   gLastCheckpoint = CheckpointId::Invalid;
 
   // Make sure there is a sandbox which is running the graphics JS module.
   if (!gGraphicsSandbox) {
     InitGraphicsSandbox();
   }
 
-  AutoSafeJSContext cx;
-  JSAutoRealm ar(cx, *gGraphicsSandbox);
-
   size_t width = gLastPaintWidth;
   size_t height = gLastPaintHeight;
   size_t stride = layers::ImageDataSerializer::ComputeRGBStride(gSurfaceFormat, width);
 
   // Make sure the width and height are appropriately sized.
   CheckedInt<size_t> scaledWidth = CheckedInt<size_t>(width) * 4;
   CheckedInt<size_t> scaledHeight = CheckedInt<size_t>(height) * stride;
   MOZ_RELEASE_ASSERT(scaledWidth.isValid() && scaledWidth.value() <= stride);
@@ -179,33 +176,53 @@ UpdateGraphicsInUIProcess(const PaintMes
     memory = gBufferMemory;
     for (size_t y = 0; y < height; y++) {
       char* src = (char*)gGraphicsMemory + y * stride;
       char* dst = (char*)gBufferMemory + y * width * 4;
       memcpy(dst, src, width * 4);
     }
   }
 
+  AutoSafeJSContext cx;
+  JSAutoRealm ar(cx, *gGraphicsSandbox);
+
   JSObject* bufferObject =
     JS_NewArrayBufferWithExternalContents(cx, width * height * 4, memory);
   MOZ_RELEASE_ASSERT(bufferObject);
 
   JS::AutoValueArray<4> args(cx);
   args[0].setObject(*bufferObject);
   args[1].setInt32(width);
   args[2].setInt32(height);
   args[3].setBoolean(hadFailure);
 
   // Call into the graphics module to update the canvas it manages.
   RootedValue rval(cx);
-  if (!JS_CallFunctionName(cx, *gGraphicsSandbox, "Update", args, &rval)) {
+  if (!JS_CallFunctionName(cx, *gGraphicsSandbox, "UpdateCanvas", args, &rval)) {
     MOZ_CRASH("UpdateGraphicsInUIProcess");
   }
 }
 
+void
+UpdateGraphicsOverlay()
+{
+  if (!gLastPaintWidth || !gLastPaintHeight) {
+    return;
+  }
+
+  AutoSafeJSContext cx;
+  JSAutoRealm ar(cx, *gGraphicsSandbox);
+
+  RootedValue rval(cx);
+  if (!JS_CallFunctionName(cx, *gGraphicsSandbox, "UpdateOverlay",
+                           JS::HandleValueArray::empty(), &rval)) {
+    MOZ_CRASH("UpdateGraphicsOverlay");
+  }
+}
+
 static void
 MaybeTriggerExplicitPaint()
 {
   if (gLastExplicitPaint && gLastExplicitPaint->mCheckpointId == gLastCheckpoint) {
     UpdateGraphicsInUIProcess(gLastExplicitPaint.get());
   }
 }
 
--- a/toolkit/recordreplay/ipc/ParentIPC.cpp
+++ b/toolkit/recordreplay/ipc/ParentIPC.cpp
@@ -606,16 +606,22 @@ SwitchActiveChild(ChildProcessInfo* aChi
   }
   aChild->SetRole(MakeUnique<ChildRoleActive>());
   if (oldActiveChild->IsRecording()) {
     oldActiveChild->SetRole(MakeUnique<ChildRoleInert>());
   } else {
     oldActiveChild->RecoverToCheckpoint(oldActiveChild->MostRecentSavedCheckpoint());
     oldActiveChild->SetRole(MakeUnique<ChildRoleStandby>());
   }
+
+  // The graphics overlay is affected when we switch between recording and
+  // replaying children.
+  if (aChild->IsRecording() != oldActiveChild->IsRecording()) {
+    UpdateGraphicsOverlay();
+  }
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 // Preferences
 ///////////////////////////////////////////////////////////////////////////////
 
 static bool gPreferencesLoaded;
 static bool gRewindingEnabled;
@@ -1176,16 +1182,20 @@ ResumeBeforeWaitingForIPDLReply()
 }
 
 static void
 RecvHitCheckpoint(const HitCheckpointMessage& aMsg)
 {
   UpdateCheckpointTimes(aMsg);
   MaybeUpdateGraphicsAtCheckpoint(aMsg.mCheckpointId);
 
+  if (!gActiveChild->IsRecording()) {
+    UpdateGraphicsOverlay();
+  }
+
   // Resume either forwards or backwards. Break the resume off into a separate
   // runnable, to avoid starving any code already on the stack and waiting for
   // the process to pause. Immediately resume if the main thread is blocked.
   if (MainThreadIsWaitingForIPDLReply()) {
     MOZ_RELEASE_ASSERT(gChildExecuteForward);
     Resume(true);
   } else if (!gResumeForwardOrBackward) {
     gResumeForwardOrBackward = true;
--- a/toolkit/recordreplay/ipc/ParentInternal.h
+++ b/toolkit/recordreplay/ipc/ParentInternal.h
@@ -89,16 +89,19 @@ extern void* gGraphicsMemory;
 void InitializeGraphicsMemory();
 void SendGraphicsMemoryToChild();
 
 // Update the graphics painted in the UI process, per painting data received
 // from a child process, or null if a repaint was triggered and failed due to
 // an unhandled recording divergence.
 void UpdateGraphicsInUIProcess(const PaintMessage* aMsg);
 
+// Update the overlay shown over the tab's graphics.
+void UpdateGraphicsOverlay();
+
 // If necessary, update graphics after the active child sends a paint message
 // or reaches a checkpoint.
 void MaybeUpdateGraphicsAtPaint(const PaintMessage& aMsg);
 void MaybeUpdateGraphicsAtCheckpoint(size_t aCheckpointId);
 
 // ID for the mach message sent from a child process to the middleman to
 // request a port for the graphics shmem.
 static const int32_t GraphicsHandshakeMessageId = 42;