1 /*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "X11ErrorHandler.h"
17 
18 // static
19 int X11ErrorHandler::s_lastErrorCode = 0;
20 
21 // static
22 android::base::Lock X11ErrorHandler::s_lock;
23 
X11ErrorHandler(EGLNativeDisplayType dpy)24 X11ErrorHandler::X11ErrorHandler(EGLNativeDisplayType dpy):
25     m_dpy(dpy) {
26     android::base::AutoLock mutex(s_lock);
27     getX11Api()->XSync((Display*)dpy, False);
28     s_lastErrorCode = 0;
29     m_oldErrorHandler = getX11Api()->XSetErrorHandler(errorHandlerProc);
30 }
31 
~X11ErrorHandler()32 X11ErrorHandler::~X11ErrorHandler() {
33     android::base::AutoLock mutex(s_lock);
34     getX11Api()->XSync((Display*)m_dpy, False);
35     getX11Api()->XSetErrorHandler(m_oldErrorHandler);
36     s_lastErrorCode = 0;
37 }
38 
39 // static
errorHandlerProc(Display * dpy,XErrorEvent * event)40 int X11ErrorHandler::errorHandlerProc(Display* dpy, XErrorEvent* event) {
41     s_lastErrorCode = event->error_code;
42     return 0;
43 }
44