blob: 0d4652362cb2c89b6038f6e0a5f800061f27a3d6 [file]
/*
* Copyright 2022 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef skgpu_graphite_DawnTexture_DEFINED
#define skgpu_graphite_DawnTexture_DEFINED
#include "include/core/SkRefCnt.h"
#include "include/gpu/graphite/dawn/DawnGraphiteTypes.h"
#include "include/private/SkTArray.h"
#include "src/gpu/graphite/Texture.h"
#include "src/gpu/graphite/TextureInfoPriv.h"
#include "webgpu/webgpu_cpp.h" // NO_G3_REWRITE
namespace skgpu::graphite {
class DawnSharedContext;
class Sampler;
class DawnTexture : public Texture {
public:
static wgpu::Texture MakeDawnTexture(const DawnSharedContext*,
SkISize dimensions,
const TextureInfo&);
static sk_sp<Texture> Make(const DawnSharedContext*,
SkISize dimensions,
const TextureInfo&,
std::string_view label);
static sk_sp<Texture> MakeWrapped(const DawnSharedContext*,
SkISize dimensions,
const TextureInfo&,
wgpu::Texture,
std::string_view label);
static sk_sp<Texture> MakeWrapped(const DawnSharedContext*,
SkISize dimensions,
const TextureInfo&,
const wgpu::TextureView&,
std::string_view label);
~DawnTexture() override {}
const wgpu::Texture& dawnTexture() const { return fTexture; }
const wgpu::TextureView& sampleTextureView() const { return fSampleTextureView; }
const wgpu::TextureView& renderTextureView() const { return fRenderTextureView; }
const DawnTextureInfo& dawnTextureInfo() const {
return TextureInfoPriv::Get<DawnTextureInfo>(this->textureInfo());
}
const wgpu::BindGroup* getCachedSingleTextureBindGroup(const Sampler*) const;
void addCachedSingleTextureBindGroup(wgpu::BindGroup, const Sampler*) const;
private:
DawnTexture(const DawnSharedContext*,
SkISize dimensions,
const TextureInfo&,
wgpu::Texture,
wgpu::TextureView sampleTextureView,
wgpu::TextureView renderTextureView,
Ownership,
std::string_view label);
void freeGpuData() override;
static std::pair<wgpu::TextureView, wgpu::TextureView> CreateTextureViews(
const wgpu::Texture& texture, const TextureInfo& info);
void setBackendLabel(char const* label) override;
wgpu::Texture fTexture;
wgpu::TextureView fSampleTextureView;
wgpu::TextureView fRenderTextureView;
// We store const Sampler pointers rather than using SkRefCnt for lifetime management because
// dynamic samplers are drawn from and kept alive by the GlobalCache.
using CachedTextureBindGroup = std::pair<const Sampler*, wgpu::BindGroup>;
mutable skia_private::STArray<3, CachedTextureBindGroup> fCachedSingleTextureBindGroups;
};
} // namespace skgpu::graphite
#endif // skgpu_graphite_DawnTexture_DEFINED