Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #include "precompiled.h" |
michael@0 | 2 | // |
michael@0 | 3 | // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. |
michael@0 | 4 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | // found in the LICENSE file. |
michael@0 | 6 | // |
michael@0 | 7 | |
michael@0 | 8 | // main.cpp: DLL entry point and management of thread-local data. |
michael@0 | 9 | |
michael@0 | 10 | #include "libGLESv2/main.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "libGLESv2/Context.h" |
michael@0 | 13 | |
michael@0 | 14 | static DWORD currentTLS = TLS_OUT_OF_INDEXES; |
michael@0 | 15 | |
michael@0 | 16 | extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) |
michael@0 | 17 | { |
michael@0 | 18 | switch (reason) |
michael@0 | 19 | { |
michael@0 | 20 | case DLL_PROCESS_ATTACH: |
michael@0 | 21 | { |
michael@0 | 22 | currentTLS = TlsAlloc(); |
michael@0 | 23 | |
michael@0 | 24 | if (currentTLS == TLS_OUT_OF_INDEXES) |
michael@0 | 25 | { |
michael@0 | 26 | return FALSE; |
michael@0 | 27 | } |
michael@0 | 28 | } |
michael@0 | 29 | // Fall throught to initialize index |
michael@0 | 30 | case DLL_THREAD_ATTACH: |
michael@0 | 31 | { |
michael@0 | 32 | gl::Current *current = (gl::Current*)LocalAlloc(LPTR, sizeof(gl::Current)); |
michael@0 | 33 | |
michael@0 | 34 | if (current) |
michael@0 | 35 | { |
michael@0 | 36 | TlsSetValue(currentTLS, current); |
michael@0 | 37 | |
michael@0 | 38 | current->context = NULL; |
michael@0 | 39 | current->display = NULL; |
michael@0 | 40 | } |
michael@0 | 41 | } |
michael@0 | 42 | break; |
michael@0 | 43 | case DLL_THREAD_DETACH: |
michael@0 | 44 | { |
michael@0 | 45 | void *current = TlsGetValue(currentTLS); |
michael@0 | 46 | |
michael@0 | 47 | if (current) |
michael@0 | 48 | { |
michael@0 | 49 | LocalFree((HLOCAL)current); |
michael@0 | 50 | } |
michael@0 | 51 | } |
michael@0 | 52 | break; |
michael@0 | 53 | case DLL_PROCESS_DETACH: |
michael@0 | 54 | { |
michael@0 | 55 | void *current = TlsGetValue(currentTLS); |
michael@0 | 56 | |
michael@0 | 57 | if (current) |
michael@0 | 58 | { |
michael@0 | 59 | LocalFree((HLOCAL)current); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | TlsFree(currentTLS); |
michael@0 | 63 | } |
michael@0 | 64 | break; |
michael@0 | 65 | default: |
michael@0 | 66 | break; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | return TRUE; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | namespace gl |
michael@0 | 73 | { |
michael@0 | 74 | void makeCurrent(Context *context, egl::Display *display, egl::Surface *surface) |
michael@0 | 75 | { |
michael@0 | 76 | Current *current = (Current*)TlsGetValue(currentTLS); |
michael@0 | 77 | |
michael@0 | 78 | current->context = context; |
michael@0 | 79 | current->display = display; |
michael@0 | 80 | |
michael@0 | 81 | if (context && display && surface) |
michael@0 | 82 | { |
michael@0 | 83 | context->makeCurrent(surface); |
michael@0 | 84 | } |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | Context *getContext() |
michael@0 | 88 | { |
michael@0 | 89 | Current *current = (Current*)TlsGetValue(currentTLS); |
michael@0 | 90 | |
michael@0 | 91 | return current->context; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | Context *getNonLostContext() |
michael@0 | 95 | { |
michael@0 | 96 | Context *context = getContext(); |
michael@0 | 97 | |
michael@0 | 98 | if (context) |
michael@0 | 99 | { |
michael@0 | 100 | if (context->isContextLost()) |
michael@0 | 101 | { |
michael@0 | 102 | gl::error(GL_OUT_OF_MEMORY); |
michael@0 | 103 | return NULL; |
michael@0 | 104 | } |
michael@0 | 105 | else |
michael@0 | 106 | { |
michael@0 | 107 | return context; |
michael@0 | 108 | } |
michael@0 | 109 | } |
michael@0 | 110 | return NULL; |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | egl::Display *getDisplay() |
michael@0 | 114 | { |
michael@0 | 115 | Current *current = (Current*)TlsGetValue(currentTLS); |
michael@0 | 116 | |
michael@0 | 117 | return current->display; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | // Records an error code |
michael@0 | 121 | void error(GLenum errorCode) |
michael@0 | 122 | { |
michael@0 | 123 | gl::Context *context = glGetCurrentContext(); |
michael@0 | 124 | |
michael@0 | 125 | if (context) |
michael@0 | 126 | { |
michael@0 | 127 | switch (errorCode) |
michael@0 | 128 | { |
michael@0 | 129 | case GL_INVALID_ENUM: |
michael@0 | 130 | context->recordInvalidEnum(); |
michael@0 | 131 | TRACE("\t! Error generated: invalid enum\n"); |
michael@0 | 132 | break; |
michael@0 | 133 | case GL_INVALID_VALUE: |
michael@0 | 134 | context->recordInvalidValue(); |
michael@0 | 135 | TRACE("\t! Error generated: invalid value\n"); |
michael@0 | 136 | break; |
michael@0 | 137 | case GL_INVALID_OPERATION: |
michael@0 | 138 | context->recordInvalidOperation(); |
michael@0 | 139 | TRACE("\t! Error generated: invalid operation\n"); |
michael@0 | 140 | break; |
michael@0 | 141 | case GL_OUT_OF_MEMORY: |
michael@0 | 142 | context->recordOutOfMemory(); |
michael@0 | 143 | TRACE("\t! Error generated: out of memory\n"); |
michael@0 | 144 | break; |
michael@0 | 145 | case GL_INVALID_FRAMEBUFFER_OPERATION: |
michael@0 | 146 | context->recordInvalidFramebufferOperation(); |
michael@0 | 147 | TRACE("\t! Error generated: invalid framebuffer operation\n"); |
michael@0 | 148 | break; |
michael@0 | 149 | default: UNREACHABLE(); |
michael@0 | 150 | } |
michael@0 | 151 | } |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | } |
michael@0 | 155 |