historie

08.11.2018 vjj 1 pravěk

INPUT

PROGRAM

OUTPUT

08.11.2018 vjj 2 evoluce • dávkové zpracování

• interaktivní práce

• prompt

• GUI

08.11.2018 vjj 3 evoluce

INPUT

PROGRAM

OUTPUT

08.11.2018 vjj 4 evoluce Windows • bitmap graphics model - Device Context • Windows does not retain a copy of what the application drew • Windows 3.0 (1990)

• bitmap graphics model - layered Device Context • Windows does retain a copy of the drawing as a bitmap • Windows 2000 (beta 1998) • .NET Framework (2001-2005)

• vector graphics model – WPF (on DirectX) • tree of user-interface elements with objects representing graphical shapes • , .NET Framework 3.0 (2006)

• Metro - deterioration • , .NET Framework 4.5 (2012)

08.11.2018 vjj 5 1: Win32 API

classique

08.11.2018 vjj 6 Uživatel Fronta zpráv GetMessage (mouse, keyboard) hardware interrupt DRIVER DispatchMessage

System message queue WindowProc WindowProc RIT Raw Input Thread

Fronta zpráv

8.11.18 vjj 7 WM_PAINT • každý ovládací prvek je samostatným oknem s vlastní procedurou na zpracovávání zpráv

• celá stavba programu/algoritmu se točila kolem přípravy dat pro vykreslení obsahu okna vždy, když přišla zpráva WM_PAINT (a že chodila často)

• během přímého kreslení se výstup do momentálně neviditelné části okna nikam nezapsal

08.11.2018 vjj 8 User

Windows OS Invalidate... Program

WM_PAINT GetDC

Program

Funkce GDI32 / GDI+

Graphics Card Frame Buffer for Screen Image data only retained as long as it remains visible on screen

08.11.2018 vjj 9 PROGRAM: direct Device Context

OUTPUT

PROGRAM PROGRAM PROGRAM PROGRAM PROGRAM WM_PAINT WM_PAINT WM_PAINT WM_PAINT WM_PAINT

08.11.2018 vjj 10 standardní funkce • TextOut • MoveToEx DrawText LineTo Rectangle Ellipse • DrawIcon Pie Arc Chord Polyline • BitBlt Polygon stretchBlt

08.11.2018 vjj 11 Device Context • standardní funkce pro kreslení do okna vyžadují hDC jako svůj první parametr • datová struktura popisující vlastnosti výstupu, např. • font – text • pero – čárová grafika • štětec – pozadí • Update Region

• hDC z funkcí BeginPaint, GetDC, ...

• CS_CLASSDC, CS_OWNDC

08.11.2018 vjj 12 bitmap graphics model • each UI element (HWND) has exclusive ownership of some region of the application's window

• within each top-level window, any given pixel in that window is controlled completely by exactly one UI element

• this prevents elements from being partially transparent

• it also preludes the use of anti-aliasing around the edges of elements

08.11.2018 vjj 13 TextOut TextOut (hDC, x, y, "text", délka) ;

SetTextAlign (hDC, TA_LEFT | TA_TOP) ; TA_RIGHT TA_BOTTOM TA_CENTER TA_NOUPDATECP TA_UPDATECP

SetTextColor (hDC, dwColorRGB) ; RGB (255, 255, 255) dwColorRGB = GetTextColor (hDC) ;

08.11.2018 vjj 29 Čárová grafika • MoveToEx (hDC, doX, doY, NULL) ; • LineTo (hDC, doX, doY) ;

• Rectangle (hDC, leftX, topY, rightX, bottomY) ;

• Ellipse (hDC, leftX, topY, rightX, bottomY) ; • Pie (hDC, leftX, topY, rightX, bottomY, x3, y3, x4, y4) ; • Arc (hDC, leftX, topY, rightX, bottomY, x3, y3, x4, y4) ; • Chord(hDC, leftX, topY, rightX, bottomY, x3, y3, x4, y4);

• Polyline (hDC, CONST POINT *lpPoints, int nPočet) ; • Polygon (hDC, CONST POINT *lpPoints, int nPočet) ;

SetPolyFillMode (hDC, ALTERNATE nebo WINDING);

08.11.2018 vjj 34 Bitmap

08.11.2018 vjj 43 2: layered window

Win32 API upgrade

08.11.2018 vjj 70 layered window

Windows WM_PAINT

Program

Funkce GDI32 / GDI+

off-screen Layered Window Buffer

Desktop Compositing Engine (DCE)

Graphics Card Frame Buffer for Screen

08.11.2018 vjj 71 2½: Windows.Forms

1st generation of .NET

08.11.2018 vjj 77 .NET GDI Graphics Model

Aplikace Drawing Objects Funkce GDI32 / GDI+

Buffer for the Window

Windows .NET runtime

Funkce GDI32 / GDI+

off-screen Layered Window Buffer

Desktop ()

Graphics Card Buffer

08.11.2018 vjj 78 3: DirectX

08.11.2018 vjj 86 3½: WPF

08.11.2018 vjj 88 Desktop Window Manager

DWM.EXE

http://en.wikipedia.org/wiki/Desktop_Window_Manager

08.11.2018 vjj 89 DWM • window undercoat • window with non-rectangular area

• window chrome • window without title bar

• window content • GDI, DirectX (WPF)

• window composition • partial transparency, blur, outer glow, anti-aliasing

08.11.2018 vjj 90 DWM • It was originally created to enable portions of the "" user experience (Windows Vista, ), which allowed for effects such as • transparency, • 3D window switching • and more • it has been subsequently • severely reduced, blocked - with advent of Windows 8 • severely reduced, code removed – Windows 8, 8.1 • partially revived – several updates of

08.11.2018 vjj 91 window chrome

08.11.2018 vjj 92 with UI chrome WindowStyle="ThreeDBorderWindow"

08.11.2018 vjj 93 without UI chrome WindowStyle="None"

08.11.2018 vjj 94 non-rectangular window

08.11.2018 vjj 95 Win32 API SetWindowRgn

SetWindowPos (hMyMainWindow, 0, 100, 100, 800, 400, SWP_NOZORDER) ; rg1 = CreateEllipticRgn (0, -400, 800, 400) ; rg2 = CreateRectRgn (0, 0, 800, 400) ; CombineRgn (rg1, rg1, rg2, RGN_AND) ; rg2 = CreateEllipticRgn (500, 50, 700, 150) ; CombineRgn (rg1, rg1, rg2, RGN_DIFF) ;

SetWindowRgn (hMyMainWindow, rg1, TRUE) ;

08.11.2018 vjj 96 Win32 API SetWindowRgn

08.11.2018 vjj 97 WPF VisualClip this.VisualClip = new EllipseGeometry (new Rect(new Point(0, 0), new Size(400, 400)));

08.11.2018 vjj 98 WPF VisualClip WindowStyle="ThreeDBorderWindow"

08.11.2018 vjj 99 WPF VisualClip WindowStyle="None"

08.11.2018 vjj 100 AllowsTransparency

AllowsTransparency="True" WindowStyle="None">

• requires WindowStyle="None“

• AllowsTransparency cannot be changed after a Window has been shown or WindowInteropHelper.EnsureHandle has been called

08.11.2018 vjj 101 WPF WindowStyle="None" AllowsTransparency="True"

08.11.2018 vjj 102 window opacity

08.11.2018 vjj 103 Opacity Opacity="0.4"

08.11.2018 vjj 104 Opacity WindowStyle="None" AllowsTransparency="True" Background="Transparent"

08.11.2018 vjj 105 Aero blur

DwmIsCompositionEnabled DwmExtendFrameIntoClientArea DwmEnableBlurBehindWindow

08.11.2018 vjj 106 Aero blur

AllowsTransparency="False"

WindowStyle="None"

Background="Transparent"> • requires desktop Aero Theme

08.11.2018 vjj 107 DwmExtendFrameIntoClientArea

08.11.2018 vjj 108 DwmExtendFrameIntoClientArea

08.11.2018 vjj 109 DwmExtendFrameIntoClientArea

08.11.2018 vjj 110 DwmExtendFrameIntoClientArea public class GlassHelper { [StructLayout(LayoutKind.Sequential)] struct MARGINS { public MARGINS( Thickness t ) { Left = (int)t.Left; Right = (int)t.Right; Top = (int)t.Top; Bottom = (int)t.Bottom; } public int Left; public int Right; public int Top; public int Bottom; } // P/Invoke [DllImport("dwmapi.dll", PreserveSig = false)] static extern void DwmExtendFrameIntoClientArea( IntPtr hWnd, ref MARGINS pMarInset); [DllImport("dwmapi.dll", PreserveSig = false)] static extern bool DwmIsCompositionEnabled();

08.11.2018 vjj 111 DwmExtendFrameIntoClientArea public static bool ExtendGlassFrame( System.Windows.Window window, Thickness margin) { IntPtr hwnd = new WindowInteropHelper( window ).Handle; if (hwnd == IntPtr.Zero) return false;

if ( ! DwmIsCompositionEnabled() ) return false;

MARGINS margins = new MARGINS( margin ); DwmExtendFrameIntoClientArea( hwnd, ref margins );

return true; } } // class GlassHelper

08.11.2018 vjj 112 DwmExtendFrameIntoClientArea private void myBackgroundVisibility_Unchecked( object sender, RoutedEventArgs e) { // Set the WPF background to transparent this.Background = Brushes.Transparent;

// Set the Win32 background to transparent IntPtr hwnd = new WindowInteropHelper(this).Handle; if (hwnd == IntPtr.Zero) return; HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent; }

08.11.2018 vjj 113 DwmEnableBlurBehindWindow

08.11.2018 vjj 114 DwmEnableBlurBehindWindow

[DllImport("dwmapi.dll", PreserveSig = false)] static extern void DwmEnableBlurBehindWindow( IntPtr hWnd, ref DWM_BLURBEHIND pBlurBehind);

[StructLayout(LayoutKind.Sequential)] struct DWM_BLURBEHIND { public DWM_BB dwFlags; public bool fEnable; public IntPtr hRgnBlur; public bool fTransitionOnMaximized; public DWM_BLURBEHIND(bool enabled) { fEnable = enabled ? true : false; hRgnBlur = IntPtr.Zero; fTransitionOnMaximized = false; dwFlags = DWM_BB.Enable; }

DWM_BLURBEHIND bb = new DWM_BLURBEHIND(bbb); DwmEnableBlurBehindWindow(hwnd, ref bb);

08.11.2018 vjj 115 WPF

08.11.2018 vjj 116 WPF • zjednodušení stromové struktury oken, ze kterých se skládá UI aplikace

• všechny ovládací prvky uvnitř okna už nejsou samostatnými okny, ale jen ilustracemi

• o rozlišení událostí, které se jich týkají, se místo jádra Windows (vlákno RAW) stará .NET runtime (tj. DLL uvnitř Win32 API aplikace hostující .NET, která zpracovává Win32 API zprávy) • Metro šlo ve zjednodušení stromové struktury oken ještě dál - runtime + všechny apps = jediný Win32 API proces s jediným oknem (full screen)

08.11.2018 vjj 118 WPF Graphics Model • Windows Presentation Foundation (Avalon)

• nadstavba nad DirectX

• HW akcelerace

• transformace jsou aplikovány na libovolnou část vizuálního stromu, tj. ne pouze na kompletní uživatelskou oblast okna jako u Win32 API

• nezávislé na hardwaru a na rozlišení • vždy vektorové • jednotky: "device-independent pixels" = 1/96th of an inch

• výpočty - float

• WPF Windows are based on old fashioned Win32 window objects. • The frame (even the modern Vista frame) is rendered by GDI/GDI+. • Only the client area is done by WPF itself

• o vykreslování kompletních oken na desktop se stará Desktop Window Manager

08.11.2018 vjj 119 borders - WindowStyle • .NET 4.5, 4.6 ve Windows 7

08.11.2018 vjj 120 DWM basics

08.11.2018 vjj 121 W7 Graphics Model Program UI Chrome

Visual Objects

Media Integration Layer (MIL)

funkce DirectX

Graphics Card Buffer for the Window GDI Frame

DWM - MIL Windows

Funkce DirectX

Graphics Card Buffer for the Screen

08.11.2018 vjj 122 Desktop Window Manager • Desktop Window Manager (DWM, previously Desktop Compositing Engine or DCE) is the desktop system in Windows Vista, 7 that enables the Windows Aero graphical user interface and visual theme.

• The Desktop Window Manager requires video cards supporting DirectX 9.0 and Model 2.0.

08.11.2018 vjj 123 DWM visual effects • Windows 7 • desktop composition is enabled only with the AERO Glass Theme • Windows Flip, automatic scaling for high resolution (DPI) scaling, thumbnail previews, and full screen

• Windows 8 • AERO Glass composition is removed • desktop composition for all themes, support for Stereoscopic 3D, and management, separation, and protection of the experience with Windows Store apps • Windows Flip, automatic scaling for high resolution (DPI) scaling, thumbnail previews, and full screen magnifier

08.11.2018 vjj 124 Windows flip

08.11.2018 vjj 125 DWM visual effects • transparency of the non-client region of a window • transition effects • rounded window corners • Glass sheet • Glow around caption buttons • Transparent background to title bar text (In Windows 8.1, the background text was drawn over an opaque background which is the same color as the personalization color chosen by the user. This restricts theme assets from being anything other than 100% transparent, otherwise the text displays incorrectly) • Title bar text glow

08.11.2018 vjj 126 system chrome • The 'system chrome' include the non-client area of all desktop windows, which DWM (as the desktop compositor) is completely responsible for. • The code for rendering window borders (including things like the colorized regions, aka the glass regions) are all a part of the udwm component. • An application may override this behavior by handling the WM_NCPAINT message, but it is otherwise rendered entirely by DWM making use of the system theme resources as necessary. • It is also responsible for rendering glass regions that the user draws in the client area either via the adjustment of border margins, or via rendering of shapes using a color key for said regions.

08.11.2018 vjj 127 off-screen buffer • The Desktop Window Manager is a Compositing window manager,

• each program has an off-screen buffer that it writes data to,

• the DWM then composites each program's buffer into a final image, and redraws windows when necessary. • compared to the stacking window manager in Windows XP and earlier (and Windows 7 and Vista with Aero disabled) which has each program writing to the same main buffer.

08.11.2018 vjj 128 DirectX compositing and rendering • Because the compositor has access to the graphics of all applications, it easily allows visual effects that string together visuals from multiple applications, such as transparency.

• The DWM uses DirectX to perform the function of compositing and rendering in the GPU, freeing the CPU of the task of managing the rendering from the off- screen buffers to the display.

• However, it does not affect applications painting to the off- screen buffers; depending on the technologies used for that, it might still be CPU-bound.

08.11.2018 vjj 130 DirectX compositing and rendering • DWM-agnostic

rendering techniques like GDI are redirected to the buffers by rendering the UI as bitmaps.

• DWM-aware

rendering technologies like WPF directly make the internal data structures available in a DWM-compatible format. The window contents in the buffers are then converted to DirectX textures.

08.11.2018 vjj 131 desktop and windows • The desktop itself is a full-screen surface,

• with windows being represented as a mesh consisting of two adjacent (and mutually-inverted) triangles, which are transformed to represent a 2D rectangle.

• The texture, representing the UI chrome, is then mapped onto these rectangles.

08.11.2018 vjj 132 DWM possibilities • underlying Direct3D surface • default – black rectangle (AllowsTransparency = "False") • transparent (AllowsTransparency = "True" WindowStyle = "None") • blur (DwmEnableBlurBehindWindow)

• chrome (WindowStyle = "ThreeDBorderWindow") • blured - Window Style Aero • frame extended into a client area (DwmExtendFrameIntoClientArea)

08.11.2018 vjj 133 desktop and windows • Window transitions are implemented as transformations of the meshes, using shader programs.

• With Windows Vista, the transitions are limited to the set of built-in that implement the transformations. • Greg Schechter, a developer at Microsoft has suggested that it might be opened up for developers and users to plug in their own effects in a future release.

• The DWM only maps the primary desktop object as a 3D surface; other desktop objects, including virtual desktops as well as the secure desktop used by are not.

08.11.2018 vjj 134 using the off-screen buffer • Since all applications render to an off-screen buffer, they can be read off the buffer embedded in other applications as well. Since the off-screen buffer is constantly updated by the application, the embedded rendering will be a dynamic representation of the application window and not a static rendering.

• This is how the live thumbnail previews, Windows Flip and Windows Flip 3D work in Windows Vista. The DWM exposes a public API that allows applications to access these thumbnail representations. • The size of the thumbnail is not fixed; applications can request the thumbnails at any size - smaller than the original window, at the same size or even larger - and DWM will scale them properly before returning. • Windows Flip 3D uses the thumbnail to get the window representations as bitmaps, and then uses that as texture for 2D rectangles, which are further processed by custom shaders to transform them to 3D meshes and rotate them in a 3D plane.

08.11.2018 vjj 135 DWM thumbnail API

HRESULT hr = S_OK; HTHUMBNAIL thumbnail = NULL;

// Register the thumbnail hr = DwmRegisterThumbnail(hwnd, FindWindow(_T("Progman"), NULL), &thumbnail); if (SUCCEEDED(hr)) { // Specify the destination rectangle size RECT dest = {0,50,100,150};

// Set the thumbnail properties for use DWM_THUMBNAIL_PROPERTIES dskThumbProps; dskThumbProps.dwFlags = DWM_TNP_SOURCECLIENTAREAONLY | DWM_TNP_VISIBLE | DWM_TNP_OPACITY | DWM_TNP_RECTDESTINATION; dskThumbProps.fSourceClientAreaOnly = FALSE; dskThumbProps.fVisible = TRUE; dskThumbProps.opacity = (255 * 70)/100; dskThumbProps.rcDestination = dest;

// Display the thumbnail

hr = DwmUpdateThumbnailProperties(thumbnail,&dskThumbProps); if (SUCCEEDED(hr)) { // ... } } return hr;

08.11.2018 vjj 136