src/hbcore/image/hbeglstate.cpp
changeset 0 16d8024aca5e
child 1 f7ac710697a9
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbCore module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include "hbeglstate_p.h"
       
    27 #include <QMutexLocker>
       
    28 
       
    29 Q_GLOBAL_STATIC(HbEglStates, instance)
       
    30 
       
    31 HbEglStates::HbEglStates( EGLDisplay d,
       
    32                           EGLSurface rs,
       
    33                           EGLSurface ds,
       
    34                           EGLContext  c,
       
    35                           EGLConfig cfg )
       
    36         : refCount(0),
       
    37         init(0),
       
    38         background(0)
       
    39 {
       
    40     fgWatcher = HbForegroundWatcher::instance();
       
    41     connect(fgWatcher, SIGNAL(foregroundLost()),
       
    42             SLOT(handleForegroundLost()));
       
    43     set(d, rs, ds, c, cfg);
       
    44 }
       
    45 
       
    46 HbEglStates::HbEglStates()
       
    47         : refCount(0),
       
    48         init(0),
       
    49         background(0)
       
    50 {
       
    51     fgWatcher = HbForegroundWatcher::instance();
       
    52     connect(fgWatcher, SIGNAL(foregroundLost()),
       
    53             SLOT(handleForegroundLost()));
       
    54     reset();
       
    55 }
       
    56 
       
    57 void HbEglStates::handleForegroundLost()
       
    58 {
       
    59     reset();
       
    60     background = 1;
       
    61     init = 0;
       
    62     HbNVGEnginePool::instance()->resetNVGEngine();
       
    63     clearImages();
       
    64 }
       
    65 
       
    66 void HbEglStates::handleForegroundGained()
       
    67 {
       
    68     background = 0;
       
    69 }
       
    70 
       
    71 void HbEglStates::clearImages()
       
    72 {
       
    73     if (!imageList.empty()) {
       
    74         QMutexLocker locker(&mutex);
       
    75         ImageListIter iter = imageList.begin();
       
    76         for (; iter != imageList.end(); ++iter) {
       
    77             VGImage * imgPtr = *iter;
       
    78             if (*imgPtr) {
       
    79                 vgDestroyImage(*imgPtr);
       
    80                 *imgPtr = 0;
       
    81             }
       
    82         }
       
    83         imageList.clear();
       
    84     }
       
    85 }
       
    86 
       
    87 void HbEglStates::reset( EGLDisplay d,
       
    88                          EGLSurface rs,
       
    89                          EGLSurface ds,
       
    90                          EGLContext  c,
       
    91                          EGLConfig cfg )
       
    92 {
       
    93     display = d;
       
    94     currentReadSurface = rs;
       
    95     currentWriteSurface = ds;
       
    96     eglContext = c;
       
    97     eglConfig = cfg;
       
    98 }
       
    99 
       
   100 void HbEglStateRestorer::restore()
       
   101 {
       
   102     if (restored) {
       
   103         return;
       
   104     }
       
   105     if (eglContext != EGL_NO_CONTEXT && currentWriteSurface != EGL_NO_SURFACE) {
       
   106         if (eglMakeCurrent(display, currentWriteSurface,
       
   107                            currentReadSurface, eglContext) == EGL_FALSE) {
       
   108 
       
   109         } else {
       
   110             restored = 1;
       
   111         }
       
   112     }
       
   113 }
       
   114 
       
   115 void HbEglStates::removeVGImage( VGImage * image )
       
   116 {
       
   117     QMutexLocker locker(&mutex);
       
   118     if (imageList.contains(image)) {
       
   119         if (*image) {
       
   120             vgDestroyImage(*image);
       
   121             *image = 0;
       
   122         }
       
   123         imageList.remove(image);
       
   124     }
       
   125 }
       
   126 
       
   127 HbEglStates * HbEglStates::global()
       
   128 {
       
   129     return instance();
       
   130 }