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 #include "gl/SkNativeGLContext.h" | 8 #include "gl/SkGLContext.h" |
9 #include "AvailabilityMacros.h" | 9 #include "AvailabilityMacros.h" |
10 | 10 |
11 SkNativeGLContext::AutoContextRestore::AutoContextRestore() { | 11 #include <OpenGL/OpenGL.h> |
12 fOldCGLContext = CGLGetCurrentContext(); | |
13 } | |
14 | 12 |
15 SkNativeGLContext::AutoContextRestore::~AutoContextRestore() { | 13 namespace { |
16 CGLSetCurrentContext(fOldCGLContext); | 14 class MacGLContext : public SkGLContext { |
17 } | 15 public: |
| 16 MacGLContext(); |
18 | 17 |
19 /////////////////////////////////////////////////////////////////////////////// | 18 virtual ~MacGLContext(); |
20 | 19 |
21 SkNativeGLContext::SkNativeGLContext() | 20 virtual void makeCurrent() const SK_OVERRIDE; |
| 21 virtual void swapBuffers() const SK_OVERRIDE; |
| 22 protected: |
| 23 virtual const GrGLInterface* createGLContext(GrGLStandard forcedGpuAPI) SK_O
VERRIDE; |
| 24 virtual void destroyGLContext() SK_OVERRIDE; |
| 25 |
| 26 private: |
| 27 CGLContextObj fContext; |
| 28 }; |
| 29 |
| 30 MacGLContext::MacGLContext() |
22 : fContext(NULL) { | 31 : fContext(NULL) { |
23 } | 32 } |
24 | 33 |
25 SkNativeGLContext::~SkNativeGLContext() { | 34 MacGLContext::~MacGLContext() { |
26 this->destroyGLContext(); | 35 this->destroyGLContext(); |
27 } | 36 } |
28 | 37 |
29 void SkNativeGLContext::destroyGLContext() { | 38 void MacGLContext::destroyGLContext() { |
30 if (fContext) { | 39 if (fContext) { |
31 CGLReleaseContext(fContext); | 40 CGLReleaseContext(fContext); |
32 } | 41 } |
33 } | 42 } |
34 | 43 |
35 const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAP
I) { | 44 const GrGLInterface* MacGLContext::createGLContext(GrGLStandard forcedGpuAPI) { |
36 SkASSERT(NULL == fContext); | 45 SkASSERT(NULL == fContext); |
37 if (kGLES_GrGLStandard == forcedGpuAPI) { | 46 if (kGLES_GrGLStandard == forcedGpuAPI) { |
38 return NULL; | 47 return NULL; |
39 } | 48 } |
40 | 49 |
41 CGLPixelFormatAttribute attributes[] = { | 50 CGLPixelFormatAttribute attributes[] = { |
42 #if MAC_OS_X_VERSION_10_7 | 51 #if MAC_OS_X_VERSION_10_7 |
43 kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core
, | 52 kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core
, |
44 #endif | 53 #endif |
45 kCGLPFADoubleBuffer, | 54 kCGLPFADoubleBuffer, |
(...skipping 22 matching lines...) Expand all Loading... |
68 const GrGLInterface* interface = GrGLCreateNativeInterface(); | 77 const GrGLInterface* interface = GrGLCreateNativeInterface(); |
69 if (NULL == interface) { | 78 if (NULL == interface) { |
70 SkDebugf("Context could not create GL interface.\n"); | 79 SkDebugf("Context could not create GL interface.\n"); |
71 this->destroyGLContext(); | 80 this->destroyGLContext(); |
72 return NULL; | 81 return NULL; |
73 } | 82 } |
74 | 83 |
75 return interface; | 84 return interface; |
76 } | 85 } |
77 | 86 |
78 void SkNativeGLContext::makeCurrent() const { | 87 void MacGLContext::makeCurrent() const { |
79 CGLSetCurrentContext(fContext); | 88 CGLSetCurrentContext(fContext); |
80 } | 89 } |
81 | 90 |
82 void SkNativeGLContext::swapBuffers() const { | 91 void MacGLContext::swapBuffers() const { |
83 CGLFlushDrawable(fContext); | 92 CGLFlushDrawable(fContext); |
84 } | 93 } |
| 94 |
| 95 } // anonymous namespace |
| 96 |
| 97 SkGLContext* SkCreatePlatformGLContext() { |
| 98 return SkNEW(MacGLContext); |
| 99 } |
OLD | NEW |