daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // main.cpp: DLL entry point and management of thread-local data. |
| 8 | |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 9 | #include "libGLESv2/main.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 10 | |
alokp@chromium.org | ea0e1af | 2010-03-22 19:33:14 +0000 | [diff] [blame] | 11 | #include "common/debug.h" |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 12 | #include "libEGL/Surface.h" |
| 13 | |
| 14 | #include "libGLESv2/Framebuffer.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 15 | |
| 16 | static DWORD currentTLS = TLS_OUT_OF_INDEXES; |
| 17 | |
| 18 | BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) |
| 19 | { |
| 20 | switch (reason) |
| 21 | { |
| 22 | case DLL_PROCESS_ATTACH: |
| 23 | { |
| 24 | currentTLS = TlsAlloc(); |
| 25 | |
| 26 | if (currentTLS == TLS_OUT_OF_INDEXES) |
| 27 | { |
| 28 | return FALSE; |
| 29 | } |
| 30 | } |
| 31 | // Fall throught to initialize index |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 32 | case DLL_THREAD_ATTACH: |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 33 | { |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 34 | gl::Current *current = (gl::Current*)LocalAlloc(LPTR, sizeof(gl::Current)); |
| 35 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 36 | if (current) |
| 37 | { |
| 38 | TlsSetValue(currentTLS, current); |
| 39 | |
| 40 | current->context = NULL; |
| 41 | current->display = NULL; |
| 42 | } |
| 43 | } |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 44 | break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 45 | case DLL_THREAD_DETACH: |
| 46 | { |
| 47 | void *current = TlsGetValue(currentTLS); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 48 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 49 | if (current) |
| 50 | { |
| 51 | LocalFree((HLOCAL)current); |
| 52 | } |
| 53 | } |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 54 | break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 55 | case DLL_PROCESS_DETACH: |
| 56 | { |
| 57 | void *current = TlsGetValue(currentTLS); |
| 58 | |
| 59 | if (current) |
| 60 | { |
| 61 | LocalFree((HLOCAL)current); |
| 62 | } |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 63 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 64 | TlsFree(currentTLS); |
| 65 | } |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 66 | break; |
| 67 | default: |
| 68 | break; |
| 69 | } |
| 70 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 71 | return TRUE; |
| 72 | } |
| 73 | |
| 74 | namespace gl |
| 75 | { |
| 76 | void makeCurrent(Context *context, egl::Display *display, egl::Surface *surface) |
| 77 | { |
| 78 | Current *current = (Current*)TlsGetValue(currentTLS); |
| 79 | |
| 80 | current->context = context; |
| 81 | current->display = display; |
| 82 | |
| 83 | if (context && display && surface) |
| 84 | { |
| 85 | context->makeCurrent(display, surface); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | Context *getContext() |
| 90 | { |
| 91 | Current *current = (Current*)TlsGetValue(currentTLS); |
| 92 | |
| 93 | return current->context; |
| 94 | } |
| 95 | |
daniel@transgaming.com | ae072af | 2010-05-05 18:47:28 +0000 | [diff] [blame] | 96 | egl::Display *getDisplay() |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 97 | { |
| 98 | Current *current = (Current*)TlsGetValue(currentTLS); |
daniel@transgaming.com | ae072af | 2010-05-05 18:47:28 +0000 | [diff] [blame] | 99 | |
| 100 | return current->display; |
| 101 | } |
| 102 | |
| 103 | IDirect3DDevice9 *getDevice() |
| 104 | { |
| 105 | egl::Display *display = getDisplay(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 106 | |
| 107 | return display->getDevice(); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | // Records an error code |
| 112 | void error(GLenum errorCode) |
| 113 | { |
| 114 | gl::Context *context = glGetCurrentContext(); |
| 115 | |
| 116 | if (context) |
| 117 | { |
| 118 | switch (errorCode) |
| 119 | { |
| 120 | case GL_INVALID_ENUM: |
| 121 | context->recordInvalidEnum(); |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame^] | 122 | TRACE("\t! Error generated: invalid enum\n"); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 123 | break; |
| 124 | case GL_INVALID_VALUE: |
| 125 | context->recordInvalidValue(); |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame^] | 126 | TRACE("\t! Error generated: invalid value\n"); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 127 | break; |
| 128 | case GL_INVALID_OPERATION: |
| 129 | context->recordInvalidOperation(); |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame^] | 130 | TRACE("\t! Error generated: invalid operation\n"); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 131 | break; |
| 132 | case GL_OUT_OF_MEMORY: |
| 133 | context->recordOutOfMemory(); |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame^] | 134 | TRACE("\t! Error generated: out of memory\n"); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 135 | break; |
| 136 | case GL_INVALID_FRAMEBUFFER_OPERATION: |
| 137 | context->recordInvalidFramebufferOperation(); |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame^] | 138 | TRACE("\t! Error generated: invalid framebuffer operation\n"); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 139 | break; |
| 140 | default: UNREACHABLE(); |
| 141 | } |
| 142 | } |
| 143 | } |