| 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 skgpu_graphite_Image_YUVA_Graphite_DEFINED |
| 9 |
#define skgpu_graphite_Image_YUVA_Graphite_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkYUVAInfo.h" |
| 12 |
#include "src/gpu/graphite/Image_Base_Graphite.h" |
| 13 |
#include "src/gpu/graphite/TextureProxyView.h" |
| 14 |
|
| 15 |
#include <functional> |
| 16 |
|
| 17 |
namespace skgpu::graphite { |
| 18 |
|
| 19 |
class Recorder; |
| 20 |
|
| 21 |
class Image_YUVA final : public Image_Base { |
| 22 |
public: |
| 23 |
~Image_YUVA() override; |
| 24 |
|
| 25 |
// Create an Image_YUVA by interpreting the multiple 'planes' using 'yuvaInfo'. If the info |
| 26 |
// or provided plane proxies do not produce a valid mulitplane image, null is returned. |
| 27 |
static sk_sp<Image_YUVA> Make(const Caps* caps, |
| 28 |
const SkYUVAInfo& yuvaInfo, |
| 29 |
SkSpan<TextureProxyView> planes, |
| 30 |
sk_sp<SkColorSpace> imageColorSpace); |
| 31 |
|
| 32 |
// Wraps the Graphite-backed Image planes into a YUV[A] image. The returned image shares |
| 33 |
// textures as well as any links to Devices that might modify those textures. |
| 34 |
static sk_sp<Image_YUVA> WrapImages(const Caps* caps, |
| 35 |
const SkYUVAInfo& yuvaInfo, |
| 36 |
SkSpan<const sk_sp<SkImage>> images, |
| 37 |
sk_sp<SkColorSpace> imageColorSpace); |
| 38 |
|
| 39 |
SkImage_Base::Type type() const override { return SkImage_Base::Type::kGraphiteYUVA; } |
| 40 |
|
| 41 |
size_t textureSize() const override; |
| 42 |
|
| 43 |
bool onHasMipmaps() const override { return fMipmapped == Mipmapped::kYes; } |
| 44 |
|
| 45 |
bool onIsProtected() const override { return fProtected == Protected::kYes; } |
| 46 |
|
| 47 |
sk_sp<SkImage> onReinterpretColorSpace(sk_sp<SkColorSpace>) const override; |
| 48 |
|
| 49 |
// Returns the proxy view that provides value for the YUVA channel specified by 'channelIndex'. |
| 50 |
// The view of the returned proxy applies a swizzle to map the relevant data channel into all |
| 51 |
// slots of the sample value. The alpha proxy may be null. |
| 52 |
const TextureProxyView& proxyView(int channelIndex) const { |
| 53 |
SkASSERT(channelIndex >= 0 && channelIndex < SkYUVAInfo::kYUVAChannelCount); |
| 54 |
return fProxies[channelIndex]; |
| 55 |
} |
| 56 |
|
| 57 |
std::tuple<int, int> uvSubsampleFactors() const { return fUVSubsampleFactors; } |
| 58 |
|
| 59 |
const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; } |
| 60 |
|
| 61 |
private: |
| 62 |
// The proxy views are ordered Y,U,V,A and if the channels are held in the same plane, the |
| 63 |
// respective proxy views will share the underlying TextureProxy but have the appropriate |
| 64 |
// swizzle to access the appropriate channel and return it in the R slot. |
| 65 |
using YUVAProxies = std::array<TextureProxyView, SkYUVAInfo::kYUVAChannelCount>; |
| 66 |
|
| 67 |
Image_YUVA(const YUVAProxies&, |
| 68 |
const SkYUVAInfo&, |
| 69 |
sk_sp<SkColorSpace>); |
| 70 |
|
| 71 |
YUVAProxies fProxies; |
| 72 |
SkYUVAInfo fYUVAInfo; |
| 73 |
std::tuple<int, int> fUVSubsampleFactors; |
| 74 |
|
| 75 |
// Aggregate mipmap/protected status from the proxies |
| 76 |
Mipmapped fMipmapped = Mipmapped::kYes; |
| 77 |
Protected fProtected = Protected::kNo; |
| 78 |
}; |
| 79 |
|
| 80 |
} // namespace skgpu::graphite |
| 81 |
|
| 82 |
#endif // skgpu_graphite_Image_YUVA_Graphite_DEFINED |