[PATCH 1/2] d2d1: Implement ID2D1Bitmap1::Map().

Nikolay Sivov nsivov at codeweavers.com
Thu May 12 11:21:08 CDT 2022


On 5/12/22 16:23, Dmitry Timoshkov wrote:
>   static HRESULT STDMETHODCALLTYPE d2d_bitmap_Map(ID2D1Bitmap1 *iface, D2D1_MAP_OPTIONS options,
>           D2D1_MAPPED_RECT *mapped_rect)
>   {
> -    FIXME("iface %p, options %#x, mapped_rect %p stub!\n", iface, options, mapped_rect);
> +    struct d2d_bitmap *bitmap = impl_from_ID2D1Bitmap1(iface);
> +    ID3D11Device *device;
> +    ID3D11DeviceContext *context;
> +    D3D11_TEXTURE2D_DESC texture_desc;
> +    ID3D11Texture2D *staging_texture;
> +    D3D11_MAPPED_SUBRESOURCE mapped_subresource;
> +    HRESULT hr;
>   
> -    return E_NOTIMPL;
> +    TRACE("iface %p, options %#x, mapped_rect %p.\n", iface, options, mapped_rect);
> +
> +    ID3D11Resource_GetDevice(bitmap->resource, &device);
> +    ID3D11Device_GetImmediateContext(device, &context);
> +    ID3D11Texture2D_GetDesc((ID3D11Texture2D *)bitmap->resource, &texture_desc);
> +
> +    texture_desc.Usage = D3D11_USAGE_STAGING;
> +    texture_desc.BindFlags = 0;
> +    texture_desc.CPUAccessFlags = d3d11_cpu_access_from_d2d1_map_options(options);
> +    ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &staging_texture);
> +    ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)staging_texture, bitmap->resource);
> +    if (SUCCEEDED(hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)staging_texture, 0,
> +            d3d11_map_from_d2d1_map_options(options), 0, &mapped_subresource)))
> +    {
> +        mapped_rect->pitch = mapped_subresource.RowPitch;
> +        mapped_rect->bits = mapped_subresource.pData;
> +        bitmap->staging_resource = (ID3D11Resource *)staging_texture;
> +    }
> +    else
> +    {
> +        WARN("Failed to map resource, hr %#lx.\n", hr);
> +        ID3D11Texture2D_Release(staging_texture);
> +    }
> +
> +    ID3D11DeviceContext_Release(context);
> +    ID3D11Device_Release(device);
> +
> +    return hr;
>   }
According to docs, Map() only works for D2D1_BITMAP_OPTIONS_CPU_READ, 
that potentially simplifies things. Also Unmap() in patch 2 will not 
write anything back.



More information about the wine-devel mailing list