1/* 2 * Copyright 2021, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 18import { BaseLayerTraceEntry } from "../common"; 19import LayerTraceEntry from "./LayerTraceEntry"; 20 21class LayerTraceEntryLazy extends BaseLayerTraceEntry { 22 private _isInitialized: boolean = false; 23 private _layersProto: any[]; 24 private _displayProtos: any[]; 25 timestamp: number; 26 timestampMs: string; 27 hwcBlob: string; 28 where: string; 29 private _lazyLayerTraceEntry: LayerTraceEntry; 30 31 constructor (layersProto: any[], displayProtos: any[], 32 timestamp: number, hwcBlob: string, where: string = '') { 33 super(); 34 this._layersProto = layersProto; 35 this._displayProtos = displayProtos; 36 this.timestamp = timestamp; 37 this.timestampMs = timestamp.toString(); 38 this.hwcBlob = hwcBlob; 39 this.where = where; 40 41 this.declareLazyProperties(); 42 } 43 44 private initialize() { 45 if (this._isInitialized) return; 46 47 this._isInitialized = true; 48 this._lazyLayerTraceEntry = LayerTraceEntry.fromProto( 49 this._layersProto, this._displayProtos, this.timestamp, 50 this.hwcBlob, this.where); 51 this._layersProto = []; 52 this._displayProtos = []; 53 } 54 55 56 private declareLazyProperties() { 57 Object.defineProperty(this, 'kind', {configurable: true, enumerable: true, get: function () { 58 this.initialize(); 59 return this._lazyLayerTraceEntry.kind; 60 }}); 61 62 Object.defineProperty(this, 'timestampMs', {configurable: true, enumerable: true, get: function () { 63 this.initialize(); 64 return this._lazyLayerTraceEntry.timestampMs; 65 }}); 66 67 Object.defineProperty(this, 'rects', {configurable: true, enumerable: true, get: function () { 68 this.initialize(); 69 return this._lazyLayerTraceEntry.rects; 70 }}); 71 72 Object.defineProperty(this, 'proto', {configurable: true, enumerable: true, get: function () { 73 this.initialize(); 74 return this._lazyLayerTraceEntry.proto; 75 }}); 76 77 Object.defineProperty(this, 'shortName', {configurable: true, enumerable: true, get: function () { 78 this.initialize(); 79 return this._lazyLayerTraceEntry.shortName; 80 }}); 81 82 Object.defineProperty(this, 'isVisible', {configurable: true, enumerable: true, get: function () { 83 this.initialize(); 84 return this._lazyLayerTraceEntry.isVisible; 85 }}); 86 87 Object.defineProperty(this, 'flattenedLayers', {configurable: true, enumerable: true, get: function () { 88 this.initialize(); 89 return this._lazyLayerTraceEntry.flattenedLayers; 90 }}); 91 92 Object.defineProperty(this, 'stableId', {configurable: true, enumerable: true, get: function () { 93 this.initialize(); 94 return this._lazyLayerTraceEntry.stableId; 95 }}); 96 97 Object.defineProperty(this, 'visibleLayers', {configurable: true, enumerable: true, get: function () { 98 this.initialize(); 99 return this._lazyLayerTraceEntry.visibleLayers; 100 }}); 101 102 Object.defineProperty(this, 'children', {configurable: true, enumerable: true, get: function () { 103 this.initialize(); 104 return this._lazyLayerTraceEntry.children; 105 }}); 106 107 Object.defineProperty(this, 'displays', {configurable: true, enumerable: true, get: function () { 108 this.initialize(); 109 return this._lazyLayerTraceEntry.displays; 110 }}); 111 } 112} 113 114export default LayerTraceEntryLazy; 115