From e7afee4bf1f6e70ceea174bcd49b074b9feeb112 Mon Sep 17 00:00:00 2001 From: Brad Werth Date: Wed, 7 Sep 2022 18:51:12 +0000 Subject: [PATCH] Bug 1781122 Part 3: Make macOS video layers prevent capture when TextureHost is DRM. r=mstange Differential Revision: https://phabricator.services.mozilla.com/D155297 --- gfx/layers/NativeLayerCA.h | 4 +++- gfx/layers/NativeLayerCA.mm | 31 +++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/gfx/layers/NativeLayerCA.h b/gfx/layers/NativeLayerCA.h index 1ab21b675e83..a43b8ccdda5d 100644 --- a/gfx/layers/NativeLayerCA.h +++ b/gfx/layers/NativeLayerCA.h @@ -362,7 +362,7 @@ class NativeLayerCA : public NativeLayer { gfx::SamplingFilter aSamplingFilter, bool aSpecializeVideo, CFTypeRefPtr aFrontSurface, - CFTypeRefPtr aColor); + CFTypeRefPtr aColor, bool aIsDRM); // Return whether any aspects of this layer representation have been mutated // since the last call to ApplyChanges, i.e. whether ApplyChanges needs to @@ -390,6 +390,7 @@ class NativeLayerCA : public NativeLayer { bool mMutatedFrontSurface : 1; bool mMutatedSamplingFilter : 1; bool mMutatedSpecializeVideo : 1; + bool mMutatedIsDRM : 1; }; Representation& GetRepresentation(WhichRepresentation aRepresentation); @@ -466,6 +467,7 @@ class NativeLayerCA : public NativeLayer { bool mRootWindowIsFullscreen = false; bool mSpecializeVideo = false; bool mHasExtent = false; + bool mIsDRM = false; }; } // namespace layers diff --git a/gfx/layers/NativeLayerCA.mm b/gfx/layers/NativeLayerCA.mm index 14b2cac4ef40..125f71e8ffd9 100644 --- a/gfx/layers/NativeLayerCA.mm +++ b/gfx/layers/NativeLayerCA.mm @@ -823,11 +823,16 @@ void NativeLayerCA::AttachExternalImage(wr::RenderTextureHost* aExternalImage) { mSpecializeVideo = ShouldSpecializeVideo(lock); bool changedSpecializeVideo = (mSpecializeVideo != oldSpecializeVideo); + bool oldIsDRM = mIsDRM; + mIsDRM = aExternalImage->IsFromDRMSource(); + bool changedIsDRM = (mIsDRM != oldIsDRM); + ForAllRepresentations([&](Representation& r) { r.mMutatedFrontSurface = true; r.mMutatedDisplayRect |= changedSizeAndDisplayRect; r.mMutatedSize |= changedSizeAndDisplayRect; r.mMutatedSpecializeVideo |= changedSpecializeVideo; + r.mMutatedIsDRM |= changedIsDRM; }); } @@ -852,12 +857,14 @@ bool NativeLayerCA::ShouldSpecializeVideo(const MutexAutoLock& aProofOfLock) { return false; } - // Beyond this point, we need to know about the format of the video. - MOZ_ASSERT(mTextureHost); - if (!mTextureHost) { - return false; + + // DRM video must use a specialized video layer. + if (mTextureHost->IsFromDRMSource()) { + return true; } + + // Beyond this point, we need to know about the format of the video. MacIOSurface* macIOSurface = mTextureHost->GetSurface(); if (macIOSurface->GetYUVColorSpace() == gfx::YUVColorSpace::BT2020) { // BT2020 is a signifier of HDR color space, whether or not the bit depth @@ -1120,7 +1127,8 @@ NativeLayerCA::Representation::Representation() mMutatedSurfaceIsFlipped(true), mMutatedFrontSurface(true), mMutatedSamplingFilter(true), - mMutatedSpecializeVideo(true) {} + mMutatedSpecializeVideo(true), + mMutatedIsDRM(true) {} NativeLayerCA::Representation::~Representation() { [mContentCALayer release]; @@ -1334,7 +1342,7 @@ bool NativeLayerCA::ApplyChanges(WhichRepresentation aRepresentation, return GetRepresentation(aRepresentation) .ApplyChanges(aUpdate, mSize, mIsOpaque, mPosition, mTransform, mDisplayRect, mClipRect, mBackingScale, mSurfaceIsFlipped, mSamplingFilter, mSpecializeVideo, surface, - mColor); + mColor, mIsDRM); } CALayer* NativeLayerCA::UnderlyingCALayer(WhichRepresentation aRepresentation) { @@ -1512,7 +1520,7 @@ bool NativeLayerCA::Representation::ApplyChanges( const IntPoint& aPosition, const Matrix4x4& aTransform, const IntRect& aDisplayRect, const Maybe& aClipRect, float aBackingScale, bool aSurfaceIsFlipped, gfx::SamplingFilter aSamplingFilter, bool aSpecializeVideo, - CFTypeRefPtr aFrontSurface, CFTypeRefPtr aColor) { + CFTypeRefPtr aFrontSurface, CFTypeRefPtr aColor, bool aIsDRM) { // If we have an OnlyVideo update, handle it and early exit. if (aUpdate == UpdateType::OnlyVideo) { // If we don't have any updates to do, exit early with success. This is @@ -1602,6 +1610,12 @@ bool NativeLayerCA::Representation::ApplyChanges( } } + if (@available(macOS 10.15, iOS 13.0, *)) { + if (aSpecializeVideo && mMutatedIsDRM) { + ((AVSampleBufferDisplayLayer*)mContentCALayer).preventsCapture = aIsDRM; + } + } + bool shouldTintOpaqueness = StaticPrefs::gfx_core_animation_tint_opaque(); if (shouldTintOpaqueness && !mOpaquenessTintLayer) { mOpaquenessTintLayer = [[CALayer layer] retain]; @@ -1748,6 +1762,7 @@ bool NativeLayerCA::Representation::ApplyChanges( mMutatedFrontSurface = false; mMutatedSamplingFilter = false; mMutatedSpecializeVideo = false; + mMutatedIsDRM = false; return true; } @@ -1761,7 +1776,7 @@ NativeLayerCA::UpdateType NativeLayerCA::Representation::HasUpdate(bool aIsVideo // if we can attempt an OnlyVideo update. if (mMutatedPosition || mMutatedTransform || mMutatedDisplayRect || mMutatedClipRect || mMutatedBackingScale || mMutatedSize || mMutatedSurfaceIsFlipped || mMutatedSamplingFilter || - mMutatedSpecializeVideo) { + mMutatedSpecializeVideo || mMutatedIsDRM) { return UpdateType::All; }