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

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

Issue 2041113004: sk_sp for gpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Reserve correctly. Created 4 years, 6 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/GrTextureParamsAdjuster.cpp ('k') | src/gpu/GrYUVProvider.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 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"
11 #include "GrClip.h" 11 #include "GrClip.h"
12 #include "GrContext.h" 12 #include "GrContext.h"
13 #include "GrDrawContext.h" 13 #include "GrDrawContext.h"
14 #include "GrPaint.h" 14 #include "GrPaint.h"
15 #include "GrTextureProvider.h" 15 #include "GrTextureProvider.h"
16 16
17 namespace { 17 namespace {
18 using CreateFPProc = const GrFragmentProcessor* (*)(const GrFragmentProcesso r*, 18 using MakeFPProc = sk_sp<GrFragmentProcessor> (*)(sk_sp<GrFragmentProcessor> ,
19 SkYUVColorSpace colorSpa ce); 19 SkYUVColorSpace colorSpace );
20 }; 20 };
21 21
22 static bool convert_texture(GrTexture* src, GrDrawContext* dst, int dstW, int ds tH, 22 static bool convert_texture(GrTexture* src, GrDrawContext* dst, int dstW, int ds tH,
23 SkYUVColorSpace colorSpace, CreateFPProc proc) { 23 SkYUVColorSpace colorSpace, MakeFPProc proc) {
24 24
25 SkScalar xScale = SkIntToScalar(src->width()) / dstW / src->width(); 25 SkScalar xScale = SkIntToScalar(src->width()) / dstW / src->width();
26 SkScalar yScale = SkIntToScalar(src->height()) / dstH / src->height(); 26 SkScalar yScale = SkIntToScalar(src->height()) / dstH / src->height();
27 GrTextureParams::FilterMode filter; 27 GrTextureParams::FilterMode filter;
28 if (dstW == src->width() && dstW == src->height()) { 28 if (dstW == src->width() && dstW == src->height()) {
29 filter = GrTextureParams::kNone_FilterMode; 29 filter = GrTextureParams::kNone_FilterMode;
30 } else { 30 } else {
31 filter = GrTextureParams::kBilerp_FilterMode; 31 filter = GrTextureParams::kBilerp_FilterMode;
32 } 32 }
33 33
34 SkAutoTUnref<const GrFragmentProcessor> fp( 34 sk_sp<GrFragmentProcessor> fp(
35 GrSimpleTextureEffect::Create(src, SkMatrix::MakeScale(xScale, yScal e), filter)); 35 GrSimpleTextureEffect::Make(src, SkMatrix::MakeScale(xScale, yScale) , filter));
36 if (!fp) { 36 if (!fp) {
37 return false; 37 return false;
38 } 38 }
39 fp.reset(proc(fp, colorSpace)); 39 fp = proc(std::move(fp), colorSpace);
40 if (!fp) { 40 if (!fp) {
41 return false; 41 return false;
42 } 42 }
43 GrPaint paint; 43 GrPaint paint;
44 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); 44 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
45 paint.addColorFragmentProcessor(fp); 45 paint.addColorFragmentProcessor(std::move(fp));
46 dst->drawRect(GrNoClip(), paint, SkMatrix::I(), SkRect::MakeIWH(dstW, dstH)) ; 46 dst->drawRect(GrNoClip(), paint, SkMatrix::I(), SkRect::MakeIWH(dstW, dstH)) ;
47 return true; 47 return true;
48 } 48 }
49 49
50 bool GrTextureToYUVPlanes(GrTexture* texture, const SkISize sizes[3], void* cons t planes[3], 50 bool GrTextureToYUVPlanes(GrTexture* texture, const SkISize sizes[3], void* cons t planes[3],
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;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 if (!uDrawContext || !vDrawContext) { 100 if (!uDrawContext || !vDrawContext) {
101 return false; 101 return false;
102 } 102 }
103 } 103 }
104 } 104 }
105 105
106 // Do all the draws before any readback. 106 // Do all the draws before any readback.
107 if (yuvDrawContext) { 107 if (yuvDrawContext) {
108 if (!convert_texture(texture, yuvDrawContext.get(), 108 if (!convert_texture(texture, yuvDrawContext.get(),
109 sizes[0].fWidth, sizes[0].fHeight, 109 sizes[0].fWidth, sizes[0].fHeight,
110 colorSpace, GrYUVEffect::CreateRGBToYUV)) { 110 colorSpace, GrYUVEffect::MakeRGBToYUV)) {
111 return false; 111 return false;
112 } 112 }
113 } else { 113 } else {
114 SkASSERT(yDrawContext); 114 SkASSERT(yDrawContext);
115 if (!convert_texture(texture, yDrawContext.get(), 115 if (!convert_texture(texture, yDrawContext.get(),
116 sizes[0].fWidth, sizes[0].fHeight, 116 sizes[0].fWidth, sizes[0].fHeight,
117 colorSpace, GrYUVEffect::CreateRGBToY)) { 117 colorSpace, GrYUVEffect::MakeRGBToY)) {
118 return false; 118 return false;
119 } 119 }
120 if (uvDrawContext) { 120 if (uvDrawContext) {
121 if (!convert_texture(texture, uvDrawContext.get(), 121 if (!convert_texture(texture, uvDrawContext.get(),
122 sizes[1].fWidth, sizes[1].fHeight, 122 sizes[1].fWidth, sizes[1].fHeight,
123 colorSpace, GrYUVEffect::CreateRGBToUV)) { 123 colorSpace, GrYUVEffect::MakeRGBToUV)) {
124 return false; 124 return false;
125 } 125 }
126 } else { 126 } else {
127 SkASSERT(uDrawContext && vDrawContext); 127 SkASSERT(uDrawContext && vDrawContext);
128 if (!convert_texture(texture, uDrawContext.get(), 128 if (!convert_texture(texture, uDrawContext.get(),
129 sizes[1].fWidth, sizes[1].fHeight, 129 sizes[1].fWidth, sizes[1].fHeight,
130 colorSpace, GrYUVEffect::CreateRGBToU)) { 130 colorSpace, GrYUVEffect::MakeRGBToU)) {
131 return false; 131 return false;
132 } 132 }
133 if (!convert_texture(texture, vDrawContext.get(), 133 if (!convert_texture(texture, vDrawContext.get(),
134 sizes[2].fWidth, sizes[2].fHeight, 134 sizes[2].fWidth, sizes[2].fHeight,
135 colorSpace, GrYUVEffect::CreateRGBToV)) { 135 colorSpace, GrYUVEffect::MakeRGBToV)) {
136 return false; 136 return false;
137 } 137 }
138 } 138 }
139 } 139 }
140 140
141 if (yuvDrawContext) { 141 if (yuvDrawContext) {
142 SkASSERT(sizes[0] == sizes[1] && sizes[1] == sizes[2]); 142 SkASSERT(sizes[0] == sizes[1] && sizes[1] == sizes[2]);
143 sk_sp<GrTexture> yuvTex(yuvDrawContext->asTexture()); 143 sk_sp<GrTexture> yuvTex(yuvDrawContext->asTexture());
144 SkASSERT(yuvTex); 144 SkASSERT(yuvTex);
145 SkISize yuvSize = sizes[0]; 145 SkISize yuvSize = sizes[0];
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 if (!tex->readPixels(0, 0, sizes[2].fWidth, sizes[2].fHeight, 221 if (!tex->readPixels(0, 0, sizes[2].fWidth, sizes[2].fHeight,
222 kAlpha_8_GrPixelConfig, planes[2], rowBytes [2])) { 222 kAlpha_8_GrPixelConfig, planes[2], rowBytes [2])) {
223 return false; 223 return false;
224 } 224 }
225 return true; 225 return true;
226 } 226 }
227 } 227 }
228 } 228 }
229 return false; 229 return false;
230 } 230 }
OLDNEW
« no previous file with comments | « src/gpu/GrTextureParamsAdjuster.cpp ('k') | src/gpu/GrYUVProvider.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698