Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrYUVABackendTextures.cpp
Go to the documentation of this file.
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
9
11
13 switch (format.channelMask()) {
14 case kRed_SkColorChannelFlag : return 1;
15 case kAlpha_SkColorChannelFlag : return 1;
16 case kGray_SkColorChannelFlag : return 1;
17 case kGrayAlpha_SkColorChannelFlags : return 2;
18 case kRG_SkColorChannelFlags : return 2;
19 case kRGB_SkColorChannelFlags : return 3;
20 case kRGBA_SkColorChannelFlags : return 4;
21 default : return 0;
22 }
23}
24
26 const GrBackendFormat formats[kMaxPlanes],
27 skgpu::Mipmapped mipmapped,
28 GrSurfaceOrigin origin)
29 : fYUVAInfo(yuvaInfo), fMipmapped(mipmapped), fTextureOrigin(origin) {
30 if (!yuvaInfo.isValid()) {
31 *this = {};
32 SkASSERT(!this->isValid());
33 return;
34 }
35 int n = yuvaInfo.numPlanes();
36 for (size_t i = 0; i < static_cast<size_t>(n); ++i) {
37 if (!formats[i].isValid() || formats[i].backend() != formats[0].backend()) {
38 *this = {};
39 SkASSERT(!this->isValid());
40 return;
41 }
42 int numRequiredChannels = yuvaInfo.numChannelsInPlane(i);
43 SkASSERT(numRequiredChannels > 0);
44 int numActualChannels = num_channels(formats[i]);
45 if (numActualChannels < numRequiredChannels) {
46 *this = {};
47 SkASSERT(!this->isValid());
48 return;
49 }
50 fPlaneFormats[i] = formats[i];
51 }
52 SkASSERT(this->isValid());
53}
54
56 if (fYUVAInfo != that.fYUVAInfo ||
57 fMipmapped != that.fMipmapped ||
58 fTextureOrigin != that.fTextureOrigin) {
59 return false;
60 }
61 int n = fYUVAInfo.numPlanes();
62 return std::equal(fPlaneFormats, fPlaneFormats + n, that.fPlaneFormats);
63}
64
66 uint32_t channelFlags[] = {fPlaneFormats[0].channelMask(),
67 fPlaneFormats[1].channelMask(),
68 fPlaneFormats[2].channelMask(),
69 fPlaneFormats[3].channelMask()};
70 auto result = fYUVAInfo.toYUVALocations(channelFlags);
73 SkASSERT(numPlanes == this->numPlanes());
74 return result;
75}
76
77//////////////////////////////////////////////////////////////////////////////
78
80 const SkYUVAInfo& yuvaInfo,
82 GrSurfaceOrigin textureOrigin)
83 : fYUVAInfo(yuvaInfo), fTextureOrigin(textureOrigin) {
84 if (!fYUVAInfo.isValid()) {
85 return;
86 }
87 SkISize planeDimensions[SkYUVAInfo::kMaxPlanes];
88 int numPlanes = yuvaInfo.planeDimensions(planeDimensions);
89 for (int i = 0; i < numPlanes; ++i) {
90 int numRequiredChannels = fYUVAInfo.numChannelsInPlane(i);
91 if (!textures[i].isValid() ||
92 textures[i].dimensions() != planeDimensions[i] ||
93 textures[i].backend() != textures[0].backend() ||
94 num_channels(textures[i].getBackendFormat()) < numRequiredChannels) {
95 *this = {};
96 return;
97 }
98 fTextures[i] = textures[i];
99 }
100}
101
103 uint32_t channelFlags[] = {fTextures[0].getBackendFormat().channelMask(),
104 fTextures[1].getBackendFormat().channelMask(),
105 fTextures[2].getBackendFormat().channelMask(),
106 fTextures[3].getBackendFormat().channelMask()};
107 auto result = fYUVAInfo.toYUVALocations(channelFlags);
110 SkASSERT(numPlanes == this->numPlanes());
111 return result;
112}
const char * backend
GrSurfaceOrigin
Definition GrTypes.h:147
static int num_channels(const GrBackendFormat &format)
#define SkASSERT(cond)
Definition SkAssert.h:116
@ kRGB_SkColorChannelFlags
Definition SkColor.h:247
@ kRGBA_SkColorChannelFlags
Definition SkColor.h:248
@ kRed_SkColorChannelFlag
Definition SkColor.h:239
@ kGrayAlpha_SkColorChannelFlags
Definition SkColor.h:245
@ kRG_SkColorChannelFlags
Definition SkColor.h:246
@ kAlpha_SkColorChannelFlag
Definition SkColor.h:242
@ kGray_SkColorChannelFlag
Definition SkColor.h:243
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
uint32_t channelMask() const
const SkYUVAInfo & yuvaInfo() const
bool operator==(const GrYUVABackendTextureInfo &) const
SkYUVAInfo::YUVALocations toYUVALocations() const
GrYUVABackendTextureInfo()=default
const SkYUVAInfo & yuvaInfo() const
const std::array< GrBackendTexture, SkYUVAInfo::kMaxPlanes > & textures() const
SkYUVAInfo::YUVALocations toYUVALocations() const
GrYUVABackendTextures()=default
int numPlanes() const
Definition SkYUVAInfo.h:204
static constexpr int kMaxPlanes
Definition SkYUVAInfo.h:98
YUVALocations toYUVALocations(const uint32_t *channelFlags) const
int planeDimensions(SkISize planeDimensions[kMaxPlanes]) const
Definition SkYUVAInfo.h:192
std::array< YUVALocation, kYUVAChannelCount > YUVALocations
Definition SkYUVAInfo.h:32
bool isValid() const
Definition SkYUVAInfo.h:233
int numChannelsInPlane(int i) const
Definition SkYUVAInfo.h:206
std::vector< std::shared_ptr< FakeTexture > > textures
GAsyncResult * result
uint32_t uint32_t * format
Mipmapped
Definition GpuTypes.h:53
static bool AreValidLocations(const SkYUVAInfo::YUVALocations &locations, int *numPlanes=nullptr)