LCOV - code coverage report
Current view: directory - gfx/src - X11Util.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 38 0 0.0 %
Date: 2012-06-02 Functions: 6 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2                 :  * vim: sw=2 ts=8 et :
       3                 :  */
       4                 : /* ***** BEGIN LICENSE BLOCK *****
       5                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       6                 :  *
       7                 :  * The contents of this file are subject to the Mozilla Public License Version
       8                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       9                 :  * the License. You may obtain a copy of the License at:
      10                 :  * http://www.mozilla.org/MPL/
      11                 :  *
      12                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      13                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      14                 :  * for the specific language governing rights and limitations under the
      15                 :  * License.
      16                 :  *
      17                 :  * The Original Code is Mozilla Code.
      18                 :  *
      19                 :  * The Initial Developer of the Original Code is
      20                 :  *   The Mozilla Foundation
      21                 :  * Portions created by the Initial Developer are Copyright (C) 2010
      22                 :  * the Initial Developer. All Rights Reserved.
      23                 :  *
      24                 :  * Contributor(s):
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      28                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #include "X11Util.h"
      41                 : 
      42                 : namespace mozilla {
      43                 : 
      44                 : bool
      45               0 : XVisualIDToInfo(Display* aDisplay, VisualID aVisualID,
      46                 :                 Visual** aVisual, unsigned int* aDepth)
      47                 : {
      48               0 :     if (aVisualID == None) {
      49               0 :         *aVisual = NULL;
      50               0 :         *aDepth = 0;
      51               0 :         return true;
      52                 :     }
      53                 : 
      54               0 :     const Screen* screen = DefaultScreenOfDisplay(aDisplay);
      55                 : 
      56               0 :     for (int d = 0; d < screen->ndepths; d++) {
      57               0 :         Depth *d_info = &screen->depths[d];
      58               0 :         for (int v = 0; v < d_info->nvisuals; v++) {
      59               0 :             Visual* visual = &d_info->visuals[v];
      60               0 :             if (visual->visualid == aVisualID) {
      61               0 :                 *aVisual = visual;
      62               0 :                 *aDepth = d_info->depth;
      63               0 :                 return true;
      64                 :             }
      65                 :         }
      66                 :     }
      67                 : 
      68               0 :     NS_ERROR("VisualID not on Screen.");
      69               0 :     return false;
      70                 : }
      71                 : 
      72                 : ScopedXErrorHandler::ErrorEvent* ScopedXErrorHandler::sXErrorPtr;
      73                 : 
      74                 : int
      75               0 : ScopedXErrorHandler::ErrorHandler(Display *, XErrorEvent *ev)
      76                 : {
      77                 :     // only record the error if no error was previously recorded.
      78                 :     // this means that in case of multiple errors, it's the first error that we report.
      79               0 :     if (!sXErrorPtr->mError.error_code)
      80               0 :       sXErrorPtr->mError = *ev;
      81               0 :     return 0;
      82                 : }
      83                 : 
      84               0 : ScopedXErrorHandler::ScopedXErrorHandler()
      85                 : {
      86                 :     // let sXErrorPtr point to this object's mXError object, but don't reset this mXError object!
      87                 :     // think of the case of nested ScopedXErrorHandler's.
      88               0 :     mOldXErrorPtr = sXErrorPtr;
      89               0 :     sXErrorPtr = &mXError;
      90               0 :     mOldErrorHandler = XSetErrorHandler(ErrorHandler);
      91               0 : }
      92                 : 
      93               0 : ScopedXErrorHandler::~ScopedXErrorHandler()
      94                 : {
      95               0 :     sXErrorPtr = mOldXErrorPtr;
      96               0 :     XSetErrorHandler(mOldErrorHandler);
      97               0 : }
      98                 : 
      99                 : bool
     100               0 : ScopedXErrorHandler::SyncAndGetError(Display *dpy, XErrorEvent *ev)
     101                 : {
     102               0 :     XSync(dpy, False);
     103               0 :     return GetError(ev);
     104                 : }
     105                 : 
     106                 : bool
     107               0 : ScopedXErrorHandler::GetError(XErrorEvent *ev)
     108                 : {
     109               0 :     bool retval = mXError.mError.error_code != 0;
     110               0 :     if (ev)
     111               0 :         *ev = mXError.mError;
     112               0 :     mXError = ErrorEvent(); // reset
     113               0 :     return retval;
     114                 : }
     115                 : 
     116                 : } // namespace mozilla

Generated by: LCOV version 1.7