Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Core / CSharp / System / Windows / Media / Effects / BitmapEffectvisualstate.cs / 2 / BitmapEffectvisualstate.cs
//------------------------------------------------------------------------------ // Microsoft Avalon // Copyright (c) Microsoft Corporation, 2005 // // File: BitmapEffectVisualState.cs //----------------------------------------------------------------------------- using System; using System.Windows.Threading; using MS.Win32; using System.Security; using System.Security.Permissions; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Composition; using System.Windows.Media.Imaging; using System.Diagnostics; using System.Collections; using System.Collections.Generic; using MS.Internal; using System.Resources; using MS.Utility; using System.Runtime.InteropServices; using MS.Internal.PresentationCore; using SR = MS.Internal.PresentationCore.SR; using SRID = MS.Internal.PresentationCore.SRID; namespace System.Windows.Media.Effects { ////// This class is used to realize the content of the /// visual if a bitmap effect is applied to it /// internal class BitmapEffectContent : IRealizationContextClient { Visual _visual; DUCE.Channel _channel; public BitmapEffectContent(Visual v, RealizationContext ctx) { _visual = v; _channel = ctx.Channel; } public void ExecuteRealizationsUpdate() { Visual.BitmapEffectStateField.GetValue(_visual).RenderBitmapEffect(_visual, _channel); } } ////// /// internal class BitmapEffectVisualState : BitmapEffectState { public BitmapEffectVisualState() { } public BitmapEffectDrawing BitmapEffectDrawing { get { if (_bitmapEffectDrawing == null) { _bitmapEffectDrawing = new BitmapEffectDrawing(); } return _bitmapEffectDrawing; } set { _bitmapEffectDrawing = null; } } ////// Remove the content from the composition node /// /// /// internal void FreeContent(Visual visual, DUCE.Channel channel) { SetContent(null, visual, channel); _bitmapEffectDrawing = null; } ////// This sets the content of the visual if there is a /// bitmap effect applied to it /// /// drawing content /// The visual /// The channel internal void SetContent(IDrawingContent content, Visual visual, DUCE.Channel channel) { DUCE.ResourceHandle visualHandle = ((DUCE.IResource)visual).GetHandle(channel); if (content != null) { content.AddRefOnChannel(channel); DUCE.CompositionNode.SetContent( visualHandle, content.GetHandle(channel), channel); // it is ok to release here, because the unmanaged code // holds a reference to the content and will release it // when the parent object is released or the content // is reset to null content.ReleaseOnChannel(channel); } else { Debug.Assert(visual.IsOnChannel(channel)); DUCE.CompositionNode.SetContent( visualHandle, DUCE.ResourceHandle.Null, channel); } } ////// This methods renders the visual to a bitmap, then applies /// the effect to the rendered bitmap, and sets the content /// of the visual to be the resulting bitmap /// /// The visual to apply the effect to /// The current channels internal void RenderBitmapEffect(Visual visual, DUCE.Channel channel) { if (_bitmapEffect == null) throw new InvalidOperationException(SR.Get(SRID.Visual_No_Effect, null)); Debug.Assert(channel != null); BitmapEffectDrawing.UpdateTransformAndDrawingLists(true); bool effectRendered = false; int drawingsCount = BitmapEffectDrawing.Drawings.Count; for (int iTransform = BitmapEffectDrawing.WorldTransforms.Count - 1; iTransform >= drawingsCount; iTransform--) { Matrix finalTransform = BitmapEffectDrawing.WorldTransforms[iTransform].Value; BitmapSource outputImage = GetEffectOutput(visual, ref _renderBitmap, finalTransform, BitmapEffectDrawing.WindowClip, out finalTransform); if (outputImage != null) { // if there was no group for that transform create one // and update it, otherwise we don't need to do anything it // NOTE: this is ok to update here since it is not // connected to the visual tree DrawingGroup effectGroup = new DrawingGroup(); effectGroup.Children.Add( new ImageDrawing(outputImage, new Rect(0, 0, outputImage.Width, outputImage.Height))); effectGroup.Transform = new MatrixTransform(finalTransform); BitmapEffectDrawing.Drawings.Insert(drawingsCount, effectGroup); effectRendered = true; } else { BitmapEffectDrawing.WorldTransforms.RemoveAt(iTransform); } } if (BitmapEffectDrawing.Drawings.Count > 0 && effectRendered == true) { SetContent(BitmapEffectDrawing, visual, channel); } visual.SetFlags(channel, false, VisualProxyFlags.IsBitmapEffectDirty); BitmapEffectDrawing.ScheduleForUpdates = true; } #region Private Fields BitmapEffectDrawing _bitmapEffectDrawing; RenderTargetBitmap _renderBitmap; #endregion } ////// This class is used to store the user provided bitmap effect data on Visual. /// It is necessary to implement the emulation layer for some legacy effects on top /// of the new pipline. /// internal class BitmapEffectData { private BitmapEffect _bitmapEffect; private BitmapEffectInput _bitmapEffectInput; public BitmapEffectData() {} public BitmapEffect BitmapEffect { get { return _bitmapEffect; } set { _bitmapEffect = value; } } public BitmapEffectInput BitmapEffectInput { get { return _bitmapEffectInput; } set { _bitmapEffectInput = value; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------------ // Microsoft Avalon // Copyright (c) Microsoft Corporation, 2005 // // File: BitmapEffectVisualState.cs //----------------------------------------------------------------------------- using System; using System.Windows.Threading; using MS.Win32; using System.Security; using System.Security.Permissions; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Composition; using System.Windows.Media.Imaging; using System.Diagnostics; using System.Collections; using System.Collections.Generic; using MS.Internal; using System.Resources; using MS.Utility; using System.Runtime.InteropServices; using MS.Internal.PresentationCore; using SR = MS.Internal.PresentationCore.SR; using SRID = MS.Internal.PresentationCore.SRID; namespace System.Windows.Media.Effects { ////// This class is used to realize the content of the /// visual if a bitmap effect is applied to it /// internal class BitmapEffectContent : IRealizationContextClient { Visual _visual; DUCE.Channel _channel; public BitmapEffectContent(Visual v, RealizationContext ctx) { _visual = v; _channel = ctx.Channel; } public void ExecuteRealizationsUpdate() { Visual.BitmapEffectStateField.GetValue(_visual).RenderBitmapEffect(_visual, _channel); } } ////// /// internal class BitmapEffectVisualState : BitmapEffectState { public BitmapEffectVisualState() { } public BitmapEffectDrawing BitmapEffectDrawing { get { if (_bitmapEffectDrawing == null) { _bitmapEffectDrawing = new BitmapEffectDrawing(); } return _bitmapEffectDrawing; } set { _bitmapEffectDrawing = null; } } ////// Remove the content from the composition node /// /// /// internal void FreeContent(Visual visual, DUCE.Channel channel) { SetContent(null, visual, channel); _bitmapEffectDrawing = null; } ////// This sets the content of the visual if there is a /// bitmap effect applied to it /// /// drawing content /// The visual /// The channel internal void SetContent(IDrawingContent content, Visual visual, DUCE.Channel channel) { DUCE.ResourceHandle visualHandle = ((DUCE.IResource)visual).GetHandle(channel); if (content != null) { content.AddRefOnChannel(channel); DUCE.CompositionNode.SetContent( visualHandle, content.GetHandle(channel), channel); // it is ok to release here, because the unmanaged code // holds a reference to the content and will release it // when the parent object is released or the content // is reset to null content.ReleaseOnChannel(channel); } else { Debug.Assert(visual.IsOnChannel(channel)); DUCE.CompositionNode.SetContent( visualHandle, DUCE.ResourceHandle.Null, channel); } } ////// This methods renders the visual to a bitmap, then applies /// the effect to the rendered bitmap, and sets the content /// of the visual to be the resulting bitmap /// /// The visual to apply the effect to /// The current channels internal void RenderBitmapEffect(Visual visual, DUCE.Channel channel) { if (_bitmapEffect == null) throw new InvalidOperationException(SR.Get(SRID.Visual_No_Effect, null)); Debug.Assert(channel != null); BitmapEffectDrawing.UpdateTransformAndDrawingLists(true); bool effectRendered = false; int drawingsCount = BitmapEffectDrawing.Drawings.Count; for (int iTransform = BitmapEffectDrawing.WorldTransforms.Count - 1; iTransform >= drawingsCount; iTransform--) { Matrix finalTransform = BitmapEffectDrawing.WorldTransforms[iTransform].Value; BitmapSource outputImage = GetEffectOutput(visual, ref _renderBitmap, finalTransform, BitmapEffectDrawing.WindowClip, out finalTransform); if (outputImage != null) { // if there was no group for that transform create one // and update it, otherwise we don't need to do anything it // NOTE: this is ok to update here since it is not // connected to the visual tree DrawingGroup effectGroup = new DrawingGroup(); effectGroup.Children.Add( new ImageDrawing(outputImage, new Rect(0, 0, outputImage.Width, outputImage.Height))); effectGroup.Transform = new MatrixTransform(finalTransform); BitmapEffectDrawing.Drawings.Insert(drawingsCount, effectGroup); effectRendered = true; } else { BitmapEffectDrawing.WorldTransforms.RemoveAt(iTransform); } } if (BitmapEffectDrawing.Drawings.Count > 0 && effectRendered == true) { SetContent(BitmapEffectDrawing, visual, channel); } visual.SetFlags(channel, false, VisualProxyFlags.IsBitmapEffectDirty); BitmapEffectDrawing.ScheduleForUpdates = true; } #region Private Fields BitmapEffectDrawing _bitmapEffectDrawing; RenderTargetBitmap _renderBitmap; #endregion } ////// This class is used to store the user provided bitmap effect data on Visual. /// It is necessary to implement the emulation layer for some legacy effects on top /// of the new pipline. /// internal class BitmapEffectData { private BitmapEffect _bitmapEffect; private BitmapEffectInput _bitmapEffectInput; public BitmapEffectData() {} public BitmapEffect BitmapEffect { get { return _bitmapEffect; } set { _bitmapEffect = value; } } public BitmapEffectInput BitmapEffectInput { get { return _bitmapEffectInput; } set { _bitmapEffectInput = value; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Utilities.cs
- Misc.cs
- DataComponentMethodGenerator.cs
- CodeActivityMetadata.cs
- ConditionedDesigner.cs
- EtwTrackingBehavior.cs
- WpfWebRequestHelper.cs
- ReadOnlyDataSource.cs
- SafeNativeMethods.cs
- AdornedElementPlaceholder.cs
- SplayTreeNode.cs
- CheckBoxDesigner.cs
- MouseWheelEventArgs.cs
- CurrencyManager.cs
- TemplateInstanceAttribute.cs
- XPathCompileException.cs
- AliasGenerator.cs
- HeaderCollection.cs
- DefaultTextStoreTextComposition.cs
- PropertySegmentSerializationProvider.cs
- EntityDataSourceMemberPath.cs
- _TransmitFileOverlappedAsyncResult.cs
- TreeNodeStyleCollection.cs
- FontClient.cs
- JsonQNameDataContract.cs
- AssemblyResourceLoader.cs
- WebPartCloseVerb.cs
- CharacterBufferReference.cs
- ZipIOCentralDirectoryFileHeader.cs
- EqualityComparer.cs
- ContourSegment.cs
- BaseTemplateCodeDomTreeGenerator.cs
- PolicyLevel.cs
- ColumnPropertiesGroup.cs
- MemoryMappedFileSecurity.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- TdsRecordBufferSetter.cs
- BrowserCapabilitiesCodeGenerator.cs
- DiscoveryClientDocuments.cs
- OdbcConnectionPoolProviderInfo.cs
- WebReferenceOptions.cs
- CursorConverter.cs
- ParamArrayAttribute.cs
- CodeGenerationManager.cs
- DbConnectionPoolGroupProviderInfo.cs
- SiteMap.cs
- CommonGetThemePartSize.cs
- Padding.cs
- WorkflowValidationFailedException.cs
- SystemDiagnosticsSection.cs
- DataServiceHostFactory.cs
- ChannelHandler.cs
- LayoutManager.cs
- LazyTextWriterCreator.cs
- CanonicalFontFamilyReference.cs
- SafeWaitHandle.cs
- SortKey.cs
- EntityDataSourceQueryBuilder.cs
- ActivityPropertyReference.cs
- PropertyValue.cs
- DiscoveryClientElement.cs
- SizeChangedInfo.cs
- HttpModuleAction.cs
- ObjectIDGenerator.cs
- ColorAnimationBase.cs
- XmlNamedNodeMap.cs
- EnumerableValidator.cs
- PageThemeCodeDomTreeGenerator.cs
- SupportsEventValidationAttribute.cs
- ExpressionBinding.cs
- OdbcRowUpdatingEvent.cs
- DocumentPageViewAutomationPeer.cs
- IsolatedStorageFile.cs
- TraceRecords.cs
- IsolationInterop.cs
- HostedHttpTransportManager.cs
- SystemIPGlobalProperties.cs
- LinqDataSourceValidationException.cs
- XmlSchemaSubstitutionGroup.cs
- DocobjHost.cs
- AuthStoreRoleProvider.cs
- DateTimeConstantAttribute.cs
- MediaScriptCommandRoutedEventArgs.cs
- Zone.cs
- DataGridView.cs
- ValueExpressions.cs
- DbParameterCollection.cs
- NumberFormatInfo.cs
- Message.cs
- SystemWebCachingSectionGroup.cs
- OleDbMetaDataFactory.cs
- DefaultValueAttribute.cs
- MemoryStream.cs
- Mouse.cs
- GridLengthConverter.cs
- MethodBuilder.cs
- CodeBlockBuilder.cs
- WebPartConnectionsConnectVerb.cs
- FieldToken.cs
- DBAsyncResult.cs