UIWebView结构体系(二)UIWebTiledView和WAKWindow

简介: UIWebTiledView是UIWebBrowserView->UIWebDocumentView->UIWebTiledView继承链中的老爷子,但这三个类的职能却是MVC的关系,UIWebBrowserView是Controller,UIWebDocumentView是Model,UIWebTiledView是View。

UIWebTiledView是UIWebBrowserView->UIWebDocumentView->UIWebTiledView继承链中的老爷子,但这三个类的职能却是MVC的关系,UIWebBrowserView是Controller,UIWebDocumentView是Model,UIWebTiledView是View。(这也是我第一次见到这样的设计,很有意思)

它的声明为: (代码好长,点此跳过)

@interface UIWebTiledView : UIView
{
    WAKWindow *_wakWindow;
    int _inGestureType;
    int _tilingArea;
    BOOL _didFirstTileLayout;
    BOOL _layoutTilesInMainThread;
    BOOL _tilingModeIsLocked;
    BOOL _allowsPaintingAndScriptsWhilePanning;
}

- (id)wakWindow;
- (void)setLayoutTilesInMainThread:(BOOL)arg1;
- (BOOL)layoutTilesInMainThread;
- (void)dumpTiles;
- (void)removeForegroundTiles;
- (void)removeAllTiles;
- (void)removeAllNonVisibleTiles;
- (BOOL)keepsZoomedOutTiles;
- (void)setKeepsZoomedOutTiles:(BOOL)arg1;
- (BOOL)tilesOpaque;
- (void)setTilesOpaque:(BOOL)arg1;
- (BOOL)tileDrawingEnabled;
- (void)setTileDrawingEnabled:(BOOL)arg1;
- (BOOL)logsTilingChanges;
- (void)setLogsTilingChanges:(BOOL)arg1;
- (BOOL)isTilingEnabled;
- (void)setTilingEnabled:(BOOL)arg1;
- (unsigned int)adjustedMaxTileCount;
- (unsigned int)maxTileCount;
- (void)setMaxTileCount:(unsigned int)arg1;
- (BOOL)drawsGrid;
- (void)setDrawsGrid:(BOOL)arg1;
- (struct CGSize)tileSize;
- (void)setTileSize:(struct CGSize)arg1;
- (void)setTransform:(struct CGAffineTransform)arg1;
- (void)setNeedsDisplay;
- (void)setNeedsDisplayInRect:(struct CGRect)arg1;
- (void)_didScroll;
- (void)setNeedsLayout;
- (void)setAllowsPaintingAndScriptsWhilePanning:(BOOL)arg1;
- (BOOL)allowsPaintingAndScriptsWhilePanning;
- (void)unlockTilingMode;
- (void)lockTilingMode;
- (int)tilingArea;
- (void)setTilingArea:(int)arg1;
- (void)setInGesture:(int)arg1;
- (void)updateTilingMode;
- (void)willMoveToWindow:(id)arg1;
- (void)_screenChanged:(id)arg1;
- (void)layoutSubviews;
- (void)layoutTilesNowForRect:(struct CGRect)arg1;
- (void)layoutTilesNowOnWebThread;
- (void)layoutTilesNow;
- (struct CGRect)visibleRect;
- (void)setWAKWindow:(id)arg1;
- (struct WKWindow *)wkWindow;
- (void)dealloc;
- (id)initWithFrame:(struct CGRect)arg1;
- (void)_updateForScreen:(id)arg1;

@end

可以看到好多名字带Tile这个词,也说明了此类专门负责绘制,而tile是分块渲染的意思,这是为了更好地利用GPU和显存。tile rendering大致意思是把屏幕分成几块区域,按照一定顺序来并行绘制这些区域,而不是一整块屏幕一起绘制,详细的信息可参考wiki:http://en.wikipedia.org/wiki/Tiled_rendering。iDevice都是用PowerVR的显卡,它正是分块渲染技术的先锋之一,也可见iOS的设计有针对硬件做优化,非常用心。


从函数和变量名看,UIWebTiledView有这些作用:

  • 确定分块的排版是在主线程还是webThread
  • 设置需要重排版、重绘,发起分块排版
  • 确定分块模式
  • 设置绘图区大小和transform等。

WAKWindow是UIWebTiledView的组合对象之一,其声明如下:(代码好长,点此跳过

@interface WAKWindow : WAKResponder
{
    struct WKWindow *_wkWindow;
    CALayer *_hostLayer;
    struct TileCache *_tileCache;
    struct CGRect _cachedVisibleRect;
    CALayer *_rootLayer;
    struct CGSize _screenSize;
    struct CGSize _availableScreenSize;
    float _screenScale;
    struct CGRect _frame;
    BOOL _useOrientationDependentFontAntialiasing;
}

+ (id)currentEvent;
+ (BOOL)hasLandscapeOrientation;
+ (void)setOrientationProvider:(id)arg1;
+ (id)_wrapperForWindowRef:(struct WKWindow *)arg1;
@property(nonatomic) BOOL useOrientationDependentFontAntialiasing; // @synthesize useOrientationDependentFontAntialiasing=_useOrientationDependentFontAntialiasing;
- (id).cxx_construct;
- (id)recursiveDescription;
- (id)description;
- (void)dumpTiles;
- (void)setAcceleratedDrawingEnabled:(BOOL)arg1;
- (void)setTilePaintCountsVisible:(BOOL)arg1;
- (void)setTileBordersVisible:(BOOL)arg1;
- (id)hostLayer;
- (void)didRotate;
- (void)willRotate;
- (void)displayRect:(struct CGRect)arg1;
- (BOOL)hasPendingDraw;
- (BOOL)keepsZoomedOutTiles;
- (void)setKeepsZoomedOutTiles:(BOOL)arg1;
- (float)currentTileScale;
- (void)setCurrentTileScale:(float)arg1;
- (float)zoomedOutTileScale;
- (void)setZoomedOutTileScale:(float)arg1;
- (int)tilingDirection;
- (void)setTilingDirection:(int)arg1;
- (int)tilingMode;
- (void)setTilingMode:(int)arg1;
- (void)removeForegroundTiles;
- (void)removeAllTiles;
- (void)removeAllNonVisibleTiles;
- (struct CGRect)visibleRect;
- (void)setTilesOpaque:(BOOL)arg1;
- (BOOL)tilesOpaque;
- (void)setNeedsDisplayInRect:(struct CGRect)arg1;
- (void)setNeedsDisplay;
- (void)layoutTilesNowForRect:(struct CGRect)arg1;
- (void)layoutTilesNow;
- (void)layoutTiles;
- (void)sendMouseMoveEvent:(id)arg1 contentChange:(int *)arg2;
- (void)sendEventSynchronously:(id)arg1;
- (void)sendEvent:(id)arg1;
- (struct WKWindow *)_windowRef;
- (id)rootLayer;
- (void)setRootLayer:(id)arg1;
- (float)screenScale;
- (void)setScreenScale:(float)arg1;
- (struct CGSize)availableScreenSize;
- (void)setAvailableScreenSize:(struct CGSize)arg1;
- (struct CGSize)screenSize;
- (void)setScreenSize:(struct CGSize)arg1;
- (void)setContentRect:(struct CGRect)arg1;
- (struct CGRect)frame;
- (void)setFrame:(struct CGRect)arg1 display:(BOOL)arg2;
- (BOOL)makeFirstResponder:(id)arg1;
- (int)keyViewSelectionDirection;
- (void)makeKeyWindow;
- (BOOL)isKeyWindow;
- (struct CGPoint)convertScreenToBase:(struct CGPoint)arg1;
- (struct CGPoint)convertBaseToScreen:(struct CGPoint)arg1;
- (id)_newFirstResponderAfterResigning;
- (BOOL)makeViewFirstResponder:(id)arg1;
- (id)firstResponder;
- (void)close;
- (id)contentView;
- (void)setContentView:(id)arg1;
- (void)dealloc;
- (id)initWithFrame:(struct CGRect)arg1;
- (id)initWithLayer:(id)arg1;

@end

根据之前《WebCore::Widget浅探》的研究,WAKWindow是模仿NSWindow的,不过也有iOS的特性。它的成员变量TileCache是对分块做缓存,可重复利用。每块Tile都会对应一个CALayer对象,所以也有成员变量叫rootLayer。 hostLayer则是放置用作硬件加速的layer的(这个不深入讲了)。


总结之:UIWebTiledView和WAKWindow共同负责页面的绘制,包括分块、排版、提供CALayer的context(绘图上下文)、缓存Layer、交互(缩放、滚动等)。WAKWindow还兼做分派用户操作信息的工作(sendEvent)。

目录
相关文章
|
6月前
|
设计模式 前端开发 JavaScript
14分布式电商项目 - 前端分层以及控制器继承
14分布式电商项目 - 前端分层以及控制器继承
41 0
|
11月前
AVPlayerItem、AVPlayer、AVPlayerLayer三者关系
AVPlayerItem、AVPlayer、AVPlayerLayer三者关系
47 0
UIView层次管理(sendSubviewToBack,bringSubviewToFront)
UIView层次管理(sendSubviewToBack,bringSubviewToFront)
333 0
什么是调用结构?西门子S7-1200的调用结构如何使用?
今天我们来介绍一下西门子S7-1200的调用结构。在西门子S7-1200中采用调用结构来描述用户程序中块的调用层级,调用结构提供了几个方面的信息,包括所用的块,对其它块的调用,各块之间的关系,每个块的数据要求以及块的状态等
什么是调用结构?西门子S7-1200的调用结构如何使用?
|
iOS开发
UIWindow的讲述以及底层
UIWindow的讲述以及底层
105 0
UIWindow的讲述以及底层
|
XML 前端开发 Java
从产品展示页面谈谈Hybris的特有概念和设计结构
从产品展示页面谈谈Hybris的特有概念和设计结构
202 0
从产品展示页面谈谈Hybris的特有概念和设计结构
|
容器
HarmonyOS的组件、布局和事件三者的关系
HarmonyOS的组件、布局和事件三者的关系
138 0
HarmonyOS的组件、布局和事件三者的关系
|
XML 缓存 视频直播
02.视频播放器整体结构
02.视频播放器整体结构
970 0
02.视频播放器整体结构
|
云计算 人工智能 数据处理
对话行癫:解密阿里云顶层设计和底层逻辑
几十个问题,万字长文,阿里云新任总裁行癫履新后首次深入讨论阿里云对云计算未来的判断,深度解读未来阿里云生态战略,揭秘阿里技术委员会和阿里中台思想的原生思考。
2291 0