holdingarea/libEGL/src/EGLThread.cpp
author Faisal Memon <faisal.memon@nokia.com>
Fri, 22 Oct 2010 10:54:17 +0100
branchbug235_bringup_0
changeset 60 dfe4593146ee
parent 24 a3f46bb01be2
permissions -rw-r--r--
Fix guestegl to actually supply the params for eglMakeCurrent
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
     1
/* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
     2
 *
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
     3
 * Permission is hereby granted, free of charge, to any person obtaining a
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
     4
 * copy of this software and /or associated documentation files
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
     5
 * (the "Materials "), to deal in the Materials without restriction,
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
     6
 * including without limitation the rights to use, copy, modify, merge,
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
     7
 * publish, distribute, sublicense, and/or sell copies of the Materials,
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
     8
 * and to permit persons to whom the Materials are furnished to do so,
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
     9
 * subject to the following conditions:
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    10
 *
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    11
 * The above copyright notice and this permission notice shall be included
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    12
 * in all copies or substantial portions of the Materials.
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    13
 *
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    14
 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    15
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    16
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    17
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    18
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    19
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    20
 * THE USE OR OTHER DEALINGS IN THE MATERIALS.
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    21
 *
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    22
 * Initial Contributors:
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    23
 * Nokia Corporation - initial contribution.
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    24
 *
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    25
 * Contributors:
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    26
 *
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    27
 * Description:
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    28
 *
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    29
 */
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    30
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    31
#include "EGLThread.h"
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    32
#include "EGLContext.h"
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    33
#include "EGLSurface.h"
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    34
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    35
CEGLThread::CEGLThread( EGLI_THREAD_ID threadId, EGLint supportedApis ) :
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    36
    m_id( threadId ),
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    37
    m_currentVGContext( NULL ),
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    38
    m_currentVGSurface( NULL ),
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    39
    m_currentGLESContext( NULL ),
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    40
	m_currentGLESReadSurface( NULL ),
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    41
    m_currentGLESDrawSurface( NULL ),
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    42
    m_currentApi( EGL_OPENGL_ES_API ),
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    43
    m_lastError( EGL_SUCCESS ),
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    44
    m_supportedApis( supportedApis )
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    45
    {
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    46
    }
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    47
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    48
CEGLThread::~CEGLThread(void)
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    49
    {
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    50
    }
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    51
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    52
bool CEGLThread::IsSupportedApi( EGLenum api ) const
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    53
    {
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    54
    bool ret = false;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    55
    switch( api )
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    56
        {
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    57
        case EGL_OPENVG_API:
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    58
            {
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    59
            if( m_supportedApis & EGL_OPENVG_BIT )
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    60
                ret = true;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    61
            break;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    62
            }
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    63
        case EGL_OPENGL_ES_API:
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    64
            {
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    65
            if( m_supportedApis & EGL_OPENGL_ES_BIT ||
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    66
                m_supportedApis & EGL_OPENGL_ES2_BIT )
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    67
                ret = true;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    68
            break;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    69
            }
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    70
        }
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    71
    return ret;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    72
    }
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    73
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    74
CEGLContext* CEGLThread::SwitchVGContext( CEGLContext* vgContext )
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    75
    {
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    76
    CEGLContext* ret = m_currentVGContext;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    77
    if( vgContext != m_currentVGContext )
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    78
        {
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    79
        m_currentVGContext = vgContext;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    80
        if( vgContext ) vgContext->SetThread( this );
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    81
        if( ret ) ret->SetThread( NULL );
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    82
        }
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    83
    return ret;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    84
    }
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    85
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    86
CEGLSurface* CEGLThread::SwitchVGSurface( CEGLSurface* vgSurface )
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    87
    {
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    88
    CEGLSurface* ret = m_currentVGSurface;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    89
    if( vgSurface != m_currentVGSurface )
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    90
        {
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    91
        m_currentVGSurface = vgSurface;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    92
        if( vgSurface ) vgSurface->SetThread( this );
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    93
        if( ret ) ret->SetThread( NULL );
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    94
        }
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    95
    return ret;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    96
    }
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    97
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    98
CEGLContext* CEGLThread::SwitchGLESContext( CEGLContext* glesContext )
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
    99
    {
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   100
    CEGLContext* ret = m_currentGLESContext;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   101
    if( glesContext != m_currentGLESContext )
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   102
        {
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   103
        m_currentGLESContext = glesContext;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   104
        if( glesContext ) glesContext->SetThread( this );
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   105
        if( ret ) ret->SetThread( NULL );
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   106
        }
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   107
    return ret;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   108
    }
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   109
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   110
void CEGLThread::SwitchGLESSurfaces( CEGLSurface* read, CEGLSurface* draw, CEGLSurface*& previousRead, CEGLSurface*& previousDraw )
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   111
    {
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   112
    previousRead = m_currentGLESReadSurface;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   113
    previousDraw = m_currentGLESDrawSurface;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   114
    m_currentGLESReadSurface = read;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   115
    if( read ) read->SetThread( this );
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   116
    if( previousRead && previousRead != read ) previousRead->SetThread( NULL );
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   117
    m_currentGLESDrawSurface = draw;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   118
    if( draw ) draw->SetThread( this );
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   119
    if( previousDraw && previousDraw != draw ) previousDraw->SetThread( NULL );
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   120
    }
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   121
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   122
void CEGLThread::CurrentGLESSurfaces( CEGLSurface** read, CEGLSurface** draw ) const
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   123
    {
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   124
    if( read ) *read = m_currentGLESReadSurface;
a3f46bb01be2 Fix line endings
Faisal Memon <faisal.memon@nokia.com>
parents: 20
diff changeset
   125
    if( draw ) *draw = m_currentGLESDrawSurface;
20
d2d6724aef32 Initial contribution of Khronos API implmentations suitable for simulator host-side.
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff changeset
   126
    }