Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Core / CSharp / System / Windows / Media / Renderer.cs / 1 / Renderer.cs
//------------------------------------------------------------------------------ // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // Though called "Renderer", this is used only for the 'rendering // to a BitmapImage' case, and not when rendering to an HwndTarget. // //----------------------------------------------------------------------------- using System; using System.Windows; using System.Collections.Generic; using System.Windows.Threading; using System.Diagnostics; using MS.Internal; using System.Windows.Media; using System.Windows.Media.Composition; using MS.Win32; using System.Security; using System.Security.Permissions; namespace System.Windows.Media { static internal class Renderer { ////// Critical - unmanaged pointer arguments, access critical resources, calls unmanaged code /// [SecurityCritical] static public void Render( IntPtr pRenderTarget, DUCE.Channel channel, Visual visual, int width, int height, double dpiX, double dpiY) { Render(pRenderTarget, channel, visual, width, height, dpiX, dpiY, Matrix.Identity, Rect.Empty, false); } ////// If fRenderForBitmapEffect is true, the method calls special methods on visual /// to render it specifically for an effect to be applied to it. It excludes /// properties such as transform, clip, offset and guidelines. /// ////// Critical - unmanaged pointer arguments, access critical resources, calls unmanaged code /// [SecurityCritical] static internal void Render( IntPtr pRenderTarget, DUCE.Channel channel, Visual visual, int width, int height, double dpiX, double dpiY, Matrix worldTransform, Rect windowClip, bool fRenderForBitmapEffect ) { DUCE.Resource target = new DUCE.Resource(); DUCE.Resource root = new DUCE.Resource(); DUCE.ResourceHandle targetHandle = DUCE.ResourceHandle.Null; DUCE.ResourceHandle rootHandle = DUCE.ResourceHandle.Null; Matrix deviceTransform = new Matrix( dpiX * (1.0 / 96.0), 0, 0, dpiY * (1.0 / 96.0), 0, 0); deviceTransform = worldTransform * deviceTransform; MatrixTransform mtDeviceTransform = new MatrixTransform(deviceTransform); DUCE.ResourceHandle deviceTransformHandle = ((DUCE.IResource)mtDeviceTransform).AddRefOnChannel(channel); try { // ----------------------------------------------------------- // Create the composition target and root visual resources. target.CreateOrAddRefOnChannel(channel, DUCE.ResourceType.TYPE_GENERICRENDERTARGET); targetHandle = target.Handle; DUCE.CompositionTarget.PrintInitialize( targetHandle, pRenderTarget, width, height, channel); root.CreateOrAddRefOnChannel(channel, DUCE.ResourceType.TYPE_VISUAL); rootHandle = root.Handle; DUCE.CompositionNode.SetTransform( rootHandle, deviceTransformHandle, channel); DUCE.CompositionTarget.SetRoot( targetHandle, rootHandle, channel); channel.Commit(); // ----------------------------------------------------------- // Render the freshly created target. RenderContext renderContext = new RenderContext(); renderContext.Initialize(channel, rootHandle); visual.Precompute(); if (fRenderForBitmapEffect) { visual.RenderForBitmapEffect(renderContext, 0); } else { visual.Render(renderContext, 0); } // Mark the visible realizations. RealizationContext realizationContext = new RealizationContext(); realizationContext.WindowClip = (windowClip.IsEmpty) ? new Rect(0, 0, width, height) : windowClip; DUCE.ChannelSet channelSet = new DUCE.ChannelSet(); channelSet.Channel = channel; realizationContext.BeginFrame(false /* full walk */, true /* walk for BitmapRenderTarget */); realizationContext.ChannelSet = channelSet; realizationContext.TransformStack.Push(ref deviceTransform, /* combine */ false); if (fRenderForBitmapEffect) { visual.MarkVisibleRealizationsForBitmapEffect(realizationContext); } else { visual.MarkVisibleRealizations(realizationContext); } realizationContext.TransformStack.Pop(); // Execute the realization updates. realizationContext.ExecuteRealizationsUpdateSchedule(); // ------------------------------------------------------------ // Flush the channel and present the composition target. channel.Commit(); channel.Present(); MediaContext mediaContext = MediaContext.CurrentMediaContext; mediaContext.NotifySyncChannelMessage(channel); // // Note: RealizationContext.EndFrame does not need to be called // here because we don't cache the realization context. // } finally { // ----------------------------------------------------------- // Clean up and release the root visual. if (!rootHandle.IsNull) { DUCE.CompositionNode.RemoveAllChildren( rootHandle, channel); if (fRenderForBitmapEffect) { visual.ReleaseOnChannelForBitmapEffect(channel); } else { ((DUCE.IResource)visual).ReleaseOnChannel(channel); } root.ReleaseOnChannel(channel); } // ------------------------------------------------------------ // Release the world transform. if (!deviceTransformHandle.IsNull) { ((DUCE.IResource)mtDeviceTransform).ReleaseOnChannel(channel); } // ------------------------------------------------------------ // Clean up and release the composition target. if (!targetHandle.IsNull) { DUCE.CompositionTarget.SetRoot( targetHandle, DUCE.ResourceHandle.Null, channel); target.ReleaseOnChannel(channel); } // // Since we initiate ReleaseOnChannel from the root, that // should not enqueue any delayed release. // Debug.Assert(channel.IsRemoveAndReleaseQueueEmpty()); // ----------------------------------------------------------- // Flush the channel and present the composition target. channel.Commit(); channel.Present(); MediaContext mediaContext = MediaContext.CurrentMediaContext; mediaContext.NotifySyncChannelMessage(channel); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------------ // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // Though called "Renderer", this is used only for the 'rendering // to a BitmapImage' case, and not when rendering to an HwndTarget. // //----------------------------------------------------------------------------- using System; using System.Windows; using System.Collections.Generic; using System.Windows.Threading; using System.Diagnostics; using MS.Internal; using System.Windows.Media; using System.Windows.Media.Composition; using MS.Win32; using System.Security; using System.Security.Permissions; namespace System.Windows.Media { static internal class Renderer { ////// Critical - unmanaged pointer arguments, access critical resources, calls unmanaged code /// [SecurityCritical] static public void Render( IntPtr pRenderTarget, DUCE.Channel channel, Visual visual, int width, int height, double dpiX, double dpiY) { Render(pRenderTarget, channel, visual, width, height, dpiX, dpiY, Matrix.Identity, Rect.Empty, false); } ////// If fRenderForBitmapEffect is true, the method calls special methods on visual /// to render it specifically for an effect to be applied to it. It excludes /// properties such as transform, clip, offset and guidelines. /// ////// Critical - unmanaged pointer arguments, access critical resources, calls unmanaged code /// [SecurityCritical] static internal void Render( IntPtr pRenderTarget, DUCE.Channel channel, Visual visual, int width, int height, double dpiX, double dpiY, Matrix worldTransform, Rect windowClip, bool fRenderForBitmapEffect ) { DUCE.Resource target = new DUCE.Resource(); DUCE.Resource root = new DUCE.Resource(); DUCE.ResourceHandle targetHandle = DUCE.ResourceHandle.Null; DUCE.ResourceHandle rootHandle = DUCE.ResourceHandle.Null; Matrix deviceTransform = new Matrix( dpiX * (1.0 / 96.0), 0, 0, dpiY * (1.0 / 96.0), 0, 0); deviceTransform = worldTransform * deviceTransform; MatrixTransform mtDeviceTransform = new MatrixTransform(deviceTransform); DUCE.ResourceHandle deviceTransformHandle = ((DUCE.IResource)mtDeviceTransform).AddRefOnChannel(channel); try { // ----------------------------------------------------------- // Create the composition target and root visual resources. target.CreateOrAddRefOnChannel(channel, DUCE.ResourceType.TYPE_GENERICRENDERTARGET); targetHandle = target.Handle; DUCE.CompositionTarget.PrintInitialize( targetHandle, pRenderTarget, width, height, channel); root.CreateOrAddRefOnChannel(channel, DUCE.ResourceType.TYPE_VISUAL); rootHandle = root.Handle; DUCE.CompositionNode.SetTransform( rootHandle, deviceTransformHandle, channel); DUCE.CompositionTarget.SetRoot( targetHandle, rootHandle, channel); channel.Commit(); // ----------------------------------------------------------- // Render the freshly created target. RenderContext renderContext = new RenderContext(); renderContext.Initialize(channel, rootHandle); visual.Precompute(); if (fRenderForBitmapEffect) { visual.RenderForBitmapEffect(renderContext, 0); } else { visual.Render(renderContext, 0); } // Mark the visible realizations. RealizationContext realizationContext = new RealizationContext(); realizationContext.WindowClip = (windowClip.IsEmpty) ? new Rect(0, 0, width, height) : windowClip; DUCE.ChannelSet channelSet = new DUCE.ChannelSet(); channelSet.Channel = channel; realizationContext.BeginFrame(false /* full walk */, true /* walk for BitmapRenderTarget */); realizationContext.ChannelSet = channelSet; realizationContext.TransformStack.Push(ref deviceTransform, /* combine */ false); if (fRenderForBitmapEffect) { visual.MarkVisibleRealizationsForBitmapEffect(realizationContext); } else { visual.MarkVisibleRealizations(realizationContext); } realizationContext.TransformStack.Pop(); // Execute the realization updates. realizationContext.ExecuteRealizationsUpdateSchedule(); // ------------------------------------------------------------ // Flush the channel and present the composition target. channel.Commit(); channel.Present(); MediaContext mediaContext = MediaContext.CurrentMediaContext; mediaContext.NotifySyncChannelMessage(channel); // // Note: RealizationContext.EndFrame does not need to be called // here because we don't cache the realization context. // } finally { // ----------------------------------------------------------- // Clean up and release the root visual. if (!rootHandle.IsNull) { DUCE.CompositionNode.RemoveAllChildren( rootHandle, channel); if (fRenderForBitmapEffect) { visual.ReleaseOnChannelForBitmapEffect(channel); } else { ((DUCE.IResource)visual).ReleaseOnChannel(channel); } root.ReleaseOnChannel(channel); } // ------------------------------------------------------------ // Release the world transform. if (!deviceTransformHandle.IsNull) { ((DUCE.IResource)mtDeviceTransform).ReleaseOnChannel(channel); } // ------------------------------------------------------------ // Clean up and release the composition target. if (!targetHandle.IsNull) { DUCE.CompositionTarget.SetRoot( targetHandle, DUCE.ResourceHandle.Null, channel); target.ReleaseOnChannel(channel); } // // Since we initiate ReleaseOnChannel from the root, that // should not enqueue any delayed release. // Debug.Assert(channel.IsRemoveAndReleaseQueueEmpty()); // ----------------------------------------------------------- // Flush the channel and present the composition target. channel.Commit(); channel.Present(); MediaContext mediaContext = MediaContext.CurrentMediaContext; mediaContext.NotifySyncChannelMessage(channel); } } } } // 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
- TypedTableHandler.cs
- ThreadStartException.cs
- CacheDependency.cs
- ViewStateModeByIdAttribute.cs
- WindowsTab.cs
- XmlNamedNodeMap.cs
- PeerNameRecord.cs
- ManualResetEvent.cs
- OutputCacheEntry.cs
- DocumentViewerConstants.cs
- ScriptRef.cs
- WaveHeader.cs
- CollectionConverter.cs
- wgx_exports.cs
- ValueTypeFixupInfo.cs
- ReadWriteSpinLock.cs
- FontSourceCollection.cs
- ChangeTracker.cs
- ButtonBase.cs
- Win32.cs
- QuinticEase.cs
- LogRecordSequence.cs
- OleDbDataReader.cs
- VariableDesigner.xaml.cs
- MessageProperties.cs
- DataGridViewCellValidatingEventArgs.cs
- WebPartTransformer.cs
- PnrpPeerResolverElement.cs
- Exceptions.cs
- BinaryWriter.cs
- BoundPropertyEntry.cs
- HtmlWindow.cs
- PerspectiveCamera.cs
- PropertyGeneratedEventArgs.cs
- Geometry.cs
- CacheMemory.cs
- ExpanderAutomationPeer.cs
- MsmqElementBase.cs
- SharedUtils.cs
- BaseValidator.cs
- PolicyException.cs
- RetrieveVirtualItemEventArgs.cs
- PopupRoot.cs
- TrackingParameters.cs
- _emptywebproxy.cs
- ToolStripDropDownClosingEventArgs.cs
- TableRowCollection.cs
- PanelDesigner.cs
- PerformanceCounterManager.cs
- CompilerGlobalScopeAttribute.cs
- XdrBuilder.cs
- GeometryGroup.cs
- IRCollection.cs
- TemplateKeyConverter.cs
- DesignerVerbToolStripMenuItem.cs
- SqlDataRecord.cs
- XmlLangPropertyAttribute.cs
- ExtensionSimplifierMarkupObject.cs
- DocumentXPathNavigator.cs
- CompilerScope.Storage.cs
- Attribute.cs
- EntityClassGenerator.cs
- FilePresentation.cs
- TableDetailsRow.cs
- IApplicationTrustManager.cs
- BidPrivateBase.cs
- DotExpr.cs
- HighlightComponent.cs
- ProfilePropertySettings.cs
- AggregateNode.cs
- CqlErrorHelper.cs
- RewritingPass.cs
- MultiBinding.cs
- ApplicationServicesHostFactory.cs
- JsonWriterDelegator.cs
- ListBoxItem.cs
- RightsManagementEncryptionTransform.cs
- KeyTimeConverter.cs
- SqlGatherConsumedAliases.cs
- DataSourceSerializationException.cs
- Win32PrintDialog.cs
- SqlXml.cs
- RegexCapture.cs
- PrimitiveOperationFormatter.cs
- DataBoundLiteralControl.cs
- ToolStripItemImageRenderEventArgs.cs
- bidPrivateBase.cs
- UserControlBuildProvider.cs
- NameScope.cs
- MemoryFailPoint.cs
- UndoManager.cs
- EventLogHandle.cs
- ResourcesGenerator.cs
- _LazyAsyncResult.cs
- AuthenticationServiceManager.cs
- Effect.cs
- SettingsProperty.cs
- TextSpan.cs
- WindowsListViewGroup.cs
- SafeCertificateContext.cs