Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp

Issue 1815823002: Move SkGLContext and some GrGLInterface implementations to skgputest module (Closed) Base URL: https://chromium.googlesource.com/skia.git@debugobject
Patch Set: fix windows and android? Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 #include "SkTypes.h"
8 #if defined(SK_BUILD_FOR_MAC)
9
10 #include "gl/SkGLContext.h"
11 #include "AvailabilityMacros.h"
12
13 #include <OpenGL/OpenGL.h>
14 #include <dlfcn.h>
15
16 namespace {
17 class MacGLContext : public SkGLContext {
18 public:
19 MacGLContext();
20 ~MacGLContext() override;
21
22 private:
23 void destroyGLContext();
24
25 void onPlatformMakeCurrent() const override;
26 void onPlatformSwapBuffers() const override;
27 GrGLFuncPtr onPlatformGetProcAddress(const char*) const override;
28
29 CGLContextObj fContext;
30 void* fGLLibrary;
31 };
32
33 MacGLContext::MacGLContext()
34 : fContext(nullptr)
35 , fGLLibrary(RTLD_DEFAULT) {
36 CGLPixelFormatAttribute attributes[] = {
37 #if MAC_OS_X_VERSION_10_7
38 kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core ,
39 #endif
40 kCGLPFADoubleBuffer,
41 (CGLPixelFormatAttribute)0
42 };
43 CGLPixelFormatObj pixFormat;
44 GLint npix;
45
46 CGLChoosePixelFormat(attributes, &pixFormat, &npix);
47
48 if (nullptr == pixFormat) {
49 SkDebugf("CGLChoosePixelFormat failed.");
50 return;
51 }
52
53 CGLCreateContext(pixFormat, nullptr, &fContext);
54 CGLReleasePixelFormat(pixFormat);
55
56 if (nullptr == fContext) {
57 SkDebugf("CGLCreateContext failed.");
58 return;
59 }
60
61 CGLSetCurrentContext(fContext);
62
63 SkAutoTUnref<const GrGLInterface> gl(GrGLCreateNativeInterface());
64 if (nullptr == gl.get()) {
65 SkDebugf("Context could not create GL interface.\n");
66 this->destroyGLContext();
67 return;
68 }
69 if (!gl->validate()) {
70 SkDebugf("Context could not validate GL interface.\n");
71 this->destroyGLContext();
72 return;
73 }
74
75 fGLLibrary = dlopen(
76 "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL. dylib",
77 RTLD_LAZY);
78
79 this->init(gl.release());
80 }
81
82 MacGLContext::~MacGLContext() {
83 this->teardown();
84 this->destroyGLContext();
85 }
86
87 void MacGLContext::destroyGLContext() {
88 if (fContext) {
89 CGLReleaseContext(fContext);
90 fContext = nullptr;
91 }
92 if (RTLD_DEFAULT != fGLLibrary) {
93 dlclose(fGLLibrary);
94 }
95 }
96
97 void MacGLContext::onPlatformMakeCurrent() const {
98 CGLSetCurrentContext(fContext);
99 }
100
101 void MacGLContext::onPlatformSwapBuffers() const {
102 CGLFlushDrawable(fContext);
103 }
104
105 GrGLFuncPtr MacGLContext::onPlatformGetProcAddress(const char* procName) const {
106 return reinterpret_cast<GrGLFuncPtr>(dlsym(fGLLibrary, procName));
107 }
108
109 } // anonymous namespace
110
111 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* s hareContext) {
112 SkASSERT(!shareContext);
113 if (shareContext) {
114 return nullptr;
115 }
116
117 if (kGLES_GrGLStandard == forcedGpuAPI) {
118 return nullptr;
119 }
120 MacGLContext* ctx = new MacGLContext;
121 if (!ctx->isValid()) {
122 delete ctx;
123 return nullptr;
124 }
125 return ctx;
126 }
127
128 #endif//defined(SK_BUILD_FOR_MAC)
OLDNEW
« no previous file with comments | « src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm ('k') | src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698