~mmach/netext73/webkit2gtk

« back to all changes in this revision

Viewing changes to Source/ThirdParty/ANGLE/src/libANGLE/Overlay.cpp

  • Committer: mmach
  • Date: 2023-06-16 17:21:37 UTC
  • Revision ID: netbit73@gmail.com-20230616172137-2rqx6yr96ga9g3kp
1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
 
3
// Use of this source code is governed by a BSD-style license that can be
 
4
// found in the LICENSE file.
 
5
//
 
6
// Overlay.cpp:
 
7
//    Implements the Overlay class.
 
8
//
 
9
 
 
10
#include "libANGLE/Overlay.h"
 
11
 
 
12
#include "common/system_utils.h"
 
13
#include "libANGLE/Context.h"
 
14
#include "libANGLE/Overlay_font_autogen.h"
 
15
#include "libANGLE/renderer/GLImplFactory.h"
 
16
#include "libANGLE/renderer/OverlayImpl.h"
 
17
 
 
18
#include <numeric>
 
19
 
 
20
namespace gl
 
21
{
 
22
namespace
 
23
{
 
24
constexpr std::pair<const char *, WidgetId> kWidgetNames[] = {
 
25
    {"FPS", WidgetId::FPS},
 
26
    {"VulkanLastValidationMessage", WidgetId::VulkanLastValidationMessage},
 
27
    {"VulkanValidationMessageCount", WidgetId::VulkanValidationMessageCount},
 
28
    {"VulkanCommandGraphSize", WidgetId::VulkanCommandGraphSize},
 
29
    {"VulkanSecondaryCommandBufferPoolWaste", WidgetId::VulkanSecondaryCommandBufferPoolWaste},
 
30
};
 
31
}  // namespace
 
32
 
 
33
OverlayState::OverlayState() : mEnabledWidgetCount(0), mOverlayWidgets{} {}
 
34
OverlayState::~OverlayState() = default;
 
35
 
 
36
Overlay::Overlay(rx::GLImplFactory *factory)
 
37
    : mLastPerSecondUpdate(0), mImplementation(factory->createOverlay(mState))
 
38
{}
 
39
Overlay::~Overlay() = default;
 
40
 
 
41
angle::Result Overlay::init(const Context *context)
 
42
{
 
43
    initOverlayWidgets();
 
44
    mLastPerSecondUpdate = angle::GetCurrentTime();
 
45
 
 
46
    ASSERT(std::all_of(
 
47
        mState.mOverlayWidgets.begin(), mState.mOverlayWidgets.end(),
 
48
        [](const std::unique_ptr<overlay::Widget> &widget) { return widget.get() != nullptr; }));
 
49
 
 
50
    enableOverlayWidgetsFromEnvironment();
 
51
 
 
52
    return mImplementation->init(context);
 
53
}
 
54
 
 
55
void Overlay::destroy(const gl::Context *context)
 
56
{
 
57
    ASSERT(mImplementation);
 
58
    mImplementation->onDestroy(context);
 
59
}
 
60
 
 
61
void Overlay::enableOverlayWidgetsFromEnvironment()
 
62
{
 
63
    std::istringstream angleOverlayWidgets(angle::GetEnvironmentVar("ANGLE_OVERLAY"));
 
64
 
 
65
    std::set<std::string> enabledWidgets;
 
66
    std::string widget;
 
67
    while (getline(angleOverlayWidgets, widget, ':'))
 
68
    {
 
69
        enabledWidgets.insert(widget);
 
70
    }
 
71
 
 
72
    for (const std::pair<const char *, WidgetId> &widgetName : kWidgetNames)
 
73
    {
 
74
        if (enabledWidgets.count(widgetName.first) > 0)
 
75
        {
 
76
            mState.mOverlayWidgets[widgetName.second]->enabled = true;
 
77
            ++mState.mEnabledWidgetCount;
 
78
        }
 
79
    }
 
80
}
 
81
 
 
82
void Overlay::onSwap() const
 
83
{
 
84
    // Increment FPS counter.
 
85
    getPerSecondWidget(WidgetId::FPS)->add(1);
 
86
 
 
87
    // Update per second values every second.
 
88
    double currentTime = angle::GetCurrentTime();
 
89
    double timeDiff    = currentTime - mLastPerSecondUpdate;
 
90
    if (timeDiff >= 1.0)
 
91
    {
 
92
        for (const std::unique_ptr<overlay::Widget> &widget : mState.mOverlayWidgets)
 
93
        {
 
94
            if (widget->type == WidgetType::PerSecond)
 
95
            {
 
96
                overlay::PerSecond *perSecond =
 
97
                    reinterpret_cast<overlay::PerSecond *>(widget.get());
 
98
                perSecond->lastPerSecondCount = static_cast<size_t>(perSecond->count / timeDiff);
 
99
                perSecond->count              = 0;
 
100
            }
 
101
        }
 
102
        mLastPerSecondUpdate += 1.0;
 
103
    }
 
104
}
 
105
 
 
106
DummyOverlay::DummyOverlay(rx::GLImplFactory *implFactory) {}
 
107
DummyOverlay::~DummyOverlay() = default;
 
108
 
 
109
}  // namespace gl