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 |
| 28 | if (interface->fGetString) { |
| 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); |
| 40 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 41 | fGLSLGeneration = GrGetGLSLGeneration(interface); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 42 | |
| 43 | fVendor = GrGLGetVendor(interface); |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 44 | |
commit-bot@chromium.org | c9424b8 | 2013-10-30 20:03:16 +0000 | [diff] [blame] | 45 | fRenderer = GrGLGetRendererFromString(renderer); |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 46 | |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 47 | fIsMesa = GrGLIsMesaFromVersionString(ver); |
| 48 | |
commit-bot@chromium.org | c9424b8 | 2013-10-30 20:03:16 +0000 | [diff] [blame] | 49 | fIsChromium = GrGLIsChromiumFromRendererString(renderer); |
| 50 | |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 51 | // This must occur before caps init. |
| 52 | fInterface.reset(SkRef(interface)); |
bsalomon@google.com | ead86f2 | 2014-01-16 17:51:07 +0000 | [diff] [blame] | 53 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 54 | fGLCaps->init(*this, interface); |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 55 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 56 | return true; |
| 57 | } |
| 58 | } |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | bool GrGLContextInfo::isInitialized() const { |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 63 | return NULL != fInterface.get(); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void GrGLContextInfo::reset() { |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 67 | fInterface.reset(NULL); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 68 | fGLVersion = GR_GL_VER(0, 0); |
| 69 | fGLSLGeneration = static_cast<GrGLSLGeneration>(0); |
| 70 | fVendor = kOther_GrGLVendor; |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 71 | fRenderer = kOther_GrGLRenderer; |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 72 | fIsMesa = false; |
commit-bot@chromium.org | c9424b8 | 2013-10-30 20:03:16 +0000 | [diff] [blame] | 73 | fIsChromium = false; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 74 | fGLCaps->reset(); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 75 | } |