Hash :
0408b129
Author :
Date :
2022-06-08T22:20:32
Overlay: Support globbing Makes it less tedious to specify multiple widgets. In particular, it also makes it possible to select many widgets on Android through `adb shell setprop debug.angle.overlay` which has a hard limit of 92 characters for the property. Bug: angleproject:5881 Change-Id: I93bd166cd3dbf8f87e5c6a5fce3f86ebb3e379a3 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3697437 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Yuxin Hu <yuxinhu@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
//
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Overlay.cpp:
// Implements the Overlay class.
//
#include "libANGLE/Overlay.h"
#include "common/string_utils.h"
#include "common/system_utils.h"
#include "libANGLE/Context.h"
#include "libANGLE/Overlay_font_autogen.h"
#include "libANGLE/renderer/GLImplFactory.h"
#include "libANGLE/renderer/OverlayImpl.h"
#include <numeric>
namespace gl
{
namespace
{
#define ANGLE_WIDGET_NAME_PROC(WIDGET_ID) {ANGLE_STRINGIFY(WIDGET_ID), WidgetId::WIDGET_ID},
constexpr std::pair<const char *, WidgetId> kWidgetNames[] = {
ANGLE_WIDGET_ID_X(ANGLE_WIDGET_NAME_PROC)};
} // namespace
OverlayState::OverlayState() : mEnabledWidgetCount(0), mOverlayWidgets{} {}
OverlayState::~OverlayState() = default;
Overlay::Overlay(rx::GLImplFactory *factory)
: mLastPerSecondUpdate(0), mImplementation(factory->createOverlay(mState))
{}
Overlay::~Overlay() = default;
void Overlay::init()
{
initOverlayWidgets();
mLastPerSecondUpdate = angle::GetCurrentSystemTime();
ASSERT(std::all_of(
mState.mOverlayWidgets.begin(), mState.mOverlayWidgets.end(),
[](const std::unique_ptr<overlay::Widget> &widget) { return widget.get() != nullptr; }));
enableOverlayWidgetsFromEnvironment();
}
void Overlay::destroy(const gl::Context *context)
{
ASSERT(mImplementation);
mImplementation->onDestroy(context);
}
void Overlay::enableOverlayWidgetsFromEnvironment()
{
std::vector<std::string> enabledWidgets = angle::GetStringsFromEnvironmentVarOrAndroidProperty(
"ANGLE_OVERLAY", "debug.angle.overlay", ":");
for (const std::pair<const char *, WidgetId> &widgetName : kWidgetNames)
{
for (const std::string &enabledWidget : enabledWidgets)
{
if (angle::NamesMatchWithWildcard(enabledWidget.c_str(), widgetName.first))
{
mState.mOverlayWidgets[widgetName.second]->enabled = true;
++mState.mEnabledWidgetCount;
break;
}
}
}
}
void Overlay::onSwap() const
{
// Increment FPS counter.
getPerSecondWidget(WidgetId::FPS)->add(1);
// Update per second values every second.
double currentTime = angle::GetCurrentSystemTime();
double timeDiff = currentTime - mLastPerSecondUpdate;
if (timeDiff >= 1.0)
{
for (const std::unique_ptr<overlay::Widget> &widget : mState.mOverlayWidgets)
{
if (widget->type == WidgetType::PerSecond)
{
overlay::PerSecond *perSecond =
reinterpret_cast<overlay::PerSecond *>(widget.get());
perSecond->lastPerSecondCount = static_cast<size_t>(perSecond->count / timeDiff);
perSecond->count = 0;
}
}
mLastPerSecondUpdate += 1.0;
}
}
MockOverlay::MockOverlay(rx::GLImplFactory *implFactory) {}
MockOverlay::~MockOverlay() = default;
} // namespace gl