Skip to content

Commit 26d0629

Browse files
committed
Clean up
1 parent 3c92d30 commit 26d0629

5 files changed

Lines changed: 15 additions & 476 deletions

File tree

hub/apps/develop/composition/composition-brushes.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ This overview assumes that you are familiar with the structure of a basic Compos
3636

3737
A [CompositionBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionbrush) "paints" an area with its output. Different brushes have different types of output. Some brushes paint an area with a solid color, others with a gradient, image, custom drawing, or effect. There are also specialized brushes that modify the behavior of other brushes. For example, opacity mask can be used to control which area is painted by a CompositionBrush, or a nine-grid can be used to control the stretch applied to a CompositionBrush when painting an area. CompositionBrush can be of one of the following types:
3838

39-
|Class |Details |Introduced In|
40-
|-------------------------------------|---------------------------------------------------------|--------------------------------------|
41-
|[CompositionColorBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositioncolorbrush) |Paints an area with a solid color |Windows 10, version 1511 (SDK 10586)|
42-
|[CompositionSurfaceBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionsurfacebrush) |Paints an area with the contents of an [ICompositionSurface](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.icompositionsurface)|Windows 10, version 1511 (SDK 10586)|
43-
|[CompositionEffectBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositioneffectbrush) |Paints an area with the contents of a composition effect |Windows 10, version 1511 (SDK 10586)|
44-
|[CompositionMaskBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionmaskbrush) |Paints a visual with a CompositionBrush with an opacity mask |Windows 10, version 1607 (SDK 14393)
45-
|[CompositionNineGridBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionninegridbrush) |Paints an area with a CompositionBrush using a NineGrid stretch |Windows 10, version 1607 (SDK 14393)
46-
|[CompositionLinearGradientBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionlineargradientbrush)|Paints an area with a linear gradient |Windows 10, version 1709 (SDK 16299)
47-
|[CompositionRadialGradientBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionradialgradientbrush)|Paints an area with a radial gradient |Windows 10, version 1903 (Insider Preview SDK)
48-
|[CompositionBackdropBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionbackdropbrush) |Paints an area by sampling background pixels from either the application or pixels directly behind the application's window on desktop. Used as an input to another CompositionBrush like a CompositionEffectBrush | Windows 10, version 1607 (SDK 14393)
39+
|Class |Details |
40+
|-------------------------------------|---------------------------------------------------------|
41+
|[CompositionColorBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositioncolorbrush) |Paints an area with a solid color |
42+
|[CompositionSurfaceBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionsurfacebrush) |Paints an area with the contents of an [ICompositionSurface](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.icompositionsurface)|
43+
|[CompositionEffectBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositioneffectbrush) |Paints an area with the contents of a composition effect |
44+
|[CompositionMaskBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionmaskbrush) |Paints a visual with a CompositionBrush with an opacity mask |
45+
|[CompositionNineGridBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionninegridbrush) |Paints an area with a CompositionBrush using a NineGrid stretch |
46+
|[CompositionLinearGradientBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionlineargradientbrush)|Paints an area with a linear gradient |
47+
|[CompositionRadialGradientBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionradialgradientbrush)|Paints an area with a radial gradient |
48+
|[CompositionBackdropBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionbackdropbrush) |Paints an area by sampling background pixels from either the application or pixels directly behind the application's window on desktop. Used as an input to another CompositionBrush like a CompositionEffectBrush |
4949

5050
### Paint with a solid color
5151

hub/apps/develop/composition/composition-native-interop.md

Lines changed: 0 additions & 229 deletions
Original file line numberDiff line numberDiff line change
@@ -538,232 +538,3 @@ int __stdcall wWinMain(HINSTANCE, HINSTANCE, PWSTR, int)
538538
}
539539
```
540540

541-
## C++/CX usage example
542-
543-
> [!NOTE]
544-
> This code example exists to help you maintain your C++/CX application. But we recommend that you use [C++/WinRT](../cpp-and-winrt-apis/intro-to-using-cpp-with-winrt.md) for new applications. C++/WinRT is an entirely standard modern C++17 language projection for Windows Runtime (WinRT) APIs, implemented as a header-file-based library, and designed to provide you with first-class access to the modern Windows API.
545-
546-
The C++/CX code example below omits the DirectWrite and Direct2D parts of the example and remains primarily useful as a migration reference for older codebases.
547-
548-
```cppcx
549-
//------------------------------------------------------------------------------
550-
//
551-
// Copyright (C) Microsoft. All rights reserved.
552-
//
553-
//------------------------------------------------------------------------------
554-
555-
#include "stdafx.h"
556-
557-
using namespace Microsoft::WRL;
558-
using namespace Windows::Foundation;
559-
using namespace Windows::Graphics::DirectX;
560-
using namespace Microsoft::UI::Composition;
561-
562-
// This is an app-provided helper to render lines of text
563-
class SampleText
564-
{
565-
private:
566-
// The text to draw
567-
ComPtr<IDWriteTextLayout> _text;
568-
569-
// The composition surface that we use in the visual tree
570-
ComPtr<ICompositionDrawingSurfaceInterop> _drawingSurfaceInterop;
571-
572-
// The device that owns the surface
573-
ComPtr<ICompositionGraphicsDevice> _compositionGraphicsDevice;
574-
575-
// For managing our event notifier
576-
EventRegistrationToken _deviceReplacedEventToken;
577-
578-
public:
579-
SampleText(IDWriteTextLayout* text, ICompositionGraphicsDevice* compositionGraphicsDevice) :
580-
_text(text),
581-
_compositionGraphicsDevice(compositionGraphicsDevice)
582-
{
583-
// Create the surface just big enough to hold the formatted text block.
584-
DWRITE_TEXT_METRICS metrics;
585-
FailFastOnFailure(text->GetMetrics(&metrics));
586-
Windows::Foundation::Size surfaceSize = { metrics.width, metrics.height };
587-
ComPtr<ICompositionDrawingSurface> drawingSurface;
588-
FailFastOnFailure(_compositionGraphicsDevice->CreateDrawingSurface(
589-
surfaceSize,
590-
DirectXPixelFormat::DirectXPixelFormat_B8G8R8A8UIntNormalized,
591-
DirectXAlphaMode::DirectXAlphaMode_Ignore,
592-
&drawingSurface));
593-
594-
// Cache the interop pointer, since that's what we always use.
595-
FailFastOnFailure(drawingSurface.As(&_drawingSurfaceInterop));
596-
597-
// Draw the text
598-
DrawText();
599-
600-
// If the rendering device is lost, the application will recreate and replace it. We then
601-
// own redrawing our pixels.
602-
FailFastOnFailure(_compositionGraphicsDevice->add_RenderingDeviceReplaced(
603-
Callback<RenderingDeviceReplacedEventHandler>([this](
604-
ICompositionGraphicsDevice* source, IRenderingDeviceReplacedEventArgs* args)
605-
-> HRESULT
606-
{
607-
// Draw the text again
608-
DrawText();
609-
return S_OK;
610-
}).Get(),
611-
&_deviceReplacedEventToken));
612-
}
613-
614-
~SampleText()
615-
{
616-
FailFastOnFailure(_compositionGraphicsDevice->remove_RenderingDeviceReplaced(
617-
_deviceReplacedEventToken));
618-
}
619-
620-
// Return the underlying surface to the caller
621-
ComPtr<ICompositionSurface> get_Surface()
622-
{
623-
// To the caller, the fact that we have a drawing surface is an implementation detail.
624-
// Return the base interface instead
625-
ComPtr<ICompositionSurface> surface;
626-
FailFastOnFailure(_drawingSurfaceInterop.As(&surface));
627-
return surface;
628-
}
629-
630-
private:
631-
// We may detect device loss on BeginDraw calls. This helper handles this condition or other
632-
// errors.
633-
bool CheckForDeviceRemoved(HRESULT hr)
634-
{
635-
if (SUCCEEDED(hr))
636-
{
637-
// Everything is fine -- go ahead and draw
638-
return true;
639-
}
640-
else if (hr == DXGI_ERROR_DEVICE_REMOVED)
641-
{
642-
// We can't draw at this time, but this failure is recoverable. Just skip drawing for
643-
// now. We will be asked to draw again once the Direct3D device is recreated
644-
return false;
645-
}
646-
else
647-
{
648-
// Any other error is unexpected and, therefore, fatal
649-
FailFast();
650-
}
651-
}
652-
653-
// Renders the text into our composition surface
654-
void DrawText()
655-
{
656-
// Begin our update of the surface pixels. If this is our first update, we are required
657-
// to specify the entire surface, which nullptr is shorthand for (but, as it works out,
658-
// any time we make an update we touch the entire surface, so we always pass nullptr).
659-
ComPtr<ID2D1DeviceContext> d2dDeviceContext;
660-
POINT offset;
661-
if (CheckForDeviceRemoved(_drawingSurfaceInterop->BeginDraw(nullptr,
662-
__uuidof(ID2D1DeviceContext), &d2dDeviceContext, &offset)))
663-
{
664-
// Create a solid color brush for the text. A more sophisticated application might want
665-
// to cache and reuse a brush across all text elements instead, taking care to recreate
666-
// it in the event of device removed.
667-
ComPtr<ID2D1SolidColorBrush> brush;
668-
FailFastOnFailure(d2dDeviceContext->CreateSolidColorBrush(
669-
D2D1::ColorF(D2D1::ColorF::Black, 1.0f), &brush));
670-
671-
// Draw the line of text at the specified offset, which corresponds to the top-left
672-
// corner of our drawing surface. Notice we don't call BeginDraw on the D2D device
673-
// context; this has already been done for us by the composition API.
674-
d2dDeviceContext->DrawTextLayout(D2D1::Point2F(offset.x, offset.y), _text.Get(),
675-
brush.Get());
676-
677-
// Our update is done. EndDraw never indicates rendering device removed, so any
678-
// failure here is unexpected and, therefore, fatal.
679-
FailFastOnFailure(_drawingSurfaceInterop->EndDraw());
680-
}
681-
}
682-
};
683-
684-
class SampleApp
685-
{
686-
ComPtr<ICompositor> _compositor;
687-
ComPtr<ID2D1Device> _d2dDevice;
688-
ComPtr<ICompositionGraphicsDevice> _compositionGraphicsDevice;
689-
std::vector<ComPtr<SampleText>> _textSurfaces;
690-
691-
public:
692-
// Run once when the application starts up
693-
void Initialize(ICompositor* compositor)
694-
{
695-
// Cache the compositor (created outside of this method)
696-
_compositor = compositor;
697-
698-
// Create a Direct2D device (helper implementation not shown here)
699-
FailFastOnFailure(CreateDirect2DDevice(&_d2dDevice));
700-
701-
// To create a composition graphics device, we need to QI for another interface
702-
ComPtr<ICompositorInterop> compositorInterop;
703-
FailFastOnFailure(_compositor.As(&compositorInterop));
704-
705-
// Create a graphics device backed by our D3D device
706-
FailFastOnFailure(compositorInterop->CreateGraphicsDevice(
707-
_d2dDevice.Get(),
708-
&_compositionGraphicsDevice));
709-
}
710-
711-
// Called when Direct3D signals the device lost event
712-
void OnDirect3DDeviceLost()
713-
{
714-
// Create a new device
715-
FailFastOnFailure(CreateDirect2DDevice(_d2dDevice.ReleaseAndGetAddressOf()));
716-
717-
// Restore our composition graphics device to good health
718-
ComPtr<ICompositionGraphicsDeviceInterop> compositionGraphicsDeviceInterop;
719-
FailFastOnFailure(_compositionGraphicsDevice.As(&compositionGraphicsDeviceInterop));
720-
FailFastOnFailure(compositionGraphicsDeviceInterop->SetRenderingDevice(_d2dDevice.Get()));
721-
}
722-
723-
// Create a surface that is asynchronously filled with an image
724-
ComPtr<ICompositionSurface> CreateSurfaceFromTextLayout(IDWriteTextLayout* text)
725-
{
726-
// Create our wrapper object that will handle downloading and decoding the image (assume
727-
// throwing new here)
728-
SampleText* textSurface = new SampleText(text, _compositionGraphicsDevice.Get());
729-
730-
// Keep our image alive
731-
_textSurfaces.push_back(textSurface);
732-
733-
// The caller is only interested in the underlying surface
734-
return textSurface->get_Surface();
735-
}
736-
737-
// Create a visual that holds an image
738-
ComPtr<IVisual> CreateVisualFromTextLayout(IDWriteTextLayout* text)
739-
{
740-
// Create a sprite visual
741-
ComPtr<ISpriteVisual> spriteVisual;
742-
FailFastOnFailure(_compositor->CreateSpriteVisual(&spriteVisual));
743-
744-
// The sprite visual needs a brush to hold the image
745-
ComPtr<ICompositionSurfaceBrush> surfaceBrush;
746-
FailFastOnFailure(_compositor->CreateSurfaceBrushWithSurface(
747-
CreateSurfaceFromTextLayout(text).Get(),
748-
&surfaceBrush));
749-
750-
// Associate the brush with the visual
751-
ComPtr<ICompositionBrush> brush;
752-
FailFastOnFailure(surfaceBrush.As(&brush));
753-
FailFastOnFailure(spriteVisual->put_Brush(brush.Get()));
754-
755-
// Return the visual to the caller as the base class
756-
ComPtr<IVisual> visual;
757-
FailFastOnFailure(spriteVisual.As(&visual));
758-
759-
return visual;
760-
}
761-
762-
private:
763-
// This helper (implementation not shown here) creates a Direct2D device and registers
764-
// for a device loss notification on the underlying Direct3D device. When that notification is
765-
// raised, assume the OnDirect3DDeviceLost method is called.
766-
HRESULT CreateDirect2DDevice(ID2D1Device** ppDevice);
767-
};
768-
```
769-

hub/apps/develop/composition/composition-visual-tree.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ There are several visual types that make up the visual tree structure plus a bas
1616
- [**Visual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.visual) – base object, the majority of the properties are here, and inherited by the other Visual objects.
1717
- [**ContainerVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.containervisual) – derives from [**Visual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.visual), and adds the ability to create children.
1818
- [**SpriteVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.spritevisual) – derives from [**ContainerVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.containervisual). Has the ability to associate a brush so that the Visual can render pixels including images, effects, or a solid color.
19-
- [**LayerVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.layervisual) – derives from [**ContainerVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.containervisual). Children of the visual are flattened into a single layer.<br/>(_Introduced in Windows 10, version 1607, SDK 14393._)
20-
- [**ShapeVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.shapevisual) – derives from [**ContainerVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.containervisual). A visual tree node that is the root of a CompositionShape.<br/>(_Introduced in Windows 10, version 1803, SDK 17134._)
21-
- [**RedirectVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.redirectvisual) – derives from [**ContainerVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.containervisual). The visual gets its content from another visual.<br/>(_Introduced in Windows 10, version 1809, SDK 17763._)
22-
- [**SceneVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.scenes.scenevisual) – derives from [**ContainerVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.containervisual). A container visual for the nodes of a 3D scene.<br/>(_Introduced in Windows 10, version 1903, SDK 18362._)
19+
- [**LayerVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.layervisual) – derives from [**ContainerVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.containervisual). Children of the visual are flattened into a single layer.
20+
- [**ShapeVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.shapevisual) – derives from [**ContainerVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.containervisual). A visual tree node that is the root of a CompositionShape.
21+
- [**RedirectVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.redirectvisual) – derives from [**ContainerVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.containervisual). The visual gets its content from another visual.
22+
- [**SceneVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.scenes.scenevisual) – derives from [**ContainerVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.containervisual). A container visual for the nodes of a 3D scene.
2323

2424
You can apply content and effects to SpriteVisuals using the [**CompositionBrush**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionbrush) and its subclasses including the [**CompositionColorBrush**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositioncolorbrush), [**CompositionSurfaceBrush**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionsurfacebrush) and [**CompositionEffectBrush**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositioneffectbrush). To learn more about brushes see [**CompositionBrush Overview**](./composition-brushes.md).
2525

0 commit comments

Comments
 (0)