blob: 93f369109ae375bef71f2e0df964e2aa20dab16b [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) {
12 fBindingInUse = ctxInfo.fBindingInUse;
13 fGLVersion = ctxInfo.fGLVersion;
14 fGLSLGeneration = ctxInfo.fGLSLGeneration;
15 fVendor = ctxInfo.fVendor;
16 fExtensions = ctxInfo.fExtensions;
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000017 fIsMesa = ctxInfo.fIsMesa;
bsalomon@google.combcce8922013-03-25 15:38:39 +000018 *fGLCaps = *ctxInfo.fGLCaps.get();
robertphillips@google.com6177e692013-02-28 20:16:25 +000019 return *this;
20}
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +000021
robertphillips@google.com6177e692013-02-28 20:16:25 +000022bool GrGLContextInfo::initialize(const GrGLInterface* interface) {
23 this->reset();
24 // We haven't validated the GrGLInterface yet, so check for GetString
25 // function pointer
26 if (interface->fGetString) {
27 const GrGLubyte* verUByte;
28 GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION));
29 const char* ver = reinterpret_cast<const char*>(verUByte);
30 GrGLBinding binding = GrGLGetBindingInUseFromString(ver);
31
32 if (0 != binding && interface->validate(binding) && fExtensions.init(binding, interface)) {
33 fBindingInUse = binding;
34
35 fGLVersion = GrGLGetVersionFromString(ver);
36
37 fGLSLGeneration = GrGetGLSLGeneration(fBindingInUse, interface);
38
39 fVendor = GrGLGetVendor(interface);
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000040
41 fIsMesa = GrGLIsMesaFromVersionString(ver);
42
bsalomon@google.combcce8922013-03-25 15:38:39 +000043 fGLCaps->init(*this, interface);
robertphillips@google.com6177e692013-02-28 20:16:25 +000044 return true;
45 }
46 }
47 return false;
48}
49
50bool GrGLContextInfo::isInitialized() const {
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +000051 return kNone_GrGLBinding != fBindingInUse;
robertphillips@google.com6177e692013-02-28 20:16:25 +000052}
53
54void GrGLContextInfo::reset() {
55 fBindingInUse = kNone_GrGLBinding;
56 fGLVersion = GR_GL_VER(0, 0);
57 fGLSLGeneration = static_cast<GrGLSLGeneration>(0);
58 fVendor = kOther_GrGLVendor;
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000059 fIsMesa = false;
robertphillips@google.com6177e692013-02-28 20:16:25 +000060 fExtensions.reset();
bsalomon@google.combcce8922013-03-25 15:38:39 +000061 fGLCaps->reset();
robertphillips@google.com6177e692013-02-28 20:16:25 +000062}
63
64////////////////////////////////////////////////////////////////////////////////
65GrGLContext::GrGLContext(const GrGLInterface* interface) {
66 fInterface = NULL;
67 this->initialize(interface);
68}
69
70GrGLContext::GrGLContext(const GrGLContext& ctx) {
71 fInterface = NULL;
72 *this = ctx;
73}
74
75GrGLContext& GrGLContext::operator = (const GrGLContext& ctx) {
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000076 SkRefCnt_SafeAssign(fInterface, ctx.fInterface);
robertphillips@google.com6177e692013-02-28 20:16:25 +000077 fInfo = ctx.fInfo;
78 return *this;
79}
80
81void GrGLContext::reset() {
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000082 SkSafeSetNull(fInterface);
robertphillips@google.com6177e692013-02-28 20:16:25 +000083 fInfo.reset();
84}
85
86bool GrGLContext::initialize(const GrGLInterface* interface) {
87 if (fInfo.initialize(interface)) {
88 fInterface = interface;
89 interface->ref();
90 return true;
91 }
92 return false;
93}