| 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->makeDrawContext(SkBackingFit::kApprox, |
| 73 sizes[0].fWidth, sizes[0].
fHeight, | 66 sizes[0].fWidth, sizes[0].
fHeight, |
| 74 kRGBA_8888_GrPixelConfig,
nullptr); | 67 kRGBA_8888_GrPixelConfig,
nullptr); |
| 75 if (!yuvDrawContext) { | 68 if (!yuvDrawContext) { |
| 76 return false; | 69 return false; |
| 77 } | 70 } |
| 78 } else { | 71 } else { |
| 79 yDrawContext = context->makeDrawContext(SkBackingFit::kApprox, | 72 yDrawContext = context->makeDrawContext(SkBackingFit::kApprox, |
| 80 sizes[0].fWidth, sizes[0].fH
eight, | 73 sizes[0].fWidth, sizes[0].fH
eight, |
| 81 singleChannelPixelConfig, nu
llptr); | 74 kAlpha_8_GrPixelConfig, null
ptr); |
| 82 if (!yDrawContext) { | 75 if (!yDrawContext) { |
| 83 return false; | 76 return false; |
| 84 } | 77 } |
| 85 if (sizes[1] == sizes[2]) { | 78 if (sizes[1] == sizes[2]) { |
| 86 // TODO: Add support for GL_RG when available. | 79 // TODO: Add support for GL_RG when available. |
| 87 uvDrawContext = context->makeDrawContext(SkBackingFit::kApprox, | 80 uvDrawContext = context->makeDrawContext(SkBackingFit::kApprox, |
| 88 sizes[1].fWidth, sizes[
1].fHeight, | 81 sizes[1].fWidth, sizes[
1].fHeight, |
| 89 kRGBA_8888_GrPixelConfi
g, nullptr); | 82 kRGBA_8888_GrPixelConfi
g, nullptr); |
| 90 if (!uvDrawContext) { | 83 if (!uvDrawContext) { |
| 91 return false; | 84 return false; |
| 92 } | 85 } |
| 93 } else { | 86 } else { |
| 94 uDrawContext = context->makeDrawContext(SkBackingFit::kApprox, | 87 uDrawContext = context->makeDrawContext(SkBackingFit::kApprox, |
| 95 sizes[1].fWidth, sizes[1
].fHeight, | 88 sizes[1].fWidth, sizes[1
].fHeight, |
| 96 singleChannelPixelConfig
, nullptr); | 89 kAlpha_8_GrPixelConfig,
nullptr); |
| 97 vDrawContext = context->makeDrawContext(SkBackingFit::kApprox, | 90 vDrawContext = context->makeDrawContext(SkBackingFit::kApprox, |
| 98 sizes[2].fWidth, sizes[2
].fHeight, | 91 sizes[2].fWidth, sizes[2
].fHeight, |
| 99 singleChannelPixelConfig
, nullptr); | 92 kAlpha_8_GrPixelConfig,
nullptr); |
| 100 if (!uDrawContext || !vDrawContext) { | 93 if (!uDrawContext || !vDrawContext) { |
| 101 return false; | 94 return false; |
| 102 } | 95 } |
| 103 } | 96 } |
| 104 } | 97 } |
| 105 | 98 |
| 106 // Do all the draws before any readback. | 99 // Do all the draws before any readback. |
| 107 if (yuvDrawContext) { | 100 if (yuvDrawContext) { |
| 108 if (!convert_texture(texture, yuvDrawContext.get(), | 101 if (!convert_texture(texture, yuvDrawContext.get(), |
| 109 sizes[0].fWidth, sizes[0].fHeight, | 102 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, | 214 if (!tex->readPixels(0, 0, sizes[2].fWidth, sizes[2].fHeight, |
| 222 kAlpha_8_GrPixelConfig, planes[2], rowBytes
[2])) { | 215 kAlpha_8_GrPixelConfig, planes[2], rowBytes
[2])) { |
| 223 return false; | 216 return false; |
| 224 } | 217 } |
| 225 return true; | 218 return true; |
| 226 } | 219 } |
| 227 } | 220 } |
| 228 } | 221 } |
| 229 return false; | 222 return false; |
| 230 } | 223 } |
| OLD | NEW |