Επεξεργασία

Κοινή χρήση μέσω


D3DImage Class

Definition

An ImageSource that displays a user-created Direct3D surface.

public ref class D3DImage : System::Windows::Media::ImageSource
public class D3DImage : System.Windows.Media.ImageSource
type D3DImage = class
    inherit ImageSource
Public Class D3DImage
Inherits ImageSource
Inheritance

Examples

The following code example shows how to declare a D3DImage in XAML. You must map the System.Windows.Interop namespace, because it is not included in the default XAML namespaces. For more information, see Walkthrough: Hosting Direct3D9 Content in WPF.

    <Window x:Class="D3DHost.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:i="clr-namespace:System.Windows.Interop;assembly=PresentationCore"
    Title="MainWindow" Height="300" Width="300" Background="PaleGoldenrod">
    <Grid>
        <Image x:Name="imgelt">
            <Image.Source>
                <i:D3DImage x:Name="d3dimg" />
            </Image.Source>
        </Image>
    </Grid>
</Window>

Remarks

Use the D3DImage class to host Direct3D content in a Windows Presentation Foundation (WPF) application.

Call the Lock method to change the Direct3D content displayed by the D3DImage. Call the SetBackBuffer method to assign a Direct3D surface to a D3DImage. Call the AddDirtyRect method to track updates to the Direct3D surface. Call the Unlock method to display the changed areas.

The D3DImage class manages two display buffers, which are called the back buffer and the front buffer. The back buffer is your Direct3D surface. Changes to the back buffer are copied forward to the front buffer when you call the Unlock method, where it is displayed on the hardware. Occasionally, the front buffer becomes unavailable. This lack of availability can be caused by screen locking, full-screen exclusive Direct3D applications, user-switching, or other system activities. When this occurs, your WPF application is notified by handling the IsFrontBufferAvailableChanged event. How your application responds to the front buffer becoming unavailable depends on whether WPF is enabled to fall back to software rendering. The SetBackBuffer method has an overload that takes a parameter that specifies whether WPF falls back to software rendering.

Responding to an Unavailable Front Buffer when WPF Does not Fall Back to Software Rendering

When you call the SetBackBuffer(D3DResourceType, IntPtr) overload or call the SetBackBuffer(D3DResourceType, IntPtr, Boolean) overload with the enableSoftwareFallback parameter set to false, the rendering system releases its reference to the back buffer when the front buffer becomes unavailable and nothing is displayed. When the front buffer is available again, the rendering system raises the IsFrontBufferAvailableChanged event to notify your WPF application. You can create an event handler for the IsFrontBufferAvailableChanged event to restart rendering again with a valid Direct3D surface. To restart rendering, you must call SetBackBuffer.

Responding to an Unavailable Front Buffer when WPF Falls Back to Software Rendering

When you call the SetBackBuffer(D3DResourceType, IntPtr, Boolean) overload with the enableSoftwareFallback parameter set to true, the rendering system retains its reference to the back buffer when the front buffer becomes unavailable, so there is no need to call SetBackBuffer when the front buffer is available again. There may be situations where the user's device becomes unavailable. When that occurs, call SetBackBuffer to release WPF's reference to the back buffer. If you need to reset your device, call SetBackBuffer with the backBuffer parameter set to null, and then call SetBackBuffer again with backBuffer set to a valid Direct3D surface.

Note

Performance depends greatly on the settings of the Direct3D surface. For more information, see Performance Considerations for Direct3D9 and WPF Interoperability.

Note

The D3DImage class does not display Direct3D content when WPF renders in software, such as over a Remote Desktop connection, unless you call SetBackBuffer(D3DResourceType, IntPtr, Boolean) and specify true for the enableSoftwareFallback parameter.

Constructors

D3DImage()

Initializes a new instance of the D3DImage class.

D3DImage(Double, Double)

Initializes a new instance of the D3DImage class with the specified display resolution.

Fields

IsFrontBufferAvailableProperty

Identifies the IsFrontBufferAvailable dependency property.

Properties

CanFreeze

Gets a value that indicates whether the object can be made unmodifiable.

(Inherited from Freezable)
DependencyObjectType

Gets the DependencyObjectType that wraps the CLR type of this instance.

(Inherited from DependencyObject)
Dispatcher

Gets the Dispatcher this DispatcherObject is associated with.

(Inherited from DispatcherObject)
HasAnimatedProperties

Gets a value that indicates whether one or more AnimationClock objects is associated with any of this object's dependency properties.

(Inherited from Animatable)
Height

Gets the height of the D3DImage.

IsFrontBufferAvailable

Gets a value that indicates whether a front buffer exists.

IsFrozen

Gets a value that indicates whether the object is currently modifiable.

(Inherited from Freezable)
IsSealed

Gets a value that indicates whether this instance is currently sealed (read-only).

(Inherited from DependencyObject)
Metadata

Gets the metadata associated with the image source.

PixelHeight

Gets the height of the D3DImage, in pixels.

PixelWidth

Gets the width of the D3DImage, in pixels.

Width

Gets the width of the D3DImage.

Methods

AddDirtyRect(Int32Rect)

Specifies the area of the back buffer that changed.

ApplyAnimationClock(DependencyProperty, AnimationClock, HandoffBehavior)

Applies an AnimationClock to the specified DependencyProperty. If the property is already animated, the specified HandoffBehavior is used.

(Inherited from Animatable)
ApplyAnimationClock(DependencyProperty, AnimationClock)

Applies an AnimationClock to the specified DependencyProperty. If the property is already animated, the SnapshotAndReplace handoff behavior is used.

(Inherited from Animatable)
BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior)

Applies an animation to the specified DependencyProperty. The animation is started when the next frame is rendered. If the specified property is already animated, the specified HandoffBehavior is used.

(Inherited from Animatable)
BeginAnimation(DependencyProperty, AnimationTimeline)

Applies an animation to the specified DependencyProperty. The animation is started when the next frame is rendered. If the specified property is already animated, the SnapshotAndReplace handoff behavior is used.

(Inherited from Animatable)
CheckAccess()

Determines whether the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)
ClearValue(DependencyProperty)

Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier.

(Inherited from DependencyObject)
ClearValue(DependencyPropertyKey)

Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey.

(Inherited from DependencyObject)
Clone()

Creates a modifiable clone of this D3DImage object, making deep copies of this object's values. When copying dependency properties, this method copies resource references and data bindings (which may no longer resolve), but not animations or their current values.

CloneCore(Freezable)

Makes the instance a clone (deep copy) of the specified Freezable using base (non-animated) property values.

CloneCurrentValue()

Creates a modifiable clone of this D3DImage object, making deep copies of this object's current values. Resource references, data bindings, and animations are not copied, but their current values are copied.

CloneCurrentValueCore(Freezable)

Makes the instance a modifiable clone (deep copy) of the specified Freezable using current property values.

CoerceValue(DependencyProperty)

Coerces the value of the specified dependency property. This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject.

(Inherited from DependencyObject)
CopyBackBuffer()

Creates a software copy of the D3DImage.

CreateInstance()

Initializes a new instance of the Freezable class.

(Inherited from Freezable)
CreateInstanceCore()

When implemented in a derived class, creates a new instance of the D3DImage derived class.

Equals(Object)

Determines whether a provided DependencyObject is equivalent to the current DependencyObject.

(Inherited from DependencyObject)
Finalize()

Frees resources and performs other cleanup operations before the D3DImage is reclaimed by garbage collection.

Freeze()

Makes the current object unmodifiable and sets its IsFrozen property to true.

(Inherited from Freezable)
FreezeCore(Boolean)

Makes the D3DImage unmodifiable or determines whether it can be made unmodifiable.

GetAnimationBaseValue(DependencyProperty)

Returns the non-animated value of the specified DependencyProperty.

(Inherited from Animatable)
GetAsFrozen()

Creates a frozen copy of the Freezable, using base (non-animated) property values. Because the copy is frozen, any frozen sub-objects are copied by reference.

(Inherited from Freezable)
GetAsFrozenCore(Freezable)

Makes the instance a frozen clone of the specified Freezable using base (non-animated) property values.

GetCurrentValueAsFrozen()

Creates a frozen copy of the Freezable using current property values. Because the copy is frozen, any frozen sub-objects are copied by reference.

(Inherited from Freezable)
GetCurrentValueAsFrozenCore(Freezable)

Makes the current instance a frozen clone of the specified Freezable. If the object has animated dependency properties, their current animated values are copied.

GetHashCode()

Gets a hash code for this DependencyObject.

(Inherited from DependencyObject)
GetLocalValueEnumerator()

Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject.

(Inherited from DependencyObject)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetValue(DependencyProperty)

Returns the current effective value of a dependency property on this instance of a DependencyObject.

(Inherited from DependencyObject)
InvalidateProperty(DependencyProperty)

Re-evaluates the effective value for the specified dependency property.

(Inherited from DependencyObject)
Lock()

Locks the D3DImage and enables operations on the back buffer.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnChanged()

Called when the current Freezable object is modified.

(Inherited from Freezable)
OnFreezablePropertyChanged(DependencyObject, DependencyObject, DependencyProperty)

This member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.

(Inherited from Freezable)
OnFreezablePropertyChanged(DependencyObject, DependencyObject)

Ensures that appropriate context pointers are established for a DependencyObjectType data member that has just been set.

(Inherited from Freezable)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

Overrides the DependencyObject implementation of OnPropertyChanged(DependencyPropertyChangedEventArgs) to also invoke any Changed handlers in response to a changing dependency property of type Freezable.

(Inherited from Freezable)
ReadLocalValue(DependencyProperty)

Returns the local value of a dependency property, if it exists.

(Inherited from DependencyObject)
ReadPreamble()

Ensures that the Freezable is being accessed from a valid thread. Inheritors of Freezable must call this method at the beginning of any API that reads data members that are not dependency properties.

(Inherited from Freezable)
SetBackBuffer(D3DResourceType, IntPtr, Boolean)

Assigns a Direct3D surface as the source of the back buffer.

SetBackBuffer(D3DResourceType, IntPtr)

Assigns a Direct3D surface as the source of the back buffer.

SetCurrentValue(DependencyProperty, Object)

Sets the value of a dependency property without changing its value source.

(Inherited from DependencyObject)
SetValue(DependencyProperty, Object)

Sets the local value of a dependency property, specified by its dependency property identifier.

(Inherited from DependencyObject)
SetValue(DependencyPropertyKey, Object)

Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property.

(Inherited from DependencyObject)
ShouldSerializeProperty(DependencyProperty)

Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property.

(Inherited from DependencyObject)
ToString()

Creates a string representation of this object based on the current culture.

(Inherited from ImageSource)
ToString(IFormatProvider)

Creates a string representation of this object based on the IFormatProvider passed in. If the provider is null, the CurrentCulture is used.

(Inherited from ImageSource)
TryLock(Duration)

Attempts to lock the D3DImage and waits for the specified duration.

Unlock()

Decrements the lock count for the D3DImage.

VerifyAccess()

Enforces that the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)
WritePostscript()

Raises the Changed event for the Freezable and invokes its OnChanged() method. Classes that derive from Freezable should call this method at the end of any API that modifies class members that are not stored as dependency properties.

(Inherited from Freezable)
WritePreamble()

Verifies that the Freezable is not frozen and that it is being accessed from a valid threading context. Freezable inheritors should call this method at the beginning of any API that writes to data members that are not dependency properties.

(Inherited from Freezable)

Events

Changed

Occurs when the Freezable or an object it contains is modified.

(Inherited from Freezable)
IsFrontBufferAvailableChanged

Occurs when the IsFrontBufferAvailable property changes.

Explicit Interface Implementations

IFormattable.ToString(String, IFormatProvider)

Formats the value of the current instance using the specified format.

(Inherited from ImageSource)

Applies to