widget/GfxInfoWebGL.cpp
author Nathan Froyd <froydnj@mozilla.com>
Wed, 19 Oct 2016 00:33:14 -0400
changeset 318541 53252ffba01d8723024e875f3410153e0ffe3b1b
parent 216163 7025a18fc63bdd98b777a038f8aeda2184d439c4
permissions -rw-r--r--
Bug 1311068 - remove InitializerList.h; r=botond We needed this polyfill for <initializer_list> when some of our C++ standard libraries did not support said header. They all do now, so the polyfill is redundant.

/* vim: se cin sw=2 ts=2 et : */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "GfxInfoWebGL.h"

#include "nsServiceManagerUtils.h"

#include "GLDefs.h"
#include "nsIDOMWebGLRenderingContext.h"
#include "nsICanvasRenderingContextInternal.h"

using namespace mozilla::widget;

nsresult
GfxInfoWebGL::GetWebGLParameter(const nsAString& aParam, nsAString& aResult)
{
  GLenum param;

  if (aParam.EqualsLiteral("vendor")) param = LOCAL_GL_VENDOR;
  else if (aParam.EqualsLiteral("renderer")) param = LOCAL_GL_RENDERER;
  else if (aParam.EqualsLiteral("version")) param = LOCAL_GL_VERSION;
  else if (aParam.EqualsLiteral("shading_language_version")) param = LOCAL_GL_SHADING_LANGUAGE_VERSION;
  else if (aParam.EqualsLiteral("extensions")) param = LOCAL_GL_EXTENSIONS;
  else if (aParam.EqualsLiteral("full-renderer")) param = 0;
  else return NS_ERROR_INVALID_ARG;

  nsCOMPtr<nsIDOMWebGLRenderingContext> webgl =
    do_CreateInstance("@mozilla.org/content/canvas-rendering-context;1?id=webgl");
  if (!webgl)
    return NS_ERROR_NOT_AVAILABLE;

  nsCOMPtr<nsICanvasRenderingContextInternal> webglInternal =
    do_QueryInterface(webgl);
  if (!webglInternal)
    return NS_ERROR_NOT_AVAILABLE;

  nsresult rv = webglInternal->SetDimensions(16, 16);
  NS_ENSURE_SUCCESS(rv, rv);

  if (param)
    return webgl->MozGetUnderlyingParamString(param, aResult);

  // this is the "full renderer" string, which is vendor + renderer + version

  nsAutoString str;

  rv = webgl->MozGetUnderlyingParamString(LOCAL_GL_VENDOR, str);
  NS_ENSURE_SUCCESS(rv, rv);

  aResult.Append(str);
  aResult.AppendLiteral(" -- ");

  rv = webgl->MozGetUnderlyingParamString(LOCAL_GL_RENDERER, str);
  NS_ENSURE_SUCCESS(rv, rv);

  aResult.Append(str);
  aResult.AppendLiteral(" -- ");

  rv = webgl->MozGetUnderlyingParamString(LOCAL_GL_VERSION, str);
  NS_ENSURE_SUCCESS(rv, rv);

  aResult.Append(str);

  return NS_OK;
}