gpt4 book ai didi

objective-c - cacheDisplayInRect 在内部是如何工作的?

转载 作者:行者123 更新时间:2023-11-28 08:51:36 25 4
gpt4 key购买 nike

当将位图数据写入 bitmapImageRep 时,[NSView cacheDisplayInRect:(NSRect)rect toBitmapImageRep:(NSBitmapImageRep *)bitmapImageRep] 如何在内部工作?

例如它是遍历并访问所有 subview 的 CALayer 层 并在调用 ...cacheDisplayInRect... 时组合它们还是简单地编写它自己的层(然后已经包含所有 subview 的表示数据)。

我的问题的背景:我使用的本地控件 (WKWebView) 在屏幕截图 ( example SO question ) 时被破坏了,而不是重新发明轮子来截取整个屏幕截图应用程序包括 WKWebView 我想修复 Cocoa 用于位图表示的方法。

最佳答案

我做了一些试验和错误,发现 ...cacheDisplayInRect... 和 ...drawInContext... 调用 - [NSView drawRect:] 在内部渲染元素。

- [CALayer drawInContext:context] 调用栈

#0  0x000000010000e28c in -[DXSecureWKWebView drawRect:] at /Users/x/dev/X/XSecureWKWebView.m:34
#1 0x00007fff8d386749 in -[NSView(NSInternal) _recursive:displayRectIgnoringOpacity:inGraphicsContext:CGContext:topView:shouldChangeFontReferenceColor:] ()
#2 0x00007fff8d386afe in -[NSView(NSInternal) _recursive:displayRectIgnoringOpacity:inGraphicsContext:CGContext:topView:shouldChangeFontReferenceColor:] ()
#3 0x00007fff8d386afe in -[NSView(NSInternal) _recursive:displayRectIgnoringOpacity:inGraphicsContext:CGContext:topView:shouldChangeFontReferenceColor:] ()
#4 0x00007fff8d386168 in __46-[NSView(NSLayerKitGlue) drawLayer:inContext:]_block_invoke ()
#5 0x00007fff8d385e11 in -[NSView(NSLayerKitGlue) _drawViewBackingLayer:inContext:drawingHandler:] ()
#6 0x00007fff8d385493 in -[NSView(NSLayerKitGlue) drawLayer:inContext:] ()

- [NSView cacheDisplayInRect:toBitmapImageRep:]调用栈

#0  0x000000010000e2dc in -[XSecureWKWebView drawRect:] at /Users/x/dev/x/XSecureWKWebView.m:34
#1 0x00007fff8d386749 in -[NSView(NSInternal) _recursive:displayRectIgnoringOpacity:inGraphicsContext:CGContext:topView:shouldChangeFontReferenceColor:] ()
#2 0x00007fff8d65fe1c in __50-[_NSViewBackingLayer _renderForegroundInContext:]_block_invoke ()
#3 0x00007fff8d385e11 in -[NSView(NSLayerKitGlue) _drawViewBackingLayer:inContext:drawingHandler:] ()
#4 0x00007fff8d50b740 in -[_NSViewBackingLayer _renderForegroundInContext:] ()
#5 0x00007fff934f5ce1 in -[CALayer renderInContext:] ()
#6 0x00007fff934f7aaf in -[CALayer _renderSublayersInContext:] ()
#7 0x00007fff8d50b807 in -[_NSViewBackingLayer _renderSublayersInContext:] ()
#8 0x00007fff934f5cf0 in -[CALayer renderInContext:] ()
#9 0x00007fff934f7aaf in -[CALayer _renderSublayersInContext:] ()
#10 0x00007fff8d50b807 in -[_NSViewBackingLayer _renderSublayersInContext:] ()
#11 0x00007fff934f5cf0 in -[CALayer renderInContext:] ()
#12 0x00007fff934f7aaf in -[CALayer _renderSublayersInContext:] ()
#13 0x00007fff8d50b807 in -[_NSViewBackingLayer _renderSublayersInContext:] ()
#14 0x00007fff934f5cf0 in -[CALayer renderInContext:] ()
#15 0x00007fff934f7aaf in -[CALayer _renderSublayersInContext:] ()
#16 0x00007fff8d50b807 in -[_NSViewBackingLayer _renderSublayersInContext:] ()
#17 0x00007fff934f5cf0 in -[CALayer renderInContext:] ()
#18 0x00007fff934f7aaf in -[CALayer _renderSublayersInContext:] ()
#19 0x00007fff8d50b807 in -[_NSViewBackingLayer _renderSublayersInContext:] ()
#20 0x00007fff934f5cf0 in -[CALayer renderInContext:] ()
#21 0x00007fff934f7aaf in -[CALayer _renderSublayersInContext:] ()
#22 0x00007fff8d50b807 in -[_NSViewBackingLayer _renderSublayersInContext:] ()
#23 0x00007fff934f5cf0 in -[CALayer renderInContext:] ()
#24 0x00007fff8d50b11d in -[NSView _layerBackedDisplayRectIgnoringOpacity:inContext:isRootView:flipContextIfNeedeed:] ()
#25 0x00007fff8d50ac74 in -[NSView displayRectIgnoringOpacity:inContext:] ()
#26 0x00007fff8d65f685 in __62-[NSView cacheDisplayInRect:toBitmapImageRep:includeSubviews:]_block_invoke ()
#27 0x00007fff8d65f3dc in __36-[NSBitmapImageRep _captureDrawing:]_block_invoke ()
#28 0x00007fff8d65f14c in -[NSBitmapImageRep _captureDrawing:] ()
#29 0x00007fff8d65f079 in -[NSView cacheDisplayInRect:toBitmapImageRep:includeSubviews:] ()

关于objective-c - cacheDisplayInRect 在内部是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34066859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com