|
1 /* vim: se cin sw=2 ts=2 et : */ |
|
2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
3 * |
|
4 * This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #include "GfxInfoWebGL.h" |
|
9 |
|
10 #include "nsServiceManagerUtils.h" |
|
11 |
|
12 #include "GLDefs.h" |
|
13 #include "nsIDOMWebGLRenderingContext.h" |
|
14 #include "nsICanvasRenderingContextInternal.h" |
|
15 |
|
16 using namespace mozilla::widget; |
|
17 |
|
18 nsresult |
|
19 GfxInfoWebGL::GetWebGLParameter(const nsAString& aParam, nsAString& aResult) |
|
20 { |
|
21 GLenum param; |
|
22 |
|
23 if (aParam.EqualsLiteral("vendor")) param = LOCAL_GL_VENDOR; |
|
24 else if (aParam.EqualsLiteral("renderer")) param = LOCAL_GL_RENDERER; |
|
25 else if (aParam.EqualsLiteral("version")) param = LOCAL_GL_VERSION; |
|
26 else if (aParam.EqualsLiteral("shading_language_version")) param = LOCAL_GL_SHADING_LANGUAGE_VERSION; |
|
27 else if (aParam.EqualsLiteral("extensions")) param = LOCAL_GL_EXTENSIONS; |
|
28 else if (aParam.EqualsLiteral("full-renderer")) param = 0; |
|
29 else return NS_ERROR_INVALID_ARG; |
|
30 |
|
31 nsCOMPtr<nsIDOMWebGLRenderingContext> webgl = |
|
32 do_CreateInstance("@mozilla.org/content/canvas-rendering-context;1?id=experimental-webgl"); |
|
33 if (!webgl) |
|
34 return NS_ERROR_NOT_AVAILABLE; |
|
35 |
|
36 nsCOMPtr<nsICanvasRenderingContextInternal> webglInternal = |
|
37 do_QueryInterface(webgl); |
|
38 if (!webglInternal) |
|
39 return NS_ERROR_NOT_AVAILABLE; |
|
40 |
|
41 nsresult rv = webglInternal->SetDimensions(16, 16); |
|
42 NS_ENSURE_SUCCESS(rv, rv); |
|
43 |
|
44 if (param) |
|
45 return webgl->MozGetUnderlyingParamString(param, aResult); |
|
46 |
|
47 // this is the "full renderer" string, which is vendor + renderer + version |
|
48 |
|
49 nsAutoString str; |
|
50 |
|
51 rv = webgl->MozGetUnderlyingParamString(LOCAL_GL_VENDOR, str); |
|
52 NS_ENSURE_SUCCESS(rv, rv); |
|
53 |
|
54 aResult.Append(str); |
|
55 aResult.AppendLiteral(" -- "); |
|
56 |
|
57 rv = webgl->MozGetUnderlyingParamString(LOCAL_GL_RENDERER, str); |
|
58 NS_ENSURE_SUCCESS(rv, rv); |
|
59 |
|
60 aResult.Append(str); |
|
61 aResult.AppendLiteral(" -- "); |
|
62 |
|
63 rv = webgl->MozGetUnderlyingParamString(LOCAL_GL_VERSION, str); |
|
64 NS_ENSURE_SUCCESS(rv, rv); |
|
65 |
|
66 aResult.Append(str); |
|
67 |
|
68 return NS_OK; |
|
69 } |