RemoteTextureHostWrapper.h (4439B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef MOZILLA_GFX_RemoteTextureHostWrapper_H 8 #define MOZILLA_GFX_RemoteTextureHostWrapper_H 9 10 #include "mozilla/layers/RemoteTextureMap.h" 11 #include "mozilla/layers/TextureHost.h" 12 #include "mozilla/Monitor.h" 13 14 namespace mozilla::layers { 15 16 // This class wraps TextureHost of remote texture. 17 // mRemoteTexture holds TextureHost of mTextureId. 18 class RemoteTextureHostWrapper : public TextureHost { 19 public: 20 static RefPtr<TextureHost> Create(const RemoteTextureId aTextureId, 21 const RemoteTextureOwnerId aOwnerId, 22 const base::ProcessId aForPid, 23 const gfx::IntSize aSize, 24 const TextureFlags aFlags); 25 26 void DeallocateDeviceData() override {} 27 28 gfx::SurfaceFormat GetFormat() const override; 29 30 already_AddRefed<gfx::DataSourceSurface> GetAsSurface( 31 gfx::DataSourceSurface* aSurface) override { 32 return nullptr; 33 } 34 35 gfx::YUVColorSpace GetYUVColorSpace() const override; 36 gfx::ColorDepth GetColorDepth() const override; 37 gfx::ColorRange GetColorRange() const override; 38 39 gfx::IntSize GetSize() const override; 40 41 bool IsValid() override; 42 43 #ifdef MOZ_LAYERS_HAVE_LOG 44 const char* Name() override { return "RemoteTextureHostWrapper"; } 45 #endif 46 47 void CreateRenderTexture( 48 const wr::ExternalImageId& aExternalImageId) override; 49 50 uint32_t NumSubTextures() override; 51 52 void PushResourceUpdates(wr::TransactionBuilder& aResources, 53 ResourceUpdateOp aOp, 54 const Range<wr::ImageKey>& aImageKeys, 55 const wr::ExternalImageId& aExtID) override; 56 57 void PushDisplayItems(wr::DisplayListBuilder& aBuilder, 58 const wr::LayoutRect& aBounds, 59 const wr::LayoutRect& aClip, wr::ImageRendering aFilter, 60 const Range<wr::ImageKey>& aImageKeys, 61 PushDisplayItemFlagSet aFlags) override; 62 63 bool SupportsExternalCompositing(WebRenderBackend aBackend) override; 64 65 void UnbindTextureSource() override; 66 67 void NotifyNotUsed() override; 68 69 void SetReadFence(Fence* aReadFence) override; 70 71 RemoteTextureHostWrapper* AsRemoteTextureHostWrapper() override { 72 return this; 73 } 74 75 TextureHostType GetTextureHostType() override; 76 77 bool IsWrappingSurfaceTextureHost() override; 78 79 bool NeedsDeferredDeletion() const override; 80 81 AndroidHardwareBuffer* GetAndroidHardwareBuffer() const override; 82 83 bool IsReadyForRendering(); 84 85 void ApplyTextureFlagsToRemoteTexture(); 86 87 void EnableWaitForRemoteTextureOwner(bool aEnable) { 88 mWaitForRemoteTextureOwner = true; 89 } 90 91 RemoteTextureInfo GetRemoteTextureInfo() const { 92 return RemoteTextureInfo(mTextureId, mOwnerId, mForPid, 93 mWaitForRemoteTextureOwner); 94 } 95 96 const RemoteTextureId mTextureId; 97 const RemoteTextureOwnerId mOwnerId; 98 const base::ProcessId mForPid; 99 const gfx::IntSize mSize; 100 101 protected: 102 RemoteTextureHostWrapper(const RemoteTextureId aTextureId, 103 const RemoteTextureOwnerId aOwnerId, 104 const base::ProcessId aForPid, 105 const gfx::IntSize aSize, const TextureFlags aFlags); 106 virtual ~RemoteTextureHostWrapper(); 107 void MaybeCreateRenderTexture(); 108 109 // Called only by RemoteTextureMap 110 TextureHost* GetRemoteTextureHost(const MonitorAutoLock& aProofOfLock); 111 // Called only by RemoteTextureMap 112 void SetRemoteTextureHost(const MonitorAutoLock& aProofOfLock, 113 TextureHost* aTextureHost); 114 void ClearRemoteTextureHost(const MonitorAutoLock& aProofOfLock); 115 116 // Updated by RemoteTextureMap 117 // 118 // Hold compositable ref of remote texture's TextureHost that is used for 119 // building WebRender display list. It is TextureHost of mTextureId. 120 CompositableTextureHostRef mRemoteTexture; 121 122 bool mRenderTextureCreated = false; 123 124 bool mWaitForRemoteTextureOwner = false; 125 126 friend class RemoteTextureMap; 127 }; 128 129 } // namespace mozilla::layers 130 131 #endif // MOZILLA_GFX_RemoteTextureHostWrapper_H