robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrGLContext.h" |
| 9 | |
| 10 | //////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 11 | |
| 12 | GrGLContextInfo& GrGLContextInfo::operator= (const GrGLContextInfo& that) { |
| 13 | fInterface.reset(SkSafeRef(that.fInterface.get())); |
| 14 | fGLVersion = that.fGLVersion; |
| 15 | fGLSLGeneration = that.fGLSLGeneration; |
| 16 | fVendor = that.fVendor; |
| 17 | fRenderer = that.fRenderer; |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 18 | fIsMesa = that.fIsMesa; |
| 19 | fIsChromium = that.fIsChromium; |
| 20 | *fGLCaps = *that.fGLCaps.get(); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 21 | return *this; |
| 22 | } |
skia.committer@gmail.com | 631cdcb | 2013-03-01 12:12:55 +0000 | [diff] [blame] | 23 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 24 | bool GrGLContextInfo::initialize(const GrGLInterface* interface) { |
| 25 | this->reset(); |
| 26 | // We haven't validated the GrGLInterface yet, so check for GetString |
| 27 | // function pointer |
commit-bot@chromium.org | c72425a | 2014-01-21 16:09:18 +0000 | [diff] [blame] | 28 | if (interface->fFunctions.fGetString) { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 29 | const GrGLubyte* verUByte; |
| 30 | GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION)); |
| 31 | const char* ver = reinterpret_cast<const char*>(verUByte); |
commit-bot@chromium.org | c9424b8 | 2013-10-30 20:03:16 +0000 | [diff] [blame] | 32 | |
| 33 | const GrGLubyte* rendererUByte; |
| 34 | GR_GL_CALL_RET(interface, rendererUByte, GetString(GR_GL_RENDERER)); |
| 35 | const char* renderer = reinterpret_cast<const char*>(rendererUByte); |
| 36 | |
commit-bot@chromium.org | 90313cc | 2014-01-17 15:05:38 +0000 | [diff] [blame] | 37 | if (interface->validate()) { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 38 | |
| 39 | fGLVersion = GrGLGetVersionFromString(ver); |
commit-bot@chromium.org | f4e67e3 | 2014-04-30 01:26:04 +0000 | [diff] [blame] | 40 | if (GR_GL_INVALID_VER == fGLVersion) { |
| 41 | return false; |
| 42 | } |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 43 | |
commit-bot@chromium.org | f4e67e3 | 2014-04-30 01:26:04 +0000 | [diff] [blame] | 44 | if (!GrGetGLSLGeneration(interface, &fGLSLGeneration)) { |
| 45 | return false; |
| 46 | } |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 47 | |
| 48 | fVendor = GrGLGetVendor(interface); |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 49 | |
rmistry | 63a9f84 | 2014-10-17 06:07:08 -0700 | [diff] [blame] | 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 | |
commit-bot@chromium.org | c9424b8 | 2013-10-30 20:03:16 +0000 | [diff] [blame] | 60 | fRenderer = GrGLGetRendererFromString(renderer); |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 61 | |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 62 | fIsMesa = GrGLIsMesaFromVersionString(ver); |
| 63 | |
commit-bot@chromium.org | c9424b8 | 2013-10-30 20:03:16 +0000 | [diff] [blame] | 64 | fIsChromium = GrGLIsChromiumFromRendererString(renderer); |
| 65 | |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 66 | // This must occur before caps init. |
| 67 | fInterface.reset(SkRef(interface)); |
bsalomon@google.com | ead86f2 | 2014-01-16 17:51:07 +0000 | [diff] [blame] | 68 | |
commit-bot@chromium.org | f4e67e3 | 2014-04-30 01:26:04 +0000 | [diff] [blame] | 69 | return fGLCaps->init(*this, interface); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | return false; |
| 73 | } |
| 74 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 75 | bool GrGLContextInfo::isInitialized() const { return SkToBool(fInterface.get()); } |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 76 | |
| 77 | void GrGLContextInfo::reset() { |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 78 | fInterface.reset(NULL); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 79 | fGLVersion = GR_GL_VER(0, 0); |
| 80 | fGLSLGeneration = static_cast<GrGLSLGeneration>(0); |
| 81 | fVendor = kOther_GrGLVendor; |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 82 | fRenderer = kOther_GrGLRenderer; |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 83 | fIsMesa = false; |
commit-bot@chromium.org | c9424b8 | 2013-10-30 20:03:16 +0000 | [diff] [blame] | 84 | fIsChromium = false; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 85 | fGLCaps->reset(); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 86 | } |