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

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

Issue 630843002: Make the Sk GL context class an abstract base class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix android link problem and ios compile problem Created 6 years, 2 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
« no previous file with comments | « src/gpu/gl/iOS/SkNativeGLContext_iOS.mm ('k') | src/gpu/gl/mac/SkNativeGLContext_mac.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « src/gpu/gl/iOS/SkNativeGLContext_iOS.mm ('k') | src/gpu/gl/mac/SkNativeGLContext_mac.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698