/src/skia/src/gpu/ganesh/GrYUVATextureProxies.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2021 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 | | #include "src/gpu/ganesh/GrYUVATextureProxies.h" |
9 | | |
10 | | #include "src/gpu/ganesh/GrTextureProxy.h" |
11 | | |
12 | | #ifdef SK_DEBUG |
13 | 0 | static int num_channels(uint32_t channelFlags) { |
14 | 0 | switch (channelFlags) { |
15 | 0 | case kRed_SkColorChannelFlag : return 1; |
16 | 0 | case kAlpha_SkColorChannelFlag : return 1; |
17 | 0 | case kGray_SkColorChannelFlag : return 1; |
18 | 0 | case kGrayAlpha_SkColorChannelFlags : return 2; |
19 | 0 | case kRG_SkColorChannelFlags : return 2; |
20 | 0 | case kRGB_SkColorChannelFlags : return 3; |
21 | 0 | case kRGBA_SkColorChannelFlags : return 4; |
22 | | |
23 | 0 | default: |
24 | 0 | SkDEBUGFAILF("Unexpected channel combination 0x%08x", channelFlags); |
25 | 0 | return 0; |
26 | 0 | } |
27 | 0 | } |
28 | | #endif |
29 | | |
30 | | GrYUVATextureProxies::GrYUVATextureProxies(const SkYUVAInfo& yuvaInfo, |
31 | | sk_sp<GrSurfaceProxy> proxies[SkYUVAInfo::kMaxPlanes], |
32 | | GrSurfaceOrigin textureOrigin) |
33 | 0 | : fYUVAInfo(yuvaInfo), fTextureOrigin(textureOrigin) { |
34 | 0 | int n = yuvaInfo.numPlanes(); |
35 | 0 | if (n == 0) { |
36 | 0 | *this = {}; |
37 | 0 | SkASSERT(!this->isValid()); |
38 | 0 | return; |
39 | 0 | } |
40 | 0 | uint32_t textureChannelMasks[SkYUVAInfo::kMaxPlanes]; |
41 | 0 | for (int i = 0; i < n; ++i) { |
42 | 0 | if (!proxies[i]) { |
43 | 0 | *this = {}; |
44 | 0 | SkASSERT(!this->isValid()); |
45 | 0 | return; |
46 | 0 | } |
47 | 0 | textureChannelMasks[i] = proxies[i]->backendFormat().channelMask(); |
48 | 0 | } |
49 | 0 | fYUVALocations = yuvaInfo.toYUVALocations(textureChannelMasks); |
50 | 0 | if (fYUVALocations[0].fPlane < 0) { |
51 | 0 | *this = {}; |
52 | 0 | SkASSERT(!this->isValid()); |
53 | 0 | return; |
54 | 0 | } |
55 | 0 | fMipmapped = skgpu::Mipmapped::kYes; |
56 | 0 | for (size_t i = 0; i < static_cast<size_t>(n); ++i) { |
57 | 0 | if (!proxies[i]) { |
58 | 0 | *this = {}; |
59 | 0 | SkASSERT(!this->isValid()); |
60 | 0 | return; |
61 | 0 | } |
62 | 0 | SkASSERT(proxies[i]->asTextureProxy()); |
63 | 0 | if (proxies[i]->asTextureProxy()->mipmapped() == skgpu::Mipmapped::kNo) { |
64 | 0 | fMipmapped = skgpu::Mipmapped::kNo; |
65 | 0 | } |
66 | 0 | fProxies[i] = std::move(proxies[i]); |
67 | 0 | } |
68 | 0 | SkASSERT(this->isValid()); |
69 | 0 | } Unexecuted instantiation: GrYUVATextureProxies::GrYUVATextureProxies(SkYUVAInfo const&, sk_sp<GrSurfaceProxy>*, GrSurfaceOrigin) Unexecuted instantiation: GrYUVATextureProxies::GrYUVATextureProxies(SkYUVAInfo const&, sk_sp<GrSurfaceProxy>*, GrSurfaceOrigin) |
70 | | |
71 | | GrYUVATextureProxies::GrYUVATextureProxies(const SkYUVAInfo& yuvaInfo, |
72 | | GrSurfaceProxyView views[SkYUVAInfo::kMaxPlanes], |
73 | | GrColorType colorTypes[SkYUVAInfo::kMaxPlanes]) |
74 | 0 | : fYUVAInfo(yuvaInfo) { |
75 | 0 | uint32_t pixmapChannelMasks[SkYUVAInfo::kMaxPlanes]; |
76 | 0 | int n = yuvaInfo.numPlanes(); |
77 | 0 | if (n == 0) { |
78 | 0 | *this = {}; |
79 | 0 | SkASSERT(!this->isValid()); |
80 | 0 | return; |
81 | 0 | } |
82 | 0 | fMipmapped = skgpu::Mipmapped::kYes; |
83 | 0 | for (int i = 0; i < n; ++i) { |
84 | 0 | pixmapChannelMasks[i] = GrColorTypeChannelFlags(colorTypes[i]); |
85 | 0 | SkASSERT(num_channels(pixmapChannelMasks[i]) <= |
86 | 0 | num_channels(views[i].proxy()->backendFormat().channelMask())); |
87 | 0 | if (!views[i] || views[i].origin() != views[0].origin()) { |
88 | 0 | *this = {}; |
89 | 0 | SkASSERT(!this->isValid()); |
90 | 0 | return; |
91 | 0 | } |
92 | 0 | if (views[i].proxy()->asTextureProxy()->mipmapped() == skgpu::Mipmapped::kNo) { |
93 | 0 | fMipmapped = skgpu::Mipmapped::kNo; |
94 | 0 | } |
95 | 0 | } |
96 | | // Initial locations refer to the CPU pixmap channels. |
97 | 0 | fYUVALocations = yuvaInfo.toYUVALocations(pixmapChannelMasks); |
98 | 0 | if (fYUVALocations[0].fPlane < 0) { |
99 | 0 | *this = {}; |
100 | 0 | SkASSERT(!this->isValid()); |
101 | 0 | return; |
102 | 0 | } |
103 | | |
104 | | // Run each location through the proxy view's swizzle to get the actual texture format channel. |
105 | 0 | for (int i = 0; i < SkYUVAInfo::kYUVAChannelCount; ++i) { |
106 | 0 | int plane = fYUVALocations[i].fPlane; |
107 | 0 | if (plane >= 0) { |
108 | 0 | int chanAsIdx = static_cast<int>(fYUVALocations[i].fChannel); |
109 | 0 | switch (views[plane].swizzle()[chanAsIdx]) { |
110 | 0 | case 'r': fYUVALocations[i].fChannel = SkColorChannel::kR; break; |
111 | 0 | case 'g': fYUVALocations[i].fChannel = SkColorChannel::kG; break; |
112 | 0 | case 'b': fYUVALocations[i].fChannel = SkColorChannel::kB; break; |
113 | 0 | case 'a': fYUVALocations[i].fChannel = SkColorChannel::kA; break; |
114 | | |
115 | 0 | default: |
116 | 0 | SkDEBUGFAILF("Unexpected swizzle value: %c", views[i].swizzle()[chanAsIdx]); |
117 | 0 | *this = {}; |
118 | 0 | SkASSERT(!this->isValid()); |
119 | 0 | return; |
120 | 0 | } |
121 | 0 | } |
122 | 0 | } |
123 | 0 | for (int i = 0; i < n; ++i) { |
124 | 0 | fProxies[i] = views[i].detachProxy(); |
125 | 0 | } |
126 | 0 | fTextureOrigin = views[0].origin(); |
127 | 0 | SkASSERT(this->isValid()); |
128 | 0 | } Unexecuted instantiation: GrYUVATextureProxies::GrYUVATextureProxies(SkYUVAInfo const&, GrSurfaceProxyView*, GrColorType*) Unexecuted instantiation: GrYUVATextureProxies::GrYUVATextureProxies(SkYUVAInfo const&, GrSurfaceProxyView*, GrColorType*) |