Ejemplo n.º 1
0
  /**
   * Batch the execution of command objects and execute all the command objects created other
   * places, e.g. call {@link IWXRenderTask#execute()}. First, it will rebuild the dom tree and do
   * pre layout staff. Then call {@link
   * com.taobao.weex.dom.flex.CSSNode#calculateLayout(CSSLayoutContext)} to start calculate layout.
   * Next, call {@link #applyUpdate(WXDomObject)} to get changed dom and creating corresponding
   * command object. Finally, walk through the queue, e.g. call {@link IWXRenderTask#execute()} for
   * every task in the queue.
   */
  void batch() {
    long start0 = System.currentTimeMillis();

    if (!mDirty || mDestroy) {
      return;
    }

    WXDomObject rootDom = mRegistry.get(WXDomObject.ROOT);
    if (rootDom == null) {
      return;
    }

    rebuildingDomTree(rootDom);

    layoutBefore(rootDom);
    long start = System.currentTimeMillis();

    rootDom.calculateLayout(mLayoutContext);

    WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
    if (instance != null) {
      instance.cssLayoutTime(System.currentTimeMillis() - start);
    }

    layoutAfter(rootDom);

    start = System.currentTimeMillis();
    applyUpdate(rootDom);

    if (instance != null) {
      instance.applyUpdateTime(System.currentTimeMillis() - start);
    }

    start = System.currentTimeMillis();
    updateDomObj();
    if (instance != null) {
      instance.updateDomObjTime(System.currentTimeMillis() - start);
    }
    parseAnimation();

    int count = mNormalTasks.size();
    for (int i = 0; i < count && !mDestroy; ++i) {
      mWXRenderManager.runOnThread(mInstanceId, mNormalTasks.get(i));
    }
    mNormalTasks.clear();
    mAddDom.clear();
    animations.clear();
    mDirty = false;
    if (instance != null) {
      instance.batchTime(System.currentTimeMillis() - start0);
    }
  }