| 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 | 11 |
| 12 GrGLContextInfo& GrGLContextInfo::operator= (const GrGLContextInfo& that) { | 12 GrGLContext* GrGLContext::Create(const GrGLInterface* interface) { |
| 13 fInterface.reset(SkSafeRef(that.fInterface.get())); | 13 // We haven't validated the GrGLInterface yet, so check for GetString functi
on pointer |
| 14 fGLVersion = that.fGLVersion; | 14 if (!interface->fFunctions.fGetString) { |
| 15 fGLSLGeneration = that.fGLSLGeneration; | 15 return NULL; |
| 16 fVendor = that.fVendor; | 16 } |
| 17 fRenderer = that.fRenderer; | 17 ConstructorArgs args; |
| 18 fIsMesa = that.fIsMesa; | 18 args.fInterface = interface; |
| 19 fIsChromium = that.fIsChromium; | 19 |
| 20 *fGLCaps = *that.fGLCaps.get(); | 20 const GrGLubyte* verUByte; |
| 21 return *this; | 21 GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION)); |
| 22 const char* ver = reinterpret_cast<const char*>(verUByte); |
| 23 |
| 24 const GrGLubyte* rendererUByte; |
| 25 GR_GL_CALL_RET(interface, rendererUByte, GetString(GR_GL_RENDERER)); |
| 26 const char* renderer = reinterpret_cast<const char*>(rendererUByte); |
| 27 |
| 28 if (!interface->validate()) { |
| 29 return NULL; |
| 30 } |
| 31 |
| 32 args.fGLVersion = GrGLGetVersionFromString(ver); |
| 33 if (GR_GL_INVALID_VER == args.fGLVersion) { |
| 34 return NULL; |
| 35 } |
| 36 |
| 37 if (!GrGetGLSLGeneration(interface, &args.fGLSLGeneration)) { |
| 38 return NULL; |
| 39 } |
| 40 |
| 41 args.fVendor = GrGLGetVendor(interface); |
| 42 |
| 43 /* |
| 44 * Qualcomm drivers have a horrendous bug with some drivers. Though they cla
im to |
| 45 * support GLES 3.00, some perfectly valid GLSL300 shaders will only compile
with |
| 46 * #version 100, and will fail to compile with #version 300 es. In the long
term, we |
| 47 * need to lock this down to a specific driver version. |
| 48 */ |
| 49 if (kQualcomm_GrGLVendor == args.fVendor) { |
| 50 args.fGLSLGeneration = k110_GrGLSLGeneration; |
| 51 } |
| 52 |
| 53 args.fRenderer = GrGLGetRendererFromString(renderer); |
| 54 |
| 55 args.fIsMesa = GrGLIsMesaFromVersionString(ver); |
| 56 |
| 57 args.fIsChromium = GrGLIsChromiumFromRendererString(renderer); |
| 58 return SkNEW_ARGS(GrGLContext, (args)); |
| 22 } | 59 } |
| 23 | 60 |
| 24 bool GrGLContextInfo::initialize(const GrGLInterface* interface) { | 61 GrGLContextInfo::GrGLContextInfo(const ConstructorArgs& args) { |
| 25 this->reset(); | 62 fInterface.reset(SkRef(args.fInterface)); |
| 26 // We haven't validated the GrGLInterface yet, so check for GetString | 63 fGLVersion = args.fGLVersion; |
| 27 // function pointer | 64 fGLSLGeneration = args.fGLSLGeneration; |
| 28 if (interface->fFunctions.fGetString) { | 65 fVendor = args.fVendor; |
| 29 const GrGLubyte* verUByte; | 66 fRenderer = args.fRenderer; |
| 30 GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION)); | 67 fIsMesa = args.fIsMesa; |
| 31 const char* ver = reinterpret_cast<const char*>(verUByte); | 68 fIsChromium = args.fIsChromium; |
| 32 | 69 |
| 33 const GrGLubyte* rendererUByte; | 70 fGLCaps.reset(SkNEW_ARGS(GrGLCaps, (*this, fInterface))); |
| 34 GR_GL_CALL_RET(interface, rendererUByte, GetString(GR_GL_RENDERER)); | |
| 35 const char* renderer = reinterpret_cast<const char*>(rendererUByte); | |
| 36 | |
| 37 if (interface->validate()) { | |
| 38 | |
| 39 fGLVersion = GrGLGetVersionFromString(ver); | |
| 40 if (GR_GL_INVALID_VER == fGLVersion) { | |
| 41 return false; | |
| 42 } | |
| 43 | |
| 44 if (!GrGetGLSLGeneration(interface, &fGLSLGeneration)) { | |
| 45 return false; | |
| 46 } | |
| 47 | |
| 48 fVendor = GrGLGetVendor(interface); | |
| 49 | |
| 50 /* | |
| 51 * Qualcomm drivers have a horrendous bug with some drivers. Though
they claim to | |
| 52 * support GLES 3.00, some perfectly valid GLSL300 shaders will only
compile with | |
| 53 * #version 100, and will fail to compile with #version 300 es. In
the long term, we | |
| 54 * need to lock this down to a specific driver version. | |
| 55 */ | |
| 56 if (kQualcomm_GrGLVendor == fVendor) { | |
| 57 fGLSLGeneration = k110_GrGLSLGeneration; | |
| 58 } | |
| 59 | |
| 60 fRenderer = GrGLGetRendererFromString(renderer); | |
| 61 | |
| 62 fIsMesa = GrGLIsMesaFromVersionString(ver); | |
| 63 | |
| 64 fIsChromium = GrGLIsChromiumFromRendererString(renderer); | |
| 65 | |
| 66 // This must occur before caps init. | |
| 67 fInterface.reset(SkRef(interface)); | |
| 68 | |
| 69 return fGLCaps->init(*this, interface); | |
| 70 } | |
| 71 } | |
| 72 return false; | |
| 73 } | 71 } |
| 74 | |
| 75 bool GrGLContextInfo::isInitialized() const { return SkToBool(fInterface.get());
} | |
| 76 | |
| 77 void GrGLContextInfo::reset() { | |
| 78 fInterface.reset(NULL); | |
| 79 fGLVersion = GR_GL_VER(0, 0); | |
| 80 fGLSLGeneration = static_cast<GrGLSLGeneration>(0); | |
| 81 fVendor = kOther_GrGLVendor; | |
| 82 fRenderer = kOther_GrGLRenderer; | |
| 83 fIsMesa = false; | |
| 84 fIsChromium = false; | |
| 85 fGLCaps->reset(); | |
| 86 } | |
| OLD | NEW |