Global Metrics

path: .metrics.halstead.estimated_program_length
old: 621.3669386801487
new: 3486.2192106242974

path: .metrics.halstead.N2
old: 466.0
new: 1001.0

path: .metrics.halstead.level
old: 0.01696300837931739
new: 0.01856679905460393

path: .metrics.halstead.effort
old: 478348.6700721294
new: 1160665.1222926783

path: .metrics.halstead.N1
old: 745.0
new: 1470.0

path: .metrics.halstead.length
old: 1211.0
new: 2471.0

path: .metrics.halstead.n1
old: 21.0
new: 41.0

path: .metrics.halstead.purity_ratio
old: 0.5131023440793961
new: 1.4108535858455271

path: .metrics.halstead.time
old: 26574.926115118305
new: 64481.39568292657

path: .metrics.halstead.volume
old: 8114.232498668862
new: 21549.836095295457

path: .metrics.halstead.n2
old: 83.0
new: 381.0

path: .metrics.halstead.bugs
old: 2.038802351636614
new: 3.681431308351549

path: .metrics.halstead.difficulty
old: 58.95180722891566
new: 53.85958005249344

path: .metrics.halstead.vocabulary
old: 104.0
new: 422.0

path: .metrics.nexits.average
old: 3.8
new: 2.5

path: .metrics.nexits.sum
old: 38.0
new: 25.0

path: .metrics.nargs.average
old: 3.4
new: 1.5

path: .metrics.nargs.sum
old: 34.0
new: 15.0

path: .metrics.loc.cloc
old: 37.0
new: 131.0

path: .metrics.loc.blank
old: 24.0
new: 85.0

path: .metrics.loc.ploc
old: 191.0
new: 477.0

path: .metrics.loc.lloc
old: 103.0
new: 242.0

path: .metrics.loc.sloc
old: 252.0
new: 693.0

path: .metrics.cyclomatic.sum
old: 57.0
new: 96.0

path: .metrics.cyclomatic.average
old: 5.181818181818182
new: 8.0

path: .metrics.cognitive.average
old: 5.0
new: 10.3

path: .metrics.cognitive.sum
old: 50.0
new: 103.0

path: .metrics.mi.mi_visual_studio
old: 12.57666626666203
new: 0.0

path: .metrics.mi.mi_sei
old: -10.902239345006183
new: -47.622227870180176

path: .metrics.mi.mi_original
old: 21.50609931599207
new: -8.930928133400755

Spaces Data

Minimal test - lines (102, 123)

path: .spaces[1].metrics.nexits.sum
old: 4.0
new: 3.0

path: .spaces[1].metrics.nexits.average
old: 4.0
new: 3.0

path: .spaces[1].metrics.mi.mi_visual_studio
old: 48.773261727539115
new: 50.20624035350515

path: .spaces[1].metrics.mi.mi_original
old: 83.4022775540919
new: 85.8526710044938

path: .spaces[1].metrics.mi.mi_sei
old: 66.34681668682296
new: 48.56565015085998

path: .spaces[1].metrics.halstead.n1
old: 18.0
new: 13.0

path: .spaces[1].metrics.halstead.difficulty
old: 17.64
new: 12.551724137931034

path: .spaces[1].metrics.halstead.n2
old: 25.0
new: 29.0

path: .spaces[1].metrics.halstead.purity_ratio
old: 1.415963368669109
new: 1.4317209484434377

path: .spaces[1].metrics.halstead.volume
old: 732.5457418847832
new: 711.7858998067965

path: .spaces[1].metrics.halstead.length
old: 135.0
new: 132.0

path: .spaces[1].metrics.halstead.estimated_program_length
old: 191.15505477032977
new: 188.98716519453376

path: .spaces[1].metrics.halstead.vocabulary
old: 43.0
new: 42.0

path: .spaces[1].metrics.halstead.bugs
old: 0.18355559687514555
new: 0.14352049474832962

path: .spaces[1].metrics.halstead.N1
old: 86.0
new: 76.0

path: .spaces[1].metrics.halstead.effort
old: 12922.106886847576
new: 8934.140259643927

path: .spaces[1].metrics.halstead.time
old: 717.8948270470876
new: 496.34112553577376

path: .spaces[1].metrics.halstead.N2
old: 49.0
new: 56.0

path: .spaces[1].metrics.halstead.level
old: 0.056689342403628114
new: 0.07967032967032968

path: .spaces[1].metrics.loc.sloc
old: 25.0
new: 22.0

path: .spaces[1].metrics.loc.cloc
old: 2.0
new: 0.0

path: .spaces[1].metrics.loc.blank
old: 3.0
new: 1.0

path: .spaces[1].metrics.loc.ploc
old: 20.0
new: 21.0

path: .spaces[1].metrics.cyclomatic.sum
old: 5.0
new: 4.0

path: .spaces[1].metrics.cyclomatic.average
old: 5.0
new: 4.0

path: .spaces[1].metrics.nargs.sum
old: 4.0
new: 3.0

path: .spaces[1].metrics.nargs.average
old: 4.0
new: 3.0

Code

LayoutDeviceIntRegion nsWindow::GetRegionToPaint(bool aForceFullRepaint,
                                                 PAINTSTRUCT ps, HDC aDC) {
  if (aForceFullRepaint) {
    RECT paintRect;
    ::GetClientRect(mWnd, &paintRect);
    return LayoutDeviceIntRegion(WinUtils::ToIntRect(paintRect));
  }

  HRGN paintRgn = ::CreateRectRgn(0, 0, 0, 0);
  if (paintRgn != nullptr) {
    int result = GetRandomRgn(aDC, paintRgn, SYSRGN);
    if (result == 1) {
      POINT pt = {0, 0};
      ::MapWindowPoints(nullptr, mWnd, &pt, 1);
      ::OffsetRgn(paintRgn, pt.x, pt.y);
    }
    LayoutDeviceIntRegion rgn(WinUtils::ConvertHRGNToRegion(paintRgn));
    ::DeleteObject(paintRgn);
    return rgn;
  }
  return LayoutDeviceIntRegion(WinUtils::ToIntRect(ps.rcPaint));
}

Minimal test - lines (130, 136)

path: .spaces[3].metrics.nexits.sum
old: 1.0
new: 0.0

path: .spaces[3].metrics.nexits.average
old: 1.0
new: 0.0

path: .spaces[3].metrics.cyclomatic.average
old: 1.0
new: 3.0

path: .spaces[3].metrics.cyclomatic.sum
old: 1.0
new: 3.0

path: .spaces[3].metrics.mi.mi_visual_studio
old: 63.20137188912845
new: 67.09175098253554

path: .spaces[3].metrics.mi.mi_original
old: 108.07434593040966
new: 114.7268941801358

path: .spaces[3].metrics.mi.mi_sei
old: 80.31929078851206
new: 90.1205288764754

path: .spaces[3].metrics.nargs.sum
old: 4.0
new: 0.0

path: .spaces[3].metrics.nargs.average
old: 4.0
new: 0.0

path: .spaces[3].metrics.loc.lloc
old: 5.0
new: 3.0

path: .spaces[3].metrics.loc.ploc
old: 8.0
new: 7.0

path: .spaces[3].metrics.loc.sloc
old: 8.0
new: 7.0

path: .spaces[3].metrics.halstead.level
old: 0.0979020979020979
new: 0.175

path: .spaces[3].metrics.halstead.n1
old: 11.0
new: 10.0

path: .spaces[3].metrics.halstead.vocabulary
old: 25.0
new: 17.0

path: .spaces[3].metrics.halstead.N2
old: 26.0
new: 8.0

path: .spaces[3].metrics.halstead.volume
old: 264.6998028171593
new: 102.18657103125848

path: .spaces[3].metrics.halstead.effort
old: 2703.7194144895557
new: 583.9232630357627

path: .spaces[3].metrics.halstead.N1
old: 31.0
new: 17.0

path: .spaces[3].metrics.halstead.length
old: 57.0
new: 25.0

path: .spaces[3].metrics.halstead.estimated_program_length
old: 91.35671671381672
new: 52.87076540327685

path: .spaces[3].metrics.halstead.bugs
old: 0.06469238438200615
new: 0.02328712799896892

path: .spaces[3].metrics.halstead.purity_ratio
old: 1.6027494160318725
new: 2.114830616131074

path: .spaces[3].metrics.halstead.time
old: 150.20663413830866
new: 32.440181279764595

path: .spaces[3].metrics.halstead.difficulty
old: 10.214285714285714
new: 5.714285714285714

path: .spaces[3].metrics.halstead.n2
old: 14.0
new: 7.0

path: .spaces[3].metrics.cognitive.sum
old: 0.0
new: 3.0

path: .spaces[3].metrics.cognitive.average
old: 0.0
new: 3.0

Code

void nsWindow::ForcePresent() {
  if (mResizeState != RESIZING) {
    if (CompositorBridgeChild* remoteRenderer = GetRemoteRenderer()) {
      remoteRenderer->SendForcePresent();
    }
  }
}

Minimal test - lines (460, 468)

path: .spaces[6].metrics.mi.mi_sei
old: 111.64485993670849
new: 118.9527071187462

path: .spaces[6].metrics.mi.mi_original
old: 129.71699971644642
new: 111.66281041186656

path: .spaces[6].metrics.mi.mi_visual_studio
old: 75.8578945710213
new: 65.29988912974653

path: .spaces[6].metrics.nargs.average
old: 1.0
new: 0.0

path: .spaces[6].metrics.nargs.sum
old: 1.0
new: 0.0

path: .spaces[6].metrics.cognitive.average
old: 1.0
new: 2.0

path: .spaces[6].metrics.cognitive.sum
old: 1.0
new: 2.0

path: .spaces[6].metrics.loc.cloc
old: 0.0
new: 2.0

path: .spaces[6].metrics.loc.lloc
old: 1.0
new: 3.0

path: .spaces[6].metrics.loc.sloc
old: 3.0
new: 9.0

path: .spaces[6].metrics.loc.ploc
old: 3.0
new: 7.0

path: .spaces[6].metrics.halstead.level
old: 0.1388888888888889
new: 0.2222222222222222

path: .spaces[6].metrics.halstead.estimated_program_length
old: 40.13896548741762
new: 48.18080946738404

path: .spaces[6].metrics.halstead.bugs
old: 0.023793834650606825
new: 0.01797527469415136

path: .spaces[6].metrics.halstead.purity_ratio
old: 1.8244984312462555
new: 2.1900367939720016

path: .spaces[6].metrics.halstead.vocabulary
old: 14.0
new: 16.0

path: .spaces[6].metrics.halstead.N1
old: 14.0
new: 15.0

path: .spaces[6].metrics.halstead.n2
old: 5.0
new: 7.0

path: .spaces[6].metrics.halstead.time
old: 33.50472331410692
new: 22.0

path: .spaces[6].metrics.halstead.volume
old: 83.76180828526729
new: 88.0

path: .spaces[6].metrics.halstead.effort
old: 603.0850196539245
new: 396.0

path: .spaces[6].metrics.halstead.difficulty
old: 7.2
new: 4.5

path: .spaces[6].metrics.halstead.N2
old: 8.0
new: 7.0

path: .spaces[6].metrics.nexits.sum
old: 1.0
new: 0.0

path: .spaces[6].metrics.nexits.average
old: 1.0
new: 0.0

Code

void nsWindow::RequestFxrOutput() {
  if (GetRemoteRenderer() != nullptr) {
    MOZ_CRASH("RequestFxrOutput should happen before Compositor is created.");
  } else {
    // The compositor isn't ready, so indicate to make the IPC call when
    // it is available.
    mRequestFxrOutputPending = true;
  }
}

Minimal test - lines (590, 617)

path: .spaces[9].metrics.mi.mi_sei
old: 80.31929078851206
new: 70.25200900507826

path: .spaces[9].metrics.mi.mi_original
old: 108.07434593040966
new: 81.58998358242185

path: .spaces[9].metrics.mi.mi_visual_studio
old: 63.20137188912845
new: 47.713440691474766

path: .spaces[9].metrics.cyclomatic.average
old: 1.0
new: 6.0

path: .spaces[9].metrics.cyclomatic.sum
old: 1.0
new: 6.0

path: .spaces[9].metrics.nargs.average
old: 4.0
new: 0.0

path: .spaces[9].metrics.nargs.sum
old: 4.0
new: 0.0

path: .spaces[9].metrics.halstead.difficulty
old: 10.214285714285714
new: 23.157894736842103

path: .spaces[9].metrics.halstead.vocabulary
old: 25.0
new: 39.0

path: .spaces[9].metrics.halstead.time
old: 150.20663413830866
new: 897.5911136594136

path: .spaces[9].metrics.halstead.effort
old: 2703.7194144895557
new: 16156.640045869444

path: .spaces[9].metrics.halstead.n2
old: 14.0
new: 19.0

path: .spaces[9].metrics.halstead.N2
old: 26.0
new: 44.0

path: .spaces[9].metrics.halstead.N1
old: 31.0
new: 88.0

path: .spaces[9].metrics.halstead.bugs
old: 0.06469238438200615
new: 0.21303262145085705

path: .spaces[9].metrics.halstead.estimated_program_length
old: 91.35671671381672
new: 167.14918465317538

path: .spaces[9].metrics.halstead.length
old: 57.0
new: 132.0

path: .spaces[9].metrics.halstead.n1
old: 11.0
new: 20.0

path: .spaces[9].metrics.halstead.level
old: 0.0979020979020979
new: 0.04318181818181818

path: .spaces[9].metrics.halstead.purity_ratio
old: 1.6027494160318725
new: 1.2662817019179953

path: .spaces[9].metrics.halstead.volume
old: 264.6998028171593
new: 697.6730928898169

path: .spaces[9].metrics.cognitive.average
old: 0.0
new: 10.0

path: .spaces[9].metrics.cognitive.sum
old: 0.0
new: 10.0

path: .spaces[9].metrics.loc.blank
old: 0.0
new: 4.0

path: .spaces[9].metrics.loc.ploc
old: 8.0
new: 20.0

path: .spaces[9].metrics.loc.sloc
old: 8.0
new: 28.0

path: .spaces[9].metrics.loc.cloc
old: 0.0
new: 4.0

path: .spaces[9].metrics.loc.lloc
old: 5.0
new: 11.0

path: .spaces[9].metrics.nexits.average
old: 1.0
new: 2.0

path: .spaces[9].metrics.nexits.sum
old: 1.0
new: 2.0

Code

uint8_t* nsWindowGfx::Data32BitTo1Bit(uint8_t* aImageData, uint32_t aWidth,
                                      uint32_t aHeight) {
  // We need (aWidth + 7) / 8 bytes plus zero-padding up to a multiple of
  // 4 bytes for each row (HBITMAP requirement). Bug 353553.
  uint32_t outBpr = ((aWidth + 31) / 8) & ~3;

  // Allocate and clear mask buffer
  uint8_t* outData = (uint8_t*)calloc(outBpr, aHeight);
  if (!outData) return nullptr;

  int32_t* imageRow = (int32_t*)aImageData;
  for (uint32_t curRow = 0; curRow < aHeight; curRow++) {
    uint8_t* outRow = outData + curRow * outBpr;
    uint8_t mask = 0x80;
    for (uint32_t curCol = 0; curCol < aWidth; curCol++) {
      // Use sign bit to test for transparency, as alpha byte is highest byte
      if (*imageRow++ < 0) *outRow |= mask;

      mask >>= 1;
      if (!mask) {
        outRow++;
        mask = 0x80;
      }
    }
  }

  return outData;
}

Minimal test - lines (138, 447)

path: .spaces[4].metrics.halstead.N1
old: 53.0
new: 653.0

path: .spaces[4].metrics.halstead.difficulty
old: 16.607142857142858
new: 34.91228070175438

path: .spaces[4].metrics.halstead.n1
old: 15.0
new: 30.0

path: .spaces[4].metrics.halstead.bugs
old: 0.1193709796408008
new: 1.4291576133153725

path: .spaces[4].metrics.halstead.N2
old: 31.0
new: 398.0

path: .spaces[4].metrics.halstead.n2
old: 14.0
new: 171.0

path: .spaces[4].metrics.halstead.estimated_program_length
old: 111.90632784293425
new: 1415.6594979137442

path: .spaces[4].metrics.halstead.time
old: 376.4935271223868
new: 15596.586843648942

path: .spaces[4].metrics.halstead.purity_ratio
old: 1.33221818860636
new: 1.3469643177105082

path: .spaces[4].metrics.halstead.volume
old: 408.070403590716
new: 8041.255327429053

path: .spaces[4].metrics.halstead.effort
old: 6776.883488202962
new: 280738.56318568095

path: .spaces[4].metrics.halstead.length
old: 84.0
new: 1051.0

path: .spaces[4].metrics.halstead.vocabulary
old: 29.0
new: 201.0

path: .spaces[4].metrics.halstead.level
old: 0.06021505376344086
new: 0.02864321608040201

path: .spaces[4].metrics.cognitive.sum
old: 3.0
new: 63.0

path: .spaces[4].metrics.cognitive.average
old: 3.0
new: 63.0

path: .spaces[4].metrics.loc.cloc
old: 0.0
new: 51.0

path: .spaces[4].metrics.loc.sloc
old: 14.0
new: 310.0

path: .spaces[4].metrics.loc.blank
old: 2.0
new: 38.0

path: .spaces[4].metrics.loc.lloc
old: 7.0
new: 124.0

path: .spaces[4].metrics.loc.ploc
old: 12.0
new: 221.0

path: .spaces[4].metrics.mi.mi_sei
old: 63.30294406487193
new: -13.332863539330276

path: .spaces[4].metrics.mi.mi_original
old: 96.0677847300744
new: 19.11735825760188

path: .spaces[4].metrics.mi.mi_visual_studio
old: 56.17999107021895
new: 11.17974167111221

path: .spaces[4].metrics.nargs.sum
old: 4.0
new: 2.0

path: .spaces[4].metrics.nargs.average
old: 4.0
new: 2.0

path: .spaces[4].metrics.cyclomatic.sum
old: 4.0
new: 53.0

path: .spaces[4].metrics.cyclomatic.average
old: 4.0
new: 53.0

path: .spaces[4].metrics.nexits.sum
old: 3.0
new: 10.0

path: .spaces[4].metrics.nexits.average
old: 3.0
new: 10.0

Code

bool nsWindow::OnPaint(HDC aDC, uint32_t aNestingLevel) {
  // We never have reentrant paint events, except when we're running our RPC
  // windows event spin loop. If we don't trap for this, we'll try to paint,
  // but view manager will refuse to paint the surface, resulting is black
  // flashes on the plugin rendering surface.
  if (mozilla::ipc::MessageChannel::IsSpinLoopActive() && mPainting)
    return false;

  DeviceResetReason resetReason = DeviceResetReason::OK;
  if (gfxWindowsPlatform::GetPlatform()->DidRenderingDeviceReset(
          &resetReason)) {
    gfxCriticalNote << "(nsWindow) Detected device reset: " << (int)resetReason;

    gfxWindowsPlatform::GetPlatform()->UpdateRenderMode();

    bool guilty;
    switch (resetReason) {
      case DeviceResetReason::HUNG:
      case DeviceResetReason::RESET:
      case DeviceResetReason::INVALID_CALL:
        guilty = true;
        break;
      default:
        guilty = false;
        break;
    }

    GPUProcessManager::Get()->OnInProcessDeviceReset(guilty);

    gfxCriticalNote << "(nsWindow) Finished device reset.";
    return false;
  }

  // After we CallUpdateWindow to the child, occasionally a WM_PAINT message
  // is posted to the parent event loop with an empty update rect. Do a
  // dummy paint so that Windows stops dispatching WM_PAINT in an inifinite
  // loop. See bug 543788.
  if (IsPlugin()) {
    RECT updateRect;
    if (!GetUpdateRect(mWnd, &updateRect, FALSE) ||
        (updateRect.left == updateRect.right &&
         updateRect.top == updateRect.bottom)) {
      PAINTSTRUCT ps;
      BeginPaint(mWnd, &ps);
      EndPaint(mWnd, &ps);
      return true;
    }

    if (mWindowType == eWindowType_plugin_ipc_chrome) {
      // Fire off an async request to the plugin to paint its window
      mozilla::dom::ContentParent::SendAsyncUpdate(this);
      ValidateRect(mWnd, nullptr);
      return true;
    }

    PluginInstanceParent* instance = reinterpret_cast(
        ::GetPropW(mWnd, L"PluginInstanceParentProperty"));
    if (instance) {
      Unused << instance->CallUpdateWindow();
    } else {
      // We should never get here since in-process plugins should have
      // subclassed our HWND and handled WM_PAINT, but in some cases that
      // could fail. Return without asserting since it's not our fault.
      NS_WARNING("Plugin failed to subclass our window");
    }

    ValidateRect(mWnd, nullptr);
    return true;
  }

  PAINTSTRUCT ps;

  // Avoid starting the GPU process for the initial navigator:blank window.
  if (mIsEarlyBlankWindow) {
    // Call BeginPaint/EndPaint or Windows will keep sending us messages.
    ::BeginPaint(mWnd, &ps);
    ::EndPaint(mWnd, &ps);
    return true;
  }

  // Clear window by transparent black when compositor window is used in GPU
  // process and non-client area rendering by DWM is enabled.
  // It is for showing non-client area rendering. See nsWindow::UpdateGlass().
  if (HasGlass() && GetLayerManager()->AsKnowsCompositor() &&
      GetLayerManager()->AsKnowsCompositor()->GetUseCompositorWnd()) {
    HDC hdc;
    RECT rect;
    hdc = ::GetWindowDC(mWnd);
    ::GetWindowRect(mWnd, &rect);
    ::MapWindowPoints(nullptr, mWnd, (LPPOINT)&rect, 2);
    ::FillRect(hdc, &rect,
               reinterpret_cast(GetStockObject(BLACK_BRUSH)));
    ReleaseDC(mWnd, hdc);
  }

  if (GetLayerManager()->AsKnowsCompositor() &&
      !mBounds.IsEqualEdges(mLastPaintBounds)) {
    // Do an early async composite so that we at least have something on the
    // screen in the right place, even if the content is out of date.
    GetLayerManager()->ScheduleComposite();
  }
  mLastPaintBounds = mBounds;

#ifdef MOZ_XUL
  if (!aDC &&
      (GetLayerManager()->GetBackendType() == LayersBackend::LAYERS_BASIC) &&
      (eTransparencyTransparent == mTransparencyMode)) {
    // For layered translucent windows all drawing should go to memory DC and no
    // WM_PAINT messages are normally generated. To support asynchronous
    // painting we force generation of WM_PAINT messages by invalidating window
    // areas with RedrawWindow, InvalidateRect or InvalidateRgn function calls.
    // BeginPaint/EndPaint must be called to make Windows think that invalid
    // area is painted. Otherwise it will continue sending the same message
    // endlessly.
    ::BeginPaint(mWnd, &ps);
    ::EndPaint(mWnd, &ps);

    // We're guaranteed to have a widget proxy since we called
    // GetLayerManager().
    aDC = mBasicLayersSurface->GetTransparentDC();
  }
#endif

  mPainting = true;

#ifdef WIDGET_DEBUG_OUTPUT
  HRGN debugPaintFlashRegion = nullptr;
  HDC debugPaintFlashDC = nullptr;

  if (debug_WantPaintFlashing()) {
    debugPaintFlashRegion = ::CreateRectRgn(0, 0, 0, 0);
    ::GetUpdateRgn(mWnd, debugPaintFlashRegion, TRUE);
    debugPaintFlashDC = ::GetDC(mWnd);
  }
#endif  // WIDGET_DEBUG_OUTPUT

  HDC hDC = aDC ? aDC : (::BeginPaint(mWnd, &ps));
  mPaintDC = hDC;

#ifdef MOZ_XUL
  bool forceRepaint = aDC || (eTransparencyTransparent == mTransparencyMode);
#else
  bool forceRepaint = nullptr != aDC;
#endif
  LayoutDeviceIntRegion region = GetRegionToPaint(forceRepaint, ps, hDC);

  if (GetLayerManager()->AsKnowsCompositor()) {
    // We need to paint to the screen even if nothing changed, since if we
    // don't have a compositing window manager, our pixels could be stale.
    GetLayerManager()->SetNeedsComposite(true);
    GetLayerManager()->SendInvalidRegion(region.ToUnknownRegion());
  }

  RefPtr strongThis(this);

  nsIWidgetListener* listener = GetPaintListener();
  if (listener) {
    listener->WillPaintWindow(this);
  }
  // Re-get the listener since the will paint notification may have killed it.
  listener = GetPaintListener();
  if (!listener) {
    return false;
  }

  if (GetLayerManager()->AsKnowsCompositor() &&
      GetLayerManager()->NeedsComposite()) {
    GetLayerManager()->ScheduleComposite();
    GetLayerManager()->SetNeedsComposite(false);
  }

  bool result = true;
  if (!region.IsEmpty() && listener) {
    // Should probably pass in a real region here, using GetRandomRgn
    // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/clipping_4q0e.asp

#ifdef WIDGET_DEBUG_OUTPUT
    debug_DumpPaintEvent(stdout, this, region.ToUnknownRegion(), "noname",
                         (int32_t)mWnd);
#endif  // WIDGET_DEBUG_OUTPUT

    switch (GetLayerManager()->GetBackendType()) {
      case LayersBackend::LAYERS_BASIC: {
        RefPtr targetSurface;

#if defined(MOZ_XUL)
        // don't support transparency for non-GDI rendering, for now
        if (eTransparencyTransparent == mTransparencyMode) {
          // This mutex needs to be held when EnsureTransparentSurface is
          // called.
          MutexAutoLock lock(mBasicLayersSurface->GetTransparentSurfaceLock());
          targetSurface = mBasicLayersSurface->EnsureTransparentSurface();
        }
#endif

        RefPtr targetSurfaceWin;
        if (!targetSurface) {
          uint32_t flags = (mTransparencyMode == eTransparencyOpaque)
                               ? 0
                               : gfxWindowsSurface::FLAG_IS_TRANSPARENT;
          targetSurfaceWin = new gfxWindowsSurface(hDC, flags);
          targetSurface = targetSurfaceWin;
        }

        if (!targetSurface) {
          NS_ERROR("Invalid RenderMode!");
          return false;
        }

        RECT paintRect;
        ::GetClientRect(mWnd, &paintRect);
        RefPtr dt = gfxPlatform::CreateDrawTargetForSurface(
            targetSurface, IntSize(paintRect.right - paintRect.left,
                                   paintRect.bottom - paintRect.top));
        if (!dt || !dt->IsValid()) {
          gfxWarning()
              << "nsWindow::OnPaint failed in CreateDrawTargetForSurface";
          return false;
        }

        // don't need to double buffer with anything but GDI
        BufferMode doubleBuffering = mozilla::layers::BufferMode::BUFFER_NONE;
#ifdef MOZ_XUL
        switch (mTransparencyMode) {
          case eTransparencyGlass:
          case eTransparencyBorderlessGlass:
          default:
            // If we're not doing translucency, then double buffer
            doubleBuffering = mozilla::layers::BufferMode::BUFFERED;
            break;
          case eTransparencyTransparent:
            // If we're rendering with translucency, we're going to be
            // rendering the whole window; make sure we clear it first
            dt->ClearRect(
                Rect(0.f, 0.f, dt->GetSize().width, dt->GetSize().height));
            break;
        }
#else
        doubleBuffering = mozilla::layers::BufferMode::BUFFERED;
#endif

        RefPtr thebesContext = gfxContext::CreateOrNull(dt);
        MOZ_ASSERT(thebesContext);  // already checked draw target above

        {
          AutoLayerManagerSetup setupLayerManager(this, thebesContext,
                                                  doubleBuffering);
          result = listener->PaintWindow(this, region);
        }

#ifdef MOZ_XUL
        if (eTransparencyTransparent == mTransparencyMode) {
          // Data from offscreen drawing surface was copied to memory bitmap of
          // transparent bitmap. Now it can be read from memory bitmap to apply
          // alpha channel and after that displayed on the screen.
          mBasicLayersSurface->RedrawTransparentWindow();
        }
#endif
      } break;
      case LayersBackend::LAYERS_CLIENT:
      case LayersBackend::LAYERS_WR: {
        result = listener->PaintWindow(this, region);
        if (!gfxEnv::DisableForcePresent() &&
            gfxWindowsPlatform::GetPlatform()->DwmCompositionEnabled()) {
          nsCOMPtr event = NewRunnableMethod(
              "nsWindow::ForcePresent", this, &nsWindow::ForcePresent);
          NS_DispatchToMainThread(event);
        }
      } break;
      default:
        NS_ERROR("Unknown layers backend used!");
        break;
    }
  }

  if (!aDC) {
    ::EndPaint(mWnd, &ps);
  }

  mPaintDC = nullptr;
  mLastPaintEndTime = TimeStamp::Now();

#if defined(WIDGET_DEBUG_OUTPUT)
  if (debug_WantPaintFlashing()) {
    // Only flash paint events which have not ignored the paint message.
    // Those that ignore the paint message aren't painting anything so there
    // is only the overhead of the dispatching the paint event.
    if (result) {
      ::InvertRgn(debugPaintFlashDC, debugPaintFlashRegion);
      PR_Sleep(PR_MillisecondsToInterval(30));
      ::InvertRgn(debugPaintFlashDC, debugPaintFlashRegion);
      PR_Sleep(PR_MillisecondsToInterval(30));
    }
    ::ReleaseDC(mWnd, debugPaintFlashDC);
    ::DeleteObject(debugPaintFlashRegion);
  }
#endif  // WIDGET_DEBUG_OUTPUT

  mPainting = false;

  // Re-get the listener since painting may have killed it.
  listener = GetPaintListener();
  if (listener) listener->DidPaintWindow();

  if (aNestingLevel == 0 && ::GetUpdateRect(mWnd, nullptr, false)) {
    OnPaint(aDC, 1);
  }

  return result;
}

Minimal test - lines (481, 587)

path: .spaces[8].metrics.cyclomatic.average
old: 5.0
new: 15.0

path: .spaces[8].metrics.cyclomatic.sum
old: 5.0
new: 15.0

path: .spaces[8].metrics.halstead.purity_ratio
old: 1.0933117349053223
new: 1.1757320584948583

path: .spaces[8].metrics.halstead.vocabulary
old: 26.0
new: 112.0

path: .spaces[8].metrics.halstead.difficulty
old: 16.5
new: 37.03488372093023

path: .spaces[8].metrics.halstead.length
old: 88.0
new: 574.0

path: .spaces[8].metrics.halstead.N1
old: 55.0
new: 329.0

path: .spaces[8].metrics.halstead.estimated_program_length
old: 96.2114326716684
new: 674.8702015760488

path: .spaces[8].metrics.halstead.bugs
old: 0.1199357939509161
new: 0.9187829488841908

path: .spaces[8].metrics.halstead.n1
old: 13.0
new: 26.0

path: .spaces[8].metrics.halstead.time
old: 379.16880393004806
new: 8039.49495798223

path: .spaces[8].metrics.halstead.n2
old: 13.0
new: 86.0

path: .spaces[8].metrics.halstead.effort
old: 6825.038470740865
new: 144710.90924368013

path: .spaces[8].metrics.halstead.N2
old: 33.0
new: 245.0

path: .spaces[8].metrics.halstead.level
old: 0.06060606060606061
new: 0.027001569858712715

path: .spaces[8].metrics.halstead.volume
old: 413.63869519641605
new: 3907.4217252610647

path: .spaces[8].metrics.nexits.sum
old: 4.0
new: 5.0

path: .spaces[8].metrics.nexits.average
old: 4.0
new: 5.0

path: .spaces[8].metrics.nargs.sum
old: 4.0
new: 5.0

path: .spaces[8].metrics.nargs.average
old: 4.0
new: 5.0

path: .spaces[8].metrics.loc.cloc
old: 0.0
new: 10.0

path: .spaces[8].metrics.loc.blank
old: 3.0
new: 11.0

path: .spaces[8].metrics.loc.sloc
old: 19.0
new: 107.0

path: .spaces[8].metrics.loc.lloc
old: 10.0
new: 48.0

path: .spaces[8].metrics.loc.ploc
old: 16.0
new: 86.0

path: .spaces[8].metrics.mi.mi_original
old: 90.82012558298317
new: 48.842881124822526

path: .spaces[8].metrics.mi.mi_sei
old: 55.83399209649225
new: 19.096576665788835

path: .spaces[8].metrics.mi.mi_visual_studio
old: 53.11118455145213
new: 28.56308837708919

path: .spaces[8].metrics.cognitive.sum
old: 4.0
new: 15.0

path: .spaces[8].metrics.cognitive.average
old: 4.0
new: 15.0

Code

nsresult nsWindowGfx::CreateIcon(imgIContainer* aContainer, bool aIsCursor,
                                 LayoutDeviceIntPoint aHotspot,
                                 LayoutDeviceIntSize aScaledSize,
                                 HICON* aIcon) {
  MOZ_ASSERT(aHotspot.x >= 0 && aHotspot.y >= 0);
  MOZ_ASSERT((aScaledSize.width > 0 && aScaledSize.height > 0) ||
             (aScaledSize.width == 0 && aScaledSize.height == 0));

  // Get the image data
  RefPtr surface = aContainer->GetFrame(
      imgIContainer::FRAME_CURRENT,
      imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY);
  NS_ENSURE_TRUE(surface, NS_ERROR_NOT_AVAILABLE);

  IntSize frameSize = surface->GetSize();
  if (frameSize.IsEmpty()) {
    return NS_ERROR_FAILURE;
  }

  IntSize iconSize(aScaledSize.width, aScaledSize.height);
  if (iconSize == IntSize(0, 0)) {  // use frame's intrinsic size
    iconSize = frameSize;
  }

  RefPtr dataSurface;
  bool mappedOK;
  DataSourceSurface::MappedSurface map;

  if (iconSize != frameSize) {
    // Scale the surface
    dataSurface =
        Factory::CreateDataSourceSurface(iconSize, SurfaceFormat::B8G8R8A8);
    NS_ENSURE_TRUE(dataSurface, NS_ERROR_FAILURE);
    mappedOK = dataSurface->Map(DataSourceSurface::MapType::READ_WRITE, &map);
    NS_ENSURE_TRUE(mappedOK, NS_ERROR_FAILURE);

    RefPtr dt = Factory::CreateDrawTargetForData(
        BackendType::CAIRO, map.mData, dataSurface->GetSize(), map.mStride,
        SurfaceFormat::B8G8R8A8);
    if (!dt) {
      gfxWarning()
          << "nsWindowGfx::CreatesIcon failed in CreateDrawTargetForData";
      return NS_ERROR_OUT_OF_MEMORY;
    }
    dt->DrawSurface(surface, Rect(0, 0, iconSize.width, iconSize.height),
                    Rect(0, 0, frameSize.width, frameSize.height),
                    DrawSurfaceOptions(),
                    DrawOptions(1.0f, CompositionOp::OP_SOURCE));
  } else if (surface->GetFormat() != SurfaceFormat::B8G8R8A8) {
    // Convert format to SurfaceFormat::B8G8R8A8
    dataSurface = gfxUtils::CopySurfaceToDataSourceSurfaceWithFormat(
        surface, SurfaceFormat::B8G8R8A8);
    NS_ENSURE_TRUE(dataSurface, NS_ERROR_FAILURE);
    mappedOK = dataSurface->Map(DataSourceSurface::MapType::READ, &map);
  } else {
    dataSurface = surface->GetDataSurface();
    NS_ENSURE_TRUE(dataSurface, NS_ERROR_FAILURE);
    mappedOK = dataSurface->Map(DataSourceSurface::MapType::READ, &map);
  }
  NS_ENSURE_TRUE(dataSurface && mappedOK, NS_ERROR_FAILURE);
  MOZ_ASSERT(dataSurface->GetFormat() == SurfaceFormat::B8G8R8A8);

  uint8_t* data = nullptr;
  UniquePtr autoDeleteArray;
  if (map.mStride == BytesPerPixel(dataSurface->GetFormat()) * iconSize.width) {
    // Mapped data is already packed
    data = map.mData;
  } else {
    // We can't use map.mData since the pixels are not packed (as required by
    // CreateDIBitmap, which is called under the DataToBitmap call below).
    //
    // We must unmap before calling SurfaceToPackedBGRA because it needs access
    // to the pixel data.
    dataSurface->Unmap();
    map.mData = nullptr;

    autoDeleteArray = SurfaceToPackedBGRA(dataSurface);
    data = autoDeleteArray.get();
    NS_ENSURE_TRUE(data, NS_ERROR_FAILURE);
  }

  HBITMAP bmp = DataToBitmap(data, iconSize.width, -iconSize.height, 32);
  uint8_t* a1data = Data32BitTo1Bit(data, iconSize.width, iconSize.height);
  if (map.mData) {
    dataSurface->Unmap();
  }
  if (!a1data) {
    return NS_ERROR_FAILURE;
  }

  HBITMAP mbmp = DataToBitmap(a1data, iconSize.width, -iconSize.height, 1);
  free(a1data);

  ICONINFO info = {0};
  info.fIcon = !aIsCursor;
  info.xHotspot = aHotspot.x;
  info.yHotspot = aHotspot.y;
  info.hbmMask = mbmp;
  info.hbmColor = bmp;

  HCURSOR icon = ::CreateIconIndirect(&info);
  ::DeleteObject(mbmp);
  ::DeleteObject(bmp);
  if (!icon) return NS_ERROR_FAILURE;
  *aIcon = icon;
  return NS_OK;
}

Minimal test - lines (452, 458)

path: .spaces[5].metrics.cyclomatic.average
old: 1.0
new: 2.0

path: .spaces[5].metrics.cyclomatic.sum
old: 1.0
new: 2.0

path: .spaces[5].metrics.loc.sloc
old: 8.0
new: 7.0

path: .spaces[5].metrics.loc.lloc
old: 5.0
new: 3.0

path: .spaces[5].metrics.loc.blank
old: 0.0
new: 1.0

path: .spaces[5].metrics.loc.ploc
old: 8.0
new: 6.0

path: .spaces[5].metrics.halstead.level
old: 0.0979020979020979
new: 0.22857142857142856

path: .spaces[5].metrics.halstead.n1
old: 11.0
new: 7.0

path: .spaces[5].metrics.halstead.vocabulary
old: 25.0
new: 11.0

path: .spaces[5].metrics.halstead.N2
old: 26.0
new: 5.0

path: .spaces[5].metrics.halstead.N1
old: 31.0
new: 14.0

path: .spaces[5].metrics.halstead.n2
old: 14.0
new: 4.0

path: .spaces[5].metrics.halstead.volume
old: 264.6998028171593
new: 65.72920075410865

path: .spaces[5].metrics.halstead.difficulty
old: 10.214285714285714
new: 4.375

path: .spaces[5].metrics.halstead.effort
old: 2703.7194144895557
new: 287.56525329922533

path: .spaces[5].metrics.halstead.purity_ratio
old: 1.6027494160318725
new: 1.455341287073854

path: .spaces[5].metrics.halstead.estimated_program_length
old: 91.35671671381672
new: 27.651484454403228

path: .spaces[5].metrics.halstead.bugs
old: 0.06469238438200615
new: 0.01452233166731256

path: .spaces[5].metrics.halstead.time
old: 150.20663413830866
new: 15.975847405512518

path: .spaces[5].metrics.halstead.length
old: 57.0
new: 19.0

path: .spaces[5].metrics.nexits.average
old: 1.0
new: 0.0

path: .spaces[5].metrics.nexits.sum
old: 1.0
new: 0.0

path: .spaces[5].metrics.cognitive.sum
old: 0.0
new: 1.0

path: .spaces[5].metrics.cognitive.average
old: 0.0
new: 1.0

path: .spaces[5].metrics.mi.mi_sei
old: 80.31929078851206
new: 93.66084506851593

path: .spaces[5].metrics.mi.mi_original
old: 108.07434593040966
new: 117.2514305154106

path: .spaces[5].metrics.mi.mi_visual_studio
old: 63.20137188912845
new: 68.56808802070795

path: .spaces[5].metrics.nargs.average
old: 4.0
new: 0.0

path: .spaces[5].metrics.nargs.sum
old: 4.0
new: 0.0

Code

void nsWindow::CreateCompositor() {
  nsWindowBase::CreateCompositor();

  if (mRequestFxrOutputPending) {
    GetRemoteRenderer()->SendRequestFxrOutput();
  }
}

Minimal test - lines (125, 128)

path: .spaces[2].metrics.cyclomatic.average
old: 29.0
new: 3.0

path: .spaces[2].metrics.cyclomatic.sum
old: 29.0
new: 3.0

path: .spaces[2].metrics.halstead.effort
old: 125414.10864546074
new: 389.71233691194976

path: .spaces[2].metrics.halstead.N1
old: 319.0
new: 12.0

path: .spaces[2].metrics.halstead.purity_ratio
old: 0.5478640629477401
new: 2.3178473693319868

path: .spaces[2].metrics.halstead.n2
old: 38.0
new: 6.0

path: .spaces[2].metrics.halstead.length
old: 501.0
new: 19.0

path: .spaces[2].metrics.halstead.level
old: 0.023199023199023196
new: 0.1904761904761905

path: .spaces[2].metrics.halstead.time
old: 6967.450480303374
new: 21.65068538399721

path: .spaces[2].metrics.halstead.volume
old: 2909.4848159508597
new: 74.23092131656186

path: .spaces[2].metrics.halstead.estimated_program_length
old: 274.4798955368178
new: 44.039100017307746

path: .spaces[2].metrics.halstead.difficulty
old: 43.10526315789474
new: 5.25

path: .spaces[2].metrics.halstead.n1
old: 18.0
new: 9.0

path: .spaces[2].metrics.halstead.N2
old: 182.0
new: 7.0

path: .spaces[2].metrics.halstead.bugs
old: 0.8351728014822635
new: 0.017784494061890636

path: .spaces[2].metrics.halstead.vocabulary
old: 56.0
new: 15.0

path: .spaces[2].metrics.nargs.sum
old: 4.0
new: 0.0

path: .spaces[2].metrics.nargs.average
old: 4.0
new: 0.0

path: .spaces[2].metrics.mi.mi_visual_studio
old: 28.123534993924594
new: 73.3653165074973

path: .spaces[2].metrics.mi.mi_sei
old: 23.01397192861325
new: 105.59746847683324

path: .spaces[2].metrics.mi.mi_original
old: 48.09124483961105
new: 125.45469122782038

path: .spaces[2].metrics.loc.cloc
old: 13.0
new: 0.0

path: .spaces[2].metrics.loc.blank
old: 12.0
new: 0.0

path: .spaces[2].metrics.loc.sloc
old: 101.0
new: 4.0

path: .spaces[2].metrics.loc.ploc
old: 76.0
new: 4.0

path: .spaces[2].metrics.loc.lloc
old: 44.0
new: 3.0

path: .spaces[2].metrics.nexits.sum
old: 17.0
new: 2.0

path: .spaces[2].metrics.nexits.average
old: 17.0
new: 2.0

path: .spaces[2].metrics.cognitive.sum
old: 32.0
new: 1.0

path: .spaces[2].metrics.cognitive.average
old: 32.0
new: 1.0

Code

nsIWidgetListener* nsWindow::GetPaintListener() {
  if (mDestroyCalled) return nullptr;
  return mAttachedWidgetListener ? mAttachedWidgetListener : mWidgetListener;
}

Minimal test - lines (470, 479)

path: .spaces[7].metrics.halstead.purity_ratio
old: 1.8244984312462555
new: 1.5711252818015184

path: .spaces[7].metrics.halstead.difficulty
old: 7.2
new: 14.083333333333334

path: .spaces[7].metrics.halstead.time
old: 33.50472331410692
new: 210.73647394524

path: .spaces[7].metrics.halstead.bugs
old: 0.023793834650606825
new: 0.08107498707437459

path: .spaces[7].metrics.halstead.length
old: 22.0
new: 58.0

path: .spaces[7].metrics.halstead.N2
old: 8.0
new: 26.0

path: .spaces[7].metrics.halstead.vocabulary
old: 14.0
new: 25.0

path: .spaces[7].metrics.halstead.N1
old: 14.0
new: 32.0

path: .spaces[7].metrics.halstead.estimated_program_length
old: 40.13896548741762
new: 91.12526634448808

path: .spaces[7].metrics.halstead.level
old: 0.1388888888888889
new: 0.07100591715976332

path: .spaces[7].metrics.halstead.volume
old: 83.76180828526729
new: 269.343659006934

path: .spaces[7].metrics.halstead.n2
old: 5.0
new: 12.0

path: .spaces[7].metrics.halstead.n1
old: 9.0
new: 13.0

path: .spaces[7].metrics.halstead.effort
old: 603.0850196539245
new: 3793.25653101432

path: .spaces[7].metrics.loc.lloc
old: 1.0
new: 3.0

path: .spaces[7].metrics.loc.ploc
old: 3.0
new: 8.0

path: .spaces[7].metrics.loc.sloc
old: 3.0
new: 10.0

path: .spaces[7].metrics.loc.blank
old: 0.0
new: 2.0

path: .spaces[7].metrics.cognitive.average
old: 1.0
new: 2.0

path: .spaces[7].metrics.cognitive.sum
old: 1.0
new: 2.0

path: .spaces[7].metrics.cyclomatic.average
old: 2.0
new: 3.0

path: .spaces[7].metrics.cyclomatic.sum
old: 2.0
new: 3.0

path: .spaces[7].metrics.mi.mi_original
old: 129.71699971644642
new: 103.90898333701774

path: .spaces[7].metrics.mi.mi_sei
old: 111.64485993670849
new: 74.51358255033007

path: .spaces[7].metrics.mi.mi_visual_studio
old: 75.8578945710213
new: 60.76548733158933

Code

LayoutDeviceIntSize nsWindowGfx::GetIconMetrics(IconSizeType aSizeType) {
  int32_t width = ::GetSystemMetrics(sIconMetrics[aSizeType].xMetric);
  int32_t height = ::GetSystemMetrics(sIconMetrics[aSizeType].yMetric);

  if (width == 0 || height == 0) {
    width = height = sIconMetrics[aSizeType].defaultSize;
  }

  return LayoutDeviceIntSize(width, height);
}

Minimal test - lines (79, 83)

path: .spaces[0].metrics.nexits.sum
old: 5.0
new: 0.0

path: .spaces[0].metrics.nexits.average
old: 5.0
new: null

path: .spaces[0].metrics.halstead.difficulty
old: 18.6
new: 1.5

path: .spaces[0].metrics.halstead.n1
old: 15.0
new: 3.0

path: .spaces[0].metrics.halstead.N2
old: 62.0
new: 4.0

path: .spaces[0].metrics.halstead.time
old: 951.3833457626976
new: 2.573408678552804

path: .spaces[0].metrics.halstead.volume
old: 920.6935604155136
new: 30.880904142633646

path: .spaces[0].metrics.halstead.N1
old: 111.0
new: 7.0

path: .spaces[0].metrics.halstead.effort
old: 17124.900223728557
new: 46.321356213950466

path: .spaces[0].metrics.halstead.level
old: 0.05376344086021505
new: 0.6666666666666666

path: .spaces[0].metrics.halstead.vocabulary
old: 40.0
new: 7.0

path: .spaces[0].metrics.halstead.estimated_program_length
old: 174.6997636784959
new: 12.754887502163468

path: .spaces[0].metrics.halstead.n2
old: 25.0
new: 4.0

path: .spaces[0].metrics.halstead.purity_ratio
old: 1.0098252235751208
new: 1.1595352274694062

path: .spaces[0].metrics.halstead.bugs
old: 0.22146109613444465
new: 0.004299318203100795

path: .spaces[0].metrics.halstead.length
old: 173.0
new: 11.0

path: .spaces[0].metrics.mi.mi_original
old: 80.73678103930794
new: 126.86038819798438

path: .spaces[0].metrics.mi.mi_sei
old: 56.07587388114769
new: 107.42182080587256

path: .spaces[0].metrics.mi.mi_visual_studio
old: 47.2144918358526
new: 74.18736151928911

path: .spaces[0].metrics.cyclomatic.average
old: 6.0
new: 1.0

path: .spaces[0].metrics.cyclomatic.sum
old: 6.0
new: 1.0

path: .spaces[0].metrics.nargs.average
old: 4.0
new: null

path: .spaces[0].metrics.nargs.sum
old: 4.0
new: 0.0

path: .spaces[0].metrics.loc.ploc
old: 22.0
new: 5.0

path: .spaces[0].metrics.loc.lloc
old: 15.0
new: 0.0

path: .spaces[0].metrics.loc.sloc
old: 27.0
new: 5.0

path: .spaces[0].metrics.loc.blank
old: 4.0
new: 0.0

path: .spaces[0].metrics.loc.cloc
old: 1.0
new: 0.0

path: .spaces[0].metrics.cognitive.average
old: 5.0
new: null

path: .spaces[0].metrics.cognitive.sum
old: 5.0
new: 0.0

path: .spaces[0].metrics.nom.functions
old: 1.0
new: 0.0

path: .spaces[0].metrics.nom.total
old: 1.0
new: 0.0

Code

struct IconMetrics {
  int32_t xMetric;
  int32_t yMetric;
  int32_t defaultSize;
};