xref: /aosp_15_r20/external/skia/include/gpu/ganesh/GrExternalTextureGenerator.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2023 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef GrExternalTextureGenerator_DEFINED
9 #define GrExternalTextureGenerator_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "include/gpu/ganesh/GrBackendSurface.h"
13 #include "include/private/base/SkAPI.h"
14 #include "include/private/gpu/ganesh/GrTextureGenerator.h"
15 
16 #include <memory>
17 
18 class GrRecordingContext;
19 class GrSurfaceProxyView;
20 class SkImage;
21 enum class GrImageTexGenPolicy : int;
22 namespace skgpu { enum class Mipmapped : bool; }
23 struct SkImageInfo;
24 
25 class GrExternalTexture {
26 public:
27     virtual ~GrExternalTexture() = default;
28     virtual GrBackendTexture getBackendTexture() = 0;
29     virtual void dispose() = 0;
30 };
31 
32 class SK_API GrExternalTextureGenerator : public GrTextureGenerator {
33 public:
34     GrExternalTextureGenerator(const SkImageInfo& info);
35 
36     GrSurfaceProxyView onGenerateTexture(GrRecordingContext*,
37                                          const SkImageInfo&,
38                                          skgpu::Mipmapped,
39                                          GrImageTexGenPolicy) override;
40     virtual std::unique_ptr<GrExternalTexture> generateExternalTexture(GrRecordingContext *,
41                                                                        skgpu::Mipmapped) = 0;
42 };
43 
44 namespace SkImages {
45 /**
46  *   Like SkImages::DeferredFromGenerator except allows for the use of GrTextureGenerator.
47  *
48  *   @param gen producer of textures
49  *   @return    created SkImage, or nullptr
50  */
51 SK_API sk_sp<SkImage> DeferredFromTextureGenerator(std::unique_ptr<GrTextureGenerator> gen);
52 }
53 
54 #endif  // GrExternalTextureGenerator_DEFINED
55