2 * Copyright 2018 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkImage_GpuYUVA_DEFINED
9 #define SkImage_GpuYUVA_DEFINED
11 #include "include/gpu/GrBackendSurface.h"
12 #include "src/core/SkCachedData.h"
13 #include "src/gpu/ganesh/GrYUVATextureProxies.h"
14 #include "src/image/SkImage_GpuBase.h"
16 class GrDirectContext;
17 class GrRecordingContext;
20 // Wraps the 1 to 4 planes of a YUVA image for consumption by the GPU.
21 // Initially any direct rendering will be done by passing the individual planes to a shader.
22 // Once any method requests a flattened image (e.g., onReadPixels), the flattened RGB
23 // proxy will be stored and used for any future rendering.
24 class SkImage_GpuYUVA final : public SkImage_GpuBase {
26 SkImage_GpuYUVA(sk_sp<GrImageContext>,
28 GrYUVATextureProxies proxies,
31 bool onHasMipmaps() const override;
33 GrSemaphoresSubmitted onFlush(GrDirectContext*, const GrFlushInfo&) const override;
35 bool isGaneshBacked() const override { return true; }
37 size_t onTextureSize() const override;
39 sk_sp<SkImage> onMakeColorTypeAndColorSpace(SkColorType, sk_sp<SkColorSpace>,
40 GrDirectContext*) const final;
42 sk_sp<SkImage> onReinterpretColorSpace(sk_sp<SkColorSpace>) const final;
45 bool isYUVA() const override { return true; }
47 bool setupMipmapsForPlanes(GrRecordingContext*) const;
50 SkImage_GpuYUVA(sk_sp<GrImageContext>, const SkImage_GpuYUVA* image, sk_sp<SkColorSpace>);
52 std::tuple<GrSurfaceProxyView, GrColorType> onAsView(GrRecordingContext*,
54 GrImageTexGenPolicy) const override;
56 std::unique_ptr<GrFragmentProcessor> onAsFragmentProcessor(GrRecordingContext*,
61 const SkRect*) const override;
63 mutable GrYUVATextureProxies fYUVAProxies;
65 // If this is non-null then the planar data should be converted from fFromColorSpace to
66 // this->colorSpace(). Otherwise we assume the planar data (post YUV->RGB conversion) is already
67 // in this->colorSpace().
68 const sk_sp<SkColorSpace> fFromColorSpace;
70 // Repeated calls to onMakeColorSpace will result in a proliferation of unique IDs and
71 // SkImage_GpuYUVA instances. Cache the result of the last successful onMakeColorSpace call.
72 mutable sk_sp<SkColorSpace> fOnMakeColorSpaceTarget;
73 mutable sk_sp<SkImage> fOnMakeColorSpaceResult;
75 using INHERITED = SkImage_GpuBase;