blob: fad885b29a0f407a02a07f3cc01819a91fd5a071 [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) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000012 fStandard = ctxInfo.fStandard;
robertphillips@google.com6177e692013-02-28 20:16:25 +000013 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
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000037 if (interface->validate() && fExtensions.init(interface)) {
robertphillips@google.com6177e692013-02-28 20:16:25 +000038
39 fGLVersion = GrGLGetVersionFromString(ver);
40
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000041 fGLSLGeneration = GrGetGLSLGeneration(interface);
robertphillips@google.com6177e692013-02-28 20:16:25 +000042
43 fVendor = GrGLGetVendor(interface);
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000044
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000045 fRenderer = GrGLGetRendererFromString(renderer);
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000046
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000047 fIsMesa = GrGLIsMesaFromVersionString(ver);
48
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000049 fIsChromium = GrGLIsChromiumFromRendererString(renderer);
50
bsalomon@google.combcce8922013-03-25 15:38:39 +000051 fGLCaps->init(*this, interface);
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000052
53 fStandard = interface->fStandard;
robertphillips@google.com6177e692013-02-28 20:16:25 +000054 return true;
55 }
56 }
57 return false;
58}
59
60bool GrGLContextInfo::isInitialized() const {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000061 return kNone_GrGLStandard != fStandard;
robertphillips@google.com6177e692013-02-28 20:16:25 +000062}
63
64void GrGLContextInfo::reset() {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000065 fStandard = kNone_GrGLStandard;
robertphillips@google.com6177e692013-02-28 20:16:25 +000066 fGLVersion = GR_GL_VER(0, 0);
67 fGLSLGeneration = static_cast<GrGLSLGeneration>(0);
68 fVendor = kOther_GrGLVendor;
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000069 fRenderer = kOther_GrGLRenderer;
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000070 fIsMesa = false;
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000071 fIsChromium = false;
robertphillips@google.com6177e692013-02-28 20:16:25 +000072 fExtensions.reset();
bsalomon@google.combcce8922013-03-25 15:38:39 +000073 fGLCaps->reset();
robertphillips@google.com6177e692013-02-28 20:16:25 +000074}
75
76////////////////////////////////////////////////////////////////////////////////
77GrGLContext::GrGLContext(const GrGLInterface* interface) {
78 fInterface = NULL;
79 this->initialize(interface);
80}
81
82GrGLContext::GrGLContext(const GrGLContext& ctx) {
83 fInterface = NULL;
84 *this = ctx;
85}
86
87GrGLContext& GrGLContext::operator = (const GrGLContext& ctx) {
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000088 SkRefCnt_SafeAssign(fInterface, ctx.fInterface);
robertphillips@google.com6177e692013-02-28 20:16:25 +000089 fInfo = ctx.fInfo;
90 return *this;
91}
92
93void GrGLContext::reset() {
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000094 SkSafeSetNull(fInterface);
robertphillips@google.com6177e692013-02-28 20:16:25 +000095 fInfo.reset();
96}
97
98bool GrGLContext::initialize(const GrGLInterface* interface) {
99 if (fInfo.initialize(interface)) {
100 fInterface = interface;
101 interface->ref();
102 return true;
103 }
104 return false;
105}