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)。

目录
相关文章
|
3月前
|
API
【鸿蒙软件开发】ArkTS基础组件之Gauge(环形图表)、LoadingProgress(动态加载)
【鸿蒙软件开发】ArkTS基础组件之Gauge(环形图表)、LoadingProgress(动态加载)
|
9月前
|
安全
组合模式——统一的公司结构
组合模式——统一的公司结构
|
vr&ar 图形学 Windows
CATIA等设计类软件实时渲染流化解决方案
**实时渲染技术可以实现在VR/AR眼镜中查看CATIA模型,其实不仅仅是VR和AR眼镜,还可以是手机、平板、电脑中直接打开网页就可以查看和浏览CATIA等3D模型。而VR/AR眼镜中通过实时渲染技术不仅仅可以查看CATIA模型,其他的比如BIM/Unreal/unity等模型也都是OK的。**那具体是怎么实现的呢?使用起来麻烦吗?能不能支持多人同时使用呢?关于这些对于实时渲染比较相关的问题,这里点量云小芹做统一解释说明。
164 0
CATIA等设计类软件实时渲染流化解决方案
UIView层次管理(sendSubviewToBack,bringSubviewToFront)
UIView层次管理(sendSubviewToBack,bringSubviewToFront)
334 0
|
JavaScript 前端开发
深度解析:Free自由协议增发逻辑技术开发详细丨Free模式系统开发项目方案讲解
深度解析:Free自由协议增发逻辑技术开发详细丨Free模式系统开发项目方案讲解
205 0
|
iOS开发
UIWindow的讲述以及底层
UIWindow的讲述以及底层
105 0
UIWindow的讲述以及底层
|
XML 前端开发 Java
从产品展示页面谈谈Hybris的特有概念和设计结构
从产品展示页面谈谈Hybris的特有概念和设计结构
204 0
从产品展示页面谈谈Hybris的特有概念和设计结构
|
XML 缓存 视频直播
02.视频播放器整体结构
02.视频播放器整体结构
973 0
02.视频播放器整体结构
|
缓存 关系型数据库 数据库