private static PathGeometryData MakeEmptyPathGeometryData() { PathGeometryData data = new PathGeometryData(); data.FillRule = FillRule.EvenOdd; data.Matrix = CompositionResourceManager.MatrixToMilMatrix3x2D(Matrix.Identity); unsafe { int size = sizeof(MIL_PATHGEOMETRY); data.SerializedData = new byte[size]; fixed(byte *pbData = data.SerializedData) { MIL_PATHGEOMETRY *pPathGeometry = (MIL_PATHGEOMETRY *)pbData; // implicitly set pPathGeometry->Flags = 0; pPathGeometry->FigureCount = 0; pPathGeometry->Size = (UInt32)size; } } return(data); }
/// <summary> /// GetPathGeometryData - returns a struct which contains this Geometry represented /// as a path geometry's serialized format. /// </summary> internal override PathGeometryData GetPathGeometryData() { PathGeometryData data = new PathGeometryData(); data.FillRule = FillRule; data.Matrix = CompositionResourceManager.TransformToMilMatrix3x2D(Transform); if (IsObviouslyEmpty()) { return(Geometry.GetEmptyPathGeometryData()); } ByteStreamGeometryContext ctx = new ByteStreamGeometryContext(); PathFigureCollection figures = Figures; int figureCount = figures == null ? 0 : figures.Count; for (int i = 0; i < figureCount; i++) { figures.Internal_GetItem(i).SerializeData(ctx); } ctx.Close(); data.SerializedData = ctx.GetData(); return(data); }
/// <summary> /// GetPathGeometryData - returns a byte[] which contains this Geometry represented /// as a path geometry's serialized format. /// </summary> internal override PathGeometryData GetPathGeometryData() { if (IsObviouslyEmpty()) { return(Geometry.GetEmptyPathGeometryData()); } PathGeometryData data = new PathGeometryData(); data.FillRule = FillRule.EvenOdd; data.Matrix = CompositionResourceManager.TransformToMilMatrix3x2D(Transform); Point[] points = GetPointList(); ByteStreamGeometryContext ctx = new ByteStreamGeometryContext(); ctx.BeginFigure(points[0], true /* is filled */, true /* is closed */); // i == 0, 3, 6, 9 for (int i = 0; i < 12; i += 3) { ctx.BezierTo(points[i + 1], points[i + 2], points[i + 3], true /* is stroked */, true /* is smooth join */); } ctx.Close(); data.SerializedData = ctx.GetData(); return(data); }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { base.UpdateResource(channel, skipOnChannelCheck); // Obtain handles for animated properties DUCE.ResourceHandle hQuaternionAnimations = GetAnimationResourceHandle(QuaternionProperty, channel); // Pack & send command packet DUCE.MILCMD_QUATERNIONROTATION3D data; unsafe { data.Type = MILCMD.MilCmdQuaternionRotation3D; data.Handle = _duceResource.GetHandle(channel); if (hQuaternionAnimations.IsNull) { data.quaternion = CompositionResourceManager.QuaternionToMilQuaternionF(Quaternion); } data.hQuaternionAnimations = hQuaternionAnimations; // Send packed command structure channel.SendCommand( (byte *)&data, sizeof(DUCE.MILCMD_QUATERNIONROTATION3D)); } } }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { base.UpdateResource(channel, skipOnChannelCheck); // Obtain handles for animated properties DUCE.ResourceHandle hRenderAtScaleAnimations = GetAnimationResourceHandle(RenderAtScaleProperty, channel); // Pack & send command packet DUCE.MILCMD_BITMAPCACHE data; unsafe { data.Type = MILCMD.MilCmdBitmapCache; data.Handle = _duceResource.GetHandle(channel); if (hRenderAtScaleAnimations.IsNull) { data.RenderAtScale = RenderAtScale; } data.hRenderAtScaleAnimations = hRenderAtScaleAnimations; data.SnapsToDevicePixels = CompositionResourceManager.BooleanToUInt32(SnapsToDevicePixels); data.EnableClearType = CompositionResourceManager.BooleanToUInt32(EnableClearType); // Send packed command structure channel.SendCommand( (byte *)&data, sizeof(DUCE.MILCMD_BITMAPCACHE)); } } }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { base.UpdateResource(channel, skipOnChannelCheck); // Obtain handles for animated properties DUCE.ResourceHandle hMatrixAnimations = GetAnimationResourceHandle(MatrixProperty, channel); // Pack & send command packet DUCE.MILCMD_MATRIXTRANSFORM data; unsafe { data.Type = MILCMD.MilCmdMatrixTransform; data.Handle = _duceResource.GetHandle(channel); if (hMatrixAnimations.IsNull) { data.Matrix = CompositionResourceManager.MatrixToMilMatrix3x2D(Matrix); } data.hMatrixAnimations = hMatrixAnimations; // Send packed command structure channel.SendCommand( (byte *)&data, sizeof(DUCE.MILCMD_MATRIXTRANSFORM)); } } }
internal static Rect ProjectBounds( ref Matrix3D viewProjMatrix, ref Rect3D originalBox) { D3DMATRIX viewProjFloatMatrix = CompositionResourceManager.Matrix3DToD3DMATRIX(viewProjMatrix); MILRect3D originalBoxFloat = new MILRect3D(ref originalBox); MilRectF outRect = new MilRectF(); HRESULT.Check( MIL3DCalcProjected2DBounds( ref viewProjFloatMatrix, ref originalBoxFloat, out outRect)); if (outRect.Left == outRect.Right || outRect.Top == outRect.Bottom) { return(Rect.Empty); } else { return(new Rect( outRect.Left, outRect.Top, outRect.Right - outRect.Left, outRect.Bottom - outRect.Top )); } }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { base.UpdateResource(channel, skipOnChannelCheck); // Read values of properties into local variables Brush vBrush = Brush; // Obtain handles for properties that implement DUCE.IResource DUCE.ResourceHandle hBrush = vBrush != null ? ((DUCE.IResource)vBrush).GetHandle(channel) : DUCE.ResourceHandle.Null; // Pack & send command packet DUCE.MILCMD_DIFFUSEMATERIAL data; unsafe { data.Type = MILCMD.MilCmdDiffuseMaterial; data.Handle = _duceResource.GetHandle(channel); data.color = CompositionResourceManager.ColorToMilColorF(Color); data.ambientColor = CompositionResourceManager.ColorToMilColorF(AmbientColor); data.hbrush = hBrush; // Send packed command structure channel.SendCommand( (byte *)&data, sizeof(DUCE.MILCMD_DIFFUSEMATERIAL)); } } }
protected override void UpdateResourceCore(DUCE.Channel channel) { Debug.Assert(_duceResource.IsOnChannel(channel)); DependencyObject dobj = ((DependencyObject)_dependencyObject.Target); // The dependency object was GCed, nothing to do here if (dobj == null) { return; } Color tempValue = (Color)dobj.GetValue(_dependencyProperty); DUCE.MILCMD_COLORRESOURCE data; data.Type = MILCMD.MilCmdColorResource; data.Handle = _duceResource.GetHandle(channel); data.Value = CompositionResourceManager.ColorToMilColorF(tempValue); unsafe { channel.SendCommand( (byte *)&data, sizeof(DUCE.MILCMD_COLORRESOURCE)); } }
internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { base.UpdateResource(channel, skipOnChannelCheck); // Read values of properties into local variables DoubleCollection vGuidelinesX = GuidelinesX; DoubleCollection vGuidelinesY = GuidelinesY; // Store the count of this resource's contained collections in local variables. int GuidelinesXCount = (vGuidelinesX == null) ? 0 : vGuidelinesX.Count; int GuidelinesYCount = (vGuidelinesY == null) ? 0 : vGuidelinesY.Count; // Pack & send command packet DUCE.MILCMD_GUIDELINESET data; unsafe { data.Type = MILCMD.MilCmdGuidelineSet; data.Handle = _duceResource.GetHandle(channel); data.GuidelinesXSize = (uint)(sizeof(Double) * GuidelinesXCount); data.GuidelinesYSize = (uint)(sizeof(Double) * GuidelinesYCount); data.IsDynamic = CompositionResourceManager.BooleanToUInt32(IsDynamic); channel.BeginCommand( (byte *)&data, sizeof(DUCE.MILCMD_GUIDELINESET), (int)(data.GuidelinesXSize + data.GuidelinesYSize) ); // Copy this collection's elements (or their handles) to reserved data for (int i = 0; i < GuidelinesXCount; i++) { Double resource = vGuidelinesX.Internal_GetItem(i); channel.AppendCommandData( (byte *)&resource, sizeof(Double) ); } // Copy this collection's elements (or their handles) to reserved data for (int i = 0; i < GuidelinesYCount; i++) { Double resource = vGuidelinesY.Internal_GetItem(i); channel.AppendCommandData( (byte *)&resource, sizeof(Double) ); } channel.EndCommand(); } } }
internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { base.UpdateResource(channel, skipOnChannelCheck); // Obtain handles for animated properties DUCE.ResourceHandle hShadowDepthAnimations = GetAnimationResourceHandle(ShadowDepthProperty, channel); DUCE.ResourceHandle hColorAnimations = GetAnimationResourceHandle(ColorProperty, channel); DUCE.ResourceHandle hDirectionAnimations = GetAnimationResourceHandle(DirectionProperty, channel); DUCE.ResourceHandle hOpacityAnimations = GetAnimationResourceHandle(OpacityProperty, channel); DUCE.ResourceHandle hBlurRadiusAnimations = GetAnimationResourceHandle(BlurRadiusProperty, channel); // Pack & send command packet DUCE.MILCMD_DROPSHADOWEFFECT data; unsafe { data.Type = MILCMD.MilCmdDropShadowEffect; data.Handle = _duceResource.GetHandle(channel); if (hShadowDepthAnimations.IsNull) { data.ShadowDepth = ShadowDepth; } data.hShadowDepthAnimations = hShadowDepthAnimations; if (hColorAnimations.IsNull) { data.Color = CompositionResourceManager.ColorToMilColorF(Color); } data.hColorAnimations = hColorAnimations; if (hDirectionAnimations.IsNull) { data.Direction = Direction; } data.hDirectionAnimations = hDirectionAnimations; if (hOpacityAnimations.IsNull) { data.Opacity = Opacity; } data.hOpacityAnimations = hOpacityAnimations; if (hBlurRadiusAnimations.IsNull) { data.BlurRadius = BlurRadius; } data.hBlurRadiusAnimations = hBlurRadiusAnimations; data.RenderingBias = RenderingBias; // Send packed command structure channel.SendCommand( (byte *)&data, sizeof(DUCE.MILCMD_DROPSHADOWEFFECT)); } } }
internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { base.UpdateResource(channel, skipOnChannelCheck); // Read values of properties into local variables Transform3D vTransform = Transform; // Obtain handles for properties that implement DUCE.IResource DUCE.ResourceHandle hTransform; if (vTransform == null || Object.ReferenceEquals(vTransform, Transform3D.Identity) ) { hTransform = DUCE.ResourceHandle.Null; } else { hTransform = ((DUCE.IResource)vTransform).GetHandle(channel); } // Obtain handles for animated properties DUCE.ResourceHandle hColorAnimations = GetAnimationResourceHandle(ColorProperty, channel); DUCE.ResourceHandle hDirectionAnimations = GetAnimationResourceHandle(DirectionProperty, channel); // Pack & send command packet DUCE.MILCMD_DIRECTIONALLIGHT data; unsafe { data.Type = MILCMD.MilCmdDirectionalLight; data.Handle = _duceResource.GetHandle(channel); data.htransform = hTransform; if (hColorAnimations.IsNull) { data.color = CompositionResourceManager.ColorToMilColorF(Color); } data.hColorAnimations = hColorAnimations; if (hDirectionAnimations.IsNull) { data.direction = CompositionResourceManager.Vector3DToMilPoint3F(Direction); } data.hDirectionAnimations = hDirectionAnimations; // Send packed command structure channel.SendCommand( (byte *)&data, sizeof(DUCE.MILCMD_DIRECTIONALLIGHT)); } } }
/// <summary> /// GetPathGeometryData - returns a struct which contains this Geometry represented /// as a path geometry's serialized format. /// </summary> internal override PathGeometryData GetPathGeometryData() { if (IsEmpty()) { return(Geometry.GetEmptyPathGeometryData()); } PathGeometryData data = new PathGeometryData(); data.FillRule = FillRule; data.Matrix = CompositionResourceManager.TransformToMilMatrix3x2D(Transform); data.SerializedData = _data; return(data); }
internal unsafe bool ContainsInternal(Pen pen, Point hitPoint, double tolerance, ToleranceType type, Point *pPoints, uint pointCount, byte *pTypes, uint typeCount) { bool contains = false; MilMatrix3x2D matrix = CompositionResourceManager.TransformToMilMatrix3x2D(Transform); MIL_PEN_DATA penData; double[] dashArray = null; if (pen != null) { pen.GetBasicPenData(&penData, out dashArray); } fixed(double *dashArrayFixed = dashArray) { int hr = MilCoreApi.MilUtility_PolygonHitTest( &matrix, (pen == null) ? null : &penData, dashArrayFixed, pPoints, pTypes, pointCount, typeCount, tolerance, type == ToleranceType.Relative, &hitPoint, out contains); if (hr == (int)MILErrors.WGXERR_BADNUMBER) { // When we encounter NaNs in the renderer, we absorb the error and draw // nothing. To be consistent, we report that the geometry is never hittable. contains = false; } else { HRESULT.Check(hr); } } return(contains); }
/// <summary> /// GetPathGeometryData - returns a byte[] which contains this Geometry represented /// as a path geometry's serialized format. /// </summary> internal override PathGeometryData GetPathGeometryData() { if (IsObviouslyEmpty()) { return(Geometry.GetEmptyPathGeometryData()); } PathGeometryData data = new PathGeometryData(); data.FillRule = FillRule.EvenOdd; data.Matrix = CompositionResourceManager.TransformToMilMatrix3x2D(Transform); double radiusX = RadiusX; double radiusY = RadiusY; Rect rect = Rect; ByteStreamGeometryContext ctx = new ByteStreamGeometryContext(); if (IsRounded(radiusX, radiusY)) { Point[] points = GetPointList(rect, radiusX, radiusY); ctx.BeginFigure(points[0], true /* is filled */, true /* is closed */); ctx.BezierTo(points[1], points[2], points[3], true /* is stroked */, false /* is smooth join */); ctx.LineTo(points[4], true /* is stroked */, false /* is smooth join */); ctx.BezierTo(points[5], points[6], points[7], true /* is stroked */, false /* is smooth join */); ctx.LineTo(points[8], true /* is stroked */, false /* is smooth join */); ctx.BezierTo(points[9], points[10], points[11], true /* is stroked */, false /* is smooth join */); ctx.LineTo(points[12], true /* is stroked */, false /* is smooth join */); ctx.BezierTo(points[13], points[14], points[15], true /* is stroked */, false /* is smooth join */); } else { ctx.BeginFigure(rect.TopLeft, true /* is filled */, true /* is closed */); ctx.LineTo(Rect.TopRight, true /* is stroked */, false /* is smooth join */); ctx.LineTo(Rect.BottomRight, true /* is stroked */, false /* is smooth join */); ctx.LineTo(Rect.BottomLeft, true /* is stroked */, false /* is smooth join */); } ctx.Close(); data.SerializedData = ctx.GetData(); return(data); }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { base.UpdateResource(channel, skipOnChannelCheck); // Read values of properties into local variables Transform3D vTransform = Transform; // Obtain handles for properties that implement DUCE.IResource DUCE.ResourceHandle hTransform; if (vTransform == null || Object.ReferenceEquals(vTransform, Transform3D.Identity) ) { hTransform = DUCE.ResourceHandle.Null; } else { hTransform = ((DUCE.IResource)vTransform).GetHandle(channel); } // Pack & send command packet DUCE.MILCMD_MATRIXCAMERA data; unsafe { data.Type = MILCMD.MilCmdMatrixCamera; data.Handle = _duceResource.GetHandle(channel); data.htransform = hTransform; data.viewMatrix = CompositionResourceManager.Matrix3DToD3DMATRIX(ViewMatrix); data.projectionMatrix = CompositionResourceManager.Matrix3DToD3DMATRIX(ProjectionMatrix); // Send packed command structure channel.SendCommand( (byte *)&data, sizeof(DUCE.MILCMD_MATRIXCAMERA)); } } }
/// <summary> /// GetPathGeometryData - returns a byte[] which contains this Geometry represented /// as a path geometry's serialized format. /// </summary> internal override PathGeometryData GetPathGeometryData() { if (IsObviouslyEmpty()) { return(Geometry.GetEmptyPathGeometryData()); } PathGeometryData data = new PathGeometryData(); data.FillRule = FillRule.EvenOdd; data.Matrix = CompositionResourceManager.TransformToMilMatrix3x2D(Transform); ByteStreamGeometryContext ctx = new ByteStreamGeometryContext(); ctx.BeginFigure(StartPoint, true /* is filled */, false /* is closed */); ctx.LineTo(EndPoint, true /* is stroked */, false /* is smooth join */); ctx.Close(); data.SerializedData = ctx.GetData(); return(data); }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { base.UpdateResource(channel, skipOnChannelCheck); // Obtain handles for animated properties DUCE.ResourceHandle hAxisAnimations = GetAnimationResourceHandle(AxisProperty, channel); DUCE.ResourceHandle hAngleAnimations = GetAnimationResourceHandle(AngleProperty, channel); // Pack & send command packet DUCE.MILCMD_AXISANGLEROTATION3D data; unsafe { data.Type = MILCMD.MilCmdAxisAngleRotation3D; data.Handle = _duceResource.GetHandle(channel); if (hAxisAnimations.IsNull) { data.axis = CompositionResourceManager.Vector3DToMilPoint3F(Axis); } data.hAxisAnimations = hAxisAnimations; if (hAngleAnimations.IsNull) { data.angle = Angle; } data.hAngleAnimations = hAngleAnimations; // Send packed command structure channel.SendCommand( (byte *)&data, sizeof(DUCE.MILCMD_AXISANGLEROTATION3D)); } } }
private void ManualUpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { checked { DUCE.MILCMD_PIXELSHADER data; data.Type = MILCMD.MilCmdPixelShader; data.Handle = _duceResource.GetHandle(channel); data.PixelShaderBytecodeSize = (_shaderBytecode.Value == null) ? 0 : (uint)(_shaderBytecode.Value).Length; data.ShaderRenderMode = ShaderRenderMode; data.CompileSoftwareShader = CompositionResourceManager.BooleanToUInt32(!(ShaderMajorVersion == 3 && ShaderMinorVersion == 0)); unsafe { channel.BeginCommand( (byte *)&data, sizeof(DUCE.MILCMD_PIXELSHADER), (int)data.PixelShaderBytecodeSize); // extra data if (data.PixelShaderBytecodeSize > 0) { fixed(byte *pPixelShaderBytecode = _shaderBytecode.Value) { channel.AppendCommandData(pPixelShaderBytecode, (int)data.PixelShaderBytecodeSize); } } } } channel.EndCommand(); } }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { base.UpdateResource(channel, skipOnChannelCheck); // Pack & send command packet DUCE.MILCMD_MATRIXTRANSFORM3D data; unsafe { data.Type = MILCMD.MilCmdMatrixTransform3D; data.Handle = _duceResource.GetHandle(channel); data.matrix = CompositionResourceManager.Matrix3DToD3DMATRIX(Matrix); // Send packed command structure channel.SendCommand( (byte *)&data, sizeof(DUCE.MILCMD_MATRIXTRANSFORM3D)); } } }
private void ManualUpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { Transform vTransform = Transform; Transform vRelativeTransform = RelativeTransform; GradientStopCollection vGradientStops = GradientStops; DUCE.ResourceHandle hTransform; if (vTransform == null || Object.ReferenceEquals(vTransform, Transform.Identity) ) { hTransform = DUCE.ResourceHandle.Null; } else { hTransform = ((DUCE.IResource)vTransform).GetHandle(channel); } DUCE.ResourceHandle hRelativeTransform; if (vRelativeTransform == null || Object.ReferenceEquals(vRelativeTransform, Transform.Identity) ) { hRelativeTransform = DUCE.ResourceHandle.Null; } else { hRelativeTransform = ((DUCE.IResource)vRelativeTransform).GetHandle(channel); } DUCE.ResourceHandle hOpacityAnimations = GetAnimationResourceHandle(OpacityProperty, channel); DUCE.ResourceHandle hStartPointAnimations = GetAnimationResourceHandle(StartPointProperty, channel); DUCE.ResourceHandle hEndPointAnimations = GetAnimationResourceHandle(EndPointProperty, channel); unsafe { DUCE.MILCMD_LINEARGRADIENTBRUSH data; data.Type = MILCMD.MilCmdLinearGradientBrush; data.Handle = _duceResource.GetHandle(channel); double tempOpacity = Opacity; DUCE.CopyBytes((byte *)&data.Opacity, (byte *)&tempOpacity, 8); data.hOpacityAnimations = hOpacityAnimations; data.hTransform = hTransform; data.hRelativeTransform = hRelativeTransform; data.ColorInterpolationMode = ColorInterpolationMode; data.MappingMode = MappingMode; data.SpreadMethod = SpreadMethod; Point tempStartPoint = StartPoint; DUCE.CopyBytes((byte *)&data.StartPoint, (byte *)&tempStartPoint, 16); data.hStartPointAnimations = hStartPointAnimations; Point tempEndPoint = EndPoint; DUCE.CopyBytes((byte *)&data.EndPoint, (byte *)&tempEndPoint, 16); data.hEndPointAnimations = hEndPointAnimations; // GradientStopCollection: Need to enforce upper-limit of gradient stop capacity int count = (vGradientStops == null) ? 0 : vGradientStops.Count; data.GradientStopsSize = (UInt32)(sizeof(DUCE.MIL_GRADIENTSTOP) * count); channel.BeginCommand( (byte *)&data, sizeof(DUCE.MILCMD_LINEARGRADIENTBRUSH), sizeof(DUCE.MIL_GRADIENTSTOP) * count ); for (int i = 0; i < count; i++) { DUCE.MIL_GRADIENTSTOP stopCmd; GradientStop gradStop = vGradientStops.Internal_GetItem(i); double temp = gradStop.Offset; DUCE.CopyBytes((byte *)&stopCmd.Position, (byte *)&temp, sizeof(double)); stopCmd.Color = CompositionResourceManager.ColorToMilColorF(gradStop.Color); channel.AppendCommandData( (byte *)&stopCmd, sizeof(DUCE.MIL_GRADIENTSTOP) ); } channel.EndCommand(); } } }
internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { base.UpdateResource(channel, skipOnChannelCheck); // Read values of properties into local variables Transform3D vTransform = Transform; // Obtain handles for properties that implement DUCE.IResource DUCE.ResourceHandle hTransform; if (vTransform == null || Object.ReferenceEquals(vTransform, Transform3D.Identity) ) { hTransform = DUCE.ResourceHandle.Null; } else { hTransform = ((DUCE.IResource)vTransform).GetHandle(channel); } // Obtain handles for animated properties DUCE.ResourceHandle hNearPlaneDistanceAnimations = GetAnimationResourceHandle(NearPlaneDistanceProperty, channel); DUCE.ResourceHandle hFarPlaneDistanceAnimations = GetAnimationResourceHandle(FarPlaneDistanceProperty, channel); DUCE.ResourceHandle hPositionAnimations = GetAnimationResourceHandle(PositionProperty, channel); DUCE.ResourceHandle hLookDirectionAnimations = GetAnimationResourceHandle(LookDirectionProperty, channel); DUCE.ResourceHandle hUpDirectionAnimations = GetAnimationResourceHandle(UpDirectionProperty, channel); DUCE.ResourceHandle hFieldOfViewAnimations = GetAnimationResourceHandle(FieldOfViewProperty, channel); // Pack & send command packet DUCE.MILCMD_PERSPECTIVECAMERA data; unsafe { data.Type = MILCMD.MilCmdPerspectiveCamera; data.Handle = _duceResource.GetHandle(channel); data.htransform = hTransform; if (hNearPlaneDistanceAnimations.IsNull) { data.nearPlaneDistance = NearPlaneDistance; } data.hNearPlaneDistanceAnimations = hNearPlaneDistanceAnimations; if (hFarPlaneDistanceAnimations.IsNull) { data.farPlaneDistance = FarPlaneDistance; } data.hFarPlaneDistanceAnimations = hFarPlaneDistanceAnimations; if (hPositionAnimations.IsNull) { data.position = CompositionResourceManager.Point3DToMilPoint3F(Position); } data.hPositionAnimations = hPositionAnimations; if (hLookDirectionAnimations.IsNull) { data.lookDirection = CompositionResourceManager.Vector3DToMilPoint3F(LookDirection); } data.hLookDirectionAnimations = hLookDirectionAnimations; if (hUpDirectionAnimations.IsNull) { data.upDirection = CompositionResourceManager.Vector3DToMilPoint3F(UpDirection); } data.hUpDirectionAnimations = hUpDirectionAnimations; if (hFieldOfViewAnimations.IsNull) { data.fieldOfView = FieldOfView; } data.hFieldOfViewAnimations = hFieldOfViewAnimations; // Send packed command structure channel.SendCommand( (byte *)&data, sizeof(DUCE.MILCMD_PERSPECTIVECAMERA)); } } }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { base.UpdateResource(channel, skipOnChannelCheck); // Read values of properties into local variables Point3DCollection vPositions = Positions; Vector3DCollection vNormals = Normals; PointCollection vTextureCoordinates = TextureCoordinates; Int32Collection vTriangleIndices = TriangleIndices; // Store the count of this resource's contained collections in local variables. int PositionsCount = (vPositions == null) ? 0 : vPositions.Count; int NormalsCount = (vNormals == null) ? 0 : vNormals.Count; int TextureCoordinatesCount = (vTextureCoordinates == null) ? 0 : vTextureCoordinates.Count; int TriangleIndicesCount = (vTriangleIndices == null) ? 0 : vTriangleIndices.Count; // Pack & send command packet DUCE.MILCMD_MESHGEOMETRY3D data; unsafe { data.Type = MILCMD.MilCmdMeshGeometry3D; data.Handle = _duceResource.GetHandle(channel); data.PositionsSize = (uint)(sizeof(MilPoint3F) * PositionsCount); data.NormalsSize = (uint)(sizeof(MilPoint3F) * NormalsCount); data.TextureCoordinatesSize = (uint)(sizeof(Point) * TextureCoordinatesCount); data.TriangleIndicesSize = (uint)(sizeof(Int32) * TriangleIndicesCount); channel.BeginCommand( (byte *)&data, sizeof(DUCE.MILCMD_MESHGEOMETRY3D), (int)(data.PositionsSize + data.NormalsSize + data.TextureCoordinatesSize + data.TriangleIndicesSize) ); // Copy this collection's elements (or their handles) to reserved data for (int i = 0; i < PositionsCount; i++) { MilPoint3F resource = CompositionResourceManager.Point3DToMilPoint3F(vPositions.Internal_GetItem(i)); channel.AppendCommandData( (byte *)&resource, sizeof(MilPoint3F) ); } // Copy this collection's elements (or their handles) to reserved data for (int i = 0; i < NormalsCount; i++) { MilPoint3F resource = CompositionResourceManager.Vector3DToMilPoint3F(vNormals.Internal_GetItem(i)); channel.AppendCommandData( (byte *)&resource, sizeof(MilPoint3F) ); } // Copy this collection's elements (or their handles) to reserved data for (int i = 0; i < TextureCoordinatesCount; i++) { Point resource = vTextureCoordinates.Internal_GetItem(i); channel.AppendCommandData( (byte *)&resource, sizeof(Point) ); } // Copy this collection's elements (or their handles) to reserved data for (int i = 0; i < TriangleIndicesCount; i++) { Int32 resource = vTriangleIndices.Internal_GetItem(i); channel.AppendCommandData( (byte *)&resource, sizeof(Int32) ); } channel.EndCommand(); } } }
internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { base.UpdateResource(channel, skipOnChannelCheck); // Read values of properties into local variables Transform vTransform = Transform; Transform vRelativeTransform = RelativeTransform; // Obtain handles for properties that implement DUCE.IResource DUCE.ResourceHandle hTransform; if (vTransform == null || Object.ReferenceEquals(vTransform, Transform.Identity) ) { hTransform = DUCE.ResourceHandle.Null; } else { hTransform = ((DUCE.IResource)vTransform).GetHandle(channel); } DUCE.ResourceHandle hRelativeTransform; if (vRelativeTransform == null || Object.ReferenceEquals(vRelativeTransform, Transform.Identity) ) { hRelativeTransform = DUCE.ResourceHandle.Null; } else { hRelativeTransform = ((DUCE.IResource)vRelativeTransform).GetHandle(channel); } // Obtain handles for animated properties DUCE.ResourceHandle hOpacityAnimations = GetAnimationResourceHandle(OpacityProperty, channel); DUCE.ResourceHandle hColorAnimations = GetAnimationResourceHandle(ColorProperty, channel); // Pack & send command packet DUCE.MILCMD_SOLIDCOLORBRUSH data; unsafe { data.Type = MILCMD.MilCmdSolidColorBrush; data.Handle = _duceResource.GetHandle(channel); if (hOpacityAnimations.IsNull) { data.Opacity = Opacity; } data.hOpacityAnimations = hOpacityAnimations; data.hTransform = hTransform; data.hRelativeTransform = hRelativeTransform; if (hColorAnimations.IsNull) { data.Color = CompositionResourceManager.ColorToMilColorF(Color); } data.hColorAnimations = hColorAnimations; // Send packed command structure channel.SendCommand( (byte *)&data, sizeof(DUCE.MILCMD_SOLIDCOLORBRUSH)); } } }
private void ManualUpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { Transform vTransform = Transform; Transform vRelativeTransform = RelativeTransform; GradientStopCollection vGradientStops = GradientStops; DUCE.ResourceHandle hTransform; if (vTransform == null || Object.ReferenceEquals(vTransform, Transform.Identity) ) { hTransform = DUCE.ResourceHandle.Null; } else { hTransform = ((DUCE.IResource)vTransform).GetHandle(channel); } DUCE.ResourceHandle hRelativeTransform; if (vRelativeTransform == null || Object.ReferenceEquals(vRelativeTransform, Transform.Identity) ) { hRelativeTransform = DUCE.ResourceHandle.Null; } else { hRelativeTransform = ((DUCE.IResource)vRelativeTransform).GetHandle(channel); } DUCE.ResourceHandle hOpacityAnimations = GetAnimationResourceHandle(OpacityProperty, channel); DUCE.ResourceHandle hCenterAnimations = GetAnimationResourceHandle(CenterProperty, channel); DUCE.ResourceHandle hRadiusXAnimations = GetAnimationResourceHandle(RadiusXProperty, channel); DUCE.ResourceHandle hRadiusYAnimations = GetAnimationResourceHandle(RadiusYProperty, channel); DUCE.ResourceHandle hGradientOriginAnimations = GetAnimationResourceHandle(GradientOriginProperty, channel); DUCE.MILCMD_RADIALGRADIENTBRUSH data; unsafe { data.Type = MILCMD.MilCmdRadialGradientBrush; data.Handle = _duceResource.GetHandle(channel); double tempOpacity = Opacity; DUCE.CopyBytes((byte *)&data.Opacity, (byte *)&tempOpacity, 8); data.hOpacityAnimations = hOpacityAnimations; data.hTransform = hTransform; data.hRelativeTransform = hRelativeTransform; data.ColorInterpolationMode = ColorInterpolationMode; data.MappingMode = MappingMode; data.SpreadMethod = SpreadMethod; Point tempCenter = Center; DUCE.CopyBytes((byte *)&data.Center, (byte *)&tempCenter, 16); data.hCenterAnimations = hCenterAnimations; double tempRadiusX = RadiusX; DUCE.CopyBytes((byte *)&data.RadiusX, (byte *)&tempRadiusX, 8); data.hRadiusXAnimations = hRadiusXAnimations; double tempRadiusY = RadiusY; DUCE.CopyBytes((byte *)&data.RadiusY, (byte *)&tempRadiusY, 8); data.hRadiusYAnimations = hRadiusYAnimations; Point tempGradientOrigin = GradientOrigin; DUCE.CopyBytes((byte *)&data.GradientOrigin, (byte *)&tempGradientOrigin, 16); data.hGradientOriginAnimations = hGradientOriginAnimations; // NTRAID#Longhorn-1011154-2004/8/12-asecchia GradientStopCollection: Need to enforce upper-limit of gradient stop capacity int count = (vGradientStops == null) ? 0 : vGradientStops.Count; data.GradientStopsSize = (UInt32)(sizeof(DUCE.MIL_GRADIENTSTOP) * count); channel.BeginCommand( (byte *)&data, sizeof(DUCE.MILCMD_RADIALGRADIENTBRUSH), sizeof(DUCE.MIL_GRADIENTSTOP) * count ); for (int i = 0; i < count; i++) { DUCE.MIL_GRADIENTSTOP stopCmd; GradientStop gradStop = vGradientStops.Internal_GetItem(i); double temp = gradStop.Offset; DUCE.CopyBytes((byte *)&stopCmd.Position, (byte *)&temp, sizeof(double)); stopCmd.Color = CompositionResourceManager.ColorToMilColorF(gradStop.Color); channel.AppendCommandData( (byte *)&stopCmd, sizeof(DUCE.MIL_GRADIENTSTOP) ); } channel.EndCommand(); } } }
internal unsafe static Rect GetBoundsHelper( Pen pen, Matrix *pWorldMatrix, Point *pPoints, byte *pTypes, uint pointCount, uint segmentCount, Matrix *pGeometryMatrix, double tolerance, ToleranceType type, bool fSkipHollows) { MIL_PEN_DATA penData; double[] dashArray = null; // If the pen contributes to the bounds, populate the CMD struct bool fPenContributesToBounds = Pen.ContributesToBounds(pen); if (fPenContributesToBounds) { pen.GetBasicPenData(&penData, out dashArray); } MilMatrix3x2D geometryMatrix; if (pGeometryMatrix != null) { geometryMatrix = CompositionResourceManager.MatrixToMilMatrix3x2D(ref (*pGeometryMatrix)); } Debug.Assert(pWorldMatrix != null); MilMatrix3x2D worldMatrix = CompositionResourceManager.MatrixToMilMatrix3x2D(ref (*pWorldMatrix)); Rect bounds; fixed(double *pDashArray = dashArray) { int hr = MilCoreApi.MilUtility_PolygonBounds( &worldMatrix, (fPenContributesToBounds) ? &penData : null, (dashArray == null) ? null : pDashArray, pPoints, pTypes, pointCount, segmentCount, (pGeometryMatrix == null) ? null : &geometryMatrix, tolerance, type == ToleranceType.Relative, fSkipHollows, &bounds ); if (hr == (int)MILErrors.WGXERR_BADNUMBER) { // When we encounter NaNs in the renderer, we absorb the error and draw // nothing. To be consistent, we report that the geometry has empty bounds. bounds = Rect.Empty; } else { HRESULT.Check(hr); } } return(bounds); }
internal override void AddToFigure( Matrix matrix, // The transformation matrid PathFigure figure, // The figure to add to ref Point current) // In: Segment start point, Out: Segment endpoint, neither transformed { Point endPoint = Point; if (matrix.IsIdentity) { figure.Segments.Add(this); } else { // The arc segment is approximated by up to 4 Bezier segments unsafe { int count; Point * points = stackalloc Point[12]; Size size = Size; Double rotation = RotationAngle; MilMatrix3x2D mat3X2 = CompositionResourceManager.MatrixToMilMatrix3x2D(ref matrix); Composition.MilCoreApi.MilUtility_ArcToBezier( current, // =start point size, rotation, IsLargeArc, SweepDirection, endPoint, &mat3X2, points, out count); // = number of Bezier segments Invariant.Assert(count <= 4); // To ensure no buffer overflows count = Math.Min(count, 4); bool isStroked = IsStroked; bool isSmoothJoin = IsSmoothJoin; // Add the segments if (count > 0) { for (int i = 0; i < count; i++) { figure.Segments.Add(new BezierSegment( points[3 * i], points[3 * i + 1], points[3 * i + 2], isStroked, (i < count - 1) || isSmoothJoin)); // Smooth join between arc pieces } } else if (count == 0) { figure.Segments.Add(new LineSegment(points[0], isStroked, isSmoothJoin)); } } // Update the last point current = endPoint; } }
internal static MilRectD GetPathBoundsAsRB( PathGeometryData pathData, Pen pen, Matrix worldMatrix, double tolerance, ToleranceType type, bool skipHollows) { // This method can't handle the empty geometry case, as it's impossible for us to // return Rect.Empty. Callers should do their own check. Debug.Assert(!pathData.IsEmpty()); unsafe { MIL_PEN_DATA penData; double[] dashArray = null; // If we have a pen, populate the CMD struct if (pen != null) { pen.GetBasicPenData(&penData, out dashArray); } MilMatrix3x2D worldMatrix3X2 = CompositionResourceManager.MatrixToMilMatrix3x2D(ref worldMatrix); fixed(byte *pbPathData = pathData.SerializedData) { MilRectD bounds; Debug.Assert(pbPathData != (byte *)0); fixed(double *pDashArray = dashArray) { int hr = UnsafeNativeMethods.MilCoreApi.MilUtility_PathGeometryBounds( (pen == null) ? null : &penData, pDashArray, &worldMatrix3X2, pathData.FillRule, pbPathData, pathData.Size, &pathData.Matrix, tolerance, type == ToleranceType.Relative, skipHollows, &bounds ); if (hr == (int)MILErrors.WGXERR_BADNUMBER) { // When we encounter NaNs in the renderer, we absorb the error and draw // nothing. To be consistent, we report that the geometry has empty bounds // (NaN will get transformed into Rect.Empty higher up). bounds = MilRectD.NaN; } else { HRESULT.Check(hr); } } return(bounds); } } }
internal static PathGeometry InternalCombine( Geometry geometry1, Geometry geometry2, GeometryCombineMode mode, Transform transform, double tolerance, ToleranceType type) { PathGeometry resultGeometry = null; unsafe { MilMatrix3x2D matrix = CompositionResourceManager.TransformToMilMatrix3x2D(transform); PathGeometryData data1 = geometry1.GetPathGeometryData(); PathGeometryData data2 = geometry2.GetPathGeometryData(); fixed(byte *pPathData1 = data1.SerializedData) { Debug.Assert(pPathData1 != (byte *)0); fixed(byte *pPathData2 = data2.SerializedData) { Debug.Assert(pPathData2 != (byte *)0); FillRule fillRule = FillRule.Nonzero; FigureList list = new FigureList(); int hr = UnsafeNativeMethods.MilCoreApi.MilUtility_PathGeometryCombine( &matrix, &data1.Matrix, data1.FillRule, pPathData1, data1.Size, &data2.Matrix, data2.FillRule, pPathData2, data2.Size, tolerance, type == ToleranceType.Relative, new AddFigureToListDelegate(list.AddFigureToList), mode, out fillRule); if (hr == (int)MILErrors.WGXERR_BADNUMBER) { // When we encounter NaNs in the renderer, we absorb the error and draw // nothing. To be consistent, we return an empty geometry. resultGeometry = new PathGeometry(); } else { HRESULT.Check(hr); resultGeometry = new PathGeometry(list.Figures, fillRule, null); } } } } return(resultGeometry); }
internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck) { // If we're told we can skip the channel check, then we must be on channel Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel)); if (skipOnChannelCheck || _duceResource.IsOnChannel(channel)) { base.UpdateResource(channel, skipOnChannelCheck); // Read values of properties into local variables Transform3D vTransform = Transform; // Obtain handles for properties that implement DUCE.IResource DUCE.ResourceHandle hTransform; if (vTransform == null || Object.ReferenceEquals(vTransform, Transform3D.Identity) ) { hTransform = DUCE.ResourceHandle.Null; } else { hTransform = ((DUCE.IResource)vTransform).GetHandle(channel); } // Obtain handles for animated properties DUCE.ResourceHandle hColorAnimations = GetAnimationResourceHandle(ColorProperty, channel); DUCE.ResourceHandle hPositionAnimations = GetAnimationResourceHandle(PositionProperty, channel); DUCE.ResourceHandle hRangeAnimations = GetAnimationResourceHandle(RangeProperty, channel); DUCE.ResourceHandle hConstantAttenuationAnimations = GetAnimationResourceHandle(ConstantAttenuationProperty, channel); DUCE.ResourceHandle hLinearAttenuationAnimations = GetAnimationResourceHandle(LinearAttenuationProperty, channel); DUCE.ResourceHandle hQuadraticAttenuationAnimations = GetAnimationResourceHandle(QuadraticAttenuationProperty, channel); DUCE.ResourceHandle hDirectionAnimations = GetAnimationResourceHandle(DirectionProperty, channel); DUCE.ResourceHandle hOuterConeAngleAnimations = GetAnimationResourceHandle(OuterConeAngleProperty, channel); DUCE.ResourceHandle hInnerConeAngleAnimations = GetAnimationResourceHandle(InnerConeAngleProperty, channel); // Pack & send command packet DUCE.MILCMD_SPOTLIGHT data; unsafe { data.Type = MILCMD.MilCmdSpotLight; data.Handle = _duceResource.GetHandle(channel); data.htransform = hTransform; if (hColorAnimations.IsNull) { data.color = CompositionResourceManager.ColorToMilColorF(Color); } data.hColorAnimations = hColorAnimations; if (hPositionAnimations.IsNull) { data.position = CompositionResourceManager.Point3DToMilPoint3F(Position); } data.hPositionAnimations = hPositionAnimations; if (hRangeAnimations.IsNull) { data.range = Range; } data.hRangeAnimations = hRangeAnimations; if (hConstantAttenuationAnimations.IsNull) { data.constantAttenuation = ConstantAttenuation; } data.hConstantAttenuationAnimations = hConstantAttenuationAnimations; if (hLinearAttenuationAnimations.IsNull) { data.linearAttenuation = LinearAttenuation; } data.hLinearAttenuationAnimations = hLinearAttenuationAnimations; if (hQuadraticAttenuationAnimations.IsNull) { data.quadraticAttenuation = QuadraticAttenuation; } data.hQuadraticAttenuationAnimations = hQuadraticAttenuationAnimations; if (hDirectionAnimations.IsNull) { data.direction = CompositionResourceManager.Vector3DToMilPoint3F(Direction); } data.hDirectionAnimations = hDirectionAnimations; if (hOuterConeAngleAnimations.IsNull) { data.outerConeAngle = OuterConeAngle; } data.hOuterConeAngleAnimations = hOuterConeAngleAnimations; if (hInnerConeAngleAnimations.IsNull) { data.innerConeAngle = InnerConeAngle; } data.hInnerConeAngleAnimations = hInnerConeAngleAnimations; // Send packed command structure channel.SendCommand( (byte *)&data, sizeof(DUCE.MILCMD_SPOTLIGHT)); } } }