diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /gfx/2d/Factory.cpp | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-upstream/125.0.1.tar.xz firefox-upstream/125.0.1.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/2d/Factory.cpp')
-rw-r--r-- | gfx/2d/Factory.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/gfx/2d/Factory.cpp b/gfx/2d/Factory.cpp index abf7a8669b..1bdf597142 100644 --- a/gfx/2d/Factory.cpp +++ b/gfx/2d/Factory.cpp @@ -1106,6 +1106,40 @@ already_AddRefed<DataSourceSurface> Factory::CreateDataSourceSurfaceWithStride( return nullptr; } +already_AddRefed<DataSourceSurface> Factory::CopyDataSourceSurface( + DataSourceSurface* aSource) { + // Don't worry too much about speed. + MOZ_ASSERT(aSource->GetFormat() == SurfaceFormat::R8G8B8A8 || + aSource->GetFormat() == SurfaceFormat::R8G8B8X8 || + aSource->GetFormat() == SurfaceFormat::B8G8R8A8 || + aSource->GetFormat() == SurfaceFormat::B8G8R8X8); + + DataSourceSurface::ScopedMap srcMap(aSource, DataSourceSurface::READ); + if (NS_WARN_IF(!srcMap.IsMapped())) { + MOZ_ASSERT_UNREACHABLE("CopyDataSourceSurface: Failed to map surface."); + return nullptr; + } + + IntSize size = aSource->GetSize(); + SurfaceFormat format = aSource->GetFormat(); + + RefPtr<DataSourceSurface> dst = CreateDataSourceSurfaceWithStride( + size, format, srcMap.GetStride(), /* aZero */ false); + if (NS_WARN_IF(!dst)) { + return nullptr; + } + + DataSourceSurface::ScopedMap dstMap(dst, DataSourceSurface::WRITE); + if (NS_WARN_IF(!dstMap.IsMapped())) { + MOZ_ASSERT_UNREACHABLE("CopyDataSourceSurface: Failed to map surface."); + return nullptr; + } + + SwizzleData(srcMap.GetData(), srcMap.GetStride(), format, dstMap.GetData(), + dstMap.GetStride(), format, size); + return dst.forget(); +} + void Factory::CopyDataSourceSurface(DataSourceSurface* aSource, DataSourceSurface* aDest) { // Don't worry too much about speed. |