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

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

Issue 639793002: Revert of Make the Sk GL context class an abstract base class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
(Empty)
1
2 /*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8 #include "gl/SkGLContext.h"
9 #include "AvailabilityMacros.h"
10
11 #include <OpenGL/OpenGL.h>
12
13 namespace {
14 class MacGLContext : public SkGLContext {
15 public:
16 MacGLContext();
17
18 virtual ~MacGLContext();
19
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()
31 : fContext(NULL) {
32 }
33
34 MacGLContext::~MacGLContext() {
35 this->destroyGLContext();
36 }
37
38 void MacGLContext::destroyGLContext() {
39 if (fContext) {
40 CGLReleaseContext(fContext);
41 }
42 }
43
44 const GrGLInterface* MacGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
45 SkASSERT(NULL == fContext);
46 if (kGLES_GrGLStandard == forcedGpuAPI) {
47 return NULL;
48 }
49
50 CGLPixelFormatAttribute attributes[] = {
51 #if MAC_OS_X_VERSION_10_7
52 kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core ,
53 #endif
54 kCGLPFADoubleBuffer,
55 (CGLPixelFormatAttribute)0
56 };
57 CGLPixelFormatObj pixFormat;
58 GLint npix;
59
60 CGLChoosePixelFormat(attributes, &pixFormat, &npix);
61
62 if (NULL == pixFormat) {
63 SkDebugf("CGLChoosePixelFormat failed.");
64 return NULL;
65 }
66
67 CGLCreateContext(pixFormat, NULL, &fContext);
68 CGLReleasePixelFormat(pixFormat);
69
70 if (NULL == fContext) {
71 SkDebugf("CGLCreateContext failed.");
72 return NULL;
73 }
74
75 CGLSetCurrentContext(fContext);
76
77 const GrGLInterface* interface = GrGLCreateNativeInterface();
78 if (NULL == interface) {
79 SkDebugf("Context could not create GL interface.\n");
80 this->destroyGLContext();
81 return NULL;
82 }
83
84 return interface;
85 }
86
87 void MacGLContext::makeCurrent() const {
88 CGLSetCurrentContext(fContext);
89 }
90
91 void MacGLContext::swapBuffers() const {
92 CGLFlushDrawable(fContext);
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