/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* 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"SourceSurfaceSharedData.h"
#include"mozilla/Likely.h" #include"mozilla/StaticPrefs_image.h" #include"mozilla/Types.h"// for decltype #include"mozilla/layers/SharedSurfacesChild.h" #include"mozilla/layers/SharedSurfacesParent.h" #include"nsDebug.h"// for NS_ABORT_OOM
#include"base/process_util.h"
#ifdef DEBUG /** * If defined, this makes SourceSurfaceSharedData::Finalize memory protect the * underlying shared buffer in the producing process (the content or UI * process). Given flushing the page table is expensive, and its utility is * predominantly diagnostic (in case of overrun), turn it off by default.
*/ # define SHARED_SURFACE_PROTECT_FINALIZED #endif
size_t len = GetAlignedDataLength();
mBuf = MakeAndAddRef<SharedMemory>(); if (!mBuf->SetHandle(std::move(aHandle), ipc::SharedMemory::RightsReadOnly)) {
MOZ_CRASH("Invalid shared memory handle!");
}
bool mapped = EnsureMapped(len); if ((sizeof(uintptr_t) <= 4 ||
StaticPrefs::image_mem_shared_unmap_force_enabled_AtStartup()) &&
len / 1024 >
StaticPrefs::image_mem_shared_unmap_min_threshold_kb_AtStartup()) {
mHandleLock.emplace("SourceSurfaceSharedDataWrapper::mHandleLock");
if (mapped) { // Tracking at the initial mapping, and not just after the first use of // the surface means we might get unmapped again before the next frame // gets rendered if a low virtual memory condition persists.
SharedSurfacesParent::AddTracking(this);
}
} elseif (!mapped) { // We don't support unmapping for this surface, and we failed to map it.
NS_ABORT_OOM(len);
} else {
mBuf->CloseHandle();
}
}
// If we have an old buffer lingering, it is because we get reallocated to // get a new handle to share, but there were still active mappings. if (MOZ_UNLIKELY(mOldBuf)) {
MOZ_ASSERT(mMapCount > 0);
MOZ_ASSERT(mFinalized); returnstatic_cast<uint8_t*>(mOldBuf->Memory());
} returnstatic_cast<uint8_t*>(mBuf->Memory());
}
if (NS_WARN_IF(!mFinalized)) { // We haven't finished populating the surface data yet, which means we are // out of luck, as we have no means of synchronizing with the producer to // write new data to a new buffer. This should be fairly rare, caused by a // crash in the GPU process, while we were decoding an image. returnfalse;
}
size_t len = GetAlignedDataLength();
RefPtr<SharedMemory> buf = new SharedMemory(); if (NS_WARN_IF(!buf->Create(len)) || NS_WARN_IF(!buf->Map(len))) { returnfalse;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.