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 | //////////////////////////////////////////////////////////////////////////////// |
| 11 | GrGLContextInfo& GrGLContextInfo::operator= (const GrGLContextInfo& ctxInfo) { |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 12 | fStandard = ctxInfo.fStandard; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 13 | fGLVersion = ctxInfo.fGLVersion; |
| 14 | fGLSLGeneration = ctxInfo.fGLSLGeneration; |
| 15 | fVendor = ctxInfo.fVendor; |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 16 | fRenderer = ctxInfo.fRenderer; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 17 | fExtensions = ctxInfo.fExtensions; |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 18 | fIsMesa = ctxInfo.fIsMesa; |
commit-bot@chromium.org | c9424b8 | 2013-10-30 20:03:16 +0000 | [diff] [blame] | 19 | fIsChromium = ctxInfo.fIsChromium; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 20 | *fGLCaps = *ctxInfo.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 | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 37 | if (interface->validate() && fExtensions.init(interface)) { |
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 | |
bsalomon@google.com | ead86f2 | 2014-01-16 17:51:07 +0000 | [diff] [blame^] | 51 | // This must be done before calling GrGLCaps::init() |
| 52 | fStandard = interface->fStandard; |
| 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 | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 63 | return kNone_GrGLStandard != fStandard; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void GrGLContextInfo::reset() { |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 67 | fStandard = kNone_GrGLStandard; |
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; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 74 | fExtensions.reset(); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 75 | fGLCaps->reset(); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | //////////////////////////////////////////////////////////////////////////////// |
| 79 | GrGLContext::GrGLContext(const GrGLInterface* interface) { |
| 80 | fInterface = NULL; |
| 81 | this->initialize(interface); |
| 82 | } |
| 83 | |
| 84 | GrGLContext::GrGLContext(const GrGLContext& ctx) { |
| 85 | fInterface = NULL; |
| 86 | *this = ctx; |
| 87 | } |
| 88 | |
| 89 | GrGLContext& GrGLContext::operator = (const GrGLContext& ctx) { |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 90 | SkRefCnt_SafeAssign(fInterface, ctx.fInterface); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 91 | fInfo = ctx.fInfo; |
| 92 | return *this; |
| 93 | } |
| 94 | |
| 95 | void GrGLContext::reset() { |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 96 | SkSafeSetNull(fInterface); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 97 | fInfo.reset(); |
| 98 | } |
| 99 | |
| 100 | bool GrGLContext::initialize(const GrGLInterface* interface) { |
| 101 | if (fInfo.initialize(interface)) { |
| 102 | fInterface = interface; |
| 103 | interface->ref(); |
| 104 | return true; |
| 105 | } |
| 106 | return false; |
| 107 | } |