• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_GpuYUVA_DEFINED
9 #define SkImage_GpuYUVA_DEFINED
10 
11 #include "include/core/SkColorSpace.h"
12 #include "include/core/SkImage.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/core/SkSamplingOptions.h"
15 #include "src/gpu/ganesh/GrYUVATextureProxies.h"
16 #include "src/image/SkImage_GpuBase.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <memory>
21 #include <tuple>
22 
23 class GrDirectContext;
24 class GrFragmentProcessor;
25 class GrImageContext;
26 class GrRecordingContext;
27 class GrSurfaceProxyView;
28 class SkMatrix;
29 enum SkColorType : int;
30 enum class GrColorType;
31 enum class GrImageTexGenPolicy : int;
32 enum class GrSemaphoresSubmitted : bool;
33 enum class SkTileMode;
34 struct GrFlushInfo;
35 struct SkRect;
36 
37 namespace skgpu {
38 enum class Mipmapped : bool;
39 }
40 
41 // Wraps the 1 to 4 planes of a YUVA image for consumption by the GPU.
42 // Initially any direct rendering will be done by passing the individual planes to a shader.
43 // Once any method requests a flattened image (e.g., onReadPixels), the flattened RGB
44 // proxy will be stored and used for any future rendering.
45 class SkImage_GpuYUVA final : public SkImage_GpuBase {
46 public:
47     SkImage_GpuYUVA(sk_sp<GrImageContext>,
48                     uint32_t uniqueID,
49                     GrYUVATextureProxies proxies,
50                     sk_sp<SkColorSpace>);
51 
52     bool onHasMipmaps() const override;
53 
54     GrSemaphoresSubmitted onFlush(GrDirectContext*, const GrFlushInfo&) const override;
55 
isGaneshBacked()56     bool isGaneshBacked() const override { return true; }
57 
58     size_t onTextureSize() const override;
59 
60     using SkImage_GpuBase::onMakeColorTypeAndColorSpace;
61     sk_sp<SkImage> onMakeColorTypeAndColorSpace(SkColorType, sk_sp<SkColorSpace>,
62                                                 GrDirectContext*) const final;
63 
64     sk_sp<SkImage> onReinterpretColorSpace(sk_sp<SkColorSpace>) const final;
65 
66 public:
isYUVA()67     bool isYUVA() const override { return true; }
68 
69     bool setupMipmapsForPlanes(GrRecordingContext*) const;
70 
71 private:
72     SkImage_GpuYUVA(sk_sp<GrImageContext>, const SkImage_GpuYUVA* image, sk_sp<SkColorSpace>);
73 
74     std::tuple<GrSurfaceProxyView, GrColorType> onAsView(GrRecordingContext*,
75                                                          skgpu::Mipmapped,
76                                                          GrImageTexGenPolicy) const override;
77 
78     std::unique_ptr<GrFragmentProcessor> onAsFragmentProcessor(GrRecordingContext*,
79                                                                SkSamplingOptions,
80                                                                const SkTileMode[2],
81                                                                const SkMatrix&,
82                                                                const SkRect*,
83                                                                const SkRect*) const override;
84 
85     mutable GrYUVATextureProxies     fYUVAProxies;
86 
87     // If this is non-null then the planar data should be converted from fFromColorSpace to
88     // this->colorSpace(). Otherwise we assume the planar data (post YUV->RGB conversion) is already
89     // in this->colorSpace().
90     const sk_sp<SkColorSpace>        fFromColorSpace;
91 
92     // Repeated calls to onMakeColorSpace will result in a proliferation of unique IDs and
93     // SkImage_GpuYUVA instances. Cache the result of the last successful onMakeColorSpace call.
94     mutable sk_sp<SkColorSpace>      fOnMakeColorSpaceTarget;
95     mutable sk_sp<SkImage>           fOnMakeColorSpaceResult;
96 
97     using INHERITED = SkImage_GpuBase;
98 };
99 
100 #endif
101