| 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" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 GrSurfaceDesc yuvDesc; | 91 GrSurfaceDesc yuvDesc; |
| 92 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; | 92 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; |
| 93 SkAutoTUnref<GrTexture> yuvTextures[3]; | 93 SkAutoTUnref<GrTexture> yuvTextures[3]; |
| 94 for (int i = 0; i < 3; ++i) { | 94 for (int i = 0; i < 3; ++i) { |
| 95 yuvDesc.fWidth = yuvInfo.fSize[i].fWidth; | 95 yuvDesc.fWidth = yuvInfo.fSize[i].fWidth; |
| 96 yuvDesc.fHeight = yuvInfo.fSize[i].fHeight; | 96 yuvDesc.fHeight = yuvInfo.fSize[i].fHeight; |
| 97 // TODO: why do we need this check? | 97 // TODO: why do we need this check? |
| 98 bool needsExactTexture = (yuvDesc.fWidth != yuvInfo.fSize[0].fWidth) || | 98 bool needsExactTexture = (yuvDesc.fWidth != yuvInfo.fSize[0].fWidth) || |
| 99 (yuvDesc.fHeight != yuvInfo.fSize[0].fHeight); | 99 (yuvDesc.fHeight != yuvInfo.fSize[0].fHeight); |
| 100 if (needsExactTexture) { | 100 if (needsExactTexture) { |
| 101 yuvTextures[i].reset(ctx->textureProvider()->createTexture(yuvDesc,
true)); | 101 yuvTextures[i].reset(ctx->textureProvider()->createTexture(yuvDesc,
SkBudgeted::kYes)); |
| 102 } else { | 102 } else { |
| 103 yuvTextures[i].reset(ctx->textureProvider()->createApproxTexture(yuv
Desc)); | 103 yuvTextures[i].reset(ctx->textureProvider()->createApproxTexture(yuv
Desc)); |
| 104 } | 104 } |
| 105 if (!yuvTextures[i] || | 105 if (!yuvTextures[i] || |
| 106 !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, | 106 !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, |
| 107 yuvDesc.fConfig, planes[i], yuvInfo.fRo
wBytes[i])) { | 107 yuvDesc.fConfig, planes[i], yuvInfo.fRo
wBytes[i])) { |
| 108 return nullptr; | 108 return nullptr; |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 GrSurfaceDesc rtDesc = desc; | 112 GrSurfaceDesc rtDesc = desc; |
| 113 rtDesc.fFlags = rtDesc.fFlags | kRenderTarget_GrSurfaceFlag; | 113 rtDesc.fFlags = rtDesc.fFlags | kRenderTarget_GrSurfaceFlag; |
| 114 | 114 |
| 115 SkAutoTUnref<GrTexture> result(ctx->textureProvider()->createTexture(rtDesc,
true, nullptr, 0)); | 115 SkAutoTUnref<GrTexture> result(ctx->textureProvider()->createTexture(rtDesc,
SkBudgeted::kYes, |
| 116 nullptr
, 0)); |
| 116 if (!result) { | 117 if (!result) { |
| 117 return nullptr; | 118 return nullptr; |
| 118 } | 119 } |
| 119 | 120 |
| 120 GrRenderTarget* renderTarget = result->asRenderTarget(); | 121 GrRenderTarget* renderTarget = result->asRenderTarget(); |
| 121 SkASSERT(renderTarget); | 122 SkASSERT(renderTarget); |
| 122 | 123 |
| 123 GrPaint paint; | 124 GrPaint paint; |
| 124 SkAutoTUnref<const GrFragmentProcessor> yuvToRgbProcessor( | 125 SkAutoTUnref<const GrFragmentProcessor> yuvToRgbProcessor( |
| 125 GrYUVEffect::CreateYUVToRGB(yuvTextures[
0], | 126 GrYUVEffect::CreateYUVToRGB(yuvTextures[
0], |
| 126 yuvTextures[
1], | 127 yuvTextures[
1], |
| 127 yuvTextures[
2], | 128 yuvTextures[
2], |
| 128 yuvInfo.fSiz
e, | 129 yuvInfo.fSiz
e, |
| 129 yuvInfo.fCol
orSpace)); | 130 yuvInfo.fCol
orSpace)); |
| 130 paint.addColorFragmentProcessor(yuvToRgbProcessor); | 131 paint.addColorFragmentProcessor(yuvToRgbProcessor); |
| 131 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 132 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
| 132 const SkRect r = SkRect::MakeIWH(yuvInfo.fSize[0].fWidth, yuvInfo.fSize[0].f
Height); | 133 const SkRect r = SkRect::MakeIWH(yuvInfo.fSize[0].fWidth, yuvInfo.fSize[0].f
Height); |
| 133 | 134 |
| 134 SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(renderTarget)); | 135 SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(renderTarget)); |
| 135 if (!drawContext) { | 136 if (!drawContext) { |
| 136 return nullptr; | 137 return nullptr; |
| 137 } | 138 } |
| 138 | 139 |
| 139 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), r); | 140 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), r); |
| 140 | 141 |
| 141 return result.detach(); | 142 return result.detach(); |
| 142 } | 143 } |
| 143 | 144 |
| OLD | NEW |