OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrGLContext.h" | 8 #include "GrGLContext.h" |
9 | 9 |
10 //////////////////////////////////////////////////////////////////////////////// | 10 //////////////////////////////////////////////////////////////////////////////// |
11 GrGLContextInfo& GrGLContextInfo::operator= (const GrGLContextInfo& ctxInfo) { | 11 |
12 fStandard = ctxInfo.fStandard; | 12 GrGLContextInfo& GrGLContextInfo::operator= (const GrGLContextInfo& that) { |
13 fGLVersion = ctxInfo.fGLVersion; | 13 fInterface.reset(SkSafeRef(that.fInterface.get())); |
14 fGLSLGeneration = ctxInfo.fGLSLGeneration; | 14 fGLVersion = that.fGLVersion; |
15 fVendor = ctxInfo.fVendor; | 15 fGLSLGeneration = that.fGLSLGeneration; |
16 fRenderer = ctxInfo.fRenderer; | 16 fVendor = that.fVendor; |
17 fExtensions = ctxInfo.fExtensions; | 17 fRenderer = that.fRenderer; |
18 fIsMesa = ctxInfo.fIsMesa; | 18 fExtensions = that.fExtensions; |
19 fIsChromium = ctxInfo.fIsChromium; | 19 fIsMesa = that.fIsMesa; |
20 *fGLCaps = *ctxInfo.fGLCaps.get(); | 20 fIsChromium = that.fIsChromium; |
| 21 *fGLCaps = *that.fGLCaps.get(); |
21 return *this; | 22 return *this; |
22 } | 23 } |
23 | 24 |
24 bool GrGLContextInfo::initialize(const GrGLInterface* interface) { | 25 bool GrGLContextInfo::initialize(const GrGLInterface* interface) { |
25 this->reset(); | 26 this->reset(); |
26 // We haven't validated the GrGLInterface yet, so check for GetString | 27 // We haven't validated the GrGLInterface yet, so check for GetString |
27 // function pointer | 28 // function pointer |
28 if (interface->fGetString) { | 29 if (interface->fGetString) { |
29 const GrGLubyte* verUByte; | 30 const GrGLubyte* verUByte; |
30 GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION)); | 31 GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION)); |
(...skipping 10 matching lines...) Expand all Loading... |
41 fGLSLGeneration = GrGetGLSLGeneration(interface); | 42 fGLSLGeneration = GrGetGLSLGeneration(interface); |
42 | 43 |
43 fVendor = GrGLGetVendor(interface); | 44 fVendor = GrGLGetVendor(interface); |
44 | 45 |
45 fRenderer = GrGLGetRendererFromString(renderer); | 46 fRenderer = GrGLGetRendererFromString(renderer); |
46 | 47 |
47 fIsMesa = GrGLIsMesaFromVersionString(ver); | 48 fIsMesa = GrGLIsMesaFromVersionString(ver); |
48 | 49 |
49 fIsChromium = GrGLIsChromiumFromRendererString(renderer); | 50 fIsChromium = GrGLIsChromiumFromRendererString(renderer); |
50 | 51 |
51 // This must be done before calling GrGLCaps::init() | 52 // This must occur before caps init. |
52 fStandard = interface->fStandard; | 53 fInterface.reset(SkRef(interface)); |
53 | 54 |
54 fGLCaps->init(*this, interface); | 55 fGLCaps->init(*this, interface); |
55 | 56 |
56 return true; | 57 return true; |
57 } | 58 } |
58 } | 59 } |
59 return false; | 60 return false; |
60 } | 61 } |
61 | 62 |
62 bool GrGLContextInfo::isInitialized() const { | 63 bool GrGLContextInfo::isInitialized() const { |
63 return kNone_GrGLStandard != fStandard; | 64 return NULL != fInterface.get(); |
64 } | 65 } |
65 | 66 |
66 void GrGLContextInfo::reset() { | 67 void GrGLContextInfo::reset() { |
67 fStandard = kNone_GrGLStandard; | 68 fInterface.reset(NULL); |
68 fGLVersion = GR_GL_VER(0, 0); | 69 fGLVersion = GR_GL_VER(0, 0); |
69 fGLSLGeneration = static_cast<GrGLSLGeneration>(0); | 70 fGLSLGeneration = static_cast<GrGLSLGeneration>(0); |
70 fVendor = kOther_GrGLVendor; | 71 fVendor = kOther_GrGLVendor; |
71 fRenderer = kOther_GrGLRenderer; | 72 fRenderer = kOther_GrGLRenderer; |
72 fIsMesa = false; | 73 fIsMesa = false; |
73 fIsChromium = false; | 74 fIsChromium = false; |
74 fExtensions.reset(); | 75 fExtensions.reset(); |
75 fGLCaps->reset(); | 76 fGLCaps->reset(); |
76 } | 77 } |
77 | |
78 //////////////////////////////////////////////////////////////////////////////// | |
79 GrGLContext::GrGLContext(const GrGLInterface* interface) { | |
80 fInterface = NULL; | |
81 this->initialize(interface); | |
82 } | |
83 | |
84 GrGLContext::GrGLContext(const GrGLContext& ctx) { | |
85 fInterface = NULL; | |
86 *this = ctx; | |
87 } | |
88 | |
89 GrGLContext& GrGLContext::operator = (const GrGLContext& ctx) { | |
90 SkRefCnt_SafeAssign(fInterface, ctx.fInterface); | |
91 fInfo = ctx.fInfo; | |
92 return *this; | |
93 } | |
94 | |
95 void GrGLContext::reset() { | |
96 SkSafeSetNull(fInterface); | |
97 fInfo.reset(); | |
98 } | |
99 | |
100 bool GrGLContext::initialize(const GrGLInterface* interface) { | |
101 if (fInfo.initialize(interface)) { | |
102 fInterface = interface; | |
103 interface->ref(); | |
104 return true; | |
105 } | |
106 return false; | |
107 } | |
OLD | NEW |