Revert "Bug 1965093 - for causing multiple failures"

This reverts commit 09959678c3.
This commit is contained in:
iulian moraru
2025-05-10 04:21:47 +03:00
committed by imoraru@mozilla.com
parent a42b1cd269
commit c3aecbcc62
4 changed files with 40 additions and 83 deletions

View File

@@ -290,7 +290,7 @@ mozilla::ipc::IPCResult RemoteDecoderManagerParent::RecvReadback(
return IPC_OK();
}
// Read directly into the shmem to avoid extra copies, if possible.
// Let's try reading directly into the shmem first to avoid extra copies.
SurfaceDescriptorBuffer sdb;
nsresult rv = image->BuildSurfaceDescriptorBuffer(
sdb, Image::BuildSdbFlags::RgbOnly, [&](uint32_t aBufferSize) {
@@ -309,8 +309,44 @@ mozilla::ipc::IPCResult RemoteDecoderManagerParent::RecvReadback(
if (sdb.data().type() == MemoryOrShmem::TShmem) {
DeallocShmem(sdb.data().get_Shmem());
}
if (rv != NS_ERROR_NOT_IMPLEMENTED) {
*aResult = null_t();
return IPC_OK();
}
// Fallback to reading to a SourceSurface and copying that into a shmem.
RefPtr<SourceSurface> source = image->GetAsSourceSurface();
if (!source) {
*aResult = null_t();
return IPC_OK();
}
SurfaceFormat format = source->GetFormat();
IntSize size = source->GetSize();
size_t length = ImageDataSerializer::ComputeRGBBufferSize(size, format);
Shmem buffer;
if (!length || !AllocShmem(length, &buffer)) {
*aResult = null_t();
return IPC_OK();
}
RefPtr<DrawTarget> dt = Factory::CreateDrawTargetForData(
gfx::BackendType::CAIRO, buffer.get<uint8_t>(), size,
ImageDataSerializer::ComputeRGBStride(format, size.width), format);
if (!dt) {
DeallocShmem(buffer);
*aResult = null_t();
return IPC_OK();
}
dt->CopySurface(source, IntRect(0, 0, size.width, size.height), IntPoint());
dt->Flush();
*aResult = SurfaceDescriptorBuffer(RGBDescriptor(size, format),
MemoryOrShmem(std::move(buffer)));
return IPC_OK();
}
mozilla::ipc::IPCResult

View File

@@ -269,13 +269,7 @@ MediaResult RemoteVideoDecoderParent::ProcessDecodedData(
}
return MemoryOrShmem();
});
if (NS_WARN_IF(NS_FAILED(rv))) {
if (sdBuffer.data().type() == MemoryOrShmem::TShmem) {
DeallocShmem(sdBuffer.data().get_Shmem());
}
return rv;
}
NS_ENSURE_SUCCESS(rv, rv);
sd = sdBuffer;
size = image->GetSize();

View File

@@ -14,7 +14,6 @@
#include "gfx2DGlue.h"
#include "gfxPlatform.h" // for gfxPlatform
#include "gfxUtils.h" // for gfxUtils
#include "GPUVideoImage.h"
#include "libyuv.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/ProfilerLabels.h"
@@ -240,68 +239,7 @@ ImageContainer::~ImageContainer() {
nsresult Image::BuildSurfaceDescriptorBuffer(
SurfaceDescriptorBuffer& aSdBuffer, BuildSdbFlags aFlags,
const std::function<MemoryOrShmem(uint32_t)>& aAllocate) {
RefPtr<SourceSurface> surface = GetAsSourceSurface();
if (NS_WARN_IF(!surface)) {
return NS_ERROR_NOT_AVAILABLE;
}
RefPtr<DataSourceSurface> dataSurface = surface->GetDataSurface();
if (NS_WARN_IF(!dataSurface)) {
return NS_ERROR_FAILURE;
}
DataSourceSurface::ScopedMap map(dataSurface, DataSourceSurface::READ);
if (NS_WARN_IF(!map.IsMapped())) {
return NS_ERROR_FAILURE;
}
SurfaceFormat format = dataSurface->GetFormat();
IntSize size = dataSurface->GetSize();
uint8_t* output = nullptr;
int32_t stride = 0;
nsresult rv = AllocateSurfaceDescriptorBufferRgb(
size, format, output, aSdBuffer, stride, aAllocate);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (NS_WARN_IF(!SwizzleData(map.GetData(), map.GetStride(), format, output,
stride, format, size))) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
nsresult Image::BuildSurfaceDescriptorGPUVideoOrBuffer(
SurfaceDescriptor& aSd, BuildSdbFlags aFlags,
const Maybe<VideoBridgeSource>& aDest,
const std::function<MemoryOrShmem(uint32_t)>& aAllocate,
const std::function<void(MemoryOrShmem&&)>& aFree) {
if (auto* gpuImage = AsGPUVideoImage()) {
if (auto maybeSd = gpuImage->GetDesc()) {
if (!aDest ||
(maybeSd->type() == SurfaceDescriptor::TSurfaceDescriptorGPUVideo &&
maybeSd->get_SurfaceDescriptorGPUVideo()
.get_SurfaceDescriptorRemoteDecoder()
.source() == aDest)) {
aSd = std::move(*maybeSd);
return NS_OK;
}
}
}
SurfaceDescriptorBuffer sdb;
nsresult rv = BuildSurfaceDescriptorBuffer(sdb, aFlags, aAllocate);
if (NS_FAILED(rv)) {
if (sdb.data().type() != MemoryOrShmem::Type::T__None) {
aFree(std::move(sdb.data()));
}
return rv;
}
aSd = std::move(sdb);
return NS_OK;
return NS_ERROR_NOT_IMPLEMENTED;
}
Maybe<SurfaceDescriptor> Image::GetDesc() { return GetDescFromTexClient(); }

View File

@@ -69,7 +69,6 @@ class D3D11YCbCrRecycleAllocator;
class MacIOSurfaceRecycleAllocator;
#endif
class SurfaceDescriptorBuffer;
enum class VideoBridgeSource : uint8_t;
struct ImageBackendData {
virtual ~ImageBackendData() = default;
@@ -146,16 +145,6 @@ class Image {
SurfaceDescriptorBuffer& aSdBuffer, BuildSdbFlags aFlags,
const std::function<MemoryOrShmem(uint32_t)>& aAllocate);
/**
* Get a SurfaceDescriptorGPUVideo if possible, with the source matching aDest
* if given. Otherwise copy the data into a SurfaceDescriptorBuffer.
*/
nsresult BuildSurfaceDescriptorGPUVideoOrBuffer(
SurfaceDescriptor& aSd, BuildSdbFlags aFlags,
const Maybe<VideoBridgeSource>& aDest,
const std::function<MemoryOrShmem(uint32_t)>& aAllocate,
const std::function<void(MemoryOrShmem&&)>& aFree);
virtual bool IsValid() const { return true; }
/**