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)24X11ErrorHandler::X11ErrorHandler(EGLNativeDisplayType dpy) { 25 android::base::AutoLock mutex(s_lock); 26 getX11Api()->XSync(dpy,False); 27 s_lastErrorCode = 0; 28 m_oldErrorHandler = getX11Api()->XSetErrorHandler(errorHandlerProc); 29 } 30 ~X11ErrorHandler()31X11ErrorHandler::~X11ErrorHandler() { 32 android::base::AutoLock mutex(s_lock); 33 getX11Api()->XSetErrorHandler(m_oldErrorHandler); 34 s_lastErrorCode = 0; 35 } 36 37 // static errorHandlerProc(EGLNativeDisplayType dpy,XErrorEvent * event)38int X11ErrorHandler::errorHandlerProc(EGLNativeDisplayType dpy, 39 XErrorEvent* event) { 40 s_lastErrorCode = event->error_code; 41 return 0; 42 } 43