NativeLayerRemoteMac.h (4044B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef mozilla_layers_NativeLayerRemoteMac_h 7 #define mozilla_layers_NativeLayerRemoteMac_h 8 9 #include <IOSurface/IOSurfaceRef.h> 10 11 #include "mozilla/layers/NativeLayer.h" 12 #include "mozilla/layers/NativeLayerCommandQueue.h" 13 #include "mozilla/layers/NativeLayerMacSurfaceHandler.h" 14 #include "NativeLayerCA.h" 15 #include "nsRegion.h" 16 17 namespace mozilla { 18 namespace layers { 19 20 class SurfacePoolHandleCA; 21 22 // NativeLayerRemoteMac is a macOS-specific NativeLayer offered up by 23 // NativeLayerRemoteMacChild, which can be rendered into and then sent to 24 // the NativeLayerRemoteMacParent. 25 class NativeLayerRemoteMac final : public NativeLayer { 26 friend class NativeLayerRootRemoteMacChild; 27 28 public: 29 // Overridden methods 30 NativeLayerRemoteMac* AsNativeLayerRemoteMac() override { return this; } 31 32 gfx::IntSize GetSize() override; 33 void SetPosition(const gfx::IntPoint& aPosition) override; 34 gfx::IntPoint GetPosition() override; 35 void SetTransform(const gfx::Matrix4x4& aTransform) override; 36 gfx::Matrix4x4 GetTransform() override; 37 gfx::IntRect GetRect() override; 38 void SetSamplingFilter(gfx::SamplingFilter aSamplingFilter) override; 39 gfx::SamplingFilter SamplingFilter() override; 40 RefPtr<gfx::DrawTarget> NextSurfaceAsDrawTarget( 41 const gfx::IntRect& aDisplayRect, const gfx::IntRegion& aUpdateRegion, 42 gfx::BackendType aBackendType) override; 43 Maybe<GLuint> NextSurfaceAsFramebuffer(const gfx::IntRect& aDisplayRect, 44 const gfx::IntRegion& aUpdateRegion, 45 bool aNeedsDepth) override; 46 47 void NotifySurfaceReady() override; 48 void DiscardBackbuffers() override; 49 50 bool IsOpaque() override; 51 bool IsDRM() { return mIsDRM; } 52 bool IsHDR() { return mIsHDR; } 53 void SetClipRect(const Maybe<gfx::IntRect>& aClipRect) override; 54 Maybe<gfx::IntRect> ClipRect() override; 55 void SetRoundedClipRect( 56 const Maybe<gfx::RoundedRect>& aRoundedClipRect) override; 57 Maybe<gfx::RoundedRect> RoundedClipRect() override; 58 gfx::IntRect CurrentSurfaceDisplayRect() override; 59 void SetSurfaceIsFlipped(bool aIsFlipped) override; 60 bool SurfaceIsFlipped() override; 61 62 void AttachExternalImage(wr::RenderTextureHost* aExternalImage) override; 63 GpuFence* GetGpuFence() override; 64 65 Maybe<SurfaceWithInvalidRegion> FrontSurface(); 66 67 NativeLayerRemoteMac(const gfx::IntSize& aSize, bool aIsOpaque, 68 SurfacePoolHandleCA* aSurfacePoolHandle); 69 explicit NativeLayerRemoteMac(bool aIsOpaque); 70 explicit NativeLayerRemoteMac(gfx::DeviceColor aColor); 71 ~NativeLayerRemoteMac() override; 72 73 // If dirty, add a CommandLayerInfo to the queue. Clear dirty flag. 74 void FlushDirtyLayerInfoToCommandQueue(); 75 76 void UpdateSnapshotLayer(); 77 CALayer* CALayerForSnapshot(); 78 79 protected: 80 NativeLayerCARepresentation mSnapshotLayer; 81 Maybe<NativeLayerMacSurfaceHandler> mSurfaceHandler; 82 RefPtr<NativeLayerCommandQueue> mCommandQueue; 83 const Maybe<gfx::DeviceColor> mColor; 84 const bool mIsOpaque = false; 85 86 bool mDirtyLayerInfo = true; 87 // mDirtyLayerInfo is set when any of these change: 88 gfx::IntPoint mPosition; 89 gfx::Matrix4x4 mTransform; 90 gfx::IntRect mDisplayRect; 91 Maybe<gfx::IntRect> mClipRect; 92 Maybe<gfx::RoundedRect> mRoundedClipRect; 93 gfx::SamplingFilter mSamplingFilter = gfx::SamplingFilter::POINT; 94 float mBackingScale = 1.0f; 95 bool mSurfaceIsFlipped = false; 96 97 bool mDirtyChangedSurface = true; 98 // mDirtyChangedSurface is set when any of these change, or when the 99 // value returned by FrontSurface() changes: 100 CFTypeRefPtr<IOSurfaceRef> mExternalImage; 101 bool mIsDRM = false; 102 bool mIsHDR = false; 103 gfx::IntSize mSize; 104 }; 105 106 } // namespace layers 107 } // namespace mozilla 108 109 #endif // mozilla_layers_NativeLayerRemoteMac_h