blob: 7c99a1cd0080eb6357ad2652c7d93547dcc97312 [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;
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000019 fIsChromium = ctxInfo.fIsChromium;
bsalomon@google.combcce8922013-03-25 15:38:39 +000020 *fGLCaps = *ctxInfo.fGLCaps.get();
robertphillips@google.com6177e692013-02-28 20:16:25 +000021 return *this;
22}
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +000023
robertphillips@google.com6177e692013-02-28 20:16:25 +000024bool 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.orgc9424b82013-10-30 20:03:16 +000032
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
robertphillips@google.com6177e692013-02-28 20:16:25 +000037 GrGLBinding binding = GrGLGetBindingInUseFromString(ver);
38
39 if (0 != binding && interface->validate(binding) && fExtensions.init(binding, interface)) {
40 fBindingInUse = binding;
41
42 fGLVersion = GrGLGetVersionFromString(ver);
43
44 fGLSLGeneration = GrGetGLSLGeneration(fBindingInUse, interface);
45
46 fVendor = GrGLGetVendor(interface);
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000047
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000048 fRenderer = GrGLGetRendererFromString(renderer);
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000049
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000050 fIsMesa = GrGLIsMesaFromVersionString(ver);
51
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000052 fIsChromium = GrGLIsChromiumFromRendererString(renderer);
53
bsalomon@google.combcce8922013-03-25 15:38:39 +000054 fGLCaps->init(*this, interface);
robertphillips@google.com6177e692013-02-28 20:16:25 +000055 return true;
56 }
57 }
58 return false;
59}
60
61bool GrGLContextInfo::isInitialized() const {
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +000062 return kNone_GrGLBinding != fBindingInUse;
robertphillips@google.com6177e692013-02-28 20:16:25 +000063}
64
65void GrGLContextInfo::reset() {
66 fBindingInUse = kNone_GrGLBinding;
67 fGLVersion = GR_GL_VER(0, 0);
68 fGLSLGeneration = static_cast<GrGLSLGeneration>(0);
69 fVendor = kOther_GrGLVendor;
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000070 fRenderer = kOther_GrGLRenderer;
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000071 fIsMesa = false;
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000072 fIsChromium = false;
robertphillips@google.com6177e692013-02-28 20:16:25 +000073 fExtensions.reset();
bsalomon@google.combcce8922013-03-25 15:38:39 +000074 fGLCaps->reset();
robertphillips@google.com6177e692013-02-28 20:16:25 +000075}
76
77////////////////////////////////////////////////////////////////////////////////
78GrGLContext::GrGLContext(const GrGLInterface* interface) {
79 fInterface = NULL;
80 this->initialize(interface);
81}
82
83GrGLContext::GrGLContext(const GrGLContext& ctx) {
84 fInterface = NULL;
85 *this = ctx;
86}
87
88GrGLContext& GrGLContext::operator = (const GrGLContext& ctx) {
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000089 SkRefCnt_SafeAssign(fInterface, ctx.fInterface);
robertphillips@google.com6177e692013-02-28 20:16:25 +000090 fInfo = ctx.fInfo;
91 return *this;
92}
93
94void GrGLContext::reset() {
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000095 SkSafeSetNull(fInterface);
robertphillips@google.com6177e692013-02-28 20:16:25 +000096 fInfo.reset();
97}
98
99bool GrGLContext::initialize(const GrGLInterface* interface) {
100 if (fInfo.initialize(interface)) {
101 fInterface = interface;
102 interface->ref();
103 return true;
104 }
105 return false;
106}