blob: d95fe1cb3c5e445abd9a2e152da43c8ac44aef70 [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;
18 fExtensions = that.fExtensions;
19 fIsMesa = that.fIsMesa;
20 fIsChromium = that.fIsChromium;
21 *fGLCaps = *that.fGLCaps.get();
robertphillips@google.com6177e692013-02-28 20:16:25 +000022 return *this;
23}
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +000024
robertphillips@google.com6177e692013-02-28 20:16:25 +000025bool GrGLContextInfo::initialize(const GrGLInterface* interface) {
26 this->reset();
27 // We haven't validated the GrGLInterface yet, so check for GetString
28 // function pointer
29 if (interface->fGetString) {
30 const GrGLubyte* verUByte;
31 GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION));
32 const char* ver = reinterpret_cast<const char*>(verUByte);
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000033
34 const GrGLubyte* rendererUByte;
35 GR_GL_CALL_RET(interface, rendererUByte, GetString(GR_GL_RENDERER));
36 const char* renderer = reinterpret_cast<const char*>(rendererUByte);
37
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000038 if (interface->validate() && fExtensions.init(interface)) {
robertphillips@google.com6177e692013-02-28 20:16:25 +000039
40 fGLVersion = GrGLGetVersionFromString(ver);
41
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000042 fGLSLGeneration = GrGetGLSLGeneration(interface);
robertphillips@google.com6177e692013-02-28 20:16:25 +000043
44 fVendor = GrGLGetVendor(interface);
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000045
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000046 fRenderer = GrGLGetRendererFromString(renderer);
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000047
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000048 fIsMesa = GrGLIsMesaFromVersionString(ver);
49
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000050 fIsChromium = GrGLIsChromiumFromRendererString(renderer);
51
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000052 // This must occur before caps init.
53 fInterface.reset(SkRef(interface));
bsalomon@google.comead86f22014-01-16 17:51:07 +000054
bsalomon@google.combcce8922013-03-25 15:38:39 +000055 fGLCaps->init(*this, interface);
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000056
robertphillips@google.com6177e692013-02-28 20:16:25 +000057 return true;
58 }
59 }
60 return false;
61}
62
63bool GrGLContextInfo::isInitialized() const {
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000064 return NULL != fInterface.get();
robertphillips@google.com6177e692013-02-28 20:16:25 +000065}
66
67void GrGLContextInfo::reset() {
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000068 fInterface.reset(NULL);
robertphillips@google.com6177e692013-02-28 20:16:25 +000069 fGLVersion = GR_GL_VER(0, 0);
70 fGLSLGeneration = static_cast<GrGLSLGeneration>(0);
71 fVendor = kOther_GrGLVendor;
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000072 fRenderer = kOther_GrGLRenderer;
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000073 fIsMesa = false;
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000074 fIsChromium = false;
robertphillips@google.com6177e692013-02-28 20:16:25 +000075 fExtensions.reset();
bsalomon@google.combcce8922013-03-25 15:38:39 +000076 fGLCaps->reset();
robertphillips@google.com6177e692013-02-28 20:16:25 +000077}