PageRenderTime 213ms CodeModel.GetById 111ms app.highlight 3ms RepoModel.GetById 97ms app.codeStats 0ms

/opengles/src/linux-ftk/ContextLinux.cpp

http://ftk.googlecode.com/
C++ | 74 lines | 25 code | 11 blank | 38 comment | 6 complexity | 8057c2efd2e6bac004fe1822e18f2caa MD5 | raw file
 1// ==========================================================================
 2//
 3// context.cpp	Rendering Context Class for 3D Rendering Library
 4//
 5// --------------------------------------------------------------------------
 6//
 7// 08-07-2003	Hans-Martin Will	initial version
 8//
 9// --------------------------------------------------------------------------
10//
11// Copyright (c) 2004, Hans-Martin Will. All rights reserved.
12// 
13// Redistribution and use in source and binary forms, with or without 
14// modification, are permitted provided that the following conditions are 
15// met:
16// 
17//	 *  Redistributions of source code must retain the above copyright
18// 		notice, this list of conditions and the following disclaimer. 
19//   *	Redistributions in binary form must reproduce the above copyright
20// 		notice, this list of conditions and the following disclaimer in the 
21// 		documentation and/or other materials provided with the distribution. 
22// 
23// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
25// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
26// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
27// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
28// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
29// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
31// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
32// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
33// THE POSSIBILITY OF SUCH DAMAGE.
34//
35// ==========================================================================
36
37
38#include "stdafx.h"
39#include "Context.h"
40#include "Surface.h"
41#include "Rasterizer.h"
42#include <pthread.h>
43
44using namespace EGL;
45
46extern pthread_key_t s_TlsIndexContext;
47
48// --------------------------------------------------------------------------
49// Context Management
50// --------------------------------------------------------------------------
51void Context :: SetCurrentContext(Context * context) 
52{
53    Context * oldContext = GetCurrentContext();
54
55    if (oldContext != context) 
56    {
57        if (oldContext != 0) 
58            oldContext->SetCurrent(false);
59        
60        pthread_setspecific(s_TlsIndexContext, 
61                            reinterpret_cast<void *>(context));
62
63        if (context != 0)
64            context->SetCurrent(true);
65    }
66}
67
68
69Context * Context :: GetCurrentContext() 
70{
71    return reinterpret_cast<EGLContext> (
72        pthread_getspecific(s_TlsIndexContext));
73}
74