#pragma once
#if ENABLE(WEBGPU)
#include "GPUTextureUsage.h"
#include <wtf/OptionSet.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#include <wtf/RetainPtr.h>
OBJC_PROTOCOL(MTLTexture);
namespace WebCore {
class GPUDevice;
class GPUErrorScopes;
struct GPUTextureDescriptor;
using PlatformTexture = MTLTexture;
using PlatformTextureSmartPtr = RetainPtr<MTLTexture>;
class GPUTexture : public RefCounted<GPUTexture> {
public:
static RefPtr<GPUTexture> tryCreate(const GPUDevice&, const GPUTextureDescriptor&, GPUErrorScopes&);
static Ref<GPUTexture> create(PlatformTextureSmartPtr&&, OptionSet<GPUTextureUsage::Flags>);
PlatformTexture *platformTexture() const { return m_platformTexture.get(); }
bool isCopySource() const { return m_usage.contains(GPUTextureUsage::Flags::CopySource); }
bool isCopyDestination() const { return m_usage.contains(GPUTextureUsage::Flags::CopyDestination); }
bool isOutputAttachment() const { return m_usage.contains(GPUTextureUsage::Flags::OutputAttachment); }
bool isReadOnly() const { return m_usage.containsAny({ GPUTextureUsage::Flags::CopySource, GPUTextureUsage::Flags::Sampled }); }
bool isSampled() const { return m_usage.contains(GPUTextureUsage::Flags::Sampled); }
bool isStorage() const { return m_usage.contains(GPUTextureUsage::Flags::Storage); }
unsigned platformUsage() const { return m_platformUsage; }
RefPtr<GPUTexture> tryCreateDefaultTextureView();
void destroy() { m_platformTexture = nullptr; }
private:
explicit GPUTexture(PlatformTextureSmartPtr&&, OptionSet<GPUTextureUsage::Flags>);
PlatformTextureSmartPtr m_platformTexture;
OptionSet<GPUTextureUsage::Flags> m_usage;
unsigned m_platformUsage;
};
}
#endif // ENABLE(WEBGPU)