LCOV - code coverage report
Current view: top level - gfx/src - X11Util.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 41 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2             :  * vim: sw=2 ts=8 et :
       3             :  */
       4             : /* This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       7             : 
       8             : #include "X11Util.h"
       9             : #include "nsDebug.h"                    // for NS_ASSERTION, etc
      10             : #include "MainThreadUtils.h"            // for NS_IsMainThread
      11             : 
      12             : namespace mozilla {
      13             : 
      14             : void
      15           0 : FindVisualAndDepth(Display* aDisplay, VisualID aVisualID,
      16             :                    Visual** aVisual, int* aDepth)
      17             : {
      18           0 :     const Screen* screen = DefaultScreenOfDisplay(aDisplay);
      19             : 
      20           0 :     for (int d = 0; d < screen->ndepths; d++) {
      21           0 :         Depth *d_info = &screen->depths[d];
      22           0 :         for (int v = 0; v < d_info->nvisuals; v++) {
      23           0 :             Visual* visual = &d_info->visuals[v];
      24           0 :             if (visual->visualid == aVisualID) {
      25           0 :                 *aVisual = visual;
      26           0 :                 *aDepth = d_info->depth;
      27           0 :                 return;
      28             :             }
      29             :         }
      30             :     }
      31             : 
      32           0 :     NS_ASSERTION(aVisualID == X11None, "VisualID not on Screen.");
      33           0 :     *aVisual = nullptr;
      34           0 :     *aDepth = 0;
      35           0 :     return;
      36             : }
      37             : 
      38             : void
      39           0 : FinishX(Display* aDisplay)
      40             : {
      41           0 :   unsigned long lastRequest = NextRequest(aDisplay) - 1;
      42           0 :   if (lastRequest == LastKnownRequestProcessed(aDisplay))
      43           0 :     return;
      44             : 
      45           0 :   XSync(aDisplay, False);
      46             : }
      47             : 
      48             : ScopedXErrorHandler::ErrorEvent* ScopedXErrorHandler::sXErrorPtr;
      49             : 
      50             : int
      51           0 : ScopedXErrorHandler::ErrorHandler(Display *, XErrorEvent *ev)
      52             : {
      53             :     // only record the error if no error was previously recorded.
      54             :     // this means that in case of multiple errors, it's the first error that we report.
      55           0 :     if (!sXErrorPtr->mError.error_code)
      56           0 :       sXErrorPtr->mError = *ev;
      57           0 :     return 0;
      58             : }
      59             : 
      60           0 : ScopedXErrorHandler::ScopedXErrorHandler(bool aAllowOffMainThread)
      61             : {
      62           0 :     if (!aAllowOffMainThread) {
      63             :       // Off main thread usage is not safe in general, but OMTC GL layers uses this
      64             :       // with the main thread blocked, which makes it safe.
      65           0 :       NS_WARNING_ASSERTION(
      66             :         NS_IsMainThread(),
      67             :         "ScopedXErrorHandler being called off main thread, may cause issues");
      68             :     }
      69             :     // let sXErrorPtr point to this object's mXError object, but don't reset this mXError object!
      70             :     // think of the case of nested ScopedXErrorHandler's.
      71           0 :     mOldXErrorPtr = sXErrorPtr;
      72           0 :     sXErrorPtr = &mXError;
      73           0 :     mOldErrorHandler = XSetErrorHandler(ErrorHandler);
      74           0 : }
      75             : 
      76           0 : ScopedXErrorHandler::~ScopedXErrorHandler()
      77             : {
      78           0 :     sXErrorPtr = mOldXErrorPtr;
      79           0 :     XSetErrorHandler(mOldErrorHandler);
      80           0 : }
      81             : 
      82             : bool
      83           0 : ScopedXErrorHandler::SyncAndGetError(Display *dpy, XErrorEvent *ev)
      84             : {
      85           0 :     FinishX(dpy);
      86             : 
      87           0 :     bool retval = mXError.mError.error_code != 0;
      88           0 :     if (ev)
      89           0 :         *ev = mXError.mError;
      90           0 :     mXError = ErrorEvent(); // reset
      91           0 :     return retval;
      92             : }
      93             : 
      94             : } // namespace mozilla

Generated by: LCOV version 1.13