Debian Codegraph @

src/gpu/ganesh/image/SkImage_GaneshYUVA.h

raw
1 /*
2 * Copyright 2018 Google Inc.
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 SkImage_GaneshYUVA_DEFINED
9 #define SkImage_GaneshYUVA_DEFINED
10
11 #include "include/core/SkColorSpace.h"
12 #include "include/core/SkColorType.h"
13 #include "include/core/SkImage.h"
14 #include "include/core/SkRefCnt.h"
15 #include "include/core/SkSamplingOptions.h"
16 #include "src/gpu/ganesh/GrYUVATextureProxies.h"
17 #include "src/gpu/ganesh/image/SkImage_GaneshBase.h"
18 #include "src/image/SkImage_Base.h"
19
20 #include <cstddef>
21 #include <cstdint>
22 #include <memory>
23 #include <tuple>
24
25 class GrDirectContext;
26 class GrFragmentProcessor;
27 class GrImageContext;
28 class GrRecordingContext;
29 class GrRenderTargetProxy;
30 class GrSurfaceProxyView;
31 class SkMatrix;
32 enum class GrColorType;
33 enum class GrImageTexGenPolicy : int;
34 enum class GrSemaphoresSubmitted : bool;
35 enum GrSurfaceOrigin : int;
36 enum class SkTileMode;
37 struct GrFlushInfo;
38 struct SkRect;
39
40 namespace skgpu {
41 enum class Mipmapped : bool;
42 }
43 namespace skgpu::ganesh { class SurfaceDrawContext; }
44
45 // Wraps the 1 to 4 planes of a YUVA image for consumption by the GPU.
46 // Initially any direct rendering will be done by passing the individual planes to a shader.
47 // Once any method requests a flattened image (e.g., onReadPixels), the flattened RGB
48 // proxy will be stored and used for any future rendering.
49 class SkImage_GaneshYUVA final : public SkImage_GaneshBase {
50 public:
51 static constexpr auto kAssumedColorType = kRGBA_8888_SkColorType;
52
53 SkImage_GaneshYUVA(sk_sp<GrImageContext>,
54 uint32_t uniqueID,
55 GrYUVATextureProxies proxies,
56 sk_sp<SkColorSpace>);
57
58 // From SkImage.h
59 size_t textureSize() const override;
60
61 // From SkImage_Base.h
62 SkImage_Base::Type type() const override { return SkImage_Base::Type::kGaneshYUVA; }
63 bool onHasMipmaps() const override;
64 bool onIsProtected() const override;
65
66 sk_sp<SkImage> onMakeColorTypeAndColorSpace(GrDirectContext*,
67 SkColorType,
68 sk_sp<SkColorSpace>) const final;
69
70 sk_sp<SkImage> onReinterpretColorSpace(sk_sp<SkColorSpace>) const final;
71
72 // From SkImage_GaneshBase.h
73 GrSemaphoresSubmitted flush(GrDirectContext*, const GrFlushInfo&) const override;
74
75 std::tuple<GrSurfaceProxyView, GrColorType> asView(GrRecordingContext*,
76 skgpu::Mipmapped,
77 GrImageTexGenPolicy,
78 GrRenderTargetProxy*) const override;
79
80 std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(skgpu::ganesh::SurfaceDrawContext*,
81 SkSamplingOptions,
82 const SkTileMode[2],
83 const SkMatrix&,
84 const SkRect*,
85 const SkRect*) const override;
86
87 bool setupMipmapsForPlanes(GrRecordingContext*) const;
88
89 GrSurfaceOrigin origin() const override { return fYUVAProxies.textureOrigin(); }
90
91 private:
92 enum class ColorSpaceMode {
93 kConvert,
94 kReinterpret,
95 };
96 SkImage_GaneshYUVA(sk_sp<GrImageContext>,
97 const SkImage_GaneshYUVA* image,
98 sk_sp<SkColorSpace> targetCS,
99 ColorSpaceMode csMode);
100
101 mutable GrYUVATextureProxies fYUVAProxies;
102
103 // If this is non-null then the planar data should be converted from fFromColorSpace to
104 // this->colorSpace(). Otherwise we assume the planar data (post YUV->RGB conversion) is already
105 // in this->colorSpace().
106 const sk_sp<SkColorSpace> fFromColorSpace;
107
108 // Repeated calls to onMakeColorSpace will result in a proliferation of unique IDs and
109 // SkImage_GaneshYUVA instances. Cache the result of the last successful onMakeColorSpace call.
110 mutable sk_sp<SkColorSpace> fOnMakeColorSpaceTarget;
111 mutable sk_sp<SkImage> fOnMakeColorSpaceResult;
112
113 using INHERITED = SkImage_GaneshBase;
114 };
115
116 #endif