| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "gl/GrGLInterface.h" | 9 #include "gl/GrGLInterface.h" |
| 10 #include "gl/GrGLAssembleInterface.h" | 10 #include "gl/GrGLAssembleInterface.h" |
| 11 #include "gl/GrGLUtil.h" | 11 #include "gl/GrGLUtil.h" |
| 12 #define WIN32_LEAN_AND_MEAN | 12 #define WIN32_LEAN_AND_MEAN |
| 13 #include <windows.h> | 13 #include <windows.h> |
| 14 | 14 |
| 15 class AutoLibraryUnload { | 15 class AutoLibraryUnload { |
| 16 public: | 16 public: |
| 17 AutoLibraryUnload(const char* moduleName) { | 17 AutoLibraryUnload(const char* moduleName) { |
| 18 fModule = LoadLibrary(moduleName); | 18 fModule = LoadLibrary(moduleName); |
| 19 } | 19 } |
| 20 ~AutoLibraryUnload() { | 20 ~AutoLibraryUnload() { |
| 21 if (NULL != fModule) { | 21 if (fModule) { |
| 22 FreeLibrary(fModule); | 22 FreeLibrary(fModule); |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 HMODULE get() const { return fModule; } | 25 HMODULE get() const { return fModule; } |
| 26 | 26 |
| 27 private: | 27 private: |
| 28 HMODULE fModule; | 28 HMODULE fModule; |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 class GLProcGetter { | 31 class GLProcGetter { |
| 32 public: | 32 public: |
| 33 GLProcGetter() : fGLLib("opengl32.dll") {} | 33 GLProcGetter() : fGLLib("opengl32.dll") {} |
| 34 | 34 |
| 35 bool isInitialized() const { return NULL != fGLLib.get(); } | 35 bool isInitialized() const { return SkToBool(fGLLib.get()); } |
| 36 | 36 |
| 37 GrGLFuncPtr getProc(const char name[]) const { | 37 GrGLFuncPtr getProc(const char name[]) const { |
| 38 GrGLFuncPtr proc; | 38 GrGLFuncPtr proc; |
| 39 if (NULL != (proc = (GrGLFuncPtr) GetProcAddress(fGLLib.get(), name))) { | 39 if ((proc = (GrGLFuncPtr) GetProcAddress(fGLLib.get(), name))) { |
| 40 return proc; | 40 return proc; |
| 41 } | 41 } |
| 42 if (NULL != (proc = (GrGLFuncPtr) wglGetProcAddress(name))) { | 42 if ((proc = (GrGLFuncPtr) wglGetProcAddress(name))) { |
| 43 return proc; | 43 return proc; |
| 44 } | 44 } |
| 45 return NULL; | 45 return NULL; |
| 46 } | 46 } |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 AutoLibraryUnload fGLLib; | 49 AutoLibraryUnload fGLLib; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 static GrGLFuncPtr win_get_gl_proc(void* ctx, const char name[]) { | 52 static GrGLFuncPtr win_get_gl_proc(void* ctx, const char name[]) { |
| 53 SkASSERT(NULL != ctx); | 53 SkASSERT(ctx); |
| 54 SkASSERT(NULL != wglGetCurrentContext()); | 54 SkASSERT(wglGetCurrentContext()); |
| 55 const GLProcGetter* getter = (const GLProcGetter*) ctx; | 55 const GLProcGetter* getter = (const GLProcGetter*) ctx; |
| 56 return getter->getProc(name); | 56 return getter->getProc(name); |
| 57 } | 57 } |
| 58 | 58 |
| 59 /* | 59 /* |
| 60 * Windows makes the GL funcs all be __stdcall instead of __cdecl :( | 60 * Windows makes the GL funcs all be __stdcall instead of __cdecl :( |
| 61 * This implementation will only work if GR_GL_FUNCTION_TYPE is __stdcall. | 61 * This implementation will only work if GR_GL_FUNCTION_TYPE is __stdcall. |
| 62 * Otherwise, a springboard would be needed that hides the calling convention. | 62 * Otherwise, a springboard would be needed that hides the calling convention. |
| 63 */ | 63 */ |
| 64 const GrGLInterface* GrGLCreateNativeInterface() { | 64 const GrGLInterface* GrGLCreateNativeInterface() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 78 const char* verStr = reinterpret_cast<const char*>(getString(GR_GL_VERSION))
; | 78 const char* verStr = reinterpret_cast<const char*>(getString(GR_GL_VERSION))
; |
| 79 GrGLStandard standard = GrGLGetStandardInUseFromString(verStr); | 79 GrGLStandard standard = GrGLGetStandardInUseFromString(verStr); |
| 80 | 80 |
| 81 if (kGLES_GrGLStandard == standard) { | 81 if (kGLES_GrGLStandard == standard) { |
| 82 return GrGLAssembleGLESInterface(&getter, win_get_gl_proc); | 82 return GrGLAssembleGLESInterface(&getter, win_get_gl_proc); |
| 83 } else if (kGL_GrGLStandard == standard) { | 83 } else if (kGL_GrGLStandard == standard) { |
| 84 return GrGLAssembleGLInterface(&getter, win_get_gl_proc); | 84 return GrGLAssembleGLInterface(&getter, win_get_gl_proc); |
| 85 } | 85 } |
| 86 return NULL; | 86 return NULL; |
| 87 } | 87 } |
| OLD | NEW |