48
Introducing Direct2D And DirectWrite Kam VedBrat Principal Lead Program Manager Microsoft Corporation Leonardo Blanco Principal Lead Software Development PC18

Kam VedBrat Principal Lead Program Manager Microsoft Corporation Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

Embed Size (px)

Citation preview

Page 1: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

IntroducingDirect2D And DirectWrite

Kam VedBratPrincipal LeadProgram ManagerMicrosoft Corporation

Leonardo BlancoPrincipal Lead Software Development EngineerMicrosoft Corporation

PC18

Page 2: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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

Page 3: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

Motivations

Page 4: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

Evolving User Experiences

Page 5: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

Reading And Text

Page 6: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

GPU Evolution

Page 7: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

Server Rendering

Page 8: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

Foundational API's

Page 9: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

DirectX Technologies

Direct2D

Direct3D

Segoe UIDirectWrite

DXVA & WIC

Page 10: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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

Page 11: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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

Page 12: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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

Page 13: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

Direct2D Performance

Demo

Page 14: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

Features: DirectWrite

Modern Typography Enables world-wide applications ClearType Works with any rendering technology Hardware accelerated with Direct2D

Page 15: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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

Page 16: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

Gabriola

Page 17: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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

Page 18: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

DirectWrite Script Support

ب�ي�ة ال�ع�ر�

Հայերէն

 বাং��লা�

  ㄓㄨ  ㄧㄣ ㄈㄨ  ㄏㄠ 

ᐃᓄᒃᑎᑐᑦ

ᏣᎳᎩ

简体汉字繁体漢字Кириллица

𐐔𐐯𐑅𐐨𐑉𐐯𐐻

द�वना�गरी�ግዕዝ

მხედრული

Ελληνικό

ગ�જરા�તી�ਗ�ਰਮ�ਖੀ�

עCבEרCית

ひらがな、カタカナ、漢字

ಕನನ�ಡអកខ�រករកខមខេ�មរភាសា

한글ພາສາລາວ

Latin

മലയാ�ളം�

ᠮᠣᠩᠭᠣᠯ ᠪᠢᠴᠢᠻ ᦟᦹᧅ ᦎᦷ ᦑᦺ

ߒߞߏ

𐒋𐒘𐒈𐒑𐒛𐒒𐒕𐒀

ଓଡ�ଆ

ꡍꡂꡛꡌ

ශදධ සං�හල

ܠܫܢܐ ܣܘܪܝܝܐᥖᥭᥰᥖᥬᥳᥑᥨᥒᥰ

தமி�ழతలు�గు�ނ� ތ�ⵜⵉⴼⵉⵏⴰⵖอ�กษรไทยདབ་ཅན་ꕙꔤ

ꆈꌠꁱꂷ

Page 19: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

DirectWrite Script Support

Page 20: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

ClearType

Page 21: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

DirectWrite RenderingPositioning using ClearType

GDI TextTimes New Roman 12 Point

ClearType Compatible Widths

DirectWriteTimes New Roman 12 Point

ClearType Sub-Pixel Positioning

Page 22: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

DirectWrite RenderingPrecise Glyph shapes

Page 23: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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

Page 24: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

Features: DirectWrite

Modern Typography Enables world-wide applications ClearType Works with any rendering technology Hardware accelerated with Direct2D

Best reading experience on the PC

Page 25: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

DirectWrite: The best reading experience on

any computer

Page 26: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

Let's Look At The APIsLeonardo Blanco

Principal Lead Software Development EngineerMicrosoft Corporation

Page 27: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft 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

Page 28: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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()

Page 29: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

Drawing With Direct2D

Demo

Page 30: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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

Page 31: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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()

Page 32: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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

Page 33: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

DirectWrite API

Win32, interface-based API Consistent with Direct3D Primarily used via C++

Layered API Font system Font rasterization Script processing Text layout

Page 34: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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

Page 35: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

Using DirectWrite And Direct2D Together

Demo

Page 36: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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

Page 37: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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

Page 38: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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

Page 39: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

Custom Text Rendering Using DirectWrite And Direct2D

Demo

Page 40: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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

Page 41: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

Direct2D And Animations

Demo

Page 42: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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

Page 43: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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

Page 44: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

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! [email protected] http://blogs.msdn.com/kamvedbrat [email protected] [email protected]

Page 45: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

Evals & Recordings

Please fill

out your

evaluation for

this session at:

This session will be available as a recording at:

www.microsoftpdc.com

Page 46: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

Please use the microphones provided

Q&A

Page 47: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation

© 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.

Page 48: Kam VedBrat Principal Lead Program Manager Microsoft Corporation  Leonardo Blanco Principal Lead Software Development Engineer Microsoft Corporation