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 |
| 52 // This must occur before caps init. |
| 53 fInterface.reset(SkRef(interface)); |
| 54 |
51 fGLCaps->init(*this, interface); | 55 fGLCaps->init(*this, interface); |
52 | 56 |
53 fStandard = interface->fStandard; | |
54 return true; | 57 return true; |
55 } | 58 } |
56 } | 59 } |
57 return false; | 60 return false; |
58 } | 61 } |
59 | 62 |
60 bool GrGLContextInfo::isInitialized() const { | 63 bool GrGLContextInfo::isInitialized() const { |
61 return kNone_GrGLStandard != fStandard; | 64 return NULL != fInterface.get(); |
62 } | 65 } |
63 | 66 |
64 void GrGLContextInfo::reset() { | 67 void GrGLContextInfo::reset() { |
65 fStandard = kNone_GrGLStandard; | 68 fInterface.reset(NULL); |
66 fGLVersion = GR_GL_VER(0, 0); | 69 fGLVersion = GR_GL_VER(0, 0); |
67 fGLSLGeneration = static_cast<GrGLSLGeneration>(0); | 70 fGLSLGeneration = static_cast<GrGLSLGeneration>(0); |
68 fVendor = kOther_GrGLVendor; | 71 fVendor = kOther_GrGLVendor; |
69 fRenderer = kOther_GrGLRenderer; | 72 fRenderer = kOther_GrGLRenderer; |
70 fIsMesa = false; | 73 fIsMesa = false; |
71 fIsChromium = false; | 74 fIsChromium = false; |
72 fExtensions.reset(); | 75 fExtensions.reset(); |
73 fGLCaps->reset(); | 76 fGLCaps->reset(); |
74 } | 77 } |
75 | |
76 //////////////////////////////////////////////////////////////////////////////// | |
77 GrGLContext::GrGLContext(const GrGLInterface* interface) { | |
78 fInterface = NULL; | |
79 this->initialize(interface); | |
80 } | |
81 | |
82 GrGLContext::GrGLContext(const GrGLContext& ctx) { | |
83 fInterface = NULL; | |
84 *this = ctx; | |
85 } | |
86 | |
87 GrGLContext& GrGLContext::operator = (const GrGLContext& ctx) { | |
88 SkRefCnt_SafeAssign(fInterface, ctx.fInterface); | |
89 fInfo = ctx.fInfo; | |
90 return *this; | |
91 } | |
92 | |
93 void GrGLContext::reset() { | |
94 SkSafeSetNull(fInterface); | |
95 fInfo.reset(); | |
96 } | |
97 | |
98 bool GrGLContext::initialize(const GrGLInterface* interface) { | |
99 if (fInfo.initialize(interface)) { | |
100 fInterface = interface; | |
101 interface->ref(); | |
102 return true; | |
103 } | |
104 return false; | |
105 } | |
OLD | NEW |