/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. #include "stdafx.h"
  37. #include "Context.h"
  38. #include "Surface.h"
  39. #include "Rasterizer.h"
  40. #include <pthread.h>
  41. using namespace EGL;
  42. extern pthread_key_t s_TlsIndexContext;
  43. // --------------------------------------------------------------------------
  44. // Context Management
  45. // --------------------------------------------------------------------------
  46. void Context :: SetCurrentContext(Context * context)
  47. {
  48. Context * oldContext = GetCurrentContext();
  49. if (oldContext != context)
  50. {
  51. if (oldContext != 0)
  52. oldContext->SetCurrent(false);
  53. pthread_setspecific(s_TlsIndexContext,
  54. reinterpret_cast<void *>(context));
  55. if (context != 0)
  56. context->SetCurrent(true);
  57. }
  58. }
  59. Context * Context :: GetCurrentContext()
  60. {
  61. return reinterpret_cast<EGLContext> (
  62. pthread_getspecific(s_TlsIndexContext));
  63. }