3 * Copyright 2011 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
9 #include "gl/GrGLInterface.h"
10 #include "gl/GrGLAssembleInterface.h"
11 #define WIN32_LEAN_AND_MEAN
14 class AutoLibraryUnload {
16 AutoLibraryUnload(const char* moduleName) {
17 fModule = LoadLibrary(moduleName);
19 ~AutoLibraryUnload() {
20 if (NULL != fModule) {
24 HMODULE get() const { return fModule; }
32 GLProcGetter() : fGLLib("opengl32.dll") {}
34 bool isInitialized() const { return NULL != fGLLib.get(); }
36 GrGLFuncPtr getProc(const char name[]) const {
38 if (NULL != (proc = (GrGLFuncPtr) GetProcAddress(fGLLib.get(), name))) {
41 if (NULL != (proc = (GrGLFuncPtr) wglGetProcAddress(name))) {
48 AutoLibraryUnload fGLLib;
51 static GrGLFuncPtr win_get_gl_proc(void* ctx, const char name[]) {
52 SkASSERT(NULL != ctx);
53 SkASSERT(NULL != wglGetCurrentContext());
54 const GLProcGetter* getter = (const GLProcGetter*) ctx;
55 return getter->getProc(name);
59 * Windows makes the GL funcs all be __stdcall instead of __cdecl :(
60 * This implementation will only work if GR_GL_FUNCTION_TYPE is __stdcall.
61 * Otherwise, a springboard would be needed that hides the calling convention.
63 const GrGLInterface* GrGLCreateNativeInterface() {
64 if (NULL == wglGetCurrentContext()) {
69 if (!getter.isInitialized()) {
73 return GrGLAssembleGLInterface(&getter, win_get_gl_proc);