blob: 2eb4893019e487ab96ddb193f7758d721bc61fa2 [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.comead86f22014-01-16 17:51:07 +000051 // This must be done before calling GrGLCaps::init()
52 fStandard = interface->fStandard;
53
bsalomon@google.combcce8922013-03-25 15:38:39 +000054 fGLCaps->init(*this, interface);
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000055
robertphillips@google.com6177e692013-02-28 20:16:25 +000056 return true;
57 }
58 }
59 return false;
60}
61
62bool GrGLContextInfo::isInitialized() const {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000063 return kNone_GrGLStandard != fStandard;
robertphillips@google.com6177e692013-02-28 20:16:25 +000064}
65
66void GrGLContextInfo::reset() {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000067 fStandard = kNone_GrGLStandard;
robertphillips@google.com6177e692013-02-28 20:16:25 +000068 fGLVersion = GR_GL_VER(0, 0);
69 fGLSLGeneration = static_cast<GrGLSLGeneration>(0);
70 fVendor = kOther_GrGLVendor;
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000071 fRenderer = kOther_GrGLRenderer;
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000072 fIsMesa = false;
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000073 fIsChromium = false;
robertphillips@google.com6177e692013-02-28 20:16:25 +000074 fExtensions.reset();
bsalomon@google.combcce8922013-03-25 15:38:39 +000075 fGLCaps->reset();
robertphillips@google.com6177e692013-02-28 20:16:25 +000076}
77
78////////////////////////////////////////////////////////////////////////////////
79GrGLContext::GrGLContext(const GrGLInterface* interface) {
80 fInterface = NULL;
81 this->initialize(interface);
82}
83
84GrGLContext::GrGLContext(const GrGLContext& ctx) {
85 fInterface = NULL;
86 *this = ctx;
87}
88
89GrGLContext& GrGLContext::operator = (const GrGLContext& ctx) {
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000090 SkRefCnt_SafeAssign(fInterface, ctx.fInterface);
robertphillips@google.com6177e692013-02-28 20:16:25 +000091 fInfo = ctx.fInfo;
92 return *this;
93}
94
95void GrGLContext::reset() {
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000096 SkSafeSetNull(fInterface);
robertphillips@google.com6177e692013-02-28 20:16:25 +000097 fInfo.reset();
98}
99
100bool GrGLContext::initialize(const GrGLInterface* interface) {
101 if (fInfo.initialize(interface)) {
102 fInterface = interface;
103 interface->ref();
104 return true;
105 }
106 return false;
107}