void WebGLContext::GetSupportedExtensions(JSContext* cx, dom::Nullable< nsTArray<nsString> >& retval) { retval.SetNull(); if (IsContextLost()) return; nsTArray<nsString>& arr = retval.SetValue(); for (size_t i = 0; i < size_t(WebGLExtensionID::Max); i++) { WebGLExtensionID extension = WebGLExtensionID(i); if (IsExtensionSupported(cx, extension)) { const char* extStr = GetExtensionString(extension); arr.AppendElement(NS_ConvertUTF8toUTF16(extStr)); } } /** * We keep backward compatibility for these deprecated vendor-prefixed * alias. Do not add new ones anymore. Hide it behind the * webgl.enable-draft-extensions flag instead. */ if (IsExtensionSupported(cx, WebGLExtensionID::WEBGL_lose_context)) arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_lose_context")); if (IsExtensionSupported(cx, WebGLExtensionID::WEBGL_compressed_texture_s3tc)) arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_s3tc")); if (IsExtensionSupported(cx, WebGLExtensionID::WEBGL_compressed_texture_atc)) arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_atc")); if (IsExtensionSupported(cx, WebGLExtensionID::WEBGL_compressed_texture_pvrtc)) arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_pvrtc")); if (IsExtensionSupported(cx, WebGLExtensionID::WEBGL_depth_texture)) arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_depth_texture")); }
void WebGLContext::GetExtension(JSContext* cx, const nsAString& wideName, JS::MutableHandle<JSObject*> retval, dom::CallerType callerType, ErrorResult& rv) { retval.set(nullptr); if (IsContextLost()) return; NS_LossyConvertUTF16toASCII name(wideName); WebGLExtensionID ext = WebGLExtensionID::Unknown; // step 1: figure what extension is wanted for (size_t i = 0; i < size_t(WebGLExtensionID::Max); i++) { WebGLExtensionID extension = WebGLExtensionID(i); if (CompareWebGLExtensionName(name, GetExtensionString(extension))) { ext = extension; break; } } if (ext == WebGLExtensionID::Unknown) return; // step 2: check if the extension is supported if (!IsExtensionSupported(callerType, ext)) return; // step 3: if the extension hadn't been previously been created, create it now, thus enabling it WebGLExtensionBase* extObj = EnableSupportedExtension(callerType, ext); if (!extObj) return; // Step 4: Enable any implied extensions. switch (ext) { case WebGLExtensionID::OES_texture_float: EnableSupportedExtension(callerType, WebGLExtensionID::WEBGL_color_buffer_float); break; case WebGLExtensionID::OES_texture_half_float: EnableSupportedExtension(callerType, WebGLExtensionID::EXT_color_buffer_half_float); break; default: break; } retval.set(WebGLObjectAsJSObject(cx, extObj, rv)); }
void WebGLContext::GetSupportedExtensions(dom::Nullable< nsTArray<nsString> >& retval, dom::CallerType callerType) { retval.SetNull(); if (IsContextLost()) return; nsTArray<nsString>& arr = retval.SetValue(); for (size_t i = 0; i < size_t(WebGLExtensionID::Max); i++) { const auto extension = WebGLExtensionID(i); if (extension == WebGLExtensionID::MOZ_debug) continue; // Hide MOZ_debug from this list. if (IsExtensionSupported(callerType, extension)) { const char* extStr = GetExtensionString(extension); arr.AppendElement(NS_ConvertUTF8toUTF16(extStr)); } } }
void WebGLContext::GetExtension(JSContext* cx, const nsAString& wideName, JS::MutableHandle<JSObject*> retval, ErrorResult& rv) { retval.set(nullptr); if (IsContextLost()) return; NS_LossyConvertUTF16toASCII name(wideName); WebGLExtensionID ext = WebGLExtensionID::Unknown; // step 1: figure what extension is wanted for (size_t i = 0; i < size_t(WebGLExtensionID::Max); i++) { WebGLExtensionID extension = WebGLExtensionID(i); if (CompareWebGLExtensionName(name, GetExtensionString(extension))) { ext = extension; break; } } if (ext == WebGLExtensionID::Unknown) { // We keep backward compatibility for these deprecated vendor-prefixed // alias. Do not add new ones anymore. Hide it behind the // webgl.enable-draft-extensions flag instead. if (CompareWebGLExtensionName(name, "MOZ_WEBGL_lose_context")) { ext = WebGLExtensionID::WEBGL_lose_context; } else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_s3tc")) { ext = WebGLExtensionID::WEBGL_compressed_texture_s3tc; } else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_atc")) { ext = WebGLExtensionID::WEBGL_compressed_texture_atc; } else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_pvrtc")) { ext = WebGLExtensionID::WEBGL_compressed_texture_pvrtc; } else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_depth_texture")) { ext = WebGLExtensionID::WEBGL_depth_texture; } if (ext != WebGLExtensionID::Unknown) { GenerateWarning("getExtension('%s'): MOZ_ prefixed WebGL extension" " strings are deprecated. Support for them will be" " removed in the future. Use unprefixed extension" " strings. To get draft extensions, set the" " webgl.enable-draft-extensions preference.", name.get()); } } if (ext == WebGLExtensionID::Unknown) return; // step 2: check if the extension is supported if (!IsExtensionSupported(cx, ext)) return; // step 3: if the extension hadn't been previously been created, create it now, thus enabling it WebGLExtensionBase* extObj = EnableSupportedExtension(cx, ext); if (!extObj) return; // Step 4: Enable any implied extensions. switch (ext) { case WebGLExtensionID::OES_texture_float: EnableSupportedExtension(cx, WebGLExtensionID::WEBGL_color_buffer_float); break; case WebGLExtensionID::OES_texture_half_float: EnableSupportedExtension(cx, WebGLExtensionID::EXT_color_buffer_half_float); break; default: break; } retval.set(WebGLObjectAsJSObject(cx, extObj, rv)); }