blob: d16147472cd7ef0be56a0389d56a9231bce14088 [file] [log] [blame]
Brandon Jones0e92e9b2021-04-01 20:46:42 +00001// 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"
Loko Kung8d195d52021-09-28 15:40:01 +000019#include "dawn_native/Forward.h"
Brandon Jones0e92e9b2021-04-01 20:46:42 +000020#include "dawn_native/ObjectBase.h"
21#include "dawn_native/Subresource.h"
22
23#include <array>
24
25namespace dawn_native {
26
27 struct ExternalTextureDescriptor;
28 class TextureViewBase;
29
30 MaybeError ValidateExternalTextureDescriptor(const DeviceBase* device,
31 const ExternalTextureDescriptor* descriptor);
32
Loko Kung8d195d52021-09-28 15:40:01 +000033 class ExternalTextureBase : public ApiObjectBase {
Brandon Jones0e92e9b2021-04-01 20:46:42 +000034 public:
35 static ResultOrError<Ref<ExternalTextureBase>> Create(
36 DeviceBase* device,
37 const ExternalTextureDescriptor* descriptor);
38
Brandon Jones39633e22021-06-01 19:45:53 +000039 const std::array<Ref<TextureViewBase>, kMaxPlanesPerFormat>& GetTextureViews() const;
40
41 MaybeError ValidateCanUseInSubmitNow() const;
Brandon Jones0e92e9b2021-04-01 20:46:42 +000042
43 static ExternalTextureBase* MakeError(DeviceBase* device);
44
Loko Kung8d195d52021-09-28 15:40:01 +000045 ObjectType GetType() const override;
46
Brandon Jones0e92e9b2021-04-01 20:46:42 +000047 void APIDestroy();
48
49 private:
Brandon Jonesb94c41a2021-06-08 20:29:37 +000050 enum class ExternalTextureState { Alive, Destroyed };
Brandon Jones0e92e9b2021-04-01 20:46:42 +000051 ExternalTextureBase(DeviceBase* device, const ExternalTextureDescriptor* descriptor);
52 ExternalTextureBase(DeviceBase* device, ObjectBase::ErrorTag tag);
53 std::array<Ref<TextureViewBase>, kMaxPlanesPerFormat> textureViews;
Brandon Jones39633e22021-06-01 19:45:53 +000054 ExternalTextureState mState;
Brandon Jones0e92e9b2021-04-01 20:46:42 +000055 };
56} // namespace dawn_native
57
Loko Kung8d195d52021-09-28 15:40:01 +000058#endif // DAWNNATIVE_EXTERNALTEXTURE_H_