public static void OutputEnum(Effects.Property enumProperty, Formatter output) { OutputVersionConditional(enumProperty.WinVer, output); output.WriteLine("[version(VERSION)]"); output.WriteLine("typedef enum " + enumProperty.TypeNameIdl); output.WriteLine("{"); output.Indent(); for (int i = 0; i < enumProperty.EnumFields.FieldsList.Count; ++i) { var enumValue = enumProperty.EnumFields.FieldsList[i]; if (i != (enumProperty.EnumFields.FieldsList.Count - 1)) { output.WriteLine(enumValue.Name + " = " + i.ToString() + ","); } else { output.WriteLine(enumValue.Name + " = " + i.ToString()); } } output.Unindent(); output.WriteLine("} " + enumProperty.TypeNameIdl + ";"); EndVersionConditional(enumProperty.WinVer, output); }
public static void OutputCommonEnums(List<Effects.Effect> effects, Formatter output) { OutputDataTypes.OutputLeadingComment(output); output.WriteLine("namespace Microsoft.Graphics.Canvas.Effects"); output.WriteLine("{"); output.Indent(); bool isFirstOutput = true; foreach (var effect in effects) { foreach (var property in effect.Properties) { // Check if property represent enum that is common to some group of effects if (property.Type == "enum" && property.EnumFields.IsRepresentative && property.ShouldProject) { var registeredEffects = effects.Where(EffectGenerator.IsEffectEnabled); // Check if any registred property need this enum if (registeredEffects.Any(e => e.Properties.Any(p => p.TypeNameIdl == property.TypeNameIdl))) { if (isFirstOutput) { isFirstOutput = false; } else { output.WriteLine(); } OutputEnum(property, output); } } } } output.Unindent(); output.WriteLine("}"); }
public static void OutputEffectMakers(List<Effects.Effect> effects, Formatter output) { OutputDataTypes.OutputLeadingComment(output); output.WriteLine("#include \"pch.h\""); output.WriteLine(); var enabledEffects = from effect in effects where EffectGenerator.IsEffectEnabled(effect) select effect; var effectsByVersion = from effect in enabledEffects orderby effect.ClassName group effect by (effect.Overrides != null ? effect.Overrides.WinVer : null) into versionGroup orderby versionGroup.Key select versionGroup; foreach (var versionGroup in effectsByVersion) { OutputVersionConditional(versionGroup.Key, output); foreach (var effect in versionGroup) { output.WriteLine("#include \"" + effect.ClassName + ".h\""); } EndVersionConditional(versionGroup.Key, output); output.WriteLine(); } output.WriteLine(); output.WriteLine("std::pair<IID, CanvasEffect::MakeEffectFunction> CanvasEffect::m_effectMakers[] ="); output.WriteLine("{"); int longestName = enabledEffects.Select(effect => effect.ClassName.Length).Max(); foreach (var versionGroup in effectsByVersion) { OutputVersionConditional(versionGroup.Key, output); output.Indent(); foreach (var effect in versionGroup) { string padding = new string(' ', longestName - effect.ClassName.Length); output.WriteLine("{ " + effect.ClassName + "::EffectId(), " + padding + "MakeEffect<" + effect.ClassName + "> " + padding + "},"); } output.Unindent(); EndVersionConditional(versionGroup.Key, output); output.WriteLine(); } output.Indent(); output.WriteLine("{ GUID_NULL, nullptr }"); output.Unindent(); output.WriteLine("};"); }
public static void OutputLeadingComment(Formatter output) { output.WriteLine("// Copyright (c) Microsoft Corporation. All rights reserved."); output.WriteLine("//"); output.WriteLine("// Licensed under the MIT License. See LICENSE.txt in the project root for license information."); output.WriteLine(); output.WriteLine("// This file was automatically generated. Please do not edit it manually."); output.WriteLine(); }
public void OutputCode(Dictionary<string, QualifiableType> typeDictionary, Formatter idlFile) { OutputLeadingComment(idlFile); var sortedTypes = m_types.OrderBy(x => x.Namespace).ThenBy(x => x.GetType()).ThenBy(x => x.ProjectedName); string currentNamespace = null; foreach (var type in sortedTypes) { UpdateNamespace(idlFile, ref currentNamespace, type.Namespace); type.OutputCode(typeDictionary, idlFile); } UpdateNamespace(idlFile, ref currentNamespace, null); }
public static void OutputLeadingComment(Formatter output) { output.WriteLine("// Copyright (c) Microsoft Corporation. All rights reserved."); output.WriteLine("//"); output.WriteLine("// Licensed under the Apache License, Version 2.0 (the \"License\"); you may"); output.WriteLine("// not use these files except in compliance with the License. You may obtain"); output.WriteLine("// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0"); output.WriteLine("//"); output.WriteLine("// Unless required by applicable law or agreed to in writing, software"); output.WriteLine("// distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT"); output.WriteLine("// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the"); output.WriteLine("// License for the specific language governing permissions and limitations"); output.WriteLine("// under the License."); output.WriteLine(); output.WriteLine("// This file was automatically generated. Please do not edit it manually."); output.WriteLine(); }
public void UpdateNamespace(Formatter idlFile, ref string currentNamespace, string newNamespace) { if (currentNamespace != newNamespace) { if (currentNamespace != null) { // end the previous namespace idlFile.Unindent(); idlFile.WriteLine("} // " + currentNamespace); idlFile.WriteLine(""); } currentNamespace = newNamespace; if (newNamespace != null) { idlFile.WriteLine("namespace " + newNamespace); idlFile.WriteLine("{"); idlFile.Indent(); } } }
public static void OutputEffectHeader(Effects.Effect effect, Formatter output) { OutputDataTypes.OutputLeadingComment(output); output.WriteLine("#pragma once"); output.WriteLine(); OutputVersionConditional(effect, output); output.WriteLine("namespace ABI { namespace Microsoft { namespace Graphics { namespace Canvas { namespace Effects "); output.WriteLine("{"); output.Indent(); output.WriteLine("using namespace ::Microsoft::WRL;"); output.WriteLine("using namespace ABI::Microsoft::Graphics::Canvas;"); output.WriteLine(); output.WriteLine("class " + effect.ClassName + " : public RuntimeClass<"); output.Indent(); output.WriteLine(effect.InterfaceName + ","); output.WriteLine("MixIn<" + effect.ClassName + ", CanvasEffect>>,"); output.WriteLine("public CanvasEffect"); output.Unindent(); output.WriteLine("{"); output.Indent(); output.WriteLine("InspectableClass(RuntimeClass_Microsoft_Graphics_Canvas_Effects_" + effect.ClassName + ", BaseTrust);"); output.WriteLine(); output.Unindent(); output.WriteLine("public:"); output.Indent(); output.WriteLine(effect.ClassName + "(ICanvasDevice* device = nullptr, ID2D1Effect* effect = nullptr);"); output.WriteLine(); output.WriteLine("static IID const& EffectId() { return " + GetEffectCLSID(effect) + "; }"); output.WriteLine(); foreach (var property in effect.Properties) { // Property with type string describes // name/author/category/description of effect but not input type if (property.Type == "string" || property.IsHidden) { continue; } var propertyMacro = property.IsArray ? "EFFECT_ARRAY_PROPERTY" : "EFFECT_PROPERTY"; output.WriteLine(propertyMacro + "(" + property.Name + ", " + property.TypeNameCpp + ");"); } if (EffectHasVariableNumberOfInputs(effect)) { output.WriteLine("EFFECT_SOURCES_PROPERTY();"); } else { for (int i = 0; i < effect.Inputs.InputsList.Count; ++i) { var input = effect.Inputs.InputsList[i]; output.WriteLine("EFFECT_PROPERTY(" + input.Name + ", IGraphicsEffectSource*);"); } } bool hasPropertyMapping = effect.Properties.Any(IsGeneratablePropertyMapping); bool hasHandCodedPropertyMapping = effect.Properties.Any(p => p.IsHandCoded); if (hasPropertyMapping || hasHandCodedPropertyMapping) { output.WriteLine(); if (hasPropertyMapping) { output.WriteLine("EFFECT_PROPERTY_MAPPING();"); } if (hasHandCodedPropertyMapping) { output.WriteLine("EFFECT_PROPERTY_MAPPING_HANDCODED();"); } } output.Unindent(); output.WriteLine("};"); if (HasStatics(effect)) { output.WriteLine(); output.WriteLine("class " + effect.ClassName + "Factory"); output.Indent(); output.WriteLine(": public AgileActivationFactory<I" + effect.ClassName + "Statics>"); output.WriteLine(", private LifespanTracker<" + effect.ClassName + "Factory>"); output.Unindent(); output.WriteLine("{"); output.Indent(); output.WriteLine("InspectableClassStatic(RuntimeClass_Microsoft_Graphics_Canvas_Effects_" + effect.ClassName + ", BaseTrust);"); output.WriteLine(); output.Unindent(); output.WriteLine("public:"); output.Indent(); output.WriteLine("IFACEMETHODIMP ActivateInstance(IInspectable**) override;"); foreach (var customDecl in effect.Overrides.CustomStaticMethodDecl) { output.WriteLine(customDecl.Trim()); } if (!string.IsNullOrEmpty(effect.Overrides.IsSupportedCheck)) { output.WriteLine("IFACEMETHOD(get_IsSupported)(boolean* value) override;"); } output.Unindent(); output.WriteLine("};"); } output.Unindent(); output.WriteLine("}}}}}"); EndVersionConditional(effect, output); }
public static void OutputEffectHeader(Effects.Effect effect, Formatter output) { OutputDataTypes.OutputLeadingComment(output); output.WriteLine("#pragma once"); output.WriteLine(); OutputVersionConditional(effect, output); output.WriteLine("namespace ABI { namespace Microsoft { namespace Graphics { namespace Canvas { namespace Effects "); output.WriteLine("{"); output.Indent(); output.WriteLine("using namespace ::Microsoft::WRL;"); output.WriteLine("using namespace ABI::Microsoft::Graphics::Canvas;"); output.WriteLine(); output.WriteLine("class " + effect.ClassName + " : public RuntimeClass<"); output.Indent(); output.WriteLine(effect.InterfaceName + ","); output.WriteLine("MixIn<" + effect.ClassName + ", CanvasEffect>>,"); output.WriteLine("public CanvasEffect"); output.Unindent(); output.WriteLine("{"); output.Indent(); output.WriteLine("InspectableClass(RuntimeClass_Microsoft_Graphics_Canvas_Effects_" + effect.ClassName + ", BaseTrust);"); output.WriteLine(); output.Unindent(); output.WriteLine("public:"); output.Indent(); output.WriteLine(effect.ClassName + "(ICanvasDevice* device = nullptr, ID2D1Effect* effect = nullptr);"); output.WriteLine(); output.WriteLine("static IID const& EffectId() { return " + GetEffectCLSID(effect) + "; }"); output.WriteLine(); foreach (var property in effect.Properties) { // Property with type string describes // name/author/category/description of effect but not input type if (property.Type == "string" || property.IsHidden) continue; var propertyMacro = property.IsArray ? "EFFECT_ARRAY_PROPERTY" : "EFFECT_PROPERTY"; output.WriteLine(propertyMacro + "(" + property.Name + ", " + property.TypeNameCpp + ");"); } if (EffectHasVariableNumberOfInputs(effect)) { output.WriteLine("EFFECT_SOURCES_PROPERTY();"); } else { for (int i = 0; i < effect.Inputs.InputsList.Count; ++i) { var input = effect.Inputs.InputsList[i]; output.WriteLine("EFFECT_PROPERTY(" + input.Name + ", IGraphicsEffectSource*);"); } } bool hasPropertyMapping = effect.Properties.Any(IsGeneratablePropertyMapping); bool hasHandCodedPropertyMapping = effect.Properties.Any(p => p.IsHandCoded); if (hasPropertyMapping || hasHandCodedPropertyMapping) { output.WriteLine(); if (hasPropertyMapping) output.WriteLine("EFFECT_PROPERTY_MAPPING();"); if (hasHandCodedPropertyMapping) output.WriteLine("EFFECT_PROPERTY_MAPPING_HANDCODED();"); } output.Unindent(); output.WriteLine("};"); output.Unindent(); output.WriteLine("}}}}}"); EndVersionConditional(effect, output); }
void OutputValueTypeProjectionCode(Dictionary<string, QualifiableType> typeDictionary, Formatter idlFile) { // This outputs to the IDL file only. There is no output to the .cpp file. idlFile.WriteLine("[version(VERSION)]"); idlFile.WriteLine("typedef struct " + m_stylizedName); idlFile.WriteLine("{"); idlFile.Indent(); foreach(StructField structField in m_structFields) { QualifiableType typeObject = typeDictionary[structField.TypeName]; idlFile.WriteLine(typeObject.IdlTypeNameQualifier + typeObject.ProjectedName + " " + structField.PropertyName + ";"); } idlFile.Unindent(); idlFile.WriteLine("} " + m_stylizedName + ";"); idlFile.WriteLine(); }
public static void OutputEffectIdl(Effects.Effect effect, Formatter output) { OutputDataTypes.OutputLeadingComment(output); OutputVersionConditional(effect, output); output.WriteLine("namespace Microsoft.Graphics.Canvas.Effects"); output.WriteLine("{"); output.Indent(); // Output all enums specific to this effect foreach (var property in effect.Properties) { if (property.Type == "enum" && property.EnumFields.Usage == Effects.EnumValues.UsageType.UsedByOneEffect && property.ShouldProject) { OutputEnum(property, output); output.WriteLine(); } } output.WriteLine("runtimeclass " + effect.ClassName + ";"); output.WriteLine(); output.WriteLine("[version(VERSION), uuid(" + effect.Uuid + "), exclusiveto(" + effect.ClassName + ")]"); output.WriteLine("interface " + effect.InterfaceName + " : IInspectable"); output.WriteIndent(); output.WriteLine("requires Microsoft.Graphics.Canvas.ICanvasImage"); output.WriteLine("{"); output.Indent(); foreach (var property in effect.Properties) { // Property with type string describes // name/author/category/description of effect but not input type if (property.Type == "string" || property.IsHidden) continue; output.WriteLine("[propget]"); if (property.IsArray) { output.WriteLine("HRESULT " + property.Name + "([out] UINT32* valueCount, [out, size_is(, *valueCount), retval] " + property.TypeNameIdl + "** valueElements);"); } else { output.WriteLine("HRESULT " + property.Name + "([out, retval] " + property.TypeNameIdl + "* value);"); } output.WriteLine(); output.WriteLine("[propput]"); if (property.IsArray) { output.WriteLine("HRESULT " + property.Name + "([in] UINT32 valueCount, [in, size_is(valueCount)] " + property.TypeNameIdl + "* valueElements);"); } else { output.WriteLine("HRESULT " + property.Name + "([in] " + property.TypeNameIdl + " value);"); } output.WriteLine(); } if (EffectHasVariableNumberOfInputs(effect)) { output.WriteLine("[propget]"); output.WriteLine("HRESULT Sources([out, retval] Windows.Foundation.Collections.IVector<IGRAPHICSEFFECTSOURCE*>** value);"); output.WriteLine(); } else { for (int i = 0; i < effect.Inputs.InputsList.Count; ++i) { var input = effect.Inputs.InputsList[i]; output.WriteLine("[propget]"); output.WriteLine("HRESULT " + input.Name + "([out, retval] IGRAPHICSEFFECTSOURCE** source);"); output.WriteLine(); output.WriteLine("[propput]"); output.WriteLine("HRESULT " + input.Name + "([in] IGRAPHICSEFFECTSOURCE* source);"); output.WriteLine(); } } output.Unindent(); output.WriteLine("};"); output.WriteLine(); output.WriteLine("[version(VERSION), activatable(VERSION)]"); output.WriteLine("runtimeclass " + effect.ClassName); output.WriteLine("{"); output.Indent(); output.WriteLine("[default] interface " + effect.InterfaceName + ";"); output.WriteLine("interface IGRAPHICSEFFECT;"); output.Unindent(); output.WriteLine("}"); output.Unindent(); output.WriteLine("}"); EndVersionConditional(effect, output); }
private static void WritePropertyMapping(Effects.Effect effect, Formatter output) { var query = from property in effect.Properties where IsGeneratablePropertyMapping(property) select new { Name = property.Name, Index = property.NativePropertyName, Mapping = GetPropertyMapping(property) }; var properties = query.ToList(); if (properties.Any()) { output.WriteLine("IMPLEMENT_EFFECT_PROPERTY_MAPPING(" + effect.ClassName + ","); output.Indent(); int maxNameLength = properties.Select(property => property.Name.Length).Max(); int maxIndexLength = properties.Select(property => property.Index.Length).Max(); int maxMappingLength = properties.Select(property => property.Mapping.Length).Max(); foreach (var property in properties) { string nameAlignment = new string(' ', maxNameLength - property.Name.Length); string indexAlignment = new string(' ', maxIndexLength - property.Index.Length); string mappingAlignment = new string(' ', maxMappingLength - property.Mapping.Length); string suffix = property.Equals(properties.Last()) ? ")" : ","; output.WriteLine("{ L\"" + property.Name + "\", " + nameAlignment + property.Index + ", " + indexAlignment + property.Mapping + mappingAlignment + " }" + suffix); } output.Unindent(); output.WriteLine(); } }
public static void OutputEffectIdl(Effects.Effect effect, Formatter output) { OutputDataTypes.OutputLeadingComment(output); output.WriteLine("namespace Microsoft.Graphics.Canvas.Effects"); output.WriteLine("{"); output.Indent(); // Output all enums specific to this effect foreach (var property in effect.Properties) { if (property.Type == "enum" && property.EnumFields.Usage == Effects.EnumValues.UsageType.UsedByOneEffect && property.ShouldProject) { OutputEnum(property, output); output.WriteLine(); } } output.WriteLine("runtimeclass " + effect.ClassName + ";"); output.WriteLine(); output.WriteLine("[version(VERSION), uuid(" + effect.Uuid + "), exclusiveto(" + effect.ClassName + ")]"); output.WriteLine("interface " + effect.InterfaceName + " : IInspectable"); output.WriteIndent(); output.WriteLine("requires Microsoft.Graphics.Canvas.ICanvasImage"); output.WriteLine("{"); output.Indent(); foreach (var property in effect.Properties) { // Property with type string describes // name/author/category/description of effect but not input type if (property.Type == "string" || property.IsHidden) { continue; } output.WriteLine("[propget]"); if (property.IsArray) { output.WriteLine("HRESULT " + property.Name + "([out] UINT32* valueCount, [out, size_is(, *valueCount), retval] " + property.TypeNameIdl + "** valueElements);"); } else { output.WriteLine("HRESULT " + property.Name + "([out, retval] " + property.TypeNameIdl + "* value);"); } output.WriteLine(); output.WriteLine("[propput]"); if (property.IsArray) { output.WriteLine("HRESULT " + property.Name + "([in] UINT32 valueCount, [in, size_is(valueCount)] " + property.TypeNameIdl + "* valueElements);"); } else { output.WriteLine("HRESULT " + property.Name + "([in] " + property.TypeNameIdl + " value);"); } output.WriteLine(); } // Check if inputs specify maximum attribute in xml and if it is marked as unlimited if (!(effect.Inputs.Maximum != null && effect.Inputs.Maximum == "0xFFFFFFFF")) { for (int i = 0; i < effect.Inputs.InputsList.Count; ++i) { var input = effect.Inputs.InputsList[i]; output.WriteLine("[propget]"); output.WriteLine("HRESULT " + input.Name + "([out, retval] IEffectInput** input);"); output.WriteLine(); output.WriteLine("[propput]"); output.WriteLine("HRESULT " + input.Name + "([in] IEffectInput* input);"); output.WriteLine(); } } output.Unindent(); output.WriteLine("};"); output.WriteLine(); output.WriteLine("[version(VERSION), activatable(VERSION)]"); output.WriteLine("runtimeclass " + effect.ClassName); output.WriteLine("{"); output.Indent(); output.WriteLine("[default] interface " + effect.InterfaceName + ";"); output.WriteLine("interface IEffect;"); output.Unindent(); output.WriteLine("}"); output.Unindent(); output.WriteLine("}"); }
private static void OutputVersionConditional(string winVer, Formatter output) { if (!string.IsNullOrEmpty(winVer)) { output.WriteLine(string.Format("#if (defined {0}) && (WINVER >= {0})", winVer)); output.WriteLine(); } }
private static void WritePropertyImplementation(Effects.Effect effect, Formatter output, Effects.Property property) { // Property with type string describes // name/author/category/description of effect but not input type if (property.Type == "string" || property.IsHandCoded || property.IsHidden) return; var min = property.Properties.Find(internalProperty => internalProperty.Name == "Min"); var max = property.Properties.Find(internalProperty => internalProperty.Name == "Max"); bool isWithUnsupported = (property.ExcludedEnumIndexes != null) && (property.ExcludedEnumIndexes.Count != 0); string customConversion = null; if (property.ConvertRadiansToDegrees) { customConversion = "ConvertRadiansToDegrees"; } else if (property.ConvertColorHdrToVector3) { customConversion = "ConvertColorHdrToVector3"; } else if (property.Name == "AlphaMode") { customConversion = "ConvertAlphaMode"; } bool isValidation = ((min != null) || (max != null) || isWithUnsupported) && (customConversion == null); string implementMacro = property.IsArray ? "IMPLEMENT_EFFECT_ARRAY_PROPERTY" : "IMPLEMENT_EFFECT_PROPERTY"; if (isValidation) { implementMacro += "_WITH_VALIDATION"; } output.WriteLine(implementMacro + "(" + effect.ClassName + ","); output.Indent(); output.WriteLine(property.Name + ","); output.WriteLine((customConversion ?? property.TypeNameBoxed) + ","); if (!property.IsArray) { output.WriteLine(property.TypeNameCpp + ","); } if (isValidation) { output.WriteLine(property.NativePropertyName + ","); var validationChecks = new List<string>(); if (min != null) { AddValidationChecks(validationChecks, property, min.Value, ">="); } if (max != null) { AddValidationChecks(validationChecks, property, max.Value, "<="); } if (isWithUnsupported) { foreach (var index in property.ExcludedEnumIndexes) { validationChecks.Add("value != static_cast<" + property.TypeNameCpp + ">(" + index + ")"); } } output.WriteLine("(" + string.Join(") && (", validationChecks) + "))"); } else { output.WriteLine(property.NativePropertyName + ")"); } output.Unindent(); output.WriteLine(); }
public static void GenerateCode(ProcessedInputFiles inputFiles, string outputDir) { Directory.CreateDirectory(outputDir); using (Formatter idlStreamWriter = new Formatter(Path.Combine(outputDir, inputFiles.FilenameBase + ".codegen.idl"))) { inputFiles.OutputDataTypes.OutputCode(inputFiles.TypeDictionary, idlStreamWriter); } }
public static void OutputEffectCpp(Effects.Effect effect, Formatter output) { OutputDataTypes.OutputLeadingComment(output); bool isInputSizeFixed = true; if (effect.Inputs.Maximum != null && effect.Inputs.Maximum == "0xFFFFFFFF") { isInputSizeFixed = false; } output.WriteLine("#include \"pch.h\""); output.WriteLine("#include \"" + effect.ClassName + ".h\""); output.WriteLine(); output.WriteLine("namespace ABI { namespace Microsoft { namespace Graphics { namespace Canvas { namespace Effects"); output.WriteLine("{"); output.Indent(); output.WriteLine(effect.ClassName + "::" + effect.ClassName + "()"); output.WriteIndent(); int inputsCount = effect.Inputs.InputsList.Count; if (effect.Inputs.Maximum != null && effect.Inputs.Maximum == "0xFFFFFFFF") { inputsCount = 0; } output.WriteLine(": CanvasEffect(CLSID_D2D1" + EffectGenerator.FormatClassName(effect.Properties[0].Value) + ", " + (effect.Properties.Count(p => !p.IsHandCoded) - 4) + ", " + inputsCount + ", " + isInputSizeFixed.ToString().ToLower() + ")"); output.WriteLine("{"); output.Indent(); output.WriteLine("// Set default values"); foreach (var property in effect.Properties) { WritePropertyInitialization(output, property); } output.Unindent(); output.WriteLine("}"); output.WriteLine(); foreach (var property in effect.Properties) { WritePropertyImplementation(effect, output, property); } if (!(effect.Inputs.Maximum != null && effect.Inputs.Maximum == "0xFFFFFFFF")) { for (int i = 0; i < effect.Inputs.InputsList.Count; ++i) { var input = effect.Inputs.InputsList[i]; output.WriteLine("IMPLEMENT_EFFECT_INPUT_PROPERTY(" + effect.ClassName + ","); output.Indent(); output.WriteLine(input.Name + ","); output.WriteLine(i.ToString() + ")"); output.Unindent(); output.WriteLine(); } } output.WriteLine("ActivatableClass(" + effect.ClassName + ");"); output.Unindent(); output.WriteLine("}}}}}"); }
public abstract void OutputCode(Dictionary<string, QualifiableType> typeDictionary, Formatter idlFile);
public static void OutputEffectCpp(Effects.Effect effect, Formatter output) { OutputDataTypes.OutputLeadingComment(output); bool isInputSizeFixed = !EffectHasVariableNumberOfInputs(effect); int inputsCount = isInputSizeFixed ? effect.Inputs.InputsList.Count : 0; output.WriteLine("#include \"pch.h\""); output.WriteLine("#include \"" + effect.ClassName + ".h\""); output.WriteLine(); OutputVersionConditional(effect, output); output.WriteLine("namespace ABI { namespace Microsoft { namespace Graphics { namespace Canvas { namespace Effects"); output.WriteLine("{"); output.Indent(); output.WriteLine(effect.ClassName + "::" + effect.ClassName + "(ICanvasDevice* device, ID2D1Effect* effect)"); output.WriteIndent(); output.WriteLine(": CanvasEffect(EffectId(), " + (effect.Properties.Count(p => (!p.IsHandCoded && !p.IsHdrAlias)) - 4) + ", " + inputsCount + ", " + isInputSizeFixed.ToString().ToLower() + ", " + "device, effect, static_cast<" + effect.InterfaceName + "*>(this))"); output.WriteLine("{"); output.Indent(); if (effect.Overrides != null && !string.IsNullOrEmpty(effect.Overrides.IsSupportedCheck)) { output.WriteLine("if (!SharedDeviceState::GetInstance()->Is" + effect.Overrides.IsSupportedCheck + "Supported())"); output.Indent(); output.WriteLine("ThrowHR(E_NOTIMPL, Strings::NotSupportedOnThisVersionOfWindows);"); output.Unindent(); output.WriteLine(); } output.WriteLine("if (!effect)"); output.WriteLine("{"); output.Indent(); output.WriteLine("// Set default values"); foreach (var property in effect.Properties) { WritePropertyInitialization(output, property); } output.Unindent(); output.WriteLine("}"); output.Unindent(); output.WriteLine("}"); output.WriteLine(); foreach (var property in effect.Properties) { WritePropertyImplementation(effect, output, property); } if (EffectHasVariableNumberOfInputs(effect)) { output.WriteLine("IMPLEMENT_EFFECT_SOURCES_PROPERTY(" + effect.ClassName + ")"); output.WriteLine(); } else { for (int i = 0; i < effect.Inputs.InputsList.Count; ++i) { var input = effect.Inputs.InputsList[i]; output.WriteLine("IMPLEMENT_EFFECT_SOURCE_PROPERTY(" + effect.ClassName + ","); output.Indent(); output.WriteLine(input.Name + ","); output.WriteLine(i.ToString() + ")"); output.Unindent(); output.WriteLine(); } } WritePropertyMapping(effect, output); if (HasStatics(effect)) { output.WriteLine("IFACEMETHODIMP " + effect.ClassName + "Factory::ActivateInstance(IInspectable** instance)"); output.WriteLine("{"); output.Indent(); output.WriteLine("return ExceptionBoundary([&]"); output.WriteLine("{"); output.Indent(); output.WriteLine("auto effect = Make<" + effect.ClassName + ">();"); output.WriteLine("CheckMakeResult(effect);"); output.WriteLine(); output.WriteLine("ThrowIfFailed(effect.CopyTo(instance));"); output.Unindent(); output.WriteLine("});"); output.Unindent(); output.WriteLine("}"); output.WriteLine(); if (!string.IsNullOrEmpty(effect.Overrides.IsSupportedCheck)) { output.WriteLine("IFACEMETHODIMP " + effect.ClassName + "Factory::get_IsSupported(_Out_ boolean* result)"); output.WriteLine("{"); output.Indent(); output.WriteLine("return ExceptionBoundary([&]"); output.WriteLine("{"); output.Indent(); output.WriteLine("CheckInPointer(result);"); output.WriteLine("*result = SharedDeviceState::GetInstance()->Is" + effect.Overrides.IsSupportedCheck + "Supported();"); output.Unindent(); output.WriteLine("});"); output.Unindent(); output.WriteLine("}"); output.WriteLine(); } output.WriteLine("ActivatableClassWithFactory(" + effect.ClassName + ", " + effect.ClassName + "Factory);"); } else { output.WriteLine("ActivatableClassWithFactory(" + effect.ClassName + ", SimpleAgileActivationFactory<" + effect.ClassName + ">);"); } output.Unindent(); output.WriteLine("}}}}}"); EndVersionConditional(effect, output); }
public static void OutputEffectIdl(Effects.Effect effect, Formatter output) { OutputDataTypes.OutputLeadingComment(output); OutputVersionConditional(effect, output); output.WriteLine("namespace Microsoft.Graphics.Canvas.Effects"); output.WriteLine("{"); output.Indent(); // Output all enums specific to this effect foreach (var property in effect.Properties) { if (property.Type == "enum" && property.EnumFields.Usage == Effects.EnumValues.UsageType.UsedByOneEffect && property.ShouldProject) { OutputEnum(property, output); output.WriteLine(); } } output.WriteLine("runtimeclass " + effect.ClassName + ";"); output.WriteLine(); output.WriteLine("[version(VERSION), uuid(" + effect.Uuid + "), exclusiveto(" + effect.ClassName + ")]"); output.WriteLine("interface " + effect.InterfaceName + " : IInspectable"); output.WriteIndent(); output.WriteLine("requires ICanvasEffect"); output.WriteLine("{"); output.Indent(); foreach (var property in effect.Properties) { // Property with type string describes // name/author/category/description of effect but not input type if (property.Type == "string" || property.IsHidden) continue; output.WriteLine("[propget]"); if (property.IsArray) { output.WriteLine("HRESULT " + property.Name + "([out] UINT32* valueCount, [out, size_is(, *valueCount), retval] " + property.TypeNameIdl + "** valueElements);"); } else { output.WriteLine("HRESULT " + property.Name + "([out, retval] " + property.TypeNameIdl + "* value);"); } output.WriteLine(); output.WriteLine("[propput]"); if (property.IsArray) { output.WriteLine("HRESULT " + property.Name + "([in] UINT32 valueCount, [in, size_is(valueCount)] " + property.TypeNameIdl + "* valueElements);"); } else { output.WriteLine("HRESULT " + property.Name + "([in] " + property.TypeNameIdl + " value);"); } output.WriteLine(); } if (EffectHasVariableNumberOfInputs(effect)) { output.WriteLine("[propget]"); output.WriteLine("HRESULT Sources([out, retval] Windows.Foundation.Collections.IVector<IGRAPHICSEFFECTSOURCE*>** value);"); output.WriteLine(); } else { for (int i = 0; i < effect.Inputs.InputsList.Count; ++i) { var input = effect.Inputs.InputsList[i]; output.WriteLine("[propget]"); output.WriteLine("HRESULT " + input.Name + "([out, retval] IGRAPHICSEFFECTSOURCE** source);"); output.WriteLine(); output.WriteLine("[propput]"); output.WriteLine("HRESULT " + input.Name + "([in] IGRAPHICSEFFECTSOURCE* source);"); output.WriteLine(); } } output.Unindent(); output.WriteLine("};"); output.WriteLine(); string staticAttribute = ""; if (HasStatics(effect)) { string staticsInterfaceName = effect.InterfaceName + "Statics"; string staticsUuid = EffectGenerator.GenerateUuid(staticsInterfaceName); staticAttribute = ", static(" + staticsInterfaceName + ", VERSION)"; output.WriteLine("[version(VERSION), uuid(" + staticsUuid + "), exclusiveto(" + effect.ClassName + ")]"); output.WriteLine("interface " + staticsInterfaceName + " : IInspectable"); output.WriteLine("{"); output.Indent(); foreach (var customIdl in effect.Overrides.CustomStaticMethodIdl) { output.WriteLine(customIdl.Trim()); } if (!string.IsNullOrEmpty(effect.Overrides.IsSupportedCheck)) { output.WriteLine("[propget] HRESULT IsSupported([out, retval] boolean* value);"); } output.Unindent(); output.WriteLine("}"); output.WriteLine(); } output.WriteLine("[STANDARD_ATTRIBUTES, activatable(VERSION)" + staticAttribute + "]"); output.WriteLine("runtimeclass " + effect.ClassName); output.WriteLine("{"); output.Indent(); output.WriteLine("[default] interface " + effect.InterfaceName + ";"); output.Unindent(); output.WriteLine("}"); output.Unindent(); output.WriteLine("}"); EndVersionConditional(effect, output); }
public static void OutputEffectCpp(Effects.Effect effect, Formatter output) { OutputDataTypes.OutputLeadingComment(output); bool isInputSizeFixed = !EffectHasVariableNumberOfInputs(effect); int inputsCount = isInputSizeFixed ? effect.Inputs.InputsList.Count : 0; output.WriteLine("#include \"pch.h\""); output.WriteLine("#include \"" + effect.ClassName + ".h\""); output.WriteLine(); OutputVersionConditional(effect, output); output.WriteLine("namespace ABI { namespace Microsoft { namespace Graphics { namespace Canvas { namespace Effects"); output.WriteLine("{"); output.Indent(); output.WriteLine(effect.ClassName + "::" + effect.ClassName + "(ICanvasDevice* device, ID2D1Effect* effect)"); output.WriteIndent(); output.WriteLine(": CanvasEffect(EffectId(), " + (effect.Properties.Count(p => (!p.IsHandCoded && !p.IsHdrAlias)) - 4) + ", " + inputsCount + ", " + isInputSizeFixed.ToString().ToLower() + ", " + "device, effect, static_cast<" + effect.InterfaceName + "*>(this))"); output.WriteLine("{"); output.Indent(); output.WriteLine("if (!effect)"); output.WriteLine("{"); output.Indent(); output.WriteLine("// Set default values"); foreach (var property in effect.Properties) { WritePropertyInitialization(output, property); } output.Unindent(); output.WriteLine("}"); output.Unindent(); output.WriteLine("}"); output.WriteLine(); foreach (var property in effect.Properties) { WritePropertyImplementation(effect, output, property); } if (EffectHasVariableNumberOfInputs(effect)) { output.WriteLine("IMPLEMENT_EFFECT_SOURCES_PROPERTY(" + effect.ClassName + ")"); output.WriteLine(); } else { for (int i = 0; i < effect.Inputs.InputsList.Count; ++i) { var input = effect.Inputs.InputsList[i]; output.WriteLine("IMPLEMENT_EFFECT_SOURCE_PROPERTY(" + effect.ClassName + ","); output.Indent(); output.WriteLine(input.Name + ","); output.WriteLine(i.ToString() + ")"); output.Unindent(); output.WriteLine(); } } WritePropertyMapping(effect, output); output.WriteLine("ActivatableClass(" + effect.ClassName + ");"); output.Unindent(); output.WriteLine("}}}}}"); EndVersionConditional(effect, output); }
private static void WritePropertyInitialization(Formatter output, Effects.Property property) { // Property with type string describes // name/author/category/description of effect but not input type if (property.Type == "string" || property.IsHandCoded || property.IsHdrAlias) return; string defaultValue = property.Properties.Find(internalProperty => internalProperty.Name == "Default").Value; string setFunction = property.IsArray ? "SetArrayProperty" : "SetBoxedProperty"; string customConversion = null; if (property.ConvertColorHdrToVector3) customConversion = "ConvertColorHdrToVector3"; output.WriteLine(setFunction + "<" + (customConversion?? property.TypeNameBoxed) + ">(" + property.NativePropertyName + ", " + FormatPropertyValue(property, defaultValue) + ");"); }
// Used for code generation. public override void OutputCode(Dictionary <string, QualifiableType> typeDictionary, Formatter idlFile) { idlFile.WriteIndent(); idlFile.Write("[version(VERSION)"); if (m_isFlags) { idlFile.Write(", flags"); } idlFile.Write("]"); idlFile.WriteLine(); idlFile.WriteLine("typedef enum " + m_stylizedName); idlFile.WriteLine("{"); idlFile.Indent(); for (int i = 0; i < m_enumValues.Count; i++) { bool isLast = i == m_enumValues.Count - 1; m_enumValues[i].OutputCode(isLast, m_isFlags, idlFile); } idlFile.Unindent(); idlFile.WriteLine("} " + m_stylizedName + ";"); idlFile.WriteLine(); }
public static void OutputEffectIdl(Effects.Effect effect, Formatter output) { OutputDataTypes.OutputLeadingComment(output); OutputVersionConditional(effect, output); output.WriteLine("namespace Microsoft.Graphics.Canvas.Effects"); output.WriteLine("{"); output.Indent(); // Output all enums specific to this effect foreach (var property in effect.Properties) { if (property.Type == "enum" && property.EnumFields.Usage == Effects.EnumValues.UsageType.UsedByOneEffect && property.ShouldProject) { OutputEnum(property, output); output.WriteLine(); } } output.WriteLine("runtimeclass " + effect.ClassName + ";"); output.WriteLine(); output.WriteLine("[version(VERSION), uuid(" + effect.Uuid + "), exclusiveto(" + effect.ClassName + ")]"); output.WriteLine("interface " + effect.InterfaceName + " : IInspectable"); output.WriteIndent(); output.WriteLine("requires ICanvasEffect"); output.WriteLine("{"); output.Indent(); foreach (var property in effect.Properties) { // Property with type string describes // name/author/category/description of effect but not input type if (property.Type == "string" || property.IsHidden) { continue; } output.WriteLine("[propget]"); if (property.IsArray) { output.WriteLine("HRESULT " + property.Name + "([out] UINT32* valueCount, [out, size_is(, *valueCount), retval] " + property.TypeNameIdl + "** valueElements);"); } else { output.WriteLine("HRESULT " + property.Name + "([out, retval] " + property.TypeNameIdl + "* value);"); } output.WriteLine(); output.WriteLine("[propput]"); if (property.IsArray) { output.WriteLine("HRESULT " + property.Name + "([in] UINT32 valueCount, [in, size_is(valueCount)] " + property.TypeNameIdl + "* valueElements);"); } else { output.WriteLine("HRESULT " + property.Name + "([in] " + property.TypeNameIdl + " value);"); } output.WriteLine(); } if (EffectHasVariableNumberOfInputs(effect)) { output.WriteLine("[propget]"); output.WriteLine("HRESULT Sources([out, retval] Windows.Foundation.Collections.IVector<IGRAPHICSEFFECTSOURCE*>** value);"); output.WriteLine(); } else { for (int i = 0; i < effect.Inputs.InputsList.Count; ++i) { var input = effect.Inputs.InputsList[i]; output.WriteLine("[propget]"); output.WriteLine("HRESULT " + input.Name + "([out, retval] IGRAPHICSEFFECTSOURCE** source);"); output.WriteLine(); output.WriteLine("[propput]"); output.WriteLine("HRESULT " + input.Name + "([in] IGRAPHICSEFFECTSOURCE* source);"); output.WriteLine(); } } output.Unindent(); output.WriteLine("};"); output.WriteLine(); string staticAttribute = ""; if (HasStatics(effect)) { string staticsInterfaceName = effect.InterfaceName + "Statics"; string staticsUuid = EffectGenerator.GenerateUuid(staticsInterfaceName); staticAttribute = ", static(" + staticsInterfaceName + ", VERSION)"; output.WriteLine("[version(VERSION), uuid(" + staticsUuid + "), exclusiveto(" + effect.ClassName + ")]"); output.WriteLine("interface " + staticsInterfaceName + " : IInspectable"); output.WriteLine("{"); output.Indent(); foreach (var customIdl in effect.Overrides.CustomStaticMethodIdl) { output.WriteLine(customIdl.Trim()); } if (!string.IsNullOrEmpty(effect.Overrides.IsSupportedCheck)) { output.WriteLine("[propget] HRESULT IsSupported([out, retval] boolean* value);"); } output.Unindent(); output.WriteLine("}"); output.WriteLine(); } output.WriteLine("[STANDARD_ATTRIBUTES, activatable(VERSION)" + staticAttribute + "]"); output.WriteLine("runtimeclass " + effect.ClassName); output.WriteLine("{"); output.Indent(); output.WriteLine("[default] interface " + effect.InterfaceName + ";"); output.Unindent(); output.WriteLine("}"); output.Unindent(); output.WriteLine("}"); EndVersionConditional(effect, output); }
// Used for code generation. public override void OutputCode(Dictionary<string, QualifiableType> typeDictionary, Formatter idlFile) { Debug.Assert(!RequiresClassProjection(typeDictionary)); OutputValueTypeProjectionCode(typeDictionary, idlFile); }
private static void EndVersionConditional(Effects.Effect effect, Formatter output) { if (effect.Overrides != null) { EndVersionConditional(effect.Overrides.WinVer, output); } }
private static void WritePropertyImplementation(Effects.Effect effect, Formatter output, Effects.Property property) { // Property with type string describes // name/author/category/description of effect but not input type if (property.Type == "string" || property.IsHandCoded || property.IsHidden) { return; } var min = property.Properties.Find(internalProperty => internalProperty.Name == "Min"); var max = property.Properties.Find(internalProperty => internalProperty.Name == "Max"); bool isWithUnsupported = (property.ExcludedEnumIndexes != null) && (property.ExcludedEnumIndexes.Count != 0); bool isValidation = ((min != null) || (max != null) || isWithUnsupported) && !property.ConvertRadiansToDegrees; string implementMacro = property.IsArray ? "IMPLEMENT_EFFECT_ARRAY_PROPERTY" : "IMPLEMENT_EFFECT_PROPERTY"; if (isValidation) { implementMacro += "_WITH_VALIDATION"; } output.WriteLine(implementMacro + "(" + effect.ClassName + ","); output.Indent(); output.WriteLine(property.Name + ","); output.WriteLine((property.ConvertRadiansToDegrees ? "ConvertRadiansToDegrees" : property.TypeNameBoxed) + ","); if (!property.IsArray) { output.WriteLine(property.TypeNameCpp + ","); } if (isValidation) { output.WriteLine(property.NativePropertyName + ","); var validationChecks = new List <string>(); if (min != null) { AddValidationChecks(validationChecks, property, min.Value, ">="); } if (max != null) { AddValidationChecks(validationChecks, property, max.Value, "<="); } if (isWithUnsupported) { foreach (var index in property.ExcludedEnumIndexes) { validationChecks.Add("value != static_cast<" + property.TypeNameCpp + ">(" + index + ")"); } } output.WriteLine("(" + string.Join(") && (", validationChecks) + "))"); } else { output.WriteLine(property.NativePropertyName + ")"); } output.Unindent(); output.WriteLine(); }
private static void EndVersionConditional(string winVer, Formatter output) { if (!string.IsNullOrEmpty(winVer)) { output.WriteLine(); output.WriteLine(string.Format("#endif // {0}", winVer)); } }
public static void GenerateCode(string inputDir, string outputDir) { List<string> files = GetInputFileList(); Overrides.XmlBindings.Settings overridesXmlData = XmlBindings.Utilities.LoadXmlData<Overrides.XmlBindings.Settings>(inputDir, "Settings.xml"); Formatter.Prefix = overridesXmlData.Prefix.Value; Formatter.Subnamespace = overridesXmlData.Subnamespace.Value; var filenameBase = overridesXmlData.FilenameBase.Value; List<D2DTypes> typeDocuments = new List<D2DTypes>(); Dictionary<string, QualifiableType> typeDictionary = new Dictionary<string, QualifiableType>(); OutputDataTypes outputDataTypes = new OutputDataTypes(); foreach (string fileName in files) { XmlBindings.D2DTypes xmlDocument = XmlBindings.Utilities.LoadXmlData<XmlBindings.D2DTypes>(inputDir, fileName); typeDocuments.Add(new D2DTypes(xmlDocument, overridesXmlData, typeDictionary, outputDataTypes)); } Directory.CreateDirectory(outputDir); OutputFiles outputFiles = new OutputFiles(); using (Formatter cppStreamWriter = new Formatter(Path.Combine(outputDir, filenameBase + ".codegen.cpp")), idlStreamWriter = new Formatter(Path.Combine(outputDir, filenameBase + ".codegen.idl"))) { outputFiles.CppFile = cppStreamWriter; outputFiles.IdlFile = idlStreamWriter; outputDataTypes.OutputCode(typeDictionary, outputFiles); } }
private static void GenerateOutput(List<Effects.Effect> effects, string outDirectory) { using (Formatter commonStreamWriter = new Formatter(Path.Combine(outDirectory, "EffectsCommon.abi.idl"))) { OutputEffectType.OutputCommonEnums(effects, commonStreamWriter); } foreach (var effect in effects.Where(IsEffectEnabled)) { Directory.CreateDirectory(outDirectory); using (Formatter idlStreamWriter = new Formatter(Path.Combine(outDirectory, effect.ClassName + ".abi.idl")), hStreamWriter = new Formatter(Path.Combine(outDirectory, effect.ClassName + ".h")), cppStreamWriter = new Formatter(Path.Combine(outDirectory, effect.ClassName + ".cpp"))) { OutputEffectType.OutputEffectIdl(effect, idlStreamWriter); OutputEffectType.OutputEffectHeader(effect, hStreamWriter); OutputEffectType.OutputEffectCpp(effect, cppStreamWriter); } } }
public Enum(Namespace parentNamespace, string rootProjectedNamespace, XmlBindings.Enum xmlData, Overrides.XmlBindings.Enum overrides, Dictionary <string, QualifiableType> typeDictionary, OutputDataTypes outputDataTypes) { m_stylizedName = Formatter.Prefix + Formatter.StylizeNameFromUnderscoreSeparators(xmlData.Name); if (parentNamespace != null) { m_rawName = parentNamespace.ApiName + "_" + xmlData.Name; typeDictionary[parentNamespace.RawName + "::" + xmlData.Name] = this; } else { // // Namespace of NULL indicates the global namespace. // These types aren't D2D types, and their full native name is // exactly what's in the name field (no need to prepend anything). // m_rawName = xmlData.Name; typeDictionary[xmlData.Name] = this; } m_isFlags = xmlData.IsFlags; m_enumValues = new List <EnumValue>(); foreach (XmlBindings.EnumValue valueXml in xmlData.EnumValues) { Overrides.XmlBindings.EnumValue overridesEnumValue = null; if (overrides != null) { overridesEnumValue = overrides.Values.Find(x => x.Name == valueXml.Name); } m_enumValues.Add(new EnumValue(valueXml, m_rawName, overridesEnumValue)); } Namespace = rootProjectedNamespace; bool shouldProject = false; if (overrides != null) { shouldProject = overrides.ShouldProject; if (overrides.ProjectedNameOverride != null) { m_stylizedName = Formatter.Prefix + overrides.ProjectedNameOverride; } if (overrides.Namespace != null) { Namespace = Namespace + "." + overrides.Namespace; } } // One of the XML files has a mistake where it doesn't properly order its enums. if (m_isFlags) { m_enumValues.Sort(new EnumValueComparer()); } // Enums in the global namespace are defined as aliases only. By convention, only enums in a namespace are output. if (parentNamespace != null && shouldProject) { outputDataTypes.AddEnum(this); } }