コード例 #1
0
ファイル: ZoomedView.java プロジェクト: leplatrem/gecko-dev
  @Override
  public void requestZoomedViewRender() {
    if (stopUpdateView) {
      return;
    }
    // remove pending runnable
    ThreadUtils.removeCallbacksFromUiThread(requestRenderRunnable);

    // "requestZoomedViewRender" can be called very often by Gecko (endDrawing in LayerRender)
    // without
    // any thing changed in the zoomed area (useless calls from the "zoomed area" point of view).
    // "requestZoomedViewRender" can take time to re-render the zoomed view, it depends of the
    // complexity
    // of the html on this area.
    // To avoid to slow down the application, the 2 following cases are tested:

    // 1- Last render is still running, plan another render later.
    if (isRendering()) {
      // post a new runnable DELAY_BEFORE_NEXT_RENDER_REQUEST_MS later
      // We need to post with a delay to be sure that the last call to requestZoomedViewRender will
      // be done.
      // For a static html page WITHOUT any animation/video, there is a last call to endDrawing and
      // we need to make
      // the zoomed render on this last call.
      ThreadUtils.postDelayedToUiThread(requestRenderRunnable, DELAY_BEFORE_NEXT_RENDER_REQUEST_MS);
      return;
    }

    // 2- Current render occurs too early, plan another render later.
    if (renderFrequencyTooHigh()) {
      // post a new runnable DELAY_BEFORE_NEXT_RENDER_REQUEST_MS later
      // We need to post with a delay to be sure that the last call to requestZoomedViewRender will
      // be done.
      // For a page WITH animation/video, the animation/video can be stopped, and we need to make
      // the zoomed render on this last call.
      ThreadUtils.postDelayedToUiThread(requestRenderRunnable, DELAY_BEFORE_NEXT_RENDER_REQUEST_MS);
      return;
    }

    startTimeReRender = System.nanoTime();
    // Allocate the buffer if it's the first call.
    // Change the buffer size if it's not the right size.
    updateBufferSize();

    int tabId = Tabs.getInstance().getSelectedTab().getId();

    ImmutableViewportMetrics metrics = layerView.getViewportMetrics();
    PointF origin = metrics.getOrigin();

    final int xPos = (int) origin.x + lastPosition.x;
    final int yPos = (int) origin.y + lastPosition.y;

    GeckoEvent e =
        GeckoEvent.createZoomedViewEvent(
            tabId, xPos, yPos, viewWidth, viewHeight, zoomFactor * metrics.zoomFactor, buffer);
    GeckoAppShell.sendEventToGecko(e);
  }