0

Following up on How can I render mixed-colour text in DirectWrite?, what's the best practice to handle device loss when passing a device-dependent resource — e.g. an ID2D1LinearGradientBrush or any other ID2D1Brush — as the first parameter of IDWriteTextLayout::SetDrawingEffect?

To the best of my knowledge, I think IDWriteTextLayout was a device-independent resource.

1 Answers1

1

Drawing effect objects have no special meaning within DirectWrite. They are assigned for text ranges, and I believe do not break shaping - everything works normally, but then Draw() simply covers for different drawing effects by making several callback calls.

That means that lost device condition exists only at Direct2D side, and most likely you'll get in corresponding error state after DrawTextLayout() returns. When that happens, you'll need to recreate brushes, and set them again, no need to recreate layout objects.

bunglehead
  • 1,104
  • 1
  • 14
  • 22
  • Just call `SetDrawingEffect` again with re-created resources, then? –  Oct 31 '22 at 08:37
  • 1
    Sure. If you use the same text ranges, that will release previous effects, and addref new ones, i.e. you don't need to call SetDrawingEffect(NULL) explicitly. – bunglehead Oct 31 '22 at 08:56
  • To clarify, directwrite layout logic will simply pass effects pointers you set back to drawing callbacks, it won't interpret them in any way. That's Direct2D that has logic to check for effects being brushes, and if they are not Direct2D itself will ignore them. If you implement your own renderer, you can give effects any meaning you want. – bunglehead Oct 31 '22 at 08:58
  • _« If you use the same text ranges, that will release previous effects, and addref new ones »_ — Will it release effects for range `[a, b]` if I set another effect for range `[a-1, b+1]`? More generally, is there documentation about overlapping effects? –  Nov 01 '22 at 20:51
  • 1
    Yes, it will. Every text position can have only one effect pointer assigned to it, there is no overlapping. – bunglehead Nov 02 '22 at 01:31