UIWebView结构体系(二)UIWebTiledView和WAKWindow

来源:互联网 发布:js escape编码中文 编辑:程序博客网 时间:2024/05/02 02:02

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

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

[cpp] view plaincopy
  1. @interface UIWebTiledView : UIView  
  2. {  
  3.     WAKWindow *_wakWindow;  
  4.     int _inGestureType;  
  5.     int _tilingArea;  
  6.     BOOL _didFirstTileLayout;  
  7.     BOOL _layoutTilesInMainThread;  
  8.     BOOL _tilingModeIsLocked;  
  9.     BOOL _allowsPaintingAndScriptsWhilePanning;  
  10. }  
  11.   
  12. - (id)wakWindow;  
  13. - (void)setLayoutTilesInMainThread:(BOOL)arg1;  
  14. - (BOOL)layoutTilesInMainThread;  
  15. - (void)dumpTiles;  
  16. - (void)removeForegroundTiles;  
  17. - (void)removeAllTiles;  
  18. - (void)removeAllNonVisibleTiles;  
  19. - (BOOL)keepsZoomedOutTiles;  
  20. - (void)setKeepsZoomedOutTiles:(BOOL)arg1;  
  21. - (BOOL)tilesOpaque;  
  22. - (void)setTilesOpaque:(BOOL)arg1;  
  23. - (BOOL)tileDrawingEnabled;  
  24. - (void)setTileDrawingEnabled:(BOOL)arg1;  
  25. - (BOOL)logsTilingChanges;  
  26. - (void)setLogsTilingChanges:(BOOL)arg1;  
  27. - (BOOL)isTilingEnabled;  
  28. - (void)setTilingEnabled:(BOOL)arg1;  
  29. - (unsigned int)adjustedMaxTileCount;  
  30. - (unsigned int)maxTileCount;  
  31. - (void)setMaxTileCount:(unsigned int)arg1;  
  32. - (BOOL)drawsGrid;  
  33. - (void)setDrawsGrid:(BOOL)arg1;  
  34. - (struct CGSize)tileSize;  
  35. - (void)setTileSize:(struct CGSize)arg1;  
  36. - (void)setTransform:(struct CGAffineTransform)arg1;  
  37. - (void)setNeedsDisplay;  
  38. - (void)setNeedsDisplayInRect:(struct CGRect)arg1;  
  39. - (void)_didScroll;  
  40. - (void)setNeedsLayout;  
  41. - (void)setAllowsPaintingAndScriptsWhilePanning:(BOOL)arg1;  
  42. - (BOOL)allowsPaintingAndScriptsWhilePanning;  
  43. - (void)unlockTilingMode;  
  44. - (void)lockTilingMode;  
  45. - (int)tilingArea;  
  46. - (void)setTilingArea:(int)arg1;  
  47. - (void)setInGesture:(int)arg1;  
  48. - (void)updateTilingMode;  
  49. - (void)willMoveToWindow:(id)arg1;  
  50. - (void)_screenChanged:(id)arg1;  
  51. - (void)layoutSubviews;  
  52. - (void)layoutTilesNowForRect:(struct CGRect)arg1;  
  53. - (void)layoutTilesNowOnWebThread;  
  54. - (void)layoutTilesNow;  
  55. - (struct CGRect)visibleRect;  
  56. - (void)setWAKWindow:(id)arg1;  
  57. - (struct WKWindow *)wkWindow;  
  58. - (void)dealloc;  
  59. - (id)initWithFrame:(struct CGRect)arg1;  
  60. - (void)_updateForScreen:(id)arg1;  
  61.   
  62. @end  

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


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

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

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

[cpp] view plaincopy
  1. @interface WAKWindow : WAKResponder  
  2. {  
  3.     struct WKWindow *_wkWindow;  
  4.     CALayer *_hostLayer;  
  5.     struct TileCache *_tileCache;  
  6.     struct CGRect _cachedVisibleRect;  
  7.     CALayer *_rootLayer;  
  8.     struct CGSize _screenSize;  
  9.     struct CGSize _availableScreenSize;  
  10.     float _screenScale;  
  11.     struct CGRect _frame;  
  12.     BOOL _useOrientationDependentFontAntialiasing;  
  13. }  
  14.   
  15. + (id)currentEvent;  
  16. + (BOOL)hasLandscapeOrientation;  
  17. + (void)setOrientationProvider:(id)arg1;  
  18. + (id)_wrapperForWindowRef:(struct WKWindow *)arg1;  
  19. @property(nonatomic) BOOL useOrientationDependentFontAntialiasing; // @synthesize useOrientationDependentFontAntialiasing=_useOrientationDependentFontAntialiasing;  
  20. - (id).cxx_construct;  
  21. - (id)recursiveDescription;  
  22. - (id)description;  
  23. - (void)dumpTiles;  
  24. - (void)setAcceleratedDrawingEnabled:(BOOL)arg1;  
  25. - (void)setTilePaintCountsVisible:(BOOL)arg1;  
  26. - (void)setTileBordersVisible:(BOOL)arg1;  
  27. - (id)hostLayer;  
  28. - (void)didRotate;  
  29. - (void)willRotate;  
  30. - (void)displayRect:(struct CGRect)arg1;  
  31. - (BOOL)hasPendingDraw;  
  32. - (BOOL)keepsZoomedOutTiles;  
  33. - (void)setKeepsZoomedOutTiles:(BOOL)arg1;  
  34. - (float)currentTileScale;  
  35. - (void)setCurrentTileScale:(float)arg1;  
  36. - (float)zoomedOutTileScale;  
  37. - (void)setZoomedOutTileScale:(float)arg1;  
  38. - (int)tilingDirection;  
  39. - (void)setTilingDirection:(int)arg1;  
  40. - (int)tilingMode;  
  41. - (void)setTilingMode:(int)arg1;  
  42. - (void)removeForegroundTiles;  
  43. - (void)removeAllTiles;  
  44. - (void)removeAllNonVisibleTiles;  
  45. - (struct CGRect)visibleRect;  
  46. - (void)setTilesOpaque:(BOOL)arg1;  
  47. - (BOOL)tilesOpaque;  
  48. - (void)setNeedsDisplayInRect:(struct CGRect)arg1;  
  49. - (void)setNeedsDisplay;  
  50. - (void)layoutTilesNowForRect:(struct CGRect)arg1;  
  51. - (void)layoutTilesNow;  
  52. - (void)layoutTiles;  
  53. - (void)sendMouseMoveEvent:(id)arg1 contentChange:(int *)arg2;  
  54. - (void)sendEventSynchronously:(id)arg1;  
  55. - (void)sendEvent:(id)arg1;  
  56. - (struct WKWindow *)_windowRef;  
  57. - (id)rootLayer;  
  58. - (void)setRootLayer:(id)arg1;  
  59. - (float)screenScale;  
  60. - (void)setScreenScale:(float)arg1;  
  61. - (struct CGSize)availableScreenSize;  
  62. - (void)setAvailableScreenSize:(struct CGSize)arg1;  
  63. - (struct CGSize)screenSize;  
  64. - (void)setScreenSize:(struct CGSize)arg1;  
  65. - (void)setContentRect:(struct CGRect)arg1;  
  66. - (struct CGRect)frame;  
  67. - (void)setFrame:(struct CGRect)arg1 display:(BOOL)arg2;  
  68. - (BOOL)makeFirstResponder:(id)arg1;  
  69. - (int)keyViewSelectionDirection;  
  70. - (void)makeKeyWindow;  
  71. - (BOOL)isKeyWindow;  
  72. - (struct CGPoint)convertScreenToBase:(struct CGPoint)arg1;  
  73. - (struct CGPoint)convertBaseToScreen:(struct CGPoint)arg1;  
  74. - (id)_newFirstResponderAfterResigning;  
  75. - (BOOL)makeViewFirstResponder:(id)arg1;  
  76. - (id)firstResponder;  
  77. - (void)close;  
  78. - (id)contentView;  
  79. - (void)setContentView:(id)arg1;  
  80. - (void)dealloc;  
  81. - (id)initWithFrame:(struct CGRect)arg1;  
  82. - (id)initWithLayer:(id)arg1;  
  83.   
  84. @end  

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


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