blob: 097fce23e2889a976758d48d67e2f8495d014d69 [file] [log] [blame]
robertphillips@google.com6177e692013-02-28 20:16:25 +00001/*
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////////////////////////////////////////////////////////////////////////////////
11GrGLContextInfo& GrGLContextInfo::operator= (const GrGLContextInfo& ctxInfo) {
12 fBindingInUse = ctxInfo.fBindingInUse;
13 fGLVersion = ctxInfo.fGLVersion;
14 fGLSLGeneration = ctxInfo.fGLSLGeneration;
15 fVendor = ctxInfo.fVendor;
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000016 fRenderer = ctxInfo.fRenderer;
robertphillips@google.com6177e692013-02-28 20:16:25 +000017 fExtensions = ctxInfo.fExtensions;
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000018 fIsMesa = ctxInfo.fIsMesa;
bsalomon@google.combcce8922013-03-25 15:38:39 +000019 *fGLCaps = *ctxInfo.fGLCaps.get();
robertphillips@google.com6177e692013-02-28 20:16:25 +000020 return *this;
21}
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +000022
robertphillips@google.com6177e692013-02-28 20:16:25 +000023bool 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.org459104c2013-06-14 14:42:56 +000041
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000042 fRenderer = GrGLGetRenderer(interface);
43
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000044 fIsMesa = GrGLIsMesaFromVersionString(ver);
45
bsalomon@google.combcce8922013-03-25 15:38:39 +000046 fGLCaps->init(*this, interface);
robertphillips@google.com6177e692013-02-28 20:16:25 +000047 return true;
48 }
49 }
50 return false;
51}
52
53bool GrGLContextInfo::isInitialized() const {
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +000054 return kNone_GrGLBinding != fBindingInUse;
robertphillips@google.com6177e692013-02-28 20:16:25 +000055}
56
57void 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.org0694ea72013-09-18 13:00:28 +000062 fRenderer = kOther_GrGLRenderer;
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000063 fIsMesa = false;
robertphillips@google.com6177e692013-02-28 20:16:25 +000064 fExtensions.reset();
bsalomon@google.combcce8922013-03-25 15:38:39 +000065 fGLCaps->reset();
robertphillips@google.com6177e692013-02-28 20:16:25 +000066}
67
68////////////////////////////////////////////////////////////////////////////////
69GrGLContext::GrGLContext(const GrGLInterface* interface) {
70 fInterface = NULL;
71 this->initialize(interface);
72}
73
74GrGLContext::GrGLContext(const GrGLContext& ctx) {
75 fInterface = NULL;
76 *this = ctx;
77}
78
79GrGLContext& GrGLContext::operator = (const GrGLContext& ctx) {
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000080 SkRefCnt_SafeAssign(fInterface, ctx.fInterface);
robertphillips@google.com6177e692013-02-28 20:16:25 +000081 fInfo = ctx.fInfo;
82 return *this;
83}
84
85void GrGLContext::reset() {
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000086 SkSafeSetNull(fInterface);
robertphillips@google.com6177e692013-02-28 20:16:25 +000087 fInfo.reset();
88}
89
90bool GrGLContext::initialize(const GrGLInterface* interface) {
91 if (fInfo.initialize(interface)) {
92 fInterface = interface;
93 interface->ref();
94 return true;
95 }
96 return false;
97}