From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- gfx/gl/SharedSurfaceIO.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 gfx/gl/SharedSurfaceIO.cpp (limited to 'gfx/gl/SharedSurfaceIO.cpp') diff --git a/gfx/gl/SharedSurfaceIO.cpp b/gfx/gl/SharedSurfaceIO.cpp new file mode 100644 index 0000000000..1fd0f22d31 --- /dev/null +++ b/gfx/gl/SharedSurfaceIO.cpp @@ -0,0 +1,103 @@ +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 4; -*- */ +/* 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 "SharedSurfaceIO.h" + +#include "GLContextCGL.h" +#include "MozFramebuffer.h" +#include "mozilla/DebugOnly.h" +#include "mozilla/gfx/MacIOSurface.h" +#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor, etc +#include "mozilla/layers/LayersTypes.h" +#include "ScopedGLHelpers.h" + +namespace mozilla { +namespace gl { + +// - +// Factory + +SurfaceFactory_IOSurface::SurfaceFactory_IOSurface(GLContext& gl) + : SurfaceFactory({&gl, SharedSurfaceType::IOSurface, + layers::TextureType::MacIOSurface, true}), + mMaxDims(gfx::IntSize::Truncate(MacIOSurface::GetMaxWidth(), + MacIOSurface::GetMaxHeight())) {} + +// - +// Surface + +static void BackTextureWithIOSurf(GLContext* const gl, const GLuint tex, + MacIOSurface* const ioSurf) { + MOZ_ASSERT(gl->IsCurrent()); + + ScopedBindTexture texture(gl, tex, LOCAL_GL_TEXTURE_RECTANGLE_ARB); + + gl->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, + LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR); + gl->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, + LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR); + gl->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_S, + LOCAL_GL_CLAMP_TO_EDGE); + gl->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_T, + LOCAL_GL_CLAMP_TO_EDGE); + + CGLContextObj cgl = GLContextCGL::Cast(gl)->GetCGLContext(); + MOZ_ASSERT(cgl); + + ioSurf->CGLTexImageIOSurface2D(gl, cgl, 0); +} + +/*static*/ +UniquePtr SharedSurface_IOSurface::Create( + const SharedSurfaceDesc& desc) { + const auto& size = desc.size; + const RefPtr ioSurf = + MacIOSurface::CreateIOSurface(size.width, size.height, true); + if (!ioSurf) { + NS_WARNING("Failed to create MacIOSurface."); + return nullptr; + } + + ioSurf->SetColorSpace(desc.colorSpace); + + // - + + auto tex = MakeUnique(*desc.gl); + BackTextureWithIOSurf(desc.gl, tex->name, ioSurf); + + const GLenum target = LOCAL_GL_TEXTURE_RECTANGLE; + auto fb = MozFramebuffer::CreateForBacking(desc.gl, desc.size, 0, false, + target, tex->name); + if (!fb) return nullptr; + + return AsUnique( + new SharedSurface_IOSurface(desc, std::move(fb), std::move(tex), ioSurf)); +} + +SharedSurface_IOSurface::SharedSurface_IOSurface( + const SharedSurfaceDesc& desc, UniquePtr fb, + UniquePtr tex, const RefPtr& ioSurf) + : SharedSurface(desc, std::move(fb)), + mTex(std::move(tex)), + mIOSurf(ioSurf) {} + +SharedSurface_IOSurface::~SharedSurface_IOSurface() = default; + +void SharedSurface_IOSurface::ProducerReleaseImpl() { + const auto& gl = mDesc.gl; + if (!gl) return; + gl->MakeCurrent(); + gl->fFlush(); +} + +Maybe +SharedSurface_IOSurface::ToSurfaceDescriptor() { + const bool isOpaque = false; // RGBA + return Some(layers::SurfaceDescriptorMacIOSurface( + mIOSurf->GetIOSurfaceID(), isOpaque, mIOSurf->GetYUVColorSpace())); +} + +} // namespace gl +} // namespace mozilla -- cgit v1.2.3