Post on 26-Dec-2015
IntroducingDirect2D And DirectWrite
Kam VedBratPrincipal LeadProgram ManagerMicrosoft Corporation
Leonardo BlancoPrincipal Lead Software Development EngineerMicrosoft Corporation
PC18
What To Expect
Features of Direct2D and DirectWrite Usage scenarios Overview of the new APIs Interoperability with GDI and Direct3D Not a graphics primer
Useful background PC04 – Writing Your Applications to
Shine on Modern Graphics Hardware PC05 – Unlocking the GPU with Direct3D
Motivations
Evolving User Experiences
Reading And Text
GPU Evolution
Server Rendering
Foundational API's
DirectX Technologies
Direct2D
Direct3D
Segoe UIDirectWrite
DXVA & WIC
Direct2D And DirectWrite
New APIs in Windows 7 Win32 developers Interoperability Usable in service context
Direct2D 2D graphics rendering tasks Increased performance and visual quality
DirectWrite Vertical stack for text services Fonts, Script Processing, Layout
Features: Direct2D
Rendering focused 2D vector graphics, bitmaps, and text Hardware or Software
Other Services Display/Device handling DXGI Printing XPS Image Encoding/Decoding WIC Text Formatting DirectWrite
Features: Direct2D
Interoperability GDI Direct3D
Performance Built on Direct3D 10.1 Lower CPU usage than GDI/GDI+
Visual Quality Alpha Blending Per-primitive anti-aliasing MSAA via Direct3D interoperability
Direct2D Performance
Demo
Features: DirectWrite
Modern Typography Enables world-wide applications ClearType Works with any rendering technology Hardware accelerated with Direct2D
DirectWrite OpenType™ Features
Every font feature can be accessed via 4-byte name tag
Capitals to Small CapsSuperscriptScientific InferiorsSubscriptOrdinalsTitling AlternatesSwashContextual SwashContextual AlternatesProportional OldstyleTabular LiningProportional LiningTabular OldstyleStandard LigaturesDiscretionary LigaturesHistorical LigaturesCase Sensitive Forms
Small CapsContextual LigaturesFractionsAlternative FractionsStylistic AlternatesStylistic SetsHistorical FormsSlashed ZeroAlternate AnnotationMathematical GreekLocalized FormsPetite CapsCapitals to Petite CapsUnicaseGlyph de/compositionRequired LigaturesMark Positioning
Mark-to-mark PositioningRuby Notation FormsExpert FormsProportional WidthsFull Widths Half Widths Third Widths Quarter Widths Simplified Forms Traditional Forms Traditional Name FormsNLC Kanji Forms Hojo Kanji Forms JIS 78 Forms JIS 83 Forms JIS 90 Forms JIS 04 Forms
Gabriola
DirectWrite Script Support
ArabicArmenian
BengaliBopomofo
Canadian aboriginal syllabicsCherokee
Chinese SimplifiedChinese Traditional
CyrillicDeseret
DevanāgarīEthiopicGeorgian
Greek
GujaratiGurmukhiHebrew
JapaneseKannadaKhmerKorean
LaoLatin
MalayalamMongolianMyanmar
New Tai LueN’Ko
OsmanyaOriya
’Phags-paSinhalaSyriacTai LeTamil
TeluguThaanaTifnagh
ThaiTibetan
VaiYi
DirectWrite Script Support
ب�ي�ة ال�ع�ر�
Հայերէն
বাং��লা�
ㄓㄨ ㄧㄣ ㄈㄨ ㄏㄠ
ᐃᓄᒃᑎᑐᑦ
ᏣᎳᎩ
简体汉字繁体漢字Кириллица
𐐔𐐯𐑅𐐨𐑉𐐯𐐻
द�वना�गरी�ግዕዝ
მხედრული
Ελληνικό
ગ�જરા�તી�ਗ�ਰਮ�ਖੀ�
עCבEרCית
ひらがな、カタカナ、漢字
ಕನನ�ಡអកខ�រករកខមខេ�មរភាសា
한글ພາສາລາວ
Latin
മലയാ�ളം�
ᠮᠣᠩᠭᠣᠯ ᠪᠢᠴᠢᠻ ᦟᦹᧅ ᦎᦷ ᦑᦺ
ߒߞߏ
𐒋𐒘𐒈𐒑𐒛𐒒𐒕𐒀
ଓଡ�ଆ
ꡍꡂꡛꡌ
ශදධ සං�හල
ܠܫܢܐ ܣܘܪܝܝܐᥖᥭᥰᥖᥬᥳᥑᥨᥒᥰ
தமி�ழతలు�గు�ނ� ތ�ⵜⵉⴼⵉⵏⴰⵖอ�กษรไทยདབ་ཅན་ꕙꔤ
ꆈꌠꁱꂷ
DirectWrite Script Support
ClearType
DirectWrite RenderingPositioning using ClearType
GDI TextTimes New Roman 12 Point
ClearType Compatible Widths
DirectWriteTimes New Roman 12 Point
ClearType Sub-Pixel Positioning
DirectWrite RenderingPrecise Glyph shapes
DirectWrite RenderingFlexibility and performance
Rendering can be performed using DirectX, GDI, or other technologies
Up to 2X faster layout performance than GDI
Hardware accelerated text with Direct2D ClearType filter and blend performed
in hardware Enables app-level hardware
caching optimizations Reduced CPU usage in Windows OS
components when drawing glyphs
Features: DirectWrite
Modern Typography Enables world-wide applications ClearType Works with any rendering technology Hardware accelerated with Direct2D
Best reading experience on the PC
DirectWrite: The best reading experience on
any computer
Let's Look At The APIsLeonardo Blanco
Principal Lead Software Development EngineerMicrosoft Corporation
Direct2D API
Win32, interface-based API Consistent with Direct3D Primarily used via C++
Immediate mode Similar to GDI Create resources up front Re-use resources frame over frame Manage resources per graphics adapter
Direct2D APISample usage
Create top-level objects D2D1CreateFactory() ID2D1Factory Factory ID2D1HwndRenderTarget Also bitmap, interop, and intermediate RTs
Create resources Factory ID2D1Geometry Also bitmaps, layers
Draw primitives using render target BeginDraw() FillGeometry() EndDraw()
Drawing With Direct2D
Demo
Direct2D APIDrawing Resources
Resolution-independent coordinate system Floating point values Affine transforms
Device-independent resources Geometries Created via ID2D1Factory
Device-dependent resources Brushes, bitmaps, intermediate render targets Created via ID2D1RenderTarget Become invalid if the target becomes invalid
Direct2D APIInteroperability with GDI
HDC from D2D render target Create GDI-compatible render target
D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_GDI_COMPAT
IBLE QI for IGdiInteropRenderTarget
GetDC() ReleaseDC()
D2D render target from HDC CreateDCRenderTarget() ID2D1DCRenderTarget::BindDC()
Direct2D APIInteroperability with Direct3D
Use a Direct3D 10 or 10Level9 device Map D3D surface to D2D render target
CreateDxgiSurfaceRenderTarget() Call EndDraw() before Present()
Works in all hardware configurations Best with WDDM 1.1 drivers and DX10 GPU
DirectWrite API
Win32, interface-based API Consistent with Direct3D Primarily used via C++
Layered API Font system Font rasterization Script processing Text layout
DirectWrite APIBasic Usage
Create factory object DWriteCreateFactory IDWriteFactory
Factory creates all other objects Create text format
IDWriteTextFormat Specifies paragraph formatting attributes
Create layout IDWriteTextLayout Applies format to string given layout rect
Draw layout to render target ID2D1RenderTarget::DrawTextLayout
Using DirectWrite And Direct2D Together
Demo
DirectWrite APIFont System
Collection (IDWriteFontCollection) System collection: Installed fonts
Family (IDWriteFontFamily) Set of stylistically related fonts E.g.,: “Franklin Gothic”
Font (IDWriteFont) Provides font metrics and information E.g.,: “Franklin Gothic”, Bold, Italic
Font face (IDWriteFontFace) Glyph metrics, rasterization, and outlines
DirectWrite APIRendering with Direct2D
Draw with ID2D1RenderTarget methods DrawText() for simple UI text DrawTextLayout() for cached layouts DrawGlyphRun() for custom layouts
Create geometry from glyph run IDWriteFontFace::GetGlyphRunOutline()
Accepts ID2D1GeometrySink
DirectWrite APICustom Rendering
Create objects Factory, text format, layout Custom renderer (IDWriteTextRenderer)
Render layout with renderer IDWriteTextLayout::Draw()
Get glyph run outline at each call back IDWriteFontFace::GetGlyphRunOutline()
Draw geometry with Direct2D
Custom Text Rendering Using DirectWrite And Direct2D
Demo
DirectWrite APIInteroperability Services
GDI-compatible metrics and rasterization
HFONT from IDWriteFont/IDWriteFontFace IDWriteGdiInterop::ConvertFontToLOGFONT() IDWriteGdiInterop::ConvertFontFaceToLOGFONT(
)
IDWriteFont/IDWriteFontFace from GDI font IDWriteGdiInterop::CreateFontFromLOGFONT() IDWriteGdiInterop::CreateFontFaceFromHdc() Uses currently selected HFONT from HDC DWrite-based rendering, GDI-based layout
Glyph run rasterizer IDWriteBitmapRenderTarget::DrawGlyphRun() Renders glyphs in software to a 32bpp bitmap Useful for GDI rendering
Direct2D And Animations
Demo
UIAnimation API
UIAnimation API COM API provides ability to create, manage, and drive
UI animation May be used with any rendering library: GDI, GDI+,
DirectX, etc.
UIAnimation Features Velocity Matching Context-sensitive Duration Contention Management Custom Transition Support
More info available in the Hands-On-Labs
Direct2D And DirectWrite
New foundations for text and graphics
Enhance the your Win32 applications Interoperability with GDI and Direct3D Better visual quality Advanced Typography
and Improved Readability Performance scales with hardware
Direct2D And DirectWrite
Review the hands-on labs DirectX, Animations, Touch
Related Sessions PC04 Writing Your Applications to Shine on Modern Graphics
Hardware PC05 Unlocking the GPU with Direct3D ES21 Presentation Virtualization: Graphics Remoting Today &
Tomorrow PC26 Microsoft Visual Studio: Building Applications with MFC
Get in touch! Kam.VedBrat@microsoft.com http://blogs.msdn.com/kamvedbrat Leonardo.Blanco@microsoft.com DGTSIG@microsoft.com
Evals & Recordings
Please fill
out your
evaluation for
this session at:
This session will be available as a recording at:
www.microsoftpdc.com
Please use the microphones provided
Q&A
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market
conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.