Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
GrYUVATextureProxies Class Reference

#include <GrYUVATextureProxies.h>

Public Member Functions

 GrYUVATextureProxies ()=default
 
 GrYUVATextureProxies (const SkYUVAInfo &, sk_sp< GrSurfaceProxy >[SkYUVAInfo::kMaxPlanes], GrSurfaceOrigin textureOrigin)
 
 GrYUVATextureProxies (const SkYUVAInfo &, GrSurfaceProxyView[SkYUVAInfo::kMaxPlanes], GrColorType[SkYUVAInfo::kMaxPlanes])
 
 GrYUVATextureProxies (const GrYUVATextureProxies &)=default
 
 GrYUVATextureProxies (GrYUVATextureProxies &&)=default
 
GrYUVATextureProxiesoperator= (const GrYUVATextureProxies &)=default
 
GrYUVATextureProxiesoperator= (GrYUVATextureProxies &&)=default
 
const SkYUVAInfoyuvaInfo () const
 
int numPlanes () const
 
GrSurfaceOrigin textureOrigin () const
 
skgpu::Mipmapped mipmapped () const
 
GrSurfaceProxyproxy (int i) const
 
const std::array< sk_sp< GrSurfaceProxy >, SkYUVAInfo::kMaxPlanes > & proxies () const
 
sk_sp< GrSurfaceProxyrefProxy (int i) const
 
GrSurfaceProxyView makeView (int i) const
 
bool isValid () const
 
const SkYUVAInfo::YUVALocationsyuvaLocations () const
 

Detailed Description

Definition at line 18 of file GrYUVATextureProxies.h.

Constructor & Destructor Documentation

◆ GrYUVATextureProxies() [1/5]

GrYUVATextureProxies::GrYUVATextureProxies ( )
default

◆ GrYUVATextureProxies() [2/5]

GrYUVATextureProxies::GrYUVATextureProxies ( const SkYUVAInfo yuvaInfo,
sk_sp< GrSurfaceProxy proxies[SkYUVAInfo::kMaxPlanes],
GrSurfaceOrigin  textureOrigin 
)

Assumes all planes are sampled with a default "rgba" swizzle.

Definition at line 30 of file GrYUVATextureProxies.cpp.

33 : fYUVAInfo(yuvaInfo), fTextureOrigin(textureOrigin) {
34 int n = yuvaInfo.numPlanes();
35 if (n == 0) {
36 *this = {};
37 SkASSERT(!this->isValid());
38 return;
39 }
40 uint32_t textureChannelMasks[SkYUVAInfo::kMaxPlanes];
41 for (int i = 0; i < n; ++i) {
42 if (!proxies[i]) {
43 *this = {};
44 SkASSERT(!this->isValid());
45 return;
46 }
47 textureChannelMasks[i] = proxies[i]->backendFormat().channelMask();
48 }
49 fYUVALocations = yuvaInfo.toYUVALocations(textureChannelMasks);
50 if (fYUVALocations[0].fPlane < 0) {
51 *this = {};
52 SkASSERT(!this->isValid());
53 return;
54 }
55 fMipmapped = skgpu::Mipmapped::kYes;
56 for (size_t i = 0; i < static_cast<size_t>(n); ++i) {
57 if (!proxies[i]) {
58 *this = {};
59 SkASSERT(!this->isValid());
60 return;
61 }
62 SkASSERT(proxies[i]->asTextureProxy());
63 if (proxies[i]->asTextureProxy()->mipmapped() == skgpu::Mipmapped::kNo) {
64 fMipmapped = skgpu::Mipmapped::kNo;
65 }
66 fProxies[i] = std::move(proxies[i]);
67 }
68 SkASSERT(this->isValid());
69}
#define SkASSERT(cond)
Definition: SkAssert.h:116
const SkYUVAInfo & yuvaInfo() const
const std::array< sk_sp< GrSurfaceProxy >, SkYUVAInfo::kMaxPlanes > & proxies() const
skgpu::Mipmapped mipmapped() const
GrSurfaceOrigin textureOrigin() const
int numPlanes() const
Definition: SkYUVAInfo.h:204
static constexpr int kMaxPlanes
Definition: SkYUVAInfo.h:98
YUVALocations toYUVALocations(const uint32_t *channelFlags) const
Definition: SkYUVAInfo.cpp:358

◆ GrYUVATextureProxies() [3/5]

GrYUVATextureProxies::GrYUVATextureProxies ( const SkYUVAInfo yuvaInfo,
GrSurfaceProxyView  views[SkYUVAInfo::kMaxPlanes],
GrColorType  colorTypes[SkYUVAInfo::kMaxPlanes] 
)

When uploading pixmaps to textures it is important that we account for how the original pixmaps' channels are swizzled into the texture during upload. This will compute a swizzle for each texture based on the original color types and the views' swizzles. The views must all have the same origin or the result will be an invalid GrYUVATextureProxies.

Definition at line 71 of file GrYUVATextureProxies.cpp.

74 : fYUVAInfo(yuvaInfo) {
75 uint32_t pixmapChannelMasks[SkYUVAInfo::kMaxPlanes];
76 int n = yuvaInfo.numPlanes();
77 if (n == 0) {
78 *this = {};
79 SkASSERT(!this->isValid());
80 return;
81 }
82 fMipmapped = skgpu::Mipmapped::kYes;
83 for (int i = 0; i < n; ++i) {
84 pixmapChannelMasks[i] = GrColorTypeChannelFlags(colorTypes[i]);
85 SkASSERT(num_channels(pixmapChannelMasks[i]) <=
86 num_channels(views[i].proxy()->backendFormat().channelMask()));
87 if (!views[i] || views[i].origin() != views[0].origin()) {
88 *this = {};
89 SkASSERT(!this->isValid());
90 return;
91 }
92 if (views[i].proxy()->asTextureProxy()->mipmapped() == skgpu::Mipmapped::kNo) {
93 fMipmapped = skgpu::Mipmapped::kNo;
94 }
95 }
96 // Initial locations refer to the CPU pixmap channels.
97 fYUVALocations = yuvaInfo.toYUVALocations(pixmapChannelMasks);
98 if (fYUVALocations[0].fPlane < 0) {
99 *this = {};
100 SkASSERT(!this->isValid());
101 return;
102 }
103
104 // Run each location through the proxy view's swizzle to get the actual texture format channel.
105 for (int i = 0; i < SkYUVAInfo::kYUVAChannelCount; ++i) {
106 int plane = fYUVALocations[i].fPlane;
107 if (plane >= 0) {
108 int chanAsIdx = static_cast<int>(fYUVALocations[i].fChannel);
109 switch (views[plane].swizzle()[chanAsIdx]) {
110 case 'r': fYUVALocations[i].fChannel = SkColorChannel::kR; break;
111 case 'g': fYUVALocations[i].fChannel = SkColorChannel::kG; break;
112 case 'b': fYUVALocations[i].fChannel = SkColorChannel::kB; break;
113 case 'a': fYUVALocations[i].fChannel = SkColorChannel::kA; break;
114
115 default:
116 SkDEBUGFAILF("Unexpected swizzle value: %c", views[i].swizzle()[chanAsIdx]);
117 *this = {};
118 SkASSERT(!this->isValid());
119 return;
120 }
121 }
122 }
123 for (int i = 0; i < n; ++i) {
124 fProxies[i] = views[i].detachProxy();
125 }
126 fTextureOrigin = views[0].origin();
127 SkASSERT(this->isValid());
128}
static constexpr uint32_t GrColorTypeChannelFlags(GrColorType ct)
Definition: GrTypesPriv.h:661
static int num_channels(const GrBackendFormat &format)
#define SkDEBUGFAILF(fmt,...)
Definition: SkAssert.h:119
sk_sp< GrSurfaceProxy > detachProxy()
GrSurfaceOrigin origin() const
GrSurfaceProxy * proxy(int i) const
static constexpr int kYUVAChannelCount
Definition: SkYUVAInfo.h:29

◆ GrYUVATextureProxies() [4/5]

GrYUVATextureProxies::GrYUVATextureProxies ( const GrYUVATextureProxies )
default

◆ GrYUVATextureProxies() [5/5]

GrYUVATextureProxies::GrYUVATextureProxies ( GrYUVATextureProxies &&  )
default

Member Function Documentation

◆ isValid()

bool GrYUVATextureProxies::isValid ( ) const
inline

Definition at line 64 of file GrYUVATextureProxies.h.

64{ return fYUVAInfo.isValid(); }
bool isValid() const
Definition: SkYUVAInfo.h:233

◆ makeView()

GrSurfaceProxyView GrYUVATextureProxies::makeView ( int  i) const
inline

Definition at line 60 of file GrYUVATextureProxies.h.

60 {
61 return {fProxies[i], fTextureOrigin, skgpu::Swizzle::RGBA()};
62 }
static constexpr Swizzle RGBA()
Definition: Swizzle.h:66

◆ mipmapped()

skgpu::Mipmapped GrYUVATextureProxies::mipmapped ( ) const
inline

Definition at line 50 of file GrYUVATextureProxies.h.

50{ return fMipmapped; }

◆ numPlanes()

int GrYUVATextureProxies::numPlanes ( ) const
inline

Definition at line 45 of file GrYUVATextureProxies.h.

45{ return fYUVAInfo.numPlanes(); }

◆ operator=() [1/2]

GrYUVATextureProxies & GrYUVATextureProxies::operator= ( const GrYUVATextureProxies )
default

◆ operator=() [2/2]

GrYUVATextureProxies & GrYUVATextureProxies::operator= ( GrYUVATextureProxies &&  )
default

◆ proxies()

const std::array< sk_sp< GrSurfaceProxy >, SkYUVAInfo::kMaxPlanes > & GrYUVATextureProxies::proxies ( ) const
inline

Definition at line 54 of file GrYUVATextureProxies.h.

54 {
55 return fProxies;
56 }

◆ proxy()

GrSurfaceProxy * GrYUVATextureProxies::proxy ( int  i) const
inline

Definition at line 52 of file GrYUVATextureProxies.h.

52{ return fProxies[i].get(); }

◆ refProxy()

sk_sp< GrSurfaceProxy > GrYUVATextureProxies::refProxy ( int  i) const
inline

Definition at line 58 of file GrYUVATextureProxies.h.

58{ return fProxies[i]; }

◆ textureOrigin()

GrSurfaceOrigin GrYUVATextureProxies::textureOrigin ( ) const
inline

Definition at line 47 of file GrYUVATextureProxies.h.

47{ return fTextureOrigin; }

◆ yuvaInfo()

const SkYUVAInfo & GrYUVATextureProxies::yuvaInfo ( ) const
inline

Definition at line 43 of file GrYUVATextureProxies.h.

43{ return fYUVAInfo; }

◆ yuvaLocations()

const SkYUVAInfo::YUVALocations & GrYUVATextureProxies::yuvaLocations ( ) const
inline

Definition at line 66 of file GrYUVATextureProxies.h.

66{ return fYUVALocations; }

The documentation for this class was generated from the following files: