alexpana / wxWidgets

Read-only mirror of the wxWidgets SVN repo (automatically updated). Report issues here: http://trac.wxwidgets.org/
http://www.wxwidgets.org/
3 stars 0 forks source link

Creating wxGraphicsBitmap from a native bitmap #11

Closed alexpana closed 10 years ago

alexpana commented 10 years ago

Native bitmaps are device-dependent resources which need to be re-acquired. Since the native bitmap does not contain information about it's source, the copy will not be able to acquire the native resources when the direct2d api requests it.

vadz commented 10 years ago

What exactly do we need in order to reacquire them? I'm asking in order to understand if there is any chance at all that we can store something that would allow us to do it, or whether the only possible solution is to give up and tell the user code to recreate the bitmap?

csomor commented 10 years ago

I'd think that we'd have to store a const wxBitmap& - or whatever device independent intermediate format there is - then in the native wxGraphicsBitmap subclass

alexpana commented 10 years ago

What exactly do we need in order to reacquire them? I'm asking in order to understand if there is any chance at all that we can store something that would allow us to do it, or whether the only possible solution is to give up and tell the user code to recreate the bitmap?

We would need to store the original wxBitmap from which the native bitmap was created, just as Stefan pointed out. The solution would then be for wxD2DGraphicsBitmap::GetNativeBitmap() to return a pointer to a structure containing both the native bitmap and the source wxBitmap. But since the native bitmap might not even be acquired, perhaps it's ok to return just a pointer to the source wxBitmap?

csomor commented 10 years ago

But this would lead to recurring conversions of the same bitmap if it is eg used in an OnPaint event, which is quite an expensive operation, wouldn't it ?

alexpana commented 10 years ago

But this would lead to recurring conversions of the same bitmap if it is eg used in an OnPaint event, which is quite an expensive operation, wouldn't it ?

Indeed it would. From a performance point of view, packing the native bitmap would benefit greatly if wxD2DGraphicsBitmap::GetNativeBitmap() is used often, since it would avoid re-acquiring the device-dependent bitmap resource.

I see that the GDI implementation does a shallow copy of the native Bitmap. If the original wxD2DGraphicsBitmap was not initialized (meaning it did not acquire the device-dependent bitmap) the 'native pointer' won't contain a valid native resource and the wxD2DGraphicsBitmaps created from that native pointer will need to acquire the actual native bitmap.

alexpana commented 10 years ago

This was fixed in 2fd0008c8e489cd3296bbfcd61e84c55a56d8862 and the previous commits which changed the structure of the wxD2DBitmapData