Line data Source code
1 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "WebGLExtensions.h"
7 :
8 : #include "mozilla/dom/WebGLRenderingContextBinding.h"
9 : #include "GLContext.h"
10 : #include "WebGLContext.h"
11 : #include "WebGLContextUtils.h"
12 :
13 : namespace mozilla {
14 :
15 0 : WebGLExtensionMOZDebug::WebGLExtensionMOZDebug(WebGLContext* webgl)
16 0 : : WebGLExtensionBase(webgl)
17 : {
18 0 : }
19 :
20 0 : WebGLExtensionMOZDebug::~WebGLExtensionMOZDebug()
21 : {
22 0 : }
23 :
24 : void
25 0 : WebGLExtensionMOZDebug::GetParameter(JSContext* cx, GLenum pname,
26 : JS::MutableHandle<JS::Value> retval,
27 : ErrorResult& er) const
28 : {
29 0 : const auto& gl = mContext->gl;
30 0 : gl->MakeCurrent();
31 :
32 0 : switch (pname) {
33 : case LOCAL_GL_EXTENSIONS:
34 : {
35 0 : nsString ret;
36 0 : if (!gl->IsCoreProfile()) {
37 0 : const auto rawExts = (const char*)gl->fGetString(LOCAL_GL_EXTENSIONS);
38 0 : ret = NS_ConvertUTF8toUTF16(rawExts);
39 : } else {
40 0 : const auto& numExts = gl->GetIntAs<GLuint>(LOCAL_GL_NUM_EXTENSIONS);
41 0 : for (GLuint i = 0; i < numExts; i++) {
42 0 : const auto rawExt = (const char*)gl->fGetStringi(LOCAL_GL_EXTENSIONS,
43 0 : i);
44 0 : if (i > 0) {
45 0 : ret.AppendLiteral(" ");
46 : }
47 0 : ret.Append(NS_ConvertUTF8toUTF16(rawExt));
48 : }
49 : }
50 0 : retval.set(StringValue(cx, ret, er));
51 0 : return;
52 : }
53 :
54 : case LOCAL_GL_RENDERER:
55 : case LOCAL_GL_VENDOR:
56 : case LOCAL_GL_VERSION:
57 : {
58 0 : const auto raw = (const char*)gl->fGetString(pname);
59 0 : retval.set(StringValue(cx, NS_ConvertUTF8toUTF16(raw), er));
60 0 : return;
61 : }
62 :
63 : case 0x10000: // "WSI_INFO"
64 : {
65 0 : nsCString info;
66 0 : gl->GetWSIInfo(&info);
67 0 : retval.set(StringValue(cx, NS_ConvertUTF8toUTF16(info), er));
68 0 : return;
69 : }
70 :
71 : default:
72 0 : mContext->ErrorInvalidEnumArg("MOZ_debug.getParameter", "pname", pname);
73 0 : retval.set(JS::NullValue());
74 0 : return;
75 : }
76 : }
77 :
78 0 : IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionMOZDebug, MOZ_debug)
79 :
80 : } // namespace mozilla
|