1// Copyright 2013 The Flutter Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5part of engine; 6 7html.HtmlElement _createContainer() { 8 final html.HtmlElement container = html.DivElement(); 9 container.style 10 ..position = 'fixed' 11 ..top = '0' 12 ..right = '0' 13 ..padding = '6px' 14 ..color = '#fff' 15 ..backgroundColor = '#000' 16 ..opacity = '0.8'; 17 return container; 18} 19 20/// An overlay in the top right corner of the page that shows statistics 21/// regarding canvas reuse. 22/// 23/// This should only be used for development purposes and never included in 24/// release builds. 25class DebugCanvasReuseOverlay { 26 DebugCanvasReuseOverlay._() { 27 final html.HtmlElement container = _createContainer(); 28 final html.HtmlElement title = html.DivElement(); 29 title.style 30 ..fontWeight = 'bold' 31 ..textDecoration = 'underline'; 32 title.text = 'Canvas Reuse'; 33 34 html.document.body.append( 35 container 36 ..append(title) 37 ..append( 38 html.DivElement() 39 ..appendText('Created: ') 40 ..append(_created), 41 ) 42 ..append( 43 html.DivElement() 44 ..appendText('Kept: ') 45 ..append(_kept), 46 ) 47 ..append( 48 html.DivElement() 49 ..appendText('Reused: ') 50 ..append(_reused), 51 ) 52 ..append( 53 html.DivElement() 54 ..appendText('Disposed: ') 55 ..append(_disposed), 56 ) 57 ..append( 58 html.DivElement() 59 ..appendText('In Recycle List: ') 60 ..append(_inRecycle), 61 ) 62 ..append( 63 html.DivElement() 64 ..append( 65 html.ButtonElement() 66 ..text = 'Reset' 67 ..addEventListener('click', (_) => _reset()), 68 ), 69 ), 70 ); 71 } 72 73 static DebugCanvasReuseOverlay _instance; 74 static DebugCanvasReuseOverlay get instance { 75 if (_instance == null) { 76 // Only call the constructor when assertions are enabled to guard against 77 // mistakingly including this class in a release build. 78 if (assertionsEnabled) { 79 _instance = DebugCanvasReuseOverlay._(); 80 } 81 } 82 return _instance; 83 } 84 85 final html.Text _created = html.Text('0'); 86 final html.Text _kept = html.Text('0'); 87 final html.Text _reused = html.Text('0'); 88 final html.Text _disposed = html.Text('0'); 89 final html.Text _inRecycle = html.Text('0'); 90 91 int _createdCount = 0; 92 int get createdCount => _createdCount; 93 set createdCount(int createdCount) { 94 _createdCount = createdCount; 95 _update(); 96 } 97 98 int _keptCount = 0; 99 int get keptCount => _keptCount; 100 set keptCount(int keptCount) { 101 _keptCount = keptCount; 102 _update(); 103 } 104 105 int _reusedCount = 0; 106 int get reusedCount => _reusedCount; 107 set reusedCount(int reusedCount) { 108 _reusedCount = reusedCount; 109 _update(); 110 } 111 112 int _disposedCount = 0; 113 int get disposedCount => _disposedCount; 114 set disposedCount(int disposedCount) { 115 _disposedCount = disposedCount; 116 _update(); 117 } 118 119 int _inRecycleCount = 0; 120 int get inRecycleCount => _inRecycleCount; 121 set inRecycleCount(int inRecycleCount) { 122 _inRecycleCount = inRecycleCount; 123 _update(); 124 } 125 126 void _update() { 127 _created.text = '$_createdCount'; 128 _kept.text = '$_keptCount'; 129 _reused.text = '$_reusedCount'; 130 _disposed.text = '$_disposedCount'; 131 _inRecycle.text = '$_inRecycleCount'; 132 } 133 134 void _reset() { 135 _createdCount = 136 _keptCount = _reusedCount = _disposedCount = _inRecycleCount = 0; 137 _update(); 138 } 139} 140