0

Is there a way to listen when drawing on the CGContext occurres? For example: listen when beginPath, addRect are called and capture their params.

I'm trying to capture the UI on ios applications whenever a change happens.

  • 1
    Can you use a wrapper object whose methods do the intercepting, then forward onto the normal drawing methods? – Alexander Feb 22 '23 at 16:35
  • This way I'll need to monkeypatch all other methods that use CGContext to use my class. I'm trying to plug in one place for the whole app and listen when the screen is drawn. – Georgis Andonis Feb 23 '23 at 08:46
  • What about screen drawing that’s done on the PU and never touched core graphics? What exactly are you trying to achieve? – Alexander Feb 25 '23 at 00:41
  • I'm trying to detect view changes and record them. For example: when a view is changed, capture the drawing instructions for this change. – Georgis Andonis Feb 27 '23 at 10:29
  • I don’t think that’s actually possible. Even if you could hook all the core graphics functions, that still wouldn’t be enough, because a lot of drawing is done by shaders on the flu that have nothing to do with CG. Tht’s why I asked what you’re typring to achieve, which you still haven’t really explained. What would you want to do with the drawing instructions you’ve captured? Is this for a screen recording app? Remote Desktop? – Alexander Feb 27 '23 at 13:47
  • Yes, it is for a screen recording app. I need to capture the drawings so I can reproduce them in a replay after that – Georgis Andonis Mar 01 '23 at 11:55
  • There’s a built in API for screen recording. https://developer.apple.com/documentation/replaykit – Alexander Mar 01 '23 at 12:34
  • This will produce big recordings. I'm trying to collect only the changed partial views (subviews) and then apply only these changes in the replay – Georgis Andonis Mar 02 '23 at 13:52
  • Yeah, I get what you mean. This is one of the things that makes the Microsoft remote desktop feature so good IMO, in that it mostly streams draw calls instead of video. But ultimately, tough luck. There's no APIs for you to hook into CoreGraphics calls across the system, or even within your own app. And I have to stress this again, because I don't think you've acknowledged it: A ton of drawing, perhaps even most, is done by the GPU from CoreAnimation or Metal shaders. Even if you could capture all CG calls, that will still be no where near enough to achieve what you're looking for. – Alexander Mar 02 '23 at 14:42

0 Answers0