<commit_before><!DOCTYPE html>
<!--
Copyright (c) 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/cc/constants.html">
<link rel="import" href="/cc/layer_tree_impl.html">
<link rel="import" href="/cc/util.html">
<link rel="import" href="/tvcm/bbox2.html">
<link rel="import" href="/tracing/trace_model/object_instance.html">

<script>
'use strict';

/**
 * @fileoverview Provides the LayerTreeHostImpl model-level objects.
 */
tvcm.exportTo('cc', function() {
  var constants = cc.constants;

  var ObjectSnapshot = tracing.trace_model.ObjectSnapshot;
  var ObjectInstance = tracing.trace_model.ObjectInstance;

  /**
   * @constructor
   */
  function LayerTreeHostImplSnapshot() {
    ObjectSnapshot.apply(this, arguments);
  }

  LayerTreeHostImplSnapshot.prototype = {
    __proto__: ObjectSnapshot.prototype,

    preInitialize: function() {
      cc.preInitializeObject(this);
    },

    initialize: function() {
      cc.moveRequiredFieldsFromArgsToToplevel(
          this, ['deviceViewportSize',
            'activeTree']);
      cc.moveOptionalFieldsFromArgsToToplevel(
          this, ['pendingTree',
            'tiles']);

      if (!this.tiles)
        this.tiles = [];

      this.activeTree.layerTreeHostImpl = this;
      this.activeTree.whichTree = constants.ACTIVE_TREE;
      if (this.pendingTree) {
        this.pendingTree.layerTreeHostImpl = this;
        this.pendingTree.whichTree = constants.PENDING_TREE;
      }
    },

    /**
     * Get all of tile scales and their associated names.
     */
    getContentsScaleNames: function() {
      var scales = {};
      for (var i = 0; i < this.tiles.length; ++i) {
        var tile = this.tiles[i];
        // Return scale -> scale name mappings.
        // Example:
        //  0.25 -> LOW_RESOLUTION
        //  1.0 -> HIGH_RESOLUTION
        //  0.75 -> NON_IDEAL_RESOLUTION
        scales[tile.contentsScale] = tile.resolution;
      }
      return scales;
    },

    getTree: function(whichTree) {
      if (whichTree == constants.ACTIVE_TREE)
        return this.activeTree;
      if (whichTree == constants.PENDING_TREE)
        return this.pendingTree;
      throw new Exception('Unknown tree type + ' + whichTree);
    },

    get tilesHaveGpuMemoryUsageInfo() {
      if (this.tilesHaveGpuMemoryUsageInfo_ !== undefined)
        return this.tilesHaveGpuMemoryUsageInfo_;

      for (var i = 0; i < this.tiles.length; i++) {
        if (this.tiles[i].gpuMemoryUsageInBytes === undefined)
          continue;
        this.tilesHaveGpuMemoryUsageInfo_ = true;
        return true;
      }
      this.tilesHaveGpuMemoryUsageInfo_ = false;
      return false;
    },

    get gpuMemoryUsageInBytes() {
      if (!this.tilesHaveGpuMemoryUsageInfo)
        return;

      var usage = 0;
      for (var i = 0; i < this.tiles.length; i++) {
        var u = this.tiles[i].gpuMemoryUsageInBytes;
        if (u !== undefined)
          usage += u;
      }
      return usage;
    }
  };

  ObjectSnapshot.register('cc::LayerTreeHostImpl', LayerTreeHostImplSnapshot);

  /**
   * @constructor
   */
  function LayerTreeHostImplInstance() {
    ObjectInstance.apply(this, arguments);

    this.allLayersBBox_ = undefined;
  }

  LayerTreeHostImplInstance.prototype = {
    __proto__: ObjectInstance.prototype,

    get allContentsScales() {
      if (this.allContentsScales_)
        return this.allContentsScales_;

      var scales = {};
      for (var tileID in this.allTileHistories_) {
        var tileHistory = this.allTileHistories_[tileID];
        scales[tileHistory.contentsScale] = true;
      }<commit_msg>Do not include inactive tiles in gpuMemoryUsageInBytes computation<commit_after><!DOCTYPE html>
<!--
Copyright (c) 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/cc/constants.html">
<link rel="import" href="/cc/layer_tree_impl.html">
<link rel="import" href="/cc/util.html">
<link rel="import" href="/tvcm/bbox2.html">
<link rel="import" href="/tracing/trace_model/object_instance.html">

<script>
'use strict';

/**
 * @fileoverview Provides the LayerTreeHostImpl model-level objects.
 */
tvcm.exportTo('cc', function() {
  var constants = cc.constants;

  var ObjectSnapshot = tracing.trace_model.ObjectSnapshot;
  var ObjectInstance = tracing.trace_model.ObjectInstance;

  /**
   * @constructor
   */
  function LayerTreeHostImplSnapshot() {
    ObjectSnapshot.apply(this, arguments);
  }

  LayerTreeHostImplSnapshot.prototype = {
    __proto__: ObjectSnapshot.prototype,

    preInitialize: function() {
      cc.preInitializeObject(this);
    },

    initialize: function() {
      cc.moveRequiredFieldsFromArgsToToplevel(
          this, ['deviceViewportSize',
            'activeTree']);
      cc.moveOptionalFieldsFromArgsToToplevel(
          this, ['pendingTree',
            'tiles']);

      if (!this.tiles)
        this.tiles = [];

      this.activeTree.layerTreeHostImpl = this;
      this.activeTree.whichTree = constants.ACTIVE_TREE;
      if (this.pendingTree) {
        this.pendingTree.layerTreeHostImpl = this;
        this.pendingTree.whichTree = constants.PENDING_TREE;
      }
    },

    /**
     * Get all of tile scales and their associated names.
     */
    getContentsScaleNames: function() {
      var scales = {};
      for (var i = 0; i < this.tiles.length; ++i) {
        var tile = this.tiles[i];
        // Return scale -> scale name mappings.
        // Example:
        //  0.25 -> LOW_RESOLUTION
        //  1.0 -> HIGH_RESOLUTION
        //  0.75 -> NON_IDEAL_RESOLUTION
        scales[tile.contentsScale] = tile.resolution;
      }
      return scales;
    },

    getTree: function(whichTree) {
      if (whichTree == constants.ACTIVE_TREE)
        return this.activeTree;
      if (whichTree == constants.PENDING_TREE)
        return this.pendingTree;
      throw new Exception('Unknown tree type + ' + whichTree);
    },

    get tilesHaveGpuMemoryUsageInfo() {
      if (this.tilesHaveGpuMemoryUsageInfo_ !== undefined)
        return this.tilesHaveGpuMemoryUsageInfo_;

      for (var i = 0; i < this.tiles.length; i++) {
        if (this.tiles[i].gpuMemoryUsageInBytes === undefined)
          continue;
        this.tilesHaveGpuMemoryUsageInfo_ = true;
        return true;
      }
      this.tilesHaveGpuMemoryUsageInfo_ = false;
      return false;
    },

    get gpuMemoryUsageInBytes() {
      if (!this.tilesHaveGpuMemoryUsageInfo)
        return;

      var usage = 0;
      for (var i = 0; i < this.tiles.length; i++) {
        if (this.tiles[i].isActiveTile === false)
          continue;
        var u = this.tiles[i].gpuMemoryUsageInBytes;
        if (u !== undefined)
          usage += u;
      }
      return usage;
    }
  };

  ObjectSnapshot.register('cc::LayerTreeHostImpl', LayerTreeHostImplSnapshot);

  /**
   * @constructor
   */
  function LayerTreeHostImplInstance() {
    ObjectInstance.apply(this, arguments);

    this.allLayersBBox_ = undefined;
  }

  LayerTreeHostImplInstance.prototype = {
    __proto__: ObjectInstance.prototype,

    get allContentsScales() {
      if (this.allContentsScales_)
        return this.allContentsScales_;

      var scales = {};
      for (var tileID in this.allTileHistories_) {
        var tileHistory = this.allTileHistories_[tileID];
        scales[tileHistory.contentsScale] = true;
      }
{'fraction_non_alphanumeric': 0.1170086035737922, 'fraction_numerical': 0.004500330906684315, 'mean_word_length': 2.702106810387065, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5313271', 'n_tokens_mistral': 2335, 'n_tokens_neox': 2262, 'n_words': 485}