Пример #1
0
        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("}");
        }
Пример #2
0
        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("};");
        }
Пример #3
0
        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);
        }
Пример #4
0
        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();
                }
            }

        }
Пример #5
0
        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();
        }
Пример #6
0
        public static void OutputEffectCpp(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 \"..\\CanvasEffect.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 inputsCoutn = effect.Inputs.InputsList.Count;

            if (effect.Inputs.Maximum != null && effect.Inputs.Maximum == "0xFFFFFFFF")
            {
                inputsCoutn = 0;
            }
            output.WriteLine(": CanvasEffect(CLSID_D2D1"
                             + effect.Properties[0].Value.Replace(" ", "") + ", "
                             + (effect.Properties.Count - 4) + ", "
                             + inputsCoutn + ", "
                             + isInputSizeFixed.ToString().ToLower() + ")");
            output.WriteLine("{");
            output.Indent();
            output.WriteLine("// Set default values");

            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")
                {
                    continue;
                }

                string defaultValue = property.Properties.Find(internalProperty => internalProperty.Name == "Default").Value;

                if (property.Type == "enum")
                {
                    string d2dDefaultEnum = property.EnumFields.NativeEnum.Enums[Int32.Parse(defaultValue)];
                    output.WriteLine("SetProperty(" + property.NativePropertyName + ", static_cast<uint32_t>(" + d2dDefaultEnum + "), true);");
                }
                else if (property.Type.StartsWith("matrix"))
                {
                    output.WriteLine(property.TypeNameCpp + " default" + property.Name + " = { " + FixSpacing(defaultValue.Substring(1, defaultValue.Length - 2)) + " };");
                    output.WriteLine("SetProperty(" + property.NativePropertyName + ", " + " default" + property.Name + ", true);");
                }
                else
                {
                    string typeExtension = "";
                    if (property.Type == "float")
                    {
                        typeExtension = "f";
                    }
                    output.WriteLine("SetProperty(" + property.NativePropertyName + ", " + defaultValue + typeExtension + ", true);");
                }
            }
            output.Unindent();
            output.WriteLine("}");
            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")
                {
                    continue;
                }

                bool isValidation = false;
                if (property.Properties.Find(internalProperty => internalProperty.Name == "Min") != null)
                {
                    isValidation = true;
                }

                bool isWithUnsupported = false;
                if (property.ExcludedEnumIndexes != null && property.ExcludedEnumIndexes.Count != 0)
                {
                    isWithUnsupported = true;
                }

                if (property.Type == "enum" && !isWithUnsupported)
                {
                    output.WriteLine("IMPLEMENT_ENUM_PROPERTY(" + effect.ClassName + ",");
                }
                else if (isValidation)
                {
                    output.WriteLine("IMPLEMENT_PROPERTY_WITH_VALIDATION(" + effect.ClassName + ",");
                }
                else if (isWithUnsupported)
                {
                    output.WriteLine("IMPLEMENT_ENUM_PROPERTY_WITH_UNSUPPORTED(" + effect.ClassName + ",");
                }
                else
                {
                    output.WriteLine("IMPLEMENT_PROPERTY(" + effect.ClassName + ",");
                }

                output.Indent();
                output.WriteLine(property.Name + ",");
                output.WriteLine(property.TypeNameCpp + ",");

                if (isValidation)
                {
                    output.WriteLine(property.NativePropertyName + ",");
                    output.WriteLine(property.Properties.Find(internalProperty => internalProperty.Name == "Min").Value + ",");
                    output.WriteLine(property.Properties.Find(internalProperty => internalProperty.Name == "Max").Value + ")");
                }
                else if (isWithUnsupported)
                {
                    output.WriteLine(property.NativePropertyName + ",");
                    var last = property.ExcludedEnumIndexes.Last();
                    foreach (var index in property.ExcludedEnumIndexes)
                    {
                        if (index == last)
                        {
                            output.WriteLine(index + "U)");
                        }
                        else
                        {
                            output.WriteLine(index + "U,");
                        }
                    }
                }
                else
                {
                    output.WriteLine(property.NativePropertyName + ")");
                }

                output.Unindent();
                output.WriteLine();
            }

            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_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("}}}}}");
        }
Пример #7
0
        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);
        }
Пример #8
0
        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();
        }
Пример #9
0
        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);
        }
Пример #10
0
        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();

        }
Пример #11
0
        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);
        }
Пример #12
0
        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);

            if (effect.Overrides == null || !effect.Overrides.HasStatics)
            {
                output.WriteLine("ActivatableClassWithFactory(" + effect.ClassName + ", SimpleAgileActivationFactory<" + effect.ClassName + ">);");
            }

            output.Unindent();
            output.WriteLine("}}}}}");

            EndVersionConditional(effect, output);
        }
Пример #13
0
        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();
        }
Пример #14
0
        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("}");
        }
Пример #15
0
        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("}}}}}");
        }
Пример #16
0
        public static void OutputEffectHeader(Effects.Effect effect, Formatter output)
        {
            OutputDataTypes.OutputLeadingComment(output);

            output.WriteLine("#pragma once");
            output.WriteLine();
            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 + "();");
            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 (!(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("EFFECT_PROPERTY(" + input.Name + ", IEffectInput*);");
                }
            }
            output.Unindent();
            output.WriteLine("};");
            output.Unindent();
            output.WriteLine("}}}}}");
        }
Пример #17
0
        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);
        }
Пример #18
0
        private 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();
        }
Пример #19
0
        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);
        }
Пример #20
0
        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);
        }
Пример #21
0
        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);
        }
Пример #22
0
        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);
        }
Пример #23
0
        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();
            }
        }
Пример #24
0
        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) + ");");
        }
Пример #25
0
 private static void EndVersionConditional(string winVer, Formatter output)
 {
     if (!string.IsNullOrEmpty(winVer))
     {
         output.WriteLine();
         output.WriteLine(string.Format("#endif // {0}", winVer));
     }
 }
Пример #26
0
        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);
        }
Пример #27
0
        public static void OutputEffectHeader(Effects.Effect effect, Formatter output)
        {
            OutputDataTypes.OutputLeadingComment(output);

            output.WriteLine("#pragma once");
            output.WriteLine();
            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 + "();");
            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("}}}}}");
        }
Пример #28
0
 private static void OutputVersionConditional(string winVer, Formatter output)
 {
     if (!string.IsNullOrEmpty(winVer))
     {
         output.WriteLine(string.Format("#if (defined {0}) && (WINVER >= {0})", winVer));
         output.WriteLine();
     }
 }
Пример #29
0
        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();
        }
Пример #30
0
        public static void OutputEffectMakers(List <Effects.Effect> effects, Formatter output)
        {
            OutputDataTypes.OutputLeadingComment(output);

            output.WriteLine("#include \"pch.h\"");
            output.WriteLine();

            var effectsByVersion = from effect in effects
                                   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 = effects.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("};");
        }
Пример #31
0
        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 + "()");
            output.WriteIndent();
            output.WriteLine(": CanvasEffect("
                             + GetEffectCLSID(effect) + ", "
                             + (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 (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);
        }