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; |
| 18 | fExtensions = that.fExtensions; |
| 19 | fIsMesa = that.fIsMesa; |
| 20 | fIsChromium = that.fIsChromium; |
| 21 | *fGLCaps = *that.fGLCaps.get(); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 22 | return *this; |
| 23 | } |
skia.committer@gmail.com | 631cdcb | 2013-03-01 12:12:55 +0000 | [diff] [blame] | 24 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 25 | bool GrGLContextInfo::initialize(const GrGLInterface* interface) { |
| 26 | this->reset(); |
| 27 | // We haven't validated the GrGLInterface yet, so check for GetString |
| 28 | // function pointer |
| 29 | if (interface->fGetString) { |
| 30 | const GrGLubyte* verUByte; |
| 31 | GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION)); |
| 32 | const char* ver = reinterpret_cast<const char*>(verUByte); |
commit-bot@chromium.org | c9424b8 | 2013-10-30 20:03:16 +0000 | [diff] [blame] | 33 | |
| 34 | const GrGLubyte* rendererUByte; |
| 35 | GR_GL_CALL_RET(interface, rendererUByte, GetString(GR_GL_RENDERER)); |
| 36 | const char* renderer = reinterpret_cast<const char*>(rendererUByte); |
| 37 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 38 | if (interface->validate() && fExtensions.init(interface)) { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 39 | |
| 40 | fGLVersion = GrGLGetVersionFromString(ver); |
| 41 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 42 | fGLSLGeneration = GrGetGLSLGeneration(interface); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 43 | |
| 44 | fVendor = GrGLGetVendor(interface); |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 45 | |
commit-bot@chromium.org | c9424b8 | 2013-10-30 20:03:16 +0000 | [diff] [blame] | 46 | fRenderer = GrGLGetRendererFromString(renderer); |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 47 | |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 48 | fIsMesa = GrGLIsMesaFromVersionString(ver); |
| 49 | |
commit-bot@chromium.org | c9424b8 | 2013-10-30 20:03:16 +0000 | [diff] [blame] | 50 | fIsChromium = GrGLIsChromiumFromRendererString(renderer); |
| 51 | |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 52 | // This must occur before caps init. |
| 53 | fInterface.reset(SkRef(interface)); |
bsalomon@google.com | ead86f2 | 2014-01-16 17:51:07 +0000 | [diff] [blame] | 54 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 55 | fGLCaps->init(*this, interface); |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 56 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 57 | return true; |
| 58 | } |
| 59 | } |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | bool GrGLContextInfo::isInitialized() const { |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 64 | return NULL != fInterface.get(); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void GrGLContextInfo::reset() { |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 68 | fInterface.reset(NULL); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 69 | fGLVersion = GR_GL_VER(0, 0); |
| 70 | fGLSLGeneration = static_cast<GrGLSLGeneration>(0); |
| 71 | fVendor = kOther_GrGLVendor; |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 72 | fRenderer = kOther_GrGLRenderer; |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 73 | fIsMesa = false; |
commit-bot@chromium.org | c9424b8 | 2013-10-30 20:03:16 +0000 | [diff] [blame] | 74 | fIsChromium = false; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 75 | fExtensions.reset(); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 76 | fGLCaps->reset(); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 77 | } |