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

目录
相关文章
|
8天前
|
弹性计算 关系型数据库 微服务
基于 Docker 与 Kubernetes(K3s)的微服务:阿里云生产环境扩容实践
在微服务架构中,如何实现“稳定扩容”与“成本可控”是企业面临的核心挑战。本文结合 Python FastAPI 微服务实战,详解如何基于阿里云基础设施,利用 Docker 封装服务、K3s 实现容器编排,构建生产级微服务架构。内容涵盖容器构建、集群部署、自动扩缩容、可观测性等关键环节,适配阿里云资源特性与服务生态,助力企业打造低成本、高可靠、易扩展的微服务解决方案。
1194 4
|
7天前
|
机器学习/深度学习 人工智能 前端开发
通义DeepResearch全面开源!同步分享可落地的高阶Agent构建方法论
通义研究团队开源发布通义 DeepResearch —— 首个在性能上可与 OpenAI DeepResearch 相媲美、并在多项权威基准测试中取得领先表现的全开源 Web Agent。
957 12
|
6天前
|
机器学习/深度学习 物联网
Wan2.2再次开源数字人:Animate-14B!一键实现电影角色替换和动作驱动
今天,通义万相的视频生成模型又又又开源了!Wan2.2系列模型家族新增数字人成员Wan2.2-Animate-14B。
538 11
|
17天前
|
人工智能 运维 安全
|
8天前
|
弹性计算 Kubernetes jenkins
如何在 ECS/EKS 集群中有效使用 Jenkins
本文探讨了如何将 Jenkins 与 AWS ECS 和 EKS 集群集成,以构建高效、灵活且具备自动扩缩容能力的 CI/CD 流水线,提升软件交付效率并优化资源成本。
341 0
|
8天前
|
消息中间件 Java Apache
SpringBoot集成RocketMq
RocketMQ 是一款开源的分布式消息中间件,采用纯 Java 编写,支持事务消息、顺序消息、批量消息、定时消息及消息回溯等功能。其优势包括去除对 ZooKeeper 的依赖、支持异步和同步刷盘、高吞吐量及消息过滤等特性。RocketMQ 具备高可用性和高可靠性,适用于大规模分布式系统,能有效保障消息传输的一致性和顺序性。
463 2
|
15天前
|
人工智能 异构计算
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
|
8天前
|
云栖大会
阿里云云栖大会2025年9月24日开启,免费申请大会门票,速度领取~
2025云栖大会将于9月24-26日举行,官网免费预约畅享票,审核后短信通知,持证件入场
1571 12