blob: 2c43c3d2d4cc2400d8186d2d700543911f14dd9b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gl/SkNativeGLContext.h"
#include "AvailabilityMacros.h"
SkNativeGLContext::AutoContextRestore::AutoContextRestore() {
fOldCGLContext = CGLGetCurrentContext();
}
SkNativeGLContext::AutoContextRestore::~AutoContextRestore() {
CGLSetCurrentContext(fOldCGLContext);
}
///////////////////////////////////////////////////////////////////////////////
SkNativeGLContext::SkNativeGLContext()
: fContext(NULL) {
}
SkNativeGLContext::~SkNativeGLContext() {
this->destroyGLContext();
}
void SkNativeGLContext::destroyGLContext() {
if (NULL != fContext) {
CGLReleaseContext(fContext);
}
}
const GrGLInterface* SkNativeGLContext::createGLContext() {
SkASSERT(NULL == fContext);
CGLPixelFormatAttribute attributes[] = {
#if MAC_OS_X_VERSION_10_7
kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core,
#endif
(CGLPixelFormatAttribute)0
};
CGLPixelFormatObj pixFormat;
GLint npix;
CGLChoosePixelFormat(attributes, &pixFormat, &npix);
if (NULL == pixFormat) {
SkDebugf("CGLChoosePixelFormat failed.");
return NULL;
}
CGLCreateContext(pixFormat, NULL, &fContext);
CGLReleasePixelFormat(pixFormat);
if (NULL == fContext) {
SkDebugf("CGLCreateContext failed.");
return NULL;
}
CGLSetCurrentContext(fContext);
const GrGLInterface* interface = GrGLCreateNativeInterface();
if (NULL == interface) {
SkDebugf("Context could not create GL interface.\n");
this->destroyGLContext();
return NULL;
}
return interface;
}
void SkNativeGLContext::makeCurrent() const {
CGLSetCurrentContext(fContext);
}
|