widget/xpwidgets/GfxInfoWebGL.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/xpwidgets/GfxInfoWebGL.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,69 @@
     1.4 +/* vim: se cin sw=2 ts=2 et : */
     1.5 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.6 + *
     1.7 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.10 +
    1.11 +#include "GfxInfoWebGL.h"
    1.12 +
    1.13 +#include "nsServiceManagerUtils.h"
    1.14 +
    1.15 +#include "GLDefs.h"
    1.16 +#include "nsIDOMWebGLRenderingContext.h"
    1.17 +#include "nsICanvasRenderingContextInternal.h"
    1.18 +
    1.19 +using namespace mozilla::widget;
    1.20 +
    1.21 +nsresult
    1.22 +GfxInfoWebGL::GetWebGLParameter(const nsAString& aParam, nsAString& aResult)
    1.23 +{
    1.24 +  GLenum param;
    1.25 +
    1.26 +  if (aParam.EqualsLiteral("vendor")) param = LOCAL_GL_VENDOR;
    1.27 +  else if (aParam.EqualsLiteral("renderer")) param = LOCAL_GL_RENDERER;
    1.28 +  else if (aParam.EqualsLiteral("version")) param = LOCAL_GL_VERSION;
    1.29 +  else if (aParam.EqualsLiteral("shading_language_version")) param = LOCAL_GL_SHADING_LANGUAGE_VERSION;
    1.30 +  else if (aParam.EqualsLiteral("extensions")) param = LOCAL_GL_EXTENSIONS;
    1.31 +  else if (aParam.EqualsLiteral("full-renderer")) param = 0;
    1.32 +  else return NS_ERROR_INVALID_ARG;
    1.33 +
    1.34 +  nsCOMPtr<nsIDOMWebGLRenderingContext> webgl =
    1.35 +    do_CreateInstance("@mozilla.org/content/canvas-rendering-context;1?id=experimental-webgl");
    1.36 +  if (!webgl)
    1.37 +    return NS_ERROR_NOT_AVAILABLE;
    1.38 +
    1.39 +  nsCOMPtr<nsICanvasRenderingContextInternal> webglInternal =
    1.40 +    do_QueryInterface(webgl);
    1.41 +  if (!webglInternal)
    1.42 +    return NS_ERROR_NOT_AVAILABLE;
    1.43 +
    1.44 +  nsresult rv = webglInternal->SetDimensions(16, 16);
    1.45 +  NS_ENSURE_SUCCESS(rv, rv);
    1.46 +
    1.47 +  if (param)
    1.48 +    return webgl->MozGetUnderlyingParamString(param, aResult);
    1.49 +
    1.50 +  // this is the "full renderer" string, which is vendor + renderer + version
    1.51 +
    1.52 +  nsAutoString str;
    1.53 +
    1.54 +  rv = webgl->MozGetUnderlyingParamString(LOCAL_GL_VENDOR, str);
    1.55 +  NS_ENSURE_SUCCESS(rv, rv);
    1.56 +
    1.57 +  aResult.Append(str);
    1.58 +  aResult.AppendLiteral(" -- ");
    1.59 +
    1.60 +  rv = webgl->MozGetUnderlyingParamString(LOCAL_GL_RENDERER, str);
    1.61 +  NS_ENSURE_SUCCESS(rv, rv);
    1.62 +
    1.63 +  aResult.Append(str);
    1.64 +  aResult.AppendLiteral(" -- ");
    1.65 +
    1.66 +  rv = webgl->MozGetUnderlyingParamString(LOCAL_GL_VERSION, str);
    1.67 +  NS_ENSURE_SUCCESS(rv, rv);
    1.68 +
    1.69 +  aResult.Append(str);
    1.70 +
    1.71 +  return NS_OK;
    1.72 +}

mercurial