hostsupport/hostegl/src/EGLProcess.cpp
branchbug235_bringup_0
changeset 53 c2ef9095503a
child 56 40cc73c24bf8
equal deleted inserted replaced
52:39e5f73667ba 53:c2ef9095503a
       
     1 /* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2  *
       
     3  * Permission is hereby granted, free of charge, to any person obtaining a
       
     4  * copy of this software and /or associated documentation files
       
     5  * (the "Materials "), to deal in the Materials without restriction,
       
     6  * including without limitation the rights to use, copy, modify, merge,
       
     7  * publish, distribute, sublicense, and/or sell copies of the Materials,
       
     8  * and to permit persons to whom the Materials are furnished to do so,
       
     9  * subject to the following conditions:
       
    10  *
       
    11  * The above copyright notice and this permission notice shall be included
       
    12  * in all copies or substantial portions of the Materials.
       
    13  *
       
    14  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
       
    15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
       
    16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
       
    17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
       
    18  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
       
    19  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
       
    20  * THE USE OR OTHER DEALINGS IN THE MATERIALS.
       
    21  *
       
    22  * Initial Contributors:
       
    23  * Nokia Corporation - initial contribution.
       
    24  *
       
    25  * Contributors:
       
    26  *
       
    27  * Description:
       
    28  *
       
    29  */
       
    30 
       
    31 #include "EGLProcess.h"
       
    32 #include "EGLThread.h"
       
    33 #include "eglInternal.h"
       
    34 
       
    35 CEGLProcess::CEGLProcess( EGLint processId ) :
       
    36     m_id( processId ),
       
    37     m_currentThread( NULL )
       
    38     {
       
    39     }
       
    40 
       
    41 CEGLProcess::~CEGLProcess(void)
       
    42     {
       
    43     DestroyPointerVector<CEGLThread>(m_threads);
       
    44     }
       
    45 
       
    46 CEGLThread* CEGLProcess::AddThread( EGLI_THREAD_ID threadId, bool setCurrent, EGLint supportedApis )
       
    47     {
       
    48     CEGLThread* thread = HasThread( threadId );
       
    49     if( !thread )
       
    50         {
       
    51         thread = EGLI_NEW CEGLThread( threadId, supportedApis );
       
    52         if( thread )
       
    53             {
       
    54             AddObject<CEGLThread>( m_threads, thread );
       
    55             }
       
    56         }    
       
    57     if( setCurrent && thread )
       
    58         {
       
    59         m_currentThread = thread;
       
    60         }
       
    61     return thread;
       
    62     }
       
    63 
       
    64 void CEGLProcess::RemoveThread( EGLI_THREAD_ID threadId )
       
    65     {
       
    66     if( m_currentThread && m_currentThread->Id() == threadId )
       
    67         {
       
    68         m_currentThread = NULL;
       
    69         }
       
    70     DeleteObjectById<CEGLThread>( m_threads, threadId );
       
    71     }
       
    72 
       
    73 CEGLThread* CEGLProcess::HasThread( EGLI_THREAD_ID threadId ) const
       
    74     {
       
    75     return FindObjectById<CEGLThread>( m_threads, threadId, NULL );
       
    76     }
       
    77 
       
    78 void CEGLProcess::SetCurrentThread( EGLI_THREAD_ID threadId )
       
    79     {
       
    80 #if defined(EGLI_USE_PLATSIM_EXTENSIONS)
       
    81     EGLI_ASSERT(m_currentThread != NULL);
       
    82     if( m_currentThread->Id() != threadId )
       
    83         {
       
    84         m_currentThread = FindObjectById<CEGLThread>( m_threads, threadId, NULL );
       
    85         EGLI_ASSERT( m_currentThread != NULL );
       
    86         }
       
    87 #else
       
    88     EGLI_ASSERT( false );
       
    89 #endif
       
    90     }
       
    91 
       
    92 CEGLThread* CEGLProcess::CurrentThread() const
       
    93     { 
       
    94 #if defined(EGLI_USE_PLATSIM_EXTENSIONS)
       
    95     EGLI_ASSERT( m_currentThread != NULL );
       
    96     return m_currentThread;
       
    97 #elif defined(_WIN32)
       
    98     EGLI_THREAD_ID threadId = GetCurrentThreadId();
       
    99     CEGLThread* thread = FindObjectById( m_threads, threadId, NULL );
       
   100     //EGLI_ASSERT( thread != NULL );
       
   101     return thread;
       
   102 #else // Linux
       
   103     // \todo
       
   104 #endif
       
   105     }
       
   106 
       
   107 CEGLSurface* CEGLProcess::FindBoundSurface( CEGLContext* context, bool readSurface ) const
       
   108      {
       
   109      EGLI_ASSERT( context != NULL );
       
   110      CEGLSurface* ret = NULL;         
       
   111      std::vector<CEGLThread*>::const_iterator iter = m_threads.begin();
       
   112      while( iter != m_threads.end() )
       
   113          {
       
   114          if( (*iter)->CurrentVGContext() == context )
       
   115              {
       
   116              ret = (*iter)->CurrentVGSurface();
       
   117              break;
       
   118              }
       
   119          else if( (*iter)->CurrentGLESContext() == context )
       
   120              {
       
   121              //TODO
       
   122              EGLI_ASSERT( false );
       
   123              }
       
   124          }
       
   125      return ret;
       
   126      }
       
   127 
       
   128