Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: src/gpu/GrYUVProvider.cpp

Issue 1967743003: Minor GrRenderTarget retraction (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more clean up Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrYUVProvider.h ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 73 }
74 74
75 if (useCache) { 75 if (useCache) {
76 // Decoding is done, cache the resulting YUV planes 76 // Decoding is done, cache the resulting YUV planes
77 SkYUVPlanesCache::Add(provider->onGetID(), fCachedData, yuvInfo); 77 SkYUVPlanesCache::Add(provider->onGetID(), fCachedData, yuvInfo);
78 } 78 }
79 } 79 }
80 return true; 80 return true;
81 } 81 }
82 82
83 GrTexture* GrYUVProvider::refAsTexture(GrContext* ctx, const GrSurfaceDesc& desc , bool useCache) { 83 sk_sp<GrTexture> GrYUVProvider::refAsTexture(GrContext* ctx,
84 const GrSurfaceDesc& desc,
85 bool useCache) {
84 SkYUVPlanesCache::Info yuvInfo; 86 SkYUVPlanesCache::Info yuvInfo;
85 void* planes[3]; 87 void* planes[3];
86 YUVScoper scoper; 88 YUVScoper scoper;
87 if (!scoper.init(this, &yuvInfo, planes, useCache)) { 89 if (!scoper.init(this, &yuvInfo, planes, useCache)) {
88 return nullptr; 90 return nullptr;
89 } 91 }
90 92
91 GrSurfaceDesc yuvDesc; 93 GrSurfaceDesc yuvDesc;
92 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; 94 yuvDesc.fConfig = kAlpha_8_GrPixelConfig;
93 SkAutoTUnref<GrTexture> yuvTextures[3]; 95 SkAutoTUnref<GrTexture> yuvTextures[3];
94 for (int i = 0; i < 3; i++) { 96 for (int i = 0; i < 3; i++) {
95 yuvDesc.fWidth = yuvInfo.fSizeInfo.fSizes[i].fWidth; 97 yuvDesc.fWidth = yuvInfo.fSizeInfo.fSizes[i].fWidth;
96 yuvDesc.fHeight = yuvInfo.fSizeInfo.fSizes[i].fHeight; 98 yuvDesc.fHeight = yuvInfo.fSizeInfo.fSizes[i].fHeight;
97 // TODO: why do we need this check? 99 // TODO: why do we need this check?
98 bool needsExactTexture = 100 bool needsExactTexture =
99 (yuvDesc.fWidth != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY]. fWidth) || 101 (yuvDesc.fWidth != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY]. fWidth) ||
100 (yuvDesc.fHeight != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY]. fHeight); 102 (yuvDesc.fHeight != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY]. fHeight);
101 if (needsExactTexture) { 103 if (needsExactTexture) {
102 yuvTextures[i].reset(ctx->textureProvider()->createTexture(yuvDesc, SkBudgeted::kYes)); 104 yuvTextures[i].reset(ctx->textureProvider()->createTexture(yuvDesc, SkBudgeted::kYes));
103 } else { 105 } else {
104 yuvTextures[i].reset(ctx->textureProvider()->createApproxTexture(yuv Desc)); 106 yuvTextures[i].reset(ctx->textureProvider()->createApproxTexture(yuv Desc));
105 } 107 }
106 if (!yuvTextures[i] || 108 if (!yuvTextures[i] ||
107 !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, yuvDesc.fConfig, 109 !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, yuvDesc.fConfig,
108 planes[i], yuvInfo.fSizeInfo.fWidthByte s[i])) { 110 planes[i], yuvInfo.fSizeInfo.fWidthByte s[i])) {
109 return nullptr; 111 return nullptr;
110 } 112 }
111 } 113 }
112 114
113 GrSurfaceDesc rtDesc = desc; 115 sk_sp<GrDrawContext> drawContext(ctx->newDrawContext(SkBackingFit::kExact,
114 rtDesc.fFlags = rtDesc.fFlags | kRenderTarget_GrSurfaceFlag; 116 desc.fWidth, desc.fHeig ht,
115 117 desc.fConfig, desc.fSam pleCnt));
116 SkAutoTUnref<GrTexture> result(ctx->textureProvider()->createTexture(rtDesc, SkBudgeted::kYes, 118 if (!drawContext) {
117 nullptr , 0));
118 if (!result) {
119 return nullptr; 119 return nullptr;
120 } 120 }
121 121
122 GrRenderTarget* renderTarget = result->asRenderTarget();
123 SkASSERT(renderTarget);
124
125 GrPaint paint; 122 GrPaint paint;
126 // We may be decoding an sRGB image, but the result of our linear math on th e YUV planes 123 // We may be decoding an sRGB image, but the result of our linear math on th e YUV planes
127 // is already in sRGB in that case. Don't convert (which will make the image too bright). 124 // is already in sRGB in that case. Don't convert (which will make the image too bright).
128 paint.setDisableOutputConversionToSRGB(true); 125 paint.setDisableOutputConversionToSRGB(true);
129 SkAutoTUnref<const GrFragmentProcessor> yuvToRgbProcessor( 126 SkAutoTUnref<const GrFragmentProcessor> yuvToRgbProcessor(
130 GrYUVEffect::CreateYUVToRGB(yuvTextures[ 0], 127 GrYUVEffect::CreateYUVToRGB(yuvTextures[ 0],
131 yuvTextures[ 1], 128 yuvTextures[ 1],
132 yuvTextures[ 2], 129 yuvTextures[ 2],
133 yuvInfo.fSiz eInfo.fSizes, 130 yuvInfo.fSiz eInfo.fSizes,
134 yuvInfo.fCol orSpace)); 131 yuvInfo.fCol orSpace));
135 paint.addColorFragmentProcessor(yuvToRgbProcessor); 132 paint.addColorFragmentProcessor(yuvToRgbProcessor);
136 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); 133 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
137 const SkRect r = SkRect::MakeIWH(yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY] .fWidth, 134 const SkRect r = SkRect::MakeIWH(yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY] .fWidth,
138 yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight); 135 yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight);
139 136
140 sk_sp<GrDrawContext> drawContext(ctx->drawContext(sk_ref_sp(renderTarget)));
141 if (!drawContext) {
142 return nullptr;
143 }
144
145 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), r); 137 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), r);
146 138
147 return result.release(); 139 return drawContext->asTexture();
148 } 140 }
OLDNEW
« no previous file with comments | « src/gpu/GrYUVProvider.h ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698