14c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck/* 24c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck * Copyright (C) 2014 The Android Open Source Project 34c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck * 44c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck * Licensed under the Apache License, Version 2.0 (the "License"); 54c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck * you may not use this file except in compliance with the License. 64c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck * You may obtain a copy of the License at 74c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck * 84c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck * http://www.apache.org/licenses/LICENSE-2.0 94c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck * 104c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck * Unless required by applicable law or agreed to in writing, software 114c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck * distributed under the License is distributed on an "AS IS" BASIS, 124c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck * See the License for the specific language governing permissions and 144c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck * limitations under the License. 154c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck */ 165e00c7ce063116c11315639f0035aca8ad73e8ccChris Craik 175e00c7ce063116c11315639f0035aca8ad73e8ccChris Craik#pragma once 184c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 194c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck#include "FrameInfo.h" 204c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck#include "Properties.h" 214c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck#include "Rect.h" 224c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck#include "utils/RingBuffer.h" 234c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 244c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck#include <utils/Timers.h> 254c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 264c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck#include <memory> 274c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 284c9e59d03c2bca38001225b79d01740b8999adfbJohn Recknamespace android { 294c9e59d03c2bca38001225b79d01740b8999adfbJohn Recknamespace uirenderer { 304c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 31de97307362c26b64e2376b21ccde8414088cdc8bMatt Sarettclass IProfileRenderer; 324c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 334c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck// TODO: This is a bit awkward as it needs to match the thing in CanvasContext 344c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck// A better abstraction here would be nice but iterators are painful 354c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck// and RingBuffer having the size baked into the template is also painful 364c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck// But making DrawProfiler also be templated is ALSO painful 374c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck// At least this is a compile failure if this doesn't match, so there's that. 384c9e59d03c2bca38001225b79d01740b8999adfbJohn Recktypedef RingBuffer<FrameInfo, 120> FrameInfoSource; 394c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 404c9e59d03c2bca38001225b79d01740b8999adfbJohn Reckclass FrameInfoVisualizer { 414c9e59d03c2bca38001225b79d01740b8999adfbJohn Reckpublic: 42faecb78a6b11c780db47bc940ca7662899ab5d5eChih-Hung Hsieh explicit FrameInfoVisualizer(FrameInfoSource& source); 434c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck ~FrameInfoVisualizer(); 444c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 454c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck bool consumeProperties(); 464c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck void setDensity(float density); 474c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 484c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck void unionDirty(SkRect* dirty); 49de97307362c26b64e2376b21ccde8414088cdc8bMatt Sarett void draw(IProfileRenderer& renderer); 504c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 514c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck void dumpData(int fd); 524c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 534c9e59d03c2bca38001225b79d01740b8999adfbJohn Reckprivate: 544c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck void createData(); 554c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck void destroyData(); 564c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 5741300274cf8efde2ca95d3c767b214d1edb97f8dJohn Reck void initializeRects(const int baseline, const int width); 58bf3c602284f9a344faf185c3a5e94a264ba44c4fJohn Reck void nextBarSegment(FrameInfoIndex start, FrameInfoIndex end); 59de97307362c26b64e2376b21ccde8414088cdc8bMatt Sarett void drawGraph(IProfileRenderer& renderer); 60de97307362c26b64e2376b21ccde8414088cdc8bMatt Sarett void drawThreshold(IProfileRenderer& renderer); 614c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 62be3fba05e823f740f65b2679929347dc3dd282adJohn Reck inline float durationMS(size_t index, FrameInfoIndex start, FrameInfoIndex end) { 63be3fba05e823f740f65b2679929347dc3dd282adJohn Reck float duration = mFrameSource[index].duration(start, end) * 0.000001f; 64bf3c602284f9a344faf185c3a5e94a264ba44c4fJohn Reck // Clamp to large to avoid spiking off the top of the screen 65bf3c602284f9a344faf185c3a5e94a264ba44c4fJohn Reck duration = duration > 50.0f ? 50.0f : duration; 664c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck return duration > 0.0f ? duration : 0.0f; 674c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck } 684c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 694c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck ProfileType mType = ProfileType::None; 704c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck float mDensity = 0; 714c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 724c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck FrameInfoSource& mFrameSource; 734c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 744c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck int mVerticalUnit = 0; 754c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck int mThresholdStroke = 0; 764c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 7741300274cf8efde2ca95d3c767b214d1edb97f8dJohn Reck int mNumFastRects; 7841300274cf8efde2ca95d3c767b214d1edb97f8dJohn Reck std::unique_ptr<float[]> mFastRects; 7941300274cf8efde2ca95d3c767b214d1edb97f8dJohn Reck int mNumJankyRects; 8041300274cf8efde2ca95d3c767b214d1edb97f8dJohn Reck std::unique_ptr<float[]> mJankyRects; 814c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 824c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck bool mShowDirtyRegions = false; 834c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck SkRect mDirtyRegion; 844c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck bool mFlashToggle = false; 854c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck nsecs_t mLastFrameLogged = 0; 864c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck}; 874c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck 884c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck} /* namespace uirenderer */ 894c9e59d03c2bca38001225b79d01740b8999adfbJohn Reck} /* namespace android */ 90