xref: /aosp_15_r20/external/skia/src/gpu/graphite/dawn/DawnTexture.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1*c8dee2aaSAndroid Build Coastguard Worker /*
2*c8dee2aaSAndroid Build Coastguard Worker  * Copyright 2022 Google LLC
3*c8dee2aaSAndroid Build Coastguard Worker  *
4*c8dee2aaSAndroid Build Coastguard Worker  * Use of this source code is governed by a BSD-style license that can be
5*c8dee2aaSAndroid Build Coastguard Worker  * found in the LICENSE file.
6*c8dee2aaSAndroid Build Coastguard Worker  */
7*c8dee2aaSAndroid Build Coastguard Worker 
8*c8dee2aaSAndroid Build Coastguard Worker #ifndef skgpu_graphite_DawnTexture_DEFINED
9*c8dee2aaSAndroid Build Coastguard Worker #define skgpu_graphite_DawnTexture_DEFINED
10*c8dee2aaSAndroid Build Coastguard Worker 
11*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkRefCnt.h"
12*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/graphite/Texture.h"
13*c8dee2aaSAndroid Build Coastguard Worker 
14*c8dee2aaSAndroid Build Coastguard Worker #include "webgpu/webgpu_cpp.h"  // NO_G3_REWRITE
15*c8dee2aaSAndroid Build Coastguard Worker 
16*c8dee2aaSAndroid Build Coastguard Worker namespace skgpu::graphite {
17*c8dee2aaSAndroid Build Coastguard Worker class DawnSharedContext;
18*c8dee2aaSAndroid Build Coastguard Worker 
19*c8dee2aaSAndroid Build Coastguard Worker class DawnTexture : public Texture {
20*c8dee2aaSAndroid Build Coastguard Worker public:
21*c8dee2aaSAndroid Build Coastguard Worker     static wgpu::Texture MakeDawnTexture(const DawnSharedContext*,
22*c8dee2aaSAndroid Build Coastguard Worker                                          SkISize dimensions,
23*c8dee2aaSAndroid Build Coastguard Worker                                          const TextureInfo&);
24*c8dee2aaSAndroid Build Coastguard Worker 
25*c8dee2aaSAndroid Build Coastguard Worker     static sk_sp<Texture> Make(const DawnSharedContext*,
26*c8dee2aaSAndroid Build Coastguard Worker                                SkISize dimensions,
27*c8dee2aaSAndroid Build Coastguard Worker                                const TextureInfo&,
28*c8dee2aaSAndroid Build Coastguard Worker                                skgpu::Budgeted);
29*c8dee2aaSAndroid Build Coastguard Worker 
30*c8dee2aaSAndroid Build Coastguard Worker     static sk_sp<Texture> MakeWrapped(const DawnSharedContext*,
31*c8dee2aaSAndroid Build Coastguard Worker                                       SkISize dimensions,
32*c8dee2aaSAndroid Build Coastguard Worker                                       const TextureInfo&,
33*c8dee2aaSAndroid Build Coastguard Worker                                       wgpu::Texture);
34*c8dee2aaSAndroid Build Coastguard Worker 
35*c8dee2aaSAndroid Build Coastguard Worker     static sk_sp<Texture> MakeWrapped(const DawnSharedContext*,
36*c8dee2aaSAndroid Build Coastguard Worker                                       SkISize dimensions,
37*c8dee2aaSAndroid Build Coastguard Worker                                       const TextureInfo&,
38*c8dee2aaSAndroid Build Coastguard Worker                                       const wgpu::TextureView&);
39*c8dee2aaSAndroid Build Coastguard Worker 
~DawnTexture()40*c8dee2aaSAndroid Build Coastguard Worker     ~DawnTexture() override {}
41*c8dee2aaSAndroid Build Coastguard Worker 
dawnTexture()42*c8dee2aaSAndroid Build Coastguard Worker     const wgpu::Texture& dawnTexture() const { return fTexture; }
sampleTextureView()43*c8dee2aaSAndroid Build Coastguard Worker     const wgpu::TextureView& sampleTextureView() const { return fSampleTextureView; }
renderTextureView()44*c8dee2aaSAndroid Build Coastguard Worker     const wgpu::TextureView& renderTextureView() const { return fRenderTextureView; }
45*c8dee2aaSAndroid Build Coastguard Worker 
46*c8dee2aaSAndroid Build Coastguard Worker private:
47*c8dee2aaSAndroid Build Coastguard Worker     DawnTexture(const DawnSharedContext*,
48*c8dee2aaSAndroid Build Coastguard Worker                 SkISize dimensions,
49*c8dee2aaSAndroid Build Coastguard Worker                 const TextureInfo&,
50*c8dee2aaSAndroid Build Coastguard Worker                 wgpu::Texture,
51*c8dee2aaSAndroid Build Coastguard Worker                 wgpu::TextureView sampleTextureView,
52*c8dee2aaSAndroid Build Coastguard Worker                 wgpu::TextureView renderTextureView,
53*c8dee2aaSAndroid Build Coastguard Worker                 Ownership,
54*c8dee2aaSAndroid Build Coastguard Worker                 skgpu::Budgeted);
55*c8dee2aaSAndroid Build Coastguard Worker 
56*c8dee2aaSAndroid Build Coastguard Worker     void freeGpuData() override;
57*c8dee2aaSAndroid Build Coastguard Worker 
58*c8dee2aaSAndroid Build Coastguard Worker     static std::pair<wgpu::TextureView, wgpu::TextureView> CreateTextureViews(
59*c8dee2aaSAndroid Build Coastguard Worker             const wgpu::Texture& texture, const TextureInfo& info);
60*c8dee2aaSAndroid Build Coastguard Worker 
61*c8dee2aaSAndroid Build Coastguard Worker     void setBackendLabel(char const* label) override;
62*c8dee2aaSAndroid Build Coastguard Worker 
63*c8dee2aaSAndroid Build Coastguard Worker     wgpu::Texture     fTexture;
64*c8dee2aaSAndroid Build Coastguard Worker     wgpu::TextureView fSampleTextureView;
65*c8dee2aaSAndroid Build Coastguard Worker     wgpu::TextureView fRenderTextureView;
66*c8dee2aaSAndroid Build Coastguard Worker };
67*c8dee2aaSAndroid Build Coastguard Worker 
68*c8dee2aaSAndroid Build Coastguard Worker }  // namespace skgpu::graphite
69*c8dee2aaSAndroid Build Coastguard Worker 
70*c8dee2aaSAndroid Build Coastguard Worker #endif // skgpu_graphite_DawnTexture_DEFINED
71