1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2018 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#ifndef SkImage_GpuYUVA_DEFINED
9cb93a386Sopenharmony_ci#define SkImage_GpuYUVA_DEFINED
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_ci#include "include/gpu/GrBackendSurface.h"
12cb93a386Sopenharmony_ci#include "src/core/SkCachedData.h"
13cb93a386Sopenharmony_ci#include "src/gpu/GrYUVATextureProxies.h"
14cb93a386Sopenharmony_ci#include "src/image/SkImage_GpuBase.h"
15cb93a386Sopenharmony_ci
16cb93a386Sopenharmony_ciclass GrDirectContext;
17cb93a386Sopenharmony_ciclass GrRecordingContext;
18cb93a386Sopenharmony_ciclass GrTexture;
19cb93a386Sopenharmony_ci
20cb93a386Sopenharmony_ci// Wraps the 1 to 4 planes of a YUVA image for consumption by the GPU.
21cb93a386Sopenharmony_ci// Initially any direct rendering will be done by passing the individual planes to a shader.
22cb93a386Sopenharmony_ci// Once any method requests a flattened image (e.g., onReadPixels), the flattened RGB
23cb93a386Sopenharmony_ci// proxy will be stored and used for any future rendering.
24cb93a386Sopenharmony_ciclass SkImage_GpuYUVA final : public SkImage_GpuBase {
25cb93a386Sopenharmony_cipublic:
26cb93a386Sopenharmony_ci    SkImage_GpuYUVA(sk_sp<GrImageContext>,
27cb93a386Sopenharmony_ci                    uint32_t uniqueID,
28cb93a386Sopenharmony_ci                    GrYUVATextureProxies proxies,
29cb93a386Sopenharmony_ci                    sk_sp<SkColorSpace>);
30cb93a386Sopenharmony_ci
31cb93a386Sopenharmony_ci    bool onHasMipmaps() const override;
32cb93a386Sopenharmony_ci
33cb93a386Sopenharmony_ci    GrSemaphoresSubmitted onFlush(GrDirectContext*, const GrFlushInfo&) const override;
34cb93a386Sopenharmony_ci
35cb93a386Sopenharmony_ci    bool onIsTextureBacked() const override { return true; }
36cb93a386Sopenharmony_ci
37cb93a386Sopenharmony_ci    size_t onTextureSize() const override;
38cb93a386Sopenharmony_ci
39cb93a386Sopenharmony_ci    sk_sp<SkImage> onMakeColorTypeAndColorSpace(SkColorType, sk_sp<SkColorSpace>,
40cb93a386Sopenharmony_ci                                                GrDirectContext*) const final;
41cb93a386Sopenharmony_ci
42cb93a386Sopenharmony_ci    sk_sp<SkImage> onReinterpretColorSpace(sk_sp<SkColorSpace>) const final;
43cb93a386Sopenharmony_ci
44cb93a386Sopenharmony_cipublic:
45cb93a386Sopenharmony_ci    bool isYUVA() const override { return true; }
46cb93a386Sopenharmony_ci
47cb93a386Sopenharmony_ci    bool setupMipmapsForPlanes(GrRecordingContext*) const;
48cb93a386Sopenharmony_ci
49cb93a386Sopenharmony_ciprivate:
50cb93a386Sopenharmony_ci    SkImage_GpuYUVA(sk_sp<GrImageContext>, const SkImage_GpuYUVA* image, sk_sp<SkColorSpace>);
51cb93a386Sopenharmony_ci
52cb93a386Sopenharmony_ci    std::tuple<GrSurfaceProxyView, GrColorType> onAsView(GrRecordingContext*,
53cb93a386Sopenharmony_ci                                                         GrMipmapped,
54cb93a386Sopenharmony_ci                                                         GrImageTexGenPolicy) const override;
55cb93a386Sopenharmony_ci
56cb93a386Sopenharmony_ci    std::unique_ptr<GrFragmentProcessor> onAsFragmentProcessor(GrRecordingContext*,
57cb93a386Sopenharmony_ci                                                               SkSamplingOptions,
58cb93a386Sopenharmony_ci                                                               const SkTileMode[],
59cb93a386Sopenharmony_ci                                                               const SkMatrix&,
60cb93a386Sopenharmony_ci                                                               const SkRect*,
61cb93a386Sopenharmony_ci                                                               const SkRect*) const override;
62cb93a386Sopenharmony_ci
63cb93a386Sopenharmony_ci    mutable GrYUVATextureProxies     fYUVAProxies;
64cb93a386Sopenharmony_ci
65cb93a386Sopenharmony_ci    // If this is non-null then the planar data should be converted from fFromColorSpace to
66cb93a386Sopenharmony_ci    // this->colorSpace(). Otherwise we assume the planar data (post YUV->RGB conversion) is already
67cb93a386Sopenharmony_ci    // in this->colorSpace().
68cb93a386Sopenharmony_ci    const sk_sp<SkColorSpace>        fFromColorSpace;
69cb93a386Sopenharmony_ci
70cb93a386Sopenharmony_ci    // Repeated calls to onMakeColorSpace will result in a proliferation of unique IDs and
71cb93a386Sopenharmony_ci    // SkImage_GpuYUVA instances. Cache the result of the last successful onMakeColorSpace call.
72cb93a386Sopenharmony_ci    mutable sk_sp<SkColorSpace>      fOnMakeColorSpaceTarget;
73cb93a386Sopenharmony_ci    mutable sk_sp<SkImage>           fOnMakeColorSpaceResult;
74cb93a386Sopenharmony_ci
75cb93a386Sopenharmony_ci    using INHERITED = SkImage_GpuBase;
76cb93a386Sopenharmony_ci};
77cb93a386Sopenharmony_ci
78cb93a386Sopenharmony_ci#endif
79