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) { |
| 12 | fBindingInUse = ctxInfo.fBindingInUse; |
| 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; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 19 | *fGLCaps = *ctxInfo.fGLCaps.get(); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 20 | return *this; |
| 21 | } |
skia.committer@gmail.com | 631cdcb | 2013-03-01 12:12:55 +0000 | [diff] [blame] | 22 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 23 | bool GrGLContextInfo::initialize(const GrGLInterface* interface) { |
| 24 | this->reset(); |
| 25 | // We haven't validated the GrGLInterface yet, so check for GetString |
| 26 | // function pointer |
| 27 | if (interface->fGetString) { |
| 28 | const GrGLubyte* verUByte; |
| 29 | GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION)); |
| 30 | const char* ver = reinterpret_cast<const char*>(verUByte); |
| 31 | GrGLBinding binding = GrGLGetBindingInUseFromString(ver); |
| 32 | |
| 33 | if (0 != binding && interface->validate(binding) && fExtensions.init(binding, interface)) { |
| 34 | fBindingInUse = binding; |
| 35 | |
| 36 | fGLVersion = GrGLGetVersionFromString(ver); |
| 37 | |
| 38 | fGLSLGeneration = GrGetGLSLGeneration(fBindingInUse, interface); |
| 39 | |
| 40 | fVendor = GrGLGetVendor(interface); |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 41 | |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 42 | fRenderer = GrGLGetRenderer(interface); |
| 43 | |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 44 | fIsMesa = GrGLIsMesaFromVersionString(ver); |
| 45 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 46 | fGLCaps->init(*this, interface); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 47 | return true; |
| 48 | } |
| 49 | } |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | bool GrGLContextInfo::isInitialized() const { |
skia.committer@gmail.com | 631cdcb | 2013-03-01 12:12:55 +0000 | [diff] [blame] | 54 | return kNone_GrGLBinding != fBindingInUse; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void GrGLContextInfo::reset() { |
| 58 | fBindingInUse = kNone_GrGLBinding; |
| 59 | fGLVersion = GR_GL_VER(0, 0); |
| 60 | fGLSLGeneration = static_cast<GrGLSLGeneration>(0); |
| 61 | fVendor = kOther_GrGLVendor; |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 62 | fRenderer = kOther_GrGLRenderer; |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 63 | fIsMesa = false; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 64 | fExtensions.reset(); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 65 | fGLCaps->reset(); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | //////////////////////////////////////////////////////////////////////////////// |
| 69 | GrGLContext::GrGLContext(const GrGLInterface* interface) { |
| 70 | fInterface = NULL; |
| 71 | this->initialize(interface); |
| 72 | } |
| 73 | |
| 74 | GrGLContext::GrGLContext(const GrGLContext& ctx) { |
| 75 | fInterface = NULL; |
| 76 | *this = ctx; |
| 77 | } |
| 78 | |
| 79 | GrGLContext& GrGLContext::operator = (const GrGLContext& ctx) { |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 80 | SkRefCnt_SafeAssign(fInterface, ctx.fInterface); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 81 | fInfo = ctx.fInfo; |
| 82 | return *this; |
| 83 | } |
| 84 | |
| 85 | void GrGLContext::reset() { |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 86 | SkSafeSetNull(fInterface); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 87 | fInfo.reset(); |
| 88 | } |
| 89 | |
| 90 | bool GrGLContext::initialize(const GrGLInterface* interface) { |
| 91 | if (fInfo.initialize(interface)) { |
| 92 | fInterface = interface; |
| 93 | interface->ref(); |
| 94 | return true; |
| 95 | } |
| 96 | return false; |
| 97 | } |