33

XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation [email protected]

Embed Size (px)

Citation preview

Page 1: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com
Page 2: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

XPS Rasterization Service in Windows 7

Georgi ChalakovSenior Software Development EngineerMicrosoft [email protected]

Page 3: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

Agenda

• XPSDrv Print Driver Architecture• XPS Rasterization Service (XPSRas)• XPS Rasterizer Object• Banding, Caches and Threads• XPSRas API• Q & A

Page 4: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

XPSDrv Print Driver Architecture

Page 5: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

XPSDrv Print Driver Architecture

Spooler Process

Version 3 Driver

GDI Print App XPS Print App

ConversionRender Module

Config Module/Plug-in Filter 1

Filter N

XPS Spool file

Filter PipelineManager

FP ConfigXML

Filter Pipeline ProcessApplication Process

Provided by: ISVIHV Microsoft

Filter 2PropertyBag

Page 6: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

Filter Pipeline

Filter 1

Filter N

Filter PipelineManager

FPConfigXML

PropertyBag

Filter Pipeline Process

XPS Rasterization Service

XPS Object Model

Filter M

Provided by: ISVIHV Microsoft

Page 7: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

XPS Rasterization Service

Page 8: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

XPS Rasterization Service

• In-box component in Windows 7• Converts XPS Object Model (XPSOM) to WIC images• Simplifies the design of an XPSDrv filter• High printing fidelity• Fast rasterization - uses next generation 2D rasterizers in

Windows 7• Access to the service is through Print Filter Pipeline only

Page 9: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

XPS Rasterization Service

XPS Rasterization Service (XPSRas)

XPS Object Model (XPSOM)

XPS OPC Service

Next Gen Rasterization

Windows Imaging Component (WIC)

Windows Color Management System (WCMS)

Next Gen Font Management

Page 10: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

XPS Rasterization Service

Filter N

XPS Rasterization Service

WIC

Imag

e

Cancel/Continue

XPS

OM

Page 11: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

XPS Rasterization Step by Step

1. Obtain XPS Rasterization Factory from the Property Bag.2. Create XPS Rasterization Object for an XPS OM Fixed Page.3. Rasterize a rectangle from the page.

Rasterize next rectangle from the page. ..Rasterize the last rectangle from the page.

4. Release XPS Rasterization Object.

Page 12: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

1. Obtaining the XPS Rasterization Factory

• The Print Filter Pipeline Manager calls the filter and passes the property bag as an input parameter.

• The call sequence:1. The pipeline manager calls

IPrintPipelineFilter::InitializeFilter2. The filter calls IPrintPipelinePropertyBag::GetProperty

MS_IXpsRasterizationService3. The filter calls IUnknown::QueryInterface for

IXpsRasterizationFactory

Page 13: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

Code Sample

• IHV_CreateRasterizationFactory

HRESULT IHV_CreateRasterizationFactory(

__in IPrintPipelinePropertyBag  *pPropertyBag, __out IXpsRasterizationFactory  **ppXPSRasFactory

){ HRESULT hr;

// Retrieve the factory object from the property bag. VARIANT var; VariantInit(&var);

hr = pPropertyBag->GetProperty(L"MS_IXpsRasterizationFactory“, &var);

//continued on the next slide

Page 14: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

Code Sample

• IHV_CreateRasterizationFactory

//continued from the previous slide

IXpsRasterizationFactory *pXPSRasFactory; if (SUCCEEDED(hr)) { // Get the factory object's IXpsRasterizationFactory interface. IUnknown *pUnknown = var.punkVal; hr = pUnknown->QueryInterface(

__uuidof(IXpsRasterizationFactory),reinterpret_cast<void**>(&pXPSRasFactory));

}

if (SUCCEEDED(hr)) { // Give the caller our reference to the IXpsRasterizationFactory interface. *ppXPSRasFactory = pXPSRasFactory;¯ }

VariantClear(&var); return hr;}

Page 15: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

XPS Rasterization Object

Page 16: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

2. Create XPS Rasterization Object

• XPS Rasterization object is created with following parameters:• XPS OM Fixed Page• Rasterization DPI (dots per inch)• Glyphs rendering mode – aliased/anti-aliased.• Non glyphs rendering mode – aliased/anti-aliased.

• XPS Rasterization object is bound to the XPS OM Fixed Page and it cannot be reused across pages.

• XPS Rasterization can be called many times to rasterize axis-aligned rectangles from the page.

Page 17: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

Code Sample

• IHV_CreateRasterizationObject

HRESULT IHV_CreateRasterizationObject (

__in IXpsRasterizationFactory  *pXPSRasFactory,__in IXpsOMPage *pXPSOMPage, __out IXpsRasterizer **ppXPSRasObject)

{ HRESULT hr;

hr =  pXPSRasFactory->CreateRasterizer(pXPSOMPage, // XPS OM Fixed Page600.0f, // DPIXPSRAS_RENDERING_MODE_ALIASED, // non text rendering modeXPSRAS_RENDERING_MODE_ANTIALIASED, // text rendering mode&ppXPSRasObject // the rasterization

object);

return hr;}

Page 18: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

3. Rasterizing Axis-Aligned Rectangle

• XPS Rasterization object can be called many times to rasterize different axis-aligned rectangles from the page

• The rectangle is represented with integer numbers and it is in device coordinate space

• The content on the bleed box can berasterized using a position outside the fixed page

Bleed BoxFixed Page

0,0

Bleed Box

width, height

-x,-y

Page 19: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

3. Rasterizing Axis-Aligned Rectangle

• The result is a new Windows Image Component (WIC) bitmap

• The image is initially cleared with white full transparent color• clear color: R=1, G=1, B=1, A=0

• The image format is GUID_WICPixelFormat32bppPBGRA• Pre-multiplied alpha• 32bpp - 8 red, 8 green, 8 blue, 8 alpha

Page 20: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

Code Sample

• IHV_RasterizeRect

HRESULT IHV_RasterizeRect(

IXpsRasterizer *pXPSRasObject,RECT const &rect,IWICBitmap **ppBitmap)

{ HRESULT  hr;

hr =  pXPSRasObject->RasterizeRect (rect.left,, // xrect.top, // yrect.right-rect.left, // widthrect.bottom-rect.top, // heightNULL, // cancel interface&ppBitmap // result);

return hr;}

Page 21: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

Rasterization Cancel Interface

interface IXpsRasterizerNotificationCallback : IUnknown{ HRESULT Continue();}

• It is called quite often.• It is called from the same thread where RasterizeRect is

called• If the client returns a failure HRESULT, the rasterization is

canceled and RasterizeRect returns the same HRESULT.• After rasterization is canceled, the rasterization object is

still valid.

Page 22: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

Banding, Caches and Threads

Page 23: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

Banding and Caches

• Banding is the main scenario and the service is optimized for calling RasterizeRect for a sequence of bands.

• Anything that doesn’t intersect with the requested axis-aligned rectangles is skipped early in the process of the rasterization.

• Any resource—font/image/brush—most likely will be cached for a while between rasterizing calls.

• First rasterization call is more expensive than the following rasterization calls on the same fixed page.

Page 24: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

Rendering Transformations on the Fixed Page

• Scaling is supported per page by providing a DPI• Translation is supported per rasterizing call by positioning

the rasterized rectangle.• For an arbitrary transformation, the XPS object model can

be modified before the rasterization object is created.• Any transformation can be applied to the XPS OM page by

wrapping the page in a canvas

Page 25: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

Thread Safety

• Calling the same XPS Rasterization object concurrently from different threads is not supported.

• Rasterizing the same page from the different XPS Rasterization object is supported—you can create more than one object per XPS OM fixed page.

• Canceling is immediate. There is no synchronization and there is no separate thread.

• XPS Rasterization Service calls the cancel interface from the same thread that calls RasterizeRect.

Page 26: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

XPS Rasterization API

Page 27: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

XPS Rasterization API• IXpsRasterizationFactory

interface IXpsRasterizationFactory : IUnknown{ [helpstring("Create a new instance of IXpsRasterizer.")]

HRESULT CreateRasterizer( [in] IXpsOMPage *xpsPage, [in] FLOAT DPI, [in] XPSRAS_RENDERING_MODE nonTextRenderingMode, [in] XPSRAS_RENDERING_MODE textRenderingMode, [out] IXpsRasterizer **ppIXPSRasterizer );}

Page 28: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

XPS Rasterization API• IXpsRasterizer

interface IXpsRasterizer : IUnknown{ [helpstring("Rasterize axis aligned rectangle to a WIC bitmap.")]

HRESULT RasterizeRect( [in] INT x, [in] INT y, [in] INT width, [in] INT height, [in] IXpsRasterizerNotificationCallback *notificationCallback, [out]IWICBitmap **bitmap );}

Page 29: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

XPS Rasterization API• IXpsRasterizerNotificationCallback

interface IXpsRasterizerNotificationCallback : IUnknown{ [helpstring("Client callback function called during

rasterization to allow client to cancel.")]

HRESULT Continue();}

Page 30: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

Summary

• XPS Rasterization Service is Windows 7 in-box component.• The access to the XPS Rasterization Service is through Filter

Pipeline Property bag therefore it is for filters from XPSDrv Filter Pipeline only.

• XPS Rasterization object is bound to an XPS Fixed Page and once it is created, the page must not be modified.

• Any content that intersects with an axis-aligned rectangle is rasterized to a 32bpp WIC bitmap.

• The service is optimized for banding. The rasterization object caches some of the resources for the next call.

• There is an optional Cancel interface for aborting the rasterization process.

Page 31: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

Call To Action

• Look for the XPS Rasterization Filter sample in Windows 7 WDK • A sample XPSDrv filter• Conversion to XPSOM model• Rasterizing the whole page as series of bands

• Read the white paper on WHDC • XPSDrv Filter Pipeline

http://www.microsoft.com/whdc/device/print/XPSDrv_FilterPipe.mspx

Page 32: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

Additional Resources

• Technical advice• [email protected]

• XPS Portal on Microsoft Web site: http://www.microsoft.com/xps• Links to relevant blogs, white papers, specifications

• XPS and Printing on the WHDC Web site:• Printing—Architecture and Driver Support• http://www.microsoft.com/whdc/device/print/default.mspx

• Printing documentation on MSDN• XPS Printer Drivers in the WDK

http://msdn.microsoft.com/en-us/library/aa907458.aspx

Page 33: XPS Rasterization Service in Windows 7 Georgi Chalakov Senior Software Development Engineer Microsoft Corporation georgi.chalakov@microsoft.com

Q&A