Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TextureMapper] Missing implementation of backingStoreMemoryEstimate #14286

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions Source/WebCore/page/linux/ResourceUsageThreadLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
#include <wtf/linux/CurrentProcessMemoryStatus.h>
#include <wtf/text/StringToIntegerConversion.h>

#if USE(NICOSIA)
#include "NicosiaBuffer.h"
#endif

namespace WebCore {

static float cpuPeriod()
Expand Down Expand Up @@ -105,6 +109,9 @@ void ResourceUsageThread::platformSaveStateBeforeStarting()
m_samplingProfilerThreadID = thread->id();
}
#endif
#if USE(NICOSIA)
Nicosia::Buffer::resetMemoryUsage();
#endif
}

struct ThreadInfo {
Expand Down Expand Up @@ -320,6 +327,10 @@ void ResourceUsageThread::platformCollectMemoryData(JSC::VM* vm, ResourceUsageDa
});
data.categories[MemoryCategory::Images].dirtySize = imagesDecodedSize;

#if USE(NICOSIA)
data.categories[MemoryCategory::Layers].dirtySize = Nicosia::Buffer::getMemoryUsage();
#endif

size_t categoriesTotalSize = 0;
for (auto& category : data.categories)
categoriesTotalSize += category.totalSize();
Expand Down
36 changes: 34 additions & 2 deletions Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@

namespace Nicosia {

Lock Buffer::s_layersMemoryUsageLock;
double Buffer::s_currentLayersMemoryUsage = 0.0;
double Buffer::s_maxLayersMemoryUsage = 0.0;

void Buffer::resetMemoryUsage()
{
Locker locker { s_layersMemoryUsageLock };
s_maxLayersMemoryUsage = s_currentLayersMemoryUsage;
}

double Buffer::getMemoryUsage()
{
// The memory usage is max of memory usage since last resetMemoryUsage or getMemoryUsage.
Locker locker { s_layersMemoryUsageLock };
const auto memoryUsage = s_maxLayersMemoryUsage;
s_maxLayersMemoryUsage = s_currentLayersMemoryUsage;
return memoryUsage;
}

Ref<Buffer> Buffer::create(const WebCore::IntSize& size, Flags flags)
{
return adoptRef(*new Buffer(size, flags));
Expand All @@ -42,11 +61,24 @@ Buffer::Buffer(const WebCore::IntSize& size, Flags flags)
: m_size(size)
, m_flags(flags)
{
auto checkedArea = size.area() * 4;
const auto checkedArea = size.area() * 4;
m_data = MallocPtr<unsigned char>::tryZeroedMalloc(checkedArea);

{
Locker locker { s_layersMemoryUsageLock };
s_currentLayersMemoryUsage += checkedArea;
s_maxLayersMemoryUsage = std::max(s_maxLayersMemoryUsage, s_currentLayersMemoryUsage);
}
}

Buffer::~Buffer() = default;
Buffer::~Buffer()
{
const auto checkedArea = m_size.area().value() * 4;
{
Locker locker { s_layersMemoryUsageLock };
s_currentLayersMemoryUsage -= checkedArea;
}
}

void Buffer::beginPainting()
{
Expand Down
7 changes: 7 additions & 0 deletions Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class Buffer : public ThreadSafeRefCounted<Buffer> {
void completePainting();
void waitUntilPaintingComplete();

static void resetMemoryUsage();
static double getMemoryUsage();

private:
Buffer(const WebCore::IntSize&, Flags);

Expand All @@ -74,6 +77,10 @@ class Buffer : public ThreadSafeRefCounted<Buffer> {
Condition condition;
PaintingState state { PaintingState::Complete };
} m_painting;

static Lock s_layersMemoryUsageLock;
static double s_currentLayersMemoryUsage;
static double s_maxLayersMemoryUsage;
};

} // namespace Nicosia
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,11 @@ void CoordinatedGraphicsLayer::dumpAdditionalProperties(TextStream& textStream,
dumpInnerLayer(textStream, "backdrop layer"_s, m_backdropLayer.get(), options);
}

double CoordinatedGraphicsLayer::backingStoreMemoryEstimate() const
{
return 0.0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just return estimatedBackingStoreMemory.value_or(0) to avoid checking whether there value is defined

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pgorszkowski-igalia @magomez : is it normal to return 0 here for CoordinatedGraphicsLayer::backingStoreMemoryEstimate()?

It seems that intermediate steps of the PR returned estimatedBackingStoreMemory.
cc @hwti


} // namespace WebCore

SPECIALIZE_TYPE_TRAITS_ANIMATEDBACKINGSTORECLIENT(WebCore::CoordinatedAnimatedBackingStoreClient, type() == Nicosia::AnimatedBackingStoreClient::Type::Coordinated)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class WEBCORE_EXPORT CoordinatedGraphicsLayer : public GraphicsLayer {

void requestBackingStoreUpdate();

double backingStoreMemoryEstimate() const override;

private:
enum class FlushNotification {
Required,
Expand Down