blob: fc8b195fd37858d48ac27182a75dd818a10bdb3d [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
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +000028 if (interface->fFunctions.fGetString) {
robertphillips@google.com6177e692013-02-28 20:16:25 +000029 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);
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +000040 if (GR_GL_INVALID_VER == fGLVersion) {
41 return false;
42 }
robertphillips@google.com6177e692013-02-28 20:16:25 +000043
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +000044 if (!GrGetGLSLGeneration(interface, &fGLSLGeneration)) {
45 return false;
46 }
robertphillips@google.com6177e692013-02-28 20:16:25 +000047
48 fVendor = GrGLGetVendor(interface);
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000049
rmistry63a9f842014-10-17 06:07:08 -070050 /*
51 * Qualcomm drivers have a horrendous bug with some drivers. Though they claim to
52 * support GLES 3.00, some perfectly valid GLSL300 shaders will only compile with
53 * #version 100, and will fail to compile with #version 300 es. In the long term, we
54 * need to lock this down to a specific driver version.
55 */
56 if (kQualcomm_GrGLVendor == fVendor) {
57 fGLSLGeneration = k110_GrGLSLGeneration;
58 }
59
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000060 fRenderer = GrGLGetRendererFromString(renderer);
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000061
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000062 fIsMesa = GrGLIsMesaFromVersionString(ver);
63
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000064 fIsChromium = GrGLIsChromiumFromRendererString(renderer);
65
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000066 // This must occur before caps init.
67 fInterface.reset(SkRef(interface));
bsalomon@google.comead86f22014-01-16 17:51:07 +000068
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +000069 return fGLCaps->init(*this, interface);
robertphillips@google.com6177e692013-02-28 20:16:25 +000070 }
71 }
72 return false;
73}
74
bsalomon49f085d2014-09-05 13:34:00 -070075bool GrGLContextInfo::isInitialized() const { return SkToBool(fInterface.get()); }
robertphillips@google.com6177e692013-02-28 20:16:25 +000076
77void GrGLContextInfo::reset() {
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000078 fInterface.reset(NULL);
robertphillips@google.com6177e692013-02-28 20:16:25 +000079 fGLVersion = GR_GL_VER(0, 0);
80 fGLSLGeneration = static_cast<GrGLSLGeneration>(0);
81 fVendor = kOther_GrGLVendor;
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000082 fRenderer = kOther_GrGLRenderer;
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000083 fIsMesa = false;
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000084 fIsChromium = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +000085 fGLCaps->reset();
robertphillips@google.com6177e692013-02-28 20:16:25 +000086}