SyncObject.h (2007B)
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_LAYERS_SYNCOBJECT_H 8 #define MOZILLA_GFX_LAYERS_SYNCOBJECT_H 9 10 #include "mozilla/gfx/FileHandleWrapper.h" 11 #include "mozilla/RefCounted.h" 12 13 struct ID3D11Device; 14 15 namespace mozilla { 16 namespace layers { 17 18 #ifdef XP_WIN 19 typedef RefPtr<gfx::FileHandleWrapper> SyncHandle; 20 #else 21 typedef uintptr_t SyncHandle; 22 #endif // XP_WIN 23 24 class SyncObjectHost : public RefCounted<SyncObjectHost> { 25 public: 26 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SyncObjectHost) 27 virtual ~SyncObjectHost() = default; 28 29 #ifdef XP_WIN 30 static already_AddRefed<SyncObjectHost> CreateSyncObjectHost( 31 ID3D11Device* aDevice); 32 #endif 33 virtual bool Init() = 0; 34 35 virtual SyncHandle GetSyncHandle() = 0; 36 37 // Return false for failed synchronization. 38 virtual bool Synchronize(bool aFallible = false) = 0; 39 40 protected: 41 SyncObjectHost() = default; 42 }; 43 44 class SyncObjectClient : public external::AtomicRefCounted<SyncObjectClient> { 45 public: 46 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SyncObjectClient) 47 virtual ~SyncObjectClient() = default; 48 49 #ifdef XP_WIN 50 static already_AddRefed<SyncObjectClient> CreateSyncObjectClient( 51 SyncHandle aHandle, ID3D11Device* aDevice); 52 #endif 53 static already_AddRefed<SyncObjectClient> 54 CreateSyncObjectClientForContentDevice(SyncHandle aHandle); 55 56 enum class SyncType { 57 D3D11, 58 }; 59 60 virtual SyncType GetSyncType() = 0; 61 62 // Return false for failed synchronization. 63 virtual bool Synchronize(bool aFallible = false) = 0; 64 65 virtual bool IsSyncObjectValid() = 0; 66 67 virtual void EnsureInitialized() = 0; 68 69 protected: 70 SyncObjectClient() = default; 71 }; 72 73 } // namespace layers 74 } // namespace mozilla 75 76 #endif // MOZILLA_GFX_LAYERS_SYNCOBJECT_H