Coverage Report

Created: 2024-09-14 07:19

/src/skia/include/gpu/ganesh/GrYUVABackendTextures.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2020 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 GrYUVABackendTextures_DEFINED
9
#define GrYUVABackendTextures_DEFINED
10
11
#include "include/core/SkTypes.h"
12
#include "include/core/SkYUVAInfo.h"
13
#include "include/gpu/GpuTypes.h"
14
#include "include/gpu/ganesh/GrBackendSurface.h"
15
#include "include/gpu/ganesh/GrTypes.h"
16
17
#include <array>
18
#include <cstddef>
19
20
enum SkYUVColorSpace : int;
21
22
/**
23
 * A description of a set GrBackendTextures that hold the planar data described by a SkYUVAInfo.
24
 */
25
class SK_API GrYUVABackendTextureInfo {
26
public:
27
    static constexpr auto kMaxPlanes = SkYUVAInfo::kMaxPlanes;
28
29
    /** Default GrYUVABackendTextureInfo is invalid. */
30
0
    GrYUVABackendTextureInfo() = default;
31
32
    /**
33
     * Initializes a GrYUVABackendTextureInfo to describe a set of textures that can store the
34
     * planes indicated by the SkYUVAInfo. The texture dimensions are taken from the SkYUVAInfo's
35
     * plane dimensions. All the described textures share a common origin. The planar image this
36
     * describes will be mip mapped if all the textures are individually mip mapped as indicated
37
     * by skgpu::Mipmapped. This will produce an invalid result (return false from isValid()) if the
38
     * passed formats' channels don't agree with SkYUVAInfo.
39
     */
40
    GrYUVABackendTextureInfo(const SkYUVAInfo&,
41
                             const GrBackendFormat[kMaxPlanes],
42
                             skgpu::Mipmapped,
43
                             GrSurfaceOrigin);
44
45
    GrYUVABackendTextureInfo(const GrYUVABackendTextureInfo&) = default;
46
47
0
    GrYUVABackendTextureInfo& operator=(const GrYUVABackendTextureInfo&) = default;
48
49
    bool operator==(const GrYUVABackendTextureInfo&) const;
50
0
    bool operator!=(const GrYUVABackendTextureInfo& that) const { return !(*this == that); }
51
52
0
    const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; }
53
54
0
    SkYUVColorSpace yuvColorSpace() const { return fYUVAInfo.yuvColorSpace(); }
55
56
0
    skgpu::Mipmapped mipmapped() const { return fMipmapped; }
57
58
0
    GrSurfaceOrigin textureOrigin() const { return fTextureOrigin; }
59
60
    /** The number of SkPixmap planes, 0 if this GrYUVABackendTextureInfo is invalid. */
61
0
    int numPlanes() const { return fYUVAInfo.numPlanes(); }
62
63
    /** Format of the ith plane, or invalid format if i >= numPlanes() */
64
0
    const GrBackendFormat& planeFormat(int i) const { return fPlaneFormats[i]; }
65
66
    /**
67
     * Returns true if this has been configured with a valid SkYUVAInfo with compatible texture
68
     * formats.
69
     */
70
0
    bool isValid() const { return fYUVAInfo.isValid(); }
71
72
    /**
73
     * Computes a YUVALocations representation of the planar layout. The result is guaranteed to be
74
     * valid if this->isValid().
75
     */
76
    SkYUVAInfo::YUVALocations toYUVALocations() const;
77
78
private:
79
    SkYUVAInfo fYUVAInfo;
80
    GrBackendFormat fPlaneFormats[kMaxPlanes];
81
    skgpu::Mipmapped fMipmapped = skgpu::Mipmapped::kNo;
82
    GrSurfaceOrigin fTextureOrigin = kTopLeft_GrSurfaceOrigin;
83
};
84
85
/**
86
 * A set of GrBackendTextures that hold the planar data for an image described a SkYUVAInfo.
87
 */
88
class SK_API GrYUVABackendTextures {
89
public:
90
0
    GrYUVABackendTextures() = default;
91
    GrYUVABackendTextures(const GrYUVABackendTextures&) = delete;
92
    GrYUVABackendTextures(GrYUVABackendTextures&&) = default;
93
94
    GrYUVABackendTextures& operator=(const GrYUVABackendTextures&) = delete;
95
0
    GrYUVABackendTextures& operator=(GrYUVABackendTextures&&) = default;
96
97
    GrYUVABackendTextures(const SkYUVAInfo&,
98
                          const GrBackendTexture[SkYUVAInfo::kMaxPlanes],
99
                          GrSurfaceOrigin textureOrigin);
100
101
0
    const std::array<GrBackendTexture, SkYUVAInfo::kMaxPlanes>& textures() const {
102
0
        return fTextures;
103
0
    }
104
105
0
    GrBackendTexture texture(int i) const {
106
0
        SkASSERT(i >= 0 && i < SkYUVAInfo::kMaxPlanes);
107
0
        return fTextures[static_cast<size_t>(i)];
108
0
    }
Unexecuted instantiation: GrYUVABackendTextures::texture(int) const
Unexecuted instantiation: GrYUVABackendTextures::texture(int) const
109
110
0
    const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; }
111
112
0
    int numPlanes() const { return fYUVAInfo.numPlanes(); }
113
114
0
    GrSurfaceOrigin textureOrigin() const { return fTextureOrigin; }
115
116
0
    bool isValid() const { return fYUVAInfo.isValid(); }
117
118
    /**
119
     * Computes a YUVALocations representation of the planar layout. The result is guaranteed to be
120
     * valid if this->isValid().
121
     */
122
    SkYUVAInfo::YUVALocations toYUVALocations() const;
123
124
private:
125
    SkYUVAInfo fYUVAInfo;
126
    std::array<GrBackendTexture, SkYUVAInfo::kMaxPlanes> fTextures;
127
    GrSurfaceOrigin fTextureOrigin = kTopLeft_GrSurfaceOrigin;
128
};
129
130
#endif