1 // Copyright 2021 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef DAWNNATIVE_EXTERNALTEXTURE_H_ 16 #define DAWNNATIVE_EXTERNALTEXTURE_H_ 17 18 #include "dawn_native/Error.h" 19 #include "dawn_native/Forward.h" 20 #include "dawn_native/ObjectBase.h" 21 #include "dawn_native/Subresource.h" 22 23 #include <array> 24 25 namespace dawn_native { 26 27 struct ExternalTextureDescriptor; 28 class TextureViewBase; 29 30 MaybeError ValidateExternalTextureDescriptor(const DeviceBase* device, 31 const ExternalTextureDescriptor* descriptor); 32 33 class ExternalTextureBase : public ApiObjectBase { 34 public: 35 static ResultOrError<Ref<ExternalTextureBase>> Create( 36 DeviceBase* device, 37 const ExternalTextureDescriptor* descriptor); 38 39 const std::array<Ref<TextureViewBase>, kMaxPlanesPerFormat>& GetTextureViews() const; 40 41 MaybeError ValidateCanUseInSubmitNow() const; 42 43 static ExternalTextureBase* MakeError(DeviceBase* device); 44 45 ObjectType GetType() const override; 46 47 void APIDestroy(); 48 49 protected: 50 // Constructor used only for mocking and testing. 51 ExternalTextureBase(DeviceBase* device); 52 void DestroyImpl() override; 53 54 private: 55 enum class ExternalTextureState { Alive, Destroyed }; 56 ExternalTextureBase(DeviceBase* device, const ExternalTextureDescriptor* descriptor); 57 ExternalTextureBase(DeviceBase* device, ObjectBase::ErrorTag tag); 58 std::array<Ref<TextureViewBase>, kMaxPlanesPerFormat> textureViews; 59 ExternalTextureState mState; 60 }; 61 } // namespace dawn_native 62 63 #endif // DAWNNATIVE_EXTERNALTEXTURE_H_ 64