All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hubspot.chrome.devtools.client.core.layertree.LayerTree Maven / Gradle / Ivy

package com.hubspot.chrome.devtools.client.core.layertree;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hubspot.chrome.devtools.base.ChromeRequest;
import com.hubspot.chrome.devtools.base.ChromeSessionCore;
import com.hubspot.chrome.devtools.client.core.dom.Rect;
import java.util.List;
import java.util.concurrent.CompletableFuture;

public final class LayerTree {
  ChromeSessionCore chromeSession;

  ObjectMapper objectMapper;

  public LayerTree(ChromeSessionCore chromeSession, ObjectMapper objectMapper) {
    this.chromeSession = chromeSession;
    this.objectMapper = objectMapper;
  }

  /**
   * Provides the reasons why the given layer was composited.
   *
   * @param layerId  The id of the layer for which we want to get the reasons it was composited.
   */
  public List compositingReasons(LayerId layerId) {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.compositingReasons");
    chromeRequest
        .putParams("layerId", layerId);
    return chromeSession.send(chromeRequest, new TypeReference>(){});
  }

  /**
   * Provides the reasons why the given layer was composited.
   *
   * @param layerId  The id of the layer for which we want to get the reasons it was composited.
   */
  public CompletableFuture> compositingReasonsAsync(LayerId layerId) {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.compositingReasons");
    chromeRequest
        .putParams("layerId", layerId);
    return chromeSession.sendAsync(chromeRequest, new TypeReference>(){});
  }

  /**
   * Disables compositing tree inspection.
   */
  public void disable() {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.disable");
    chromeSession.send(chromeRequest);
  }

  /**
   * Disables compositing tree inspection.
   */
  public void disableAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.disable");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Enables compositing tree inspection.
   */
  public void enable() {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.enable");
    chromeSession.send(chromeRequest);
  }

  /**
   * Enables compositing tree inspection.
   */
  public void enableAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.enable");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Returns the snapshot identifier.
   *
   * @param tiles  An array of tiles composing the snapshot.
   */
  public SnapshotId loadSnapshot(List tiles) {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.loadSnapshot");
    chromeRequest
        .putParams("tiles", tiles);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns the snapshot identifier.
   *
   * @param tiles  An array of tiles composing the snapshot.
   */
  public CompletableFuture loadSnapshotAsync(List tiles) {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.loadSnapshot");
    chromeRequest
        .putParams("tiles", tiles);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns the layer snapshot identifier.
   *
   * @param layerId  The id of the layer.
   */
  public SnapshotId makeSnapshot(LayerId layerId) {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.makeSnapshot");
    chromeRequest
        .putParams("layerId", layerId);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Returns the layer snapshot identifier.
   *
   * @param layerId  The id of the layer.
   */
  public CompletableFuture makeSnapshotAsync(LayerId layerId) {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.makeSnapshot");
    chromeRequest
        .putParams("layerId", layerId);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  public List profileSnapshot(SnapshotId snapshotId, Integer minRepeatCount,
      Number minDuration, Rect clipRect) {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.profileSnapshot");
    chromeRequest
        .putParams("snapshotId", snapshotId)
        .putParams("minRepeatCount", minRepeatCount)
        .putParams("minDuration", minDuration)
        .putParams("clipRect", clipRect);
    return chromeSession.send(chromeRequest, new TypeReference>(){});
  }

  public CompletableFuture> profileSnapshotAsync(SnapshotId snapshotId,
      Integer minRepeatCount, Number minDuration, Rect clipRect) {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.profileSnapshot");
    chromeRequest
        .putParams("snapshotId", snapshotId)
        .putParams("minRepeatCount", minRepeatCount)
        .putParams("minDuration", minDuration)
        .putParams("clipRect", clipRect);
    return chromeSession.sendAsync(chromeRequest, new TypeReference>(){});
  }

  /**
   * Releases layer snapshot captured by the back-end.
   *
   * @param snapshotId  The id of the layer snapshot.
   */
  public void releaseSnapshot(SnapshotId snapshotId) {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.releaseSnapshot");
    chromeRequest
        .putParams("snapshotId", snapshotId);
    chromeSession.send(chromeRequest);
  }

  /**
   * Releases layer snapshot captured by the back-end.
   *
   * @param snapshotId  The id of the layer snapshot.
   */
  public void releaseSnapshotAsync(SnapshotId snapshotId) {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.releaseSnapshot");
    chromeRequest
        .putParams("snapshotId", snapshotId);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Replays the layer snapshot and returns the resulting bitmap.
   *
   * @param snapshotId  The id of the layer snapshot.
   * @param fromStep [Optional] The first step to replay from (replay from the very start if not specified).
   * @param toStep [Optional] The last step to replay to (replay till the end if not specified).
   * @param scale [Optional] The scale to apply while replaying (defaults to 1).
   */
  public String replaySnapshot(SnapshotId snapshotId, Integer fromStep, Integer toStep,
      Number scale) {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.replaySnapshot");
    chromeRequest
        .putParams("snapshotId", snapshotId)
        .putParams("fromStep", fromStep)
        .putParams("toStep", toStep)
        .putParams("scale", scale);
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Replays the layer snapshot and returns the resulting bitmap.
   *
   * @param snapshotId  The id of the layer snapshot.
   * @param fromStep [Optional] The first step to replay from (replay from the very start if not specified).
   * @param toStep [Optional] The last step to replay to (replay till the end if not specified).
   * @param scale [Optional] The scale to apply while replaying (defaults to 1).
   */
  public CompletableFuture replaySnapshotAsync(SnapshotId snapshotId, Integer fromStep,
      Integer toStep, Number scale) {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.replaySnapshot");
    chromeRequest
        .putParams("snapshotId", snapshotId)
        .putParams("fromStep", fromStep)
        .putParams("toStep", toStep)
        .putParams("scale", scale);
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Replays the layer snapshot and returns canvas log.
   *
   * @param snapshotId  The id of the layer snapshot.
   */
  public List snapshotCommandLog(SnapshotId snapshotId) {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.snapshotCommandLog");
    chromeRequest
        .putParams("snapshotId", snapshotId);
    return chromeSession.send(chromeRequest, new TypeReference>(){});
  }

  /**
   * Replays the layer snapshot and returns canvas log.
   *
   * @param snapshotId  The id of the layer snapshot.
   */
  public CompletableFuture> snapshotCommandLogAsync(SnapshotId snapshotId) {
    ChromeRequest chromeRequest = new ChromeRequest("LayerTree.snapshotCommandLog");
    chromeRequest
        .putParams("snapshotId", snapshotId);
    return chromeSession.sendAsync(chromeRequest, new TypeReference>(){});
  }
}