1f987d1b2348258970cae675135b6dedda079de48bsalomon@google.com 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc. 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7f987d1b2348258970cae675135b6dedda079de48bsalomon@google.com */ 8f987d1b2348258970cae675135b6dedda079de48bsalomon@google.com 9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 106c8c34e65ff8248ec7374e0d662d7f5684d800fatomhudson@google.com#include "gl/GrGLInterface.h" 119add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.org#include "gl/GrGLAssembleInterface.h" 12f987d1b2348258970cae675135b6dedda079de48bsalomon@google.com 1314882947f3531cddfa34101d110724b2d130551fbsalomon@google.com#include <dlfcn.h> 14beccb1eb84be583d51d109b6021258562d3e8124bsalomon@google.com 1597876d91d72bc70960db28f74e6862beb52f156fbsalomon@google.comclass GLLoader { 1697876d91d72bc70960db28f74e6862beb52f156fbsalomon@google.compublic: 1797876d91d72bc70960db28f74e6862beb52f156fbsalomon@google.com GLLoader() { 1897876d91d72bc70960db28f74e6862beb52f156fbsalomon@google.com fLibrary = dlopen( 1997876d91d72bc70960db28f74e6862beb52f156fbsalomon@google.com "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib", 2097876d91d72bc70960db28f74e6862beb52f156fbsalomon@google.com RTLD_LAZY); 2197876d91d72bc70960db28f74e6862beb52f156fbsalomon@google.com } 229add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.org 2397876d91d72bc70960db28f74e6862beb52f156fbsalomon@google.com ~GLLoader() { 2449f085dddff10473b6ebf832a974288300224e60bsalomon if (fLibrary) { 2597876d91d72bc70960db28f74e6862beb52f156fbsalomon@google.com dlclose(fLibrary); 2697876d91d72bc70960db28f74e6862beb52f156fbsalomon@google.com } 2797876d91d72bc70960db28f74e6862beb52f156fbsalomon@google.com } 289add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.org 299add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.org void* handle() const { 3097876d91d72bc70960db28f74e6862beb52f156fbsalomon@google.com return NULL == fLibrary ? RTLD_DEFAULT : fLibrary; 3197876d91d72bc70960db28f74e6862beb52f156fbsalomon@google.com } 329add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.org 3397876d91d72bc70960db28f74e6862beb52f156fbsalomon@google.comprivate: 3497876d91d72bc70960db28f74e6862beb52f156fbsalomon@google.com void* fLibrary; 3597876d91d72bc70960db28f74e6862beb52f156fbsalomon@google.com}; 3697876d91d72bc70960db28f74e6862beb52f156fbsalomon@google.com 379add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.orgclass GLProcGetter { 389add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.orgpublic: 399add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.org GLProcGetter() {} 40eeaeafebdeec2c546134b741ab8b3c6b7c5190abskia.committer@gmail.com 419add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.org GrGLFuncPtr getProc(const char name[]) const { 429add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.org return (GrGLFuncPtr) dlsym(fLoader.handle(), name); 436fb736fc2ea5f3f7ac44494211cc6755180ca192bsalomon@google.com } 4490313cc36a6f43a3e9d3818aca536cd6631c222bcommit-bot@chromium.org 459add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.orgprivate: 469add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.org GLLoader fLoader; 479add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.org}; 48a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org 499add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.orgstatic GrGLFuncPtr mac_get_gl_proc(void* ctx, const char name[]) { 5049f085dddff10473b6ebf832a974288300224e60bsalomon SkASSERT(ctx); 519add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.org const GLProcGetter* getter = (const GLProcGetter*) ctx; 529add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.org return getter->getProc(name); 539add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.org} 54a34bb60c4e319f2289106d519544fe09d43eabd5bsalomon@google.com 559add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.orgconst GrGLInterface* GrGLCreateNativeInterface() { 569add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.org GLProcGetter getter; 579add5dc33f10ea6c48268dab448b1df0fc96daaacommit-bot@chromium.org return GrGLAssembleGLInterface(&getter, mac_get_gl_proc); 58f987d1b2348258970cae675135b6dedda079de48bsalomon@google.com} 59