• I'm rendering DirectX content to a XAML control in a C++/XAML app using the SurfaceImageSource approach described here: http://msdn.microsoft.com/en-us/library/windows/apps/hh825871.aspx . I'm then using ID2D1DeviceContext::CreateBitmapFromDxgiSurface() to write Direct2D content on top of the 3D content.

    It works fine, but I was wondering about memory when CreateBitmapFromDxgiSurface() is called. Does it share the SurfaceImageSource's memory, or is a copy of the memory being taken? Since I may be doing the drawing many times within a loop, it would be nice if it wasn't creating new bitmap bits for each draw. Or even if it is, maybe I shouldn't be concerned with it?

    I notice there's a function:  ID2D1RenderTarget::CreateSharedBitmap(). This returns a  ID2D1Bitmap as opposed to the ID2D1Bitmap1 returned by CreateBitmapFromDxgiSurface().  Anyway, I tried passing the SurfaceImageSource's IDXGISurface to it, but got an error message saying the bitmap pixel format is unsupported.

    Thanks in advance for any feedback.


    Thursday, July 19, 2012 11:51 AM

All replies

  • I managed to get ID2D1RenderTarget::CreateSharedBitmap() to work by retrieving the DXGI_FORMAT from IDXGISurface and passing it into the bitmapProperties argument as follows:

    ComPtr<ID2D1Bitmap> bitmap; ComPtr<ID2D1DeviceContext> d2dContext; ComPtr<IDXGISurface> surface; DXGI_SURFACE_DESC desc; D2D1_BITMAP_PROPERTIES bp; surface -> GetDesc(&desc); bp.pixelFormat = PixelFormat(desc.Format, D2D1_ALPHA_MODE_IGNORE); bp.dpiX = bp.dpiY = 0.0f; d2dContext -> CreateSharedBitmap(__uuidof(IDXGISurface), surface.Get(), &bp, &bitmap);

    d2dContext -> SetTarget(bitmap.Get());

    I'd still be interested in any feedback anyone may have on using this approach, and whether using ID2D1DeviceContext::CreateBitmapFromDxgiSurface() does in fact create extra memory.


    • Edited by RobertHF Thursday, July 19, 2012 1:33 PM text formatting
    Thursday, July 19, 2012 1:27 PM
  • I think they both use shared memory. The difference is who create the resource ,d2d or d3d.

    C++ DX11

    Wednesday, July 25, 2012 3:02 AM