blob: 296eaa57f4bb84b6ce1531def6010c420307d4b5 [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////////////////////////////////////////////////////////////////////////////////
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000011
12GrGLContextInfo& GrGLContextInfo::operator= (const GrGLContextInfo& that) {
13 fInterface.reset(SkSafeRef(that.fInterface.get()));
14 fGLVersion = that.fGLVersion;
15 fGLSLGeneration = that.fGLSLGeneration;
16 fVendor = that.fVendor;
17 fRenderer = that.fRenderer;
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000018 fIsMesa = that.fIsMesa;
19 fIsChromium = that.fIsChromium;
20 *fGLCaps = *that.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.org90313cc2014-01-17 15:05:38 +000037 if (interface->validate()) {
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
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000051 // This must occur before caps init.
52 fInterface.reset(SkRef(interface));
bsalomon@google.comead86f22014-01-16 17:51:07 +000053
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.orgb1854a82014-01-16 18:39:04 +000063 return NULL != fInterface.get();
robertphillips@google.com6177e692013-02-28 20:16:25 +000064}
65
66void GrGLContextInfo::reset() {
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000067 fInterface.reset(NULL);
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;
bsalomon@google.combcce8922013-03-25 15:38:39 +000074 fGLCaps->reset();
robertphillips@google.com6177e692013-02-28 20:16:25 +000075}