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