| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GrContext.h" | 8 #include "GrContext.h" |
| 9 #include "GrDrawContext.h" | 9 #include "GrDrawContext.h" |
| 10 #include "GrYUVProvider.h" | 10 #include "GrYUVProvider.h" |
| 11 #include "effects/GrGammaEffect.h" |
| 11 #include "effects/GrYUVEffect.h" | 12 #include "effects/GrYUVEffect.h" |
| 12 | 13 |
| 13 #include "SkCachedData.h" | 14 #include "SkCachedData.h" |
| 14 #include "SkRefCnt.h" | 15 #include "SkRefCnt.h" |
| 15 #include "SkResourceCache.h" | 16 #include "SkResourceCache.h" |
| 16 #include "SkYUVPlanesCache.h" | 17 #include "SkYUVPlanesCache.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 /** | 20 /** |
| 20 * Helper class to manage the resources used for storing the YUV planar data. D
epending on the | 21 * Helper class to manage the resources used for storing the YUV planar data. D
epending on the |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 114 } |
| 114 | 115 |
| 115 sk_sp<GrDrawContext> drawContext(ctx->newDrawContext(SkBackingFit::kExact, | 116 sk_sp<GrDrawContext> drawContext(ctx->newDrawContext(SkBackingFit::kExact, |
| 116 desc.fWidth, desc.fHeig
ht, | 117 desc.fWidth, desc.fHeig
ht, |
| 117 desc.fConfig, desc.fSam
pleCnt)); | 118 desc.fConfig, desc.fSam
pleCnt)); |
| 118 if (!drawContext) { | 119 if (!drawContext) { |
| 119 return nullptr; | 120 return nullptr; |
| 120 } | 121 } |
| 121 | 122 |
| 122 GrPaint paint; | 123 GrPaint paint; |
| 123 // We may be decoding an sRGB image, but the result of our linear math on th
e YUV planes | |
| 124 // is already in sRGB in that case. Don't convert (which will make the image
too bright). | |
| 125 paint.setDisableOutputConversionToSRGB(true); | |
| 126 SkAutoTUnref<const GrFragmentProcessor> yuvToRgbProcessor( | 124 SkAutoTUnref<const GrFragmentProcessor> yuvToRgbProcessor( |
| 127 GrYUVEffect::CreateYUVToRGB(yuvTextures[
0], | 125 GrYUVEffect::CreateYUVToRGB(yuvTextures[
0], |
| 128 yuvTextures[
1], | 126 yuvTextures[
1], |
| 129 yuvTextures[
2], | 127 yuvTextures[
2], |
| 130 yuvInfo.fSiz
eInfo.fSizes, | 128 yuvInfo.fSiz
eInfo.fSizes, |
| 131 yuvInfo.fCol
orSpace)); | 129 yuvInfo.fCol
orSpace)); |
| 132 paint.addColorFragmentProcessor(yuvToRgbProcessor); | 130 paint.addColorFragmentProcessor(yuvToRgbProcessor); |
| 131 |
| 132 // If we're decoding an sRGB image, the result of our linear math on the YUV
planes is already |
| 133 // in sRGB. (The encoding is just math on bytes, with no concept of color sp
aces.) So, we need |
| 134 // to output the results of that math directly to the buffer that we will th
en consider sRGB. |
| 135 // If we have sRGB write control, we can just tell the HW not to do the Line
ar -> sRGB step. |
| 136 // Otherwise, we do our shader math to go from YUV -> sRGB, manually convert
sRGB -> Linear, |
| 137 // then let the HW convert Linear -> sRGB. |
| 138 if (GrPixelConfigIsSRGB(desc.fConfig)) { |
| 139 if (ctx->caps()->srgbWriteControl()) { |
| 140 paint.setDisableOutputConversionToSRGB(true); |
| 141 } else { |
| 142 paint.addColorFragmentProcessor(GrGammaEffect::Create(2.2f))->unref(
); |
| 143 } |
| 144 } |
| 145 |
| 133 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 146 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
| 134 const SkRect r = SkRect::MakeIWH(yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY]
.fWidth, | 147 const SkRect r = SkRect::MakeIWH(yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY]
.fWidth, |
| 135 yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight); | 148 yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight); |
| 136 | 149 |
| 137 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), r); | 150 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), r); |
| 138 | 151 |
| 139 return drawContext->asTexture(); | 152 return drawContext->asTexture(); |
| 140 } | 153 } |
| OLD | NEW |