diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/canvas/WebGLChild.cpp | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/canvas/WebGLChild.cpp')
-rw-r--r-- | dom/canvas/WebGLChild.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/dom/canvas/WebGLChild.cpp b/dom/canvas/WebGLChild.cpp new file mode 100644 index 0000000000..f330ebabd3 --- /dev/null +++ b/dom/canvas/WebGLChild.cpp @@ -0,0 +1,109 @@ +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "WebGLChild.h" + +#include "ClientWebGLContext.h" +#include "mozilla/StaticPrefs_webgl.h" +#include "WebGLMethodDispatcher.h" + +namespace mozilla::dom { + +WebGLChild::WebGLChild(ClientWebGLContext& context) + : mContext(&context), + mDefaultCmdsShmemSize(StaticPrefs::webgl_out_of_process_shmem_size()) {} + +WebGLChild::~WebGLChild() { (void)Send__delete__(this); } + +void WebGLChild::ActorDestroy(ActorDestroyReason why) { + mPendingCmdsShmem = {}; +} + +// - + +Maybe<Range<uint8_t>> WebGLChild::AllocPendingCmdBytes( + const size_t size, const size_t fyiAlignmentOverhead) { + if (!mPendingCmdsShmem.Size()) { + size_t capacity = mDefaultCmdsShmemSize; + if (capacity < size) { + capacity = size; + } + + mPendingCmdsShmem = mozilla::ipc::BigBuffer::TryAlloc(capacity); + if (!mPendingCmdsShmem.Size()) { + NS_WARNING("Failed to alloc shmem for AllocPendingCmdBytes."); + return {}; + } + mPendingCmdsPos = 0; + mPendingCmdsAlignmentOverhead = 0; + + if (kIsDebug) { + const auto ptr = mPendingCmdsShmem.Data(); + const auto initialOffset = AlignmentOffset(kUniversalAlignment, ptr); + MOZ_ALWAYS_TRUE(!initialOffset); + } + } + + const auto range = Range<uint8_t>{mPendingCmdsShmem.AsSpan()}; + + auto itr = range.begin() + mPendingCmdsPos; + const auto offset = AlignmentOffset(kUniversalAlignment, itr.get()); + mPendingCmdsPos += offset; + mPendingCmdsAlignmentOverhead += offset; + const auto required = mPendingCmdsPos + size; + if (required > range.length()) { + FlushPendingCmds(); + return AllocPendingCmdBytes(size, fyiAlignmentOverhead); + } + itr = range.begin() + mPendingCmdsPos; + const auto remaining = Range<uint8_t>{itr, range.end()}; + mPendingCmdsPos += size; + mPendingCmdsAlignmentOverhead += fyiAlignmentOverhead; + return Some(Range<uint8_t>{remaining.begin(), remaining.begin() + size}); +} + +void WebGLChild::FlushPendingCmds() { + if (!mPendingCmdsShmem.Size()) return; + + const auto byteSize = mPendingCmdsPos; + SendDispatchCommands(std::move(mPendingCmdsShmem), byteSize); + mPendingCmdsShmem = {}; + + mFlushedCmdInfo.flushes += 1; + mFlushedCmdInfo.flushedCmdBytes += byteSize; + mFlushedCmdInfo.overhead += mPendingCmdsAlignmentOverhead; + + if (gl::GLContext::ShouldSpew()) { + const auto overheadRatio = float(mPendingCmdsAlignmentOverhead) / + (byteSize - mPendingCmdsAlignmentOverhead); + const auto totalOverheadRatio = + float(mFlushedCmdInfo.overhead) / + (mFlushedCmdInfo.flushedCmdBytes - mFlushedCmdInfo.overhead); + printf_stderr( + "[WebGLChild] Flushed %zu (%zu=%.2f%% overhead) bytes." + " (%zu (%.2f%% overhead) over %zu flushes)\n", + byteSize, mPendingCmdsAlignmentOverhead, 100 * overheadRatio, + mFlushedCmdInfo.flushedCmdBytes, 100 * totalOverheadRatio, + mFlushedCmdInfo.flushes); + } +} + +// - + +mozilla::ipc::IPCResult WebGLChild::RecvJsWarning( + const std::string& text) const { + if (!mContext) return IPC_OK(); + mContext->JsWarning(text); + return IPC_OK(); +} + +mozilla::ipc::IPCResult WebGLChild::RecvOnContextLoss( + const webgl::ContextLossReason reason) const { + if (!mContext) return IPC_OK(); + mContext->OnContextLoss(reason); + return IPC_OK(); +} + +} // namespace mozilla::dom |