2017-10-28 02:10:06 +03:00
|
|
|
/* -*- 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
|
2013-11-18 06:04:38 +04:00
|
|
|
* 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 "MacIOSurfaceTextureHostOGL.h"
|
2020-08-13 00:25:17 +03:00
|
|
|
#include "mozilla/gfx/gfxVars.h"
|
2013-11-18 06:04:38 +04:00
|
|
|
#include "mozilla/gfx/MacIOSurface.h"
|
2020-10-14 10:58:18 +03:00
|
|
|
#include "mozilla/webrender/RenderMacIOSurfaceTextureHost.h"
|
2017-06-15 12:07:46 +03:00
|
|
|
#include "mozilla/webrender/RenderThread.h"
|
2017-05-18 17:59:07 +03:00
|
|
|
#include "mozilla/webrender/WebRenderAPI.h"
|
2014-01-08 00:02:18 +04:00
|
|
|
#include "GLContextCGL.h"
|
2013-11-18 06:04:38 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2013-12-12 05:44:47 +04:00
|
|
|
MacIOSurfaceTextureHostOGL::MacIOSurfaceTextureHostOGL(
|
2013-11-18 06:04:38 +04:00
|
|
|
TextureFlags aFlags, const SurfaceDescriptorMacIOSurface& aDescriptor)
|
2022-08-16 03:29:51 +03:00
|
|
|
: TextureHost(TextureHostType::MacIOSurface, aFlags) {
|
2015-07-29 18:57:03 +03:00
|
|
|
MOZ_COUNT_CTOR(MacIOSurfaceTextureHostOGL);
|
2021-04-08 19:42:06 +03:00
|
|
|
mSurface = MacIOSurface::LookupSurface(aDescriptor.surfaceId(),
|
|
|
|
!aDescriptor.isOpaque(),
|
|
|
|
aDescriptor.yUVColorSpace());
|
2021-02-23 01:41:51 +03:00
|
|
|
if (!mSurface) {
|
|
|
|
gfxCriticalNote << "Failed to look up MacIOSurface";
|
|
|
|
}
|
2013-11-18 06:04:38 +04:00
|
|
|
}
|
|
|
|
|
2015-07-29 18:57:03 +03:00
|
|
|
MacIOSurfaceTextureHostOGL::~MacIOSurfaceTextureHostOGL() {
|
|
|
|
MOZ_COUNT_DTOR(MacIOSurfaceTextureHostOGL);
|
|
|
|
}
|
|
|
|
|
2014-02-18 00:36:57 +04:00
|
|
|
gfx::SurfaceFormat MacIOSurfaceTextureHostOGL::GetFormat() const {
|
2018-02-07 17:33:12 +03:00
|
|
|
if (!mSurface) {
|
|
|
|
return gfx::SurfaceFormat::UNKNOWN;
|
|
|
|
}
|
2015-08-04 00:57:26 +03:00
|
|
|
return mSurface->GetFormat();
|
2014-02-18 00:36:57 +04:00
|
|
|
}
|
|
|
|
|
2016-02-23 05:26:27 +03:00
|
|
|
gfx::SurfaceFormat MacIOSurfaceTextureHostOGL::GetReadFormat() const {
|
2018-02-07 17:33:12 +03:00
|
|
|
if (!mSurface) {
|
|
|
|
return gfx::SurfaceFormat::UNKNOWN;
|
|
|
|
}
|
2016-02-23 05:26:27 +03:00
|
|
|
return mSurface->GetReadFormat();
|
|
|
|
}
|
|
|
|
|
2014-02-18 00:36:57 +04:00
|
|
|
gfx::IntSize MacIOSurfaceTextureHostOGL::GetSize() const {
|
|
|
|
if (!mSurface) {
|
|
|
|
return gfx::IntSize();
|
|
|
|
}
|
|
|
|
return gfx::IntSize(mSurface->GetDevicePixelWidth(),
|
|
|
|
mSurface->GetDevicePixelHeight());
|
|
|
|
}
|
|
|
|
|
2021-11-22 12:49:59 +03:00
|
|
|
gl::GLContext* MacIOSurfaceTextureHostOGL::gl() const { return nullptr; }
|
2016-03-22 17:28:27 +03:00
|
|
|
|
2019-04-11 15:36:31 +03:00
|
|
|
gfx::YUVColorSpace MacIOSurfaceTextureHostOGL::GetYUVColorSpace() const {
|
|
|
|
if (!mSurface) {
|
2021-03-19 03:58:23 +03:00
|
|
|
return gfx::YUVColorSpace::Identity;
|
2019-04-11 15:36:31 +03:00
|
|
|
}
|
|
|
|
return mSurface->GetYUVColorSpace();
|
|
|
|
}
|
|
|
|
|
2019-07-26 11:45:31 +03:00
|
|
|
gfx::ColorRange MacIOSurfaceTextureHostOGL::GetColorRange() const {
|
|
|
|
if (!mSurface) {
|
|
|
|
return gfx::ColorRange::LIMITED;
|
|
|
|
}
|
|
|
|
return mSurface->IsFullRange() ? gfx::ColorRange::FULL
|
|
|
|
: gfx::ColorRange::LIMITED;
|
|
|
|
}
|
|
|
|
|
2017-06-15 12:07:46 +03:00
|
|
|
void MacIOSurfaceTextureHostOGL::CreateRenderTexture(
|
|
|
|
const wr::ExternalImageId& aExternalImageId) {
|
2020-10-14 10:58:45 +03:00
|
|
|
RefPtr<wr::RenderTextureHost> texture =
|
|
|
|
new wr::RenderMacIOSurfaceTextureHost(GetMacIOSurface());
|
2017-06-15 12:07:46 +03:00
|
|
|
|
2022-09-07 21:51:12 +03:00
|
|
|
bool isDRM = (bool)(mFlags & TextureFlags::DRM_SOURCE);
|
|
|
|
texture->SetIsFromDRMSource(isDRM);
|
|
|
|
|
2021-11-07 10:26:45 +03:00
|
|
|
wr::RenderThread::Get()->RegisterExternalImage(aExternalImageId,
|
2017-06-15 12:07:46 +03:00
|
|
|
texture.forget());
|
|
|
|
}
|
|
|
|
|
2019-07-24 16:33:57 +03:00
|
|
|
uint32_t MacIOSurfaceTextureHostOGL::NumSubTextures() {
|
2021-02-23 01:41:51 +03:00
|
|
|
if (!mSurface) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-07 18:44:04 +03:00
|
|
|
switch (GetFormat()) {
|
|
|
|
case gfx::SurfaceFormat::R8G8B8X8:
|
|
|
|
case gfx::SurfaceFormat::R8G8B8A8:
|
|
|
|
case gfx::SurfaceFormat::B8G8R8A8:
|
2017-09-26 16:30:46 +03:00
|
|
|
case gfx::SurfaceFormat::B8G8R8X8:
|
2017-06-07 18:44:04 +03:00
|
|
|
case gfx::SurfaceFormat::YUV422: {
|
2017-09-26 16:30:46 +03:00
|
|
|
return 1;
|
2017-06-07 18:44:04 +03:00
|
|
|
}
|
2022-03-05 20:31:18 +03:00
|
|
|
case gfx::SurfaceFormat::NV12:
|
|
|
|
case gfx::SurfaceFormat::P010: {
|
2017-09-26 16:30:46 +03:00
|
|
|
return 2;
|
2017-06-07 18:44:04 +03:00
|
|
|
}
|
|
|
|
default: {
|
2017-09-26 16:30:46 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected format");
|
|
|
|
return 1;
|
2017-06-07 18:44:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 16:33:39 +03:00
|
|
|
void MacIOSurfaceTextureHostOGL::PushResourceUpdates(
|
|
|
|
wr::TransactionBuilder& aResources, ResourceUpdateOp aOp,
|
2020-03-10 06:52:08 +03:00
|
|
|
const Range<wr::ImageKey>& aImageKeys, const wr::ExternalImageId& aExtID) {
|
2017-05-18 17:59:07 +03:00
|
|
|
MOZ_ASSERT(mSurface);
|
|
|
|
|
2018-01-29 16:33:39 +03:00
|
|
|
auto method = aOp == TextureHost::ADD_IMAGE
|
|
|
|
? &wr::TransactionBuilder::AddExternalImage
|
|
|
|
: &wr::TransactionBuilder::UpdateExternalImage;
|
2019-05-29 01:03:54 +03:00
|
|
|
auto imageType =
|
2020-11-13 01:25:59 +03:00
|
|
|
wr::ExternalImageType::TextureHandle(wr::ImageBufferKind::TextureRect);
|
2017-09-26 16:30:51 +03:00
|
|
|
|
2017-05-18 17:59:07 +03:00
|
|
|
switch (GetFormat()) {
|
2020-10-20 01:27:23 +03:00
|
|
|
case gfx::SurfaceFormat::B8G8R8A8:
|
|
|
|
case gfx::SurfaceFormat::B8G8R8X8: {
|
2017-05-18 19:25:41 +03:00
|
|
|
MOZ_ASSERT(aImageKeys.length() == 1);
|
2017-05-18 17:59:07 +03:00
|
|
|
MOZ_ASSERT(mSurface->GetPlaneCount() == 0);
|
2018-01-09 09:12:02 +03:00
|
|
|
// The internal pixel format of MacIOSurface is always BGRX or BGRA
|
|
|
|
// format.
|
2020-10-20 01:27:23 +03:00
|
|
|
auto format = GetFormat() == gfx::SurfaceFormat::B8G8R8A8
|
2018-01-09 09:12:02 +03:00
|
|
|
? gfx::SurfaceFormat::B8G8R8A8
|
|
|
|
: gfx::SurfaceFormat::B8G8R8X8;
|
2020-03-10 06:52:08 +03:00
|
|
|
wr::ImageDescriptor descriptor(GetSize(), format);
|
2019-05-29 01:03:54 +03:00
|
|
|
(aResources.*method)(aImageKeys[0], descriptor, aExtID, imageType, 0);
|
2017-05-18 17:59:07 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case gfx::SurfaceFormat::YUV422: {
|
|
|
|
// This is the special buffer format. The buffer contents could be a
|
|
|
|
// converted RGB interleaving data or a YCbCr interleaving data depending
|
|
|
|
// on the different platform setting. (e.g. It will be RGB at OpenGL 2.1
|
|
|
|
// and YCbCr at OpenGL 3.1)
|
2017-05-18 19:25:41 +03:00
|
|
|
MOZ_ASSERT(aImageKeys.length() == 1);
|
2017-05-18 17:59:07 +03:00
|
|
|
MOZ_ASSERT(mSurface->GetPlaneCount() == 0);
|
2020-03-10 06:52:08 +03:00
|
|
|
wr::ImageDescriptor descriptor(GetSize(), gfx::SurfaceFormat::B8G8R8X8);
|
2019-05-29 01:03:54 +03:00
|
|
|
(aResources.*method)(aImageKeys[0], descriptor, aExtID, imageType, 0);
|
2017-05-18 17:59:07 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case gfx::SurfaceFormat::NV12: {
|
2017-05-18 19:25:41 +03:00
|
|
|
MOZ_ASSERT(aImageKeys.length() == 2);
|
2017-05-18 17:59:07 +03:00
|
|
|
MOZ_ASSERT(mSurface->GetPlaneCount() == 2);
|
|
|
|
wr::ImageDescriptor descriptor0(
|
|
|
|
gfx::IntSize(mSurface->GetDevicePixelWidth(0),
|
|
|
|
mSurface->GetDevicePixelHeight(0)),
|
2020-03-10 06:52:08 +03:00
|
|
|
gfx::SurfaceFormat::A8);
|
2017-05-18 17:59:07 +03:00
|
|
|
wr::ImageDescriptor descriptor1(
|
|
|
|
gfx::IntSize(mSurface->GetDevicePixelWidth(1),
|
|
|
|
mSurface->GetDevicePixelHeight(1)),
|
2020-03-10 06:52:08 +03:00
|
|
|
gfx::SurfaceFormat::R8G8);
|
2019-05-29 01:03:54 +03:00
|
|
|
(aResources.*method)(aImageKeys[0], descriptor0, aExtID, imageType, 0);
|
|
|
|
(aResources.*method)(aImageKeys[1], descriptor1, aExtID, imageType, 1);
|
2017-05-18 17:59:07 +03:00
|
|
|
break;
|
|
|
|
}
|
2022-03-05 20:31:18 +03:00
|
|
|
case gfx::SurfaceFormat::P010: {
|
|
|
|
MOZ_ASSERT(aImageKeys.length() == 2);
|
|
|
|
MOZ_ASSERT(mSurface->GetPlaneCount() == 2);
|
|
|
|
wr::ImageDescriptor descriptor0(
|
|
|
|
gfx::IntSize(mSurface->GetDevicePixelWidth(0),
|
|
|
|
mSurface->GetDevicePixelHeight(0)),
|
|
|
|
gfx::SurfaceFormat::A16);
|
|
|
|
wr::ImageDescriptor descriptor1(
|
|
|
|
gfx::IntSize(mSurface->GetDevicePixelWidth(1),
|
|
|
|
mSurface->GetDevicePixelHeight(1)),
|
|
|
|
gfx::SurfaceFormat::R16G16);
|
|
|
|
(aResources.*method)(aImageKeys[0], descriptor0, aExtID, imageType, 0);
|
|
|
|
(aResources.*method)(aImageKeys[1], descriptor1, aExtID, imageType, 1);
|
|
|
|
break;
|
|
|
|
}
|
2017-05-18 17:59:07 +03:00
|
|
|
default: {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
|
|
|
}
|
|
|
|
}
|
2017-05-18 17:59:07 +03:00
|
|
|
}
|
|
|
|
|
2017-09-26 16:31:00 +03:00
|
|
|
void MacIOSurfaceTextureHostOGL::PushDisplayItems(
|
|
|
|
wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds,
|
|
|
|
const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
|
2020-10-14 10:56:47 +03:00
|
|
|
const Range<wr::ImageKey>& aImageKeys, PushDisplayItemFlagSet aFlags) {
|
|
|
|
bool preferCompositorSurface =
|
|
|
|
aFlags.contains(PushDisplayItemFlag::PREFER_COMPOSITOR_SURFACE);
|
2017-06-07 18:44:04 +03:00
|
|
|
switch (GetFormat()) {
|
|
|
|
case gfx::SurfaceFormat::B8G8R8A8:
|
|
|
|
case gfx::SurfaceFormat::B8G8R8X8: {
|
|
|
|
MOZ_ASSERT(aImageKeys.length() == 1);
|
|
|
|
MOZ_ASSERT(mSurface->GetPlaneCount() == 0);
|
2020-10-16 01:39:30 +03:00
|
|
|
// We disable external compositing for RGB surfaces for now until
|
|
|
|
// we've tested support more thoroughly. Bug 1667917.
|
2022-02-23 16:37:39 +03:00
|
|
|
aBuilder.PushImage(aBounds, aClip, true, false, aFilter, aImageKeys[0],
|
2020-03-10 06:52:08 +03:00
|
|
|
!(mFlags & TextureFlags::NON_PREMULTIPLIED),
|
|
|
|
wr::ColorF{1.0f, 1.0f, 1.0f, 1.0f},
|
2020-10-14 10:56:47 +03:00
|
|
|
preferCompositorSurface,
|
2022-05-03 02:54:09 +03:00
|
|
|
/* aSupportsExternalCompositing */ true);
|
2017-06-07 18:44:04 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case gfx::SurfaceFormat::YUV422: {
|
|
|
|
MOZ_ASSERT(aImageKeys.length() == 1);
|
|
|
|
MOZ_ASSERT(mSurface->GetPlaneCount() == 0);
|
2018-09-26 17:58:25 +03:00
|
|
|
// Those images can only be generated at present by the Apple H264 decoder
|
|
|
|
// which only supports 8 bits color depth.
|
2017-06-07 18:44:04 +03:00
|
|
|
aBuilder.PushYCbCrInterleavedImage(
|
2018-09-26 17:58:25 +03:00
|
|
|
aBounds, aClip, true, aImageKeys[0], wr::ColorDepth::Color8,
|
2019-07-26 11:45:31 +03:00
|
|
|
wr::ToWrYuvColorSpace(GetYUVColorSpace()),
|
2020-10-14 10:56:47 +03:00
|
|
|
wr::ToWrColorRange(GetColorRange()), aFilter, preferCompositorSurface,
|
|
|
|
/* aSupportsExternalCompositing */ true);
|
2017-06-07 18:44:04 +03:00
|
|
|
break;
|
|
|
|
}
|
2022-03-05 20:31:19 +03:00
|
|
|
case gfx::SurfaceFormat::NV12: {
|
2017-06-07 18:44:04 +03:00
|
|
|
MOZ_ASSERT(aImageKeys.length() == 2);
|
|
|
|
MOZ_ASSERT(mSurface->GetPlaneCount() == 2);
|
2020-08-04 04:19:59 +03:00
|
|
|
aBuilder.PushNV12Image(
|
|
|
|
aBounds, aClip, true, aImageKeys[0], aImageKeys[1],
|
2022-03-05 20:31:19 +03:00
|
|
|
wr::ColorDepth::Color8, wr::ToWrYuvColorSpace(GetYUVColorSpace()),
|
|
|
|
wr::ToWrColorRange(GetColorRange()), aFilter, preferCompositorSurface,
|
|
|
|
/* aSupportsExternalCompositing */ true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case gfx::SurfaceFormat::P010: {
|
|
|
|
MOZ_ASSERT(aImageKeys.length() == 2);
|
|
|
|
MOZ_ASSERT(mSurface->GetPlaneCount() == 2);
|
|
|
|
aBuilder.PushP010Image(
|
|
|
|
aBounds, aClip, true, aImageKeys[0], aImageKeys[1],
|
|
|
|
wr::ColorDepth::Color10, wr::ToWrYuvColorSpace(GetYUVColorSpace()),
|
2020-10-14 10:56:47 +03:00
|
|
|
wr::ToWrColorRange(GetColorRange()), aFilter, preferCompositorSurface,
|
|
|
|
/* aSupportsExternalCompositing */ true);
|
2017-06-07 18:44:04 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|