1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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/. */
9 #include "nsDebug.h" // for NS_ASSERTION, etc
10 #include "MainThreadUtils.h" // for NS_IsMainThread
15 FindVisualAndDepth(Display
* aDisplay
, VisualID aVisualID
,
16 Visual
** aVisual
, int* aDepth
)
18 const Screen
* screen
= DefaultScreenOfDisplay(aDisplay
);
20 for (int d
= 0; d
< screen
->ndepths
; d
++) {
21 Depth
*d_info
= &screen
->depths
[d
];
22 for (int v
= 0; v
< d_info
->nvisuals
; v
++) {
23 Visual
* visual
= &d_info
->visuals
[v
];
24 if (visual
->visualid
== aVisualID
) {
26 *aDepth
= d_info
->depth
;
32 NS_ASSERTION(aVisualID
== None
, "VisualID not on Screen.");
39 FinishX(Display
* aDisplay
)
41 unsigned long lastRequest
= NextRequest(aDisplay
) - 1;
42 if (lastRequest
== LastKnownRequestProcessed(aDisplay
))
45 XSync(aDisplay
, False
);
48 ScopedXErrorHandler::ErrorEvent
* ScopedXErrorHandler::sXErrorPtr
;
51 ScopedXErrorHandler::ErrorHandler(Display
*, XErrorEvent
*ev
)
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 if (!sXErrorPtr
->mError
.error_code
)
56 sXErrorPtr
->mError
= *ev
;
60 ScopedXErrorHandler::ScopedXErrorHandler()
62 // Off main thread usage is not safe in general, but OMTC GL layers uses this
63 // with the main thread blocked, which makes it safe.
64 NS_WARN_IF_FALSE(NS_IsMainThread(), "ScopedXErrorHandler being called off main thread, may cause issues");
65 // let sXErrorPtr point to this object's mXError object, but don't reset this mXError object!
66 // think of the case of nested ScopedXErrorHandler's.
67 mOldXErrorPtr
= sXErrorPtr
;
68 sXErrorPtr
= &mXError
;
69 mOldErrorHandler
= XSetErrorHandler(ErrorHandler
);
72 ScopedXErrorHandler::~ScopedXErrorHandler()
74 sXErrorPtr
= mOldXErrorPtr
;
75 XSetErrorHandler(mOldErrorHandler
);
79 ScopedXErrorHandler::SyncAndGetError(Display
*dpy
, XErrorEvent
*ev
)
83 bool retval
= mXError
.mError
.error_code
!= 0;
86 mXError
= ErrorEvent(); // reset
90 } // namespace mozilla