OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrTextureToYUVPlanes.h" | 8 #include "GrTextureToYUVPlanes.h" |
9 #include "effects/GrSimpleTextureEffect.h" | 9 #include "effects/GrSimpleTextureEffect.h" |
10 #include "effects/GrYUVEffect.h" | 10 #include "effects/GrYUVEffect.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 const size_t rowBytes[3], SkYUVColorSpace colorSpace)
{ | 51 const size_t rowBytes[3], SkYUVColorSpace colorSpace)
{ |
52 if (GrContext* context = texture->getContext()) { | 52 if (GrContext* context = texture->getContext()) { |
53 // Depending on the relative sizes of the y, u, and v planes we may do 1
to 3 draws/ | 53 // Depending on the relative sizes of the y, u, and v planes we may do 1
to 3 draws/ |
54 // readbacks. | 54 // readbacks. |
55 sk_sp<GrDrawContext> yuvDrawContext; | 55 sk_sp<GrDrawContext> yuvDrawContext; |
56 sk_sp<GrDrawContext> yDrawContext; | 56 sk_sp<GrDrawContext> yDrawContext; |
57 sk_sp<GrDrawContext> uvDrawContext; | 57 sk_sp<GrDrawContext> uvDrawContext; |
58 sk_sp<GrDrawContext> uDrawContext; | 58 sk_sp<GrDrawContext> uDrawContext; |
59 sk_sp<GrDrawContext> vDrawContext; | 59 sk_sp<GrDrawContext> vDrawContext; |
60 | 60 |
61 GrPixelConfig singleChannelPixelConfig; | |
62 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false))
{ | |
63 singleChannelPixelConfig = kAlpha_8_GrPixelConfig; | |
64 } else { | |
65 singleChannelPixelConfig = kRGBA_8888_GrPixelConfig; | |
66 } | |
67 | |
68 // We issue draw(s) to convert from RGBA to Y, U, and V. All three plane
s may have different | 61 // We issue draw(s) to convert from RGBA to Y, U, and V. All three plane
s may have different |
69 // sizes however we optimize for two other cases - all planes are the sa
me (1 draw to YUV), | 62 // sizes however we optimize for two other cases - all planes are the sa
me (1 draw to YUV), |
70 // and U and V are the same but Y differs (2 draws, one for Y, one for U
V). | 63 // and U and V are the same but Y differs (2 draws, one for Y, one for U
V). |
71 if (sizes[0] == sizes[1] && sizes[1] == sizes[2]) { | 64 if (sizes[0] == sizes[1] && sizes[1] == sizes[2]) { |
72 yuvDrawContext = context->makeDrawContext(SkBackingFit::kApprox, | 65 yuvDrawContext = context->makeDrawContextWithFallback(SkBackingFit::
kApprox, |
73 sizes[0].fWidth, sizes[0].
fHeight, | 66 sizes[0].fWidt
h, |
74 kRGBA_8888_GrPixelConfig,
nullptr); | 67 sizes[0].fHeig
ht, |
| 68 kRGBA_8888_GrP
ixelConfig, |
| 69 nullptr); |
75 if (!yuvDrawContext) { | 70 if (!yuvDrawContext) { |
76 return false; | 71 return false; |
77 } | 72 } |
78 } else { | 73 } else { |
79 yDrawContext = context->makeDrawContext(SkBackingFit::kApprox, | 74 yDrawContext = context->makeDrawContextWithFallback(SkBackingFit::kA
pprox, |
80 sizes[0].fWidth, sizes[0].fH
eight, | 75 sizes[0].fWidth, |
81 singleChannelPixelConfig, nu
llptr); | 76 sizes[0].fHeight
, |
| 77 kAlpha_8_GrPixel
Config, |
| 78 nullptr); |
82 if (!yDrawContext) { | 79 if (!yDrawContext) { |
83 return false; | 80 return false; |
84 } | 81 } |
85 if (sizes[1] == sizes[2]) { | 82 if (sizes[1] == sizes[2]) { |
86 // TODO: Add support for GL_RG when available. | 83 // TODO: Add support for GL_RG when available. |
87 uvDrawContext = context->makeDrawContext(SkBackingFit::kApprox, | 84 uvDrawContext = context->makeDrawContextWithFallback(SkBackingFi
t::kApprox, |
88 sizes[1].fWidth, sizes[
1].fHeight, | 85 sizes[1].fW
idth, |
89 kRGBA_8888_GrPixelConfi
g, nullptr); | 86 sizes[1].fH
eight, |
| 87 kRGBA_8888_
GrPixelConfig, |
| 88 nullptr); |
90 if (!uvDrawContext) { | 89 if (!uvDrawContext) { |
91 return false; | 90 return false; |
92 } | 91 } |
93 } else { | 92 } else { |
94 uDrawContext = context->makeDrawContext(SkBackingFit::kApprox, | 93 uDrawContext = context->makeDrawContextWithFallback(SkBackingFit
::kApprox, |
95 sizes[1].fWidth, sizes[1
].fHeight, | 94 sizes[1].fWi
dth, |
96 singleChannelPixelConfig
, nullptr); | 95 sizes[1].fHe
ight, |
97 vDrawContext = context->makeDrawContext(SkBackingFit::kApprox, | 96 kAlpha_8_GrP
ixelConfig, |
98 sizes[2].fWidth, sizes[2
].fHeight, | 97 nullptr); |
99 singleChannelPixelConfig
, nullptr); | 98 vDrawContext = context->makeDrawContextWithFallback(SkBackingFit
::kApprox, |
| 99 sizes[2].fWi
dth, |
| 100 sizes[2].fHe
ight, |
| 101 kAlpha_8_GrP
ixelConfig, |
| 102 nullptr); |
100 if (!uDrawContext || !vDrawContext) { | 103 if (!uDrawContext || !vDrawContext) { |
101 return false; | 104 return false; |
102 } | 105 } |
103 } | 106 } |
104 } | 107 } |
105 | 108 |
106 // Do all the draws before any readback. | 109 // Do all the draws before any readback. |
107 if (yuvDrawContext) { | 110 if (yuvDrawContext) { |
108 if (!convert_texture(texture, yuvDrawContext.get(), | 111 if (!convert_texture(texture, yuvDrawContext.get(), |
109 sizes[0].fWidth, sizes[0].fHeight, | 112 sizes[0].fWidth, sizes[0].fHeight, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 if (!tex->readPixels(0, 0, sizes[2].fWidth, sizes[2].fHeight, | 224 if (!tex->readPixels(0, 0, sizes[2].fWidth, sizes[2].fHeight, |
222 kAlpha_8_GrPixelConfig, planes[2], rowBytes
[2])) { | 225 kAlpha_8_GrPixelConfig, planes[2], rowBytes
[2])) { |
223 return false; | 226 return false; |
224 } | 227 } |
225 return true; | 228 return true; |
226 } | 229 } |
227 } | 230 } |
228 } | 231 } |
229 return false; | 232 return false; |
230 } | 233 } |
OLD | NEW |