OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkImage_Gpu.h" | 8 #include "SkImage_Gpu.h" |
9 #include "GrContext.h" | |
10 #include "GrDrawContext.h" | |
11 #include "effects/GrYUVtoRGBEffect.h" | |
9 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
10 #include "GrContext.h" | |
11 #include "SkGpuDevice.h" | 13 #include "SkGpuDevice.h" |
12 | 14 |
15 | |
13 SkImage_Gpu::SkImage_Gpu(int w, int h, SkAlphaType at, GrTexture* tex, | 16 SkImage_Gpu::SkImage_Gpu(int w, int h, SkAlphaType at, GrTexture* tex, |
14 int sampleCountForNewSurfaces, SkSurface::Budgeted budg eted) | 17 int sampleCountForNewSurfaces, SkSurface::Budgeted budg eted) |
15 : INHERITED(w, h, NULL) | 18 : INHERITED(w, h, NULL) |
16 , fTexture(SkRef(tex)) | 19 , fTexture(SkRef(tex)) |
17 , fSampleCountForNewSurfaces(sampleCountForNewSurfaces) | 20 , fSampleCountForNewSurfaces(sampleCountForNewSurfaces) |
18 , fAlphaType(at) | 21 , fAlphaType(at) |
19 , fBudgeted(budgeted) | 22 , fBudgeted(budgeted) |
20 {} | 23 {} |
21 | 24 |
22 SkSurface* SkImage_Gpu::onNewSurface(const SkImageInfo& info, const SkSurfacePro ps& props) const { | 25 SkSurface* SkImage_Gpu::onNewSurface(const SkImageInfo& info, const SkSurfacePro ps& props) const { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 } | 155 } |
153 | 156 |
154 const SkIRect srcR = SkIRect::MakeWH(dstDesc.fWidth, dstDesc.fHeight); | 157 const SkIRect srcR = SkIRect::MakeWH(dstDesc.fWidth, dstDesc.fHeight); |
155 const SkIPoint dstP = SkIPoint::Make(0, 0); | 158 const SkIPoint dstP = SkIPoint::Make(0, 0); |
156 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); | 159 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); |
157 | 160 |
158 const int sampleCount = 0; // todo: make this an explicit parameter to newS urface()? | 161 const int sampleCount = 0; // todo: make this an explicit parameter to newS urface()? |
159 return SkNEW_ARGS(SkImage_Gpu, (dstDesc.fWidth, dstDesc.fHeight, at, dst, sa mpleCount, | 162 return SkNEW_ARGS(SkImage_Gpu, (dstDesc.fWidth, dstDesc.fHeight, at, dst, sa mpleCount, |
160 budgeted)); | 163 budgeted)); |
161 } | 164 } |
165 | |
166 SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS pace, | |
167 const GrBackendObject yuvTextureHandles [3], | |
168 const SkISize yuvSizes[3], | |
169 GrSurfaceOrigin origin) { | |
170 const bool isBudgeted = true; | |
171 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; | |
172 | |
173 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || | |
174 yuvSizes[1].fWidth <= 0 || yuvSizes[1].fHeight <= 0 || | |
175 yuvSizes[2].fWidth <= 0 || yuvSizes[2].fHeight <= 0) { | |
176 return NULL; | |
177 } | |
178 static const GrPixelConfig kConfig = kAlpha_8_GrPixelConfig; | |
179 GrBackendTextureDesc yDesc; | |
180 yDesc.fConfig = kConfig; | |
181 yDesc.fOrigin = origin; | |
182 yDesc.fSampleCnt = 0; | |
183 yDesc.fTextureHandle = yuvTextureHandles[0]; | |
184 yDesc.fWidth = yuvSizes[0].fWidth; | |
185 yDesc.fHeight = yuvSizes[0].fHeight; | |
186 | |
187 GrBackendTextureDesc uDesc; | |
188 uDesc.fConfig = kConfig; | |
189 uDesc.fOrigin = origin; | |
190 uDesc.fSampleCnt = 0; | |
191 uDesc.fTextureHandle = yuvTextureHandles[1]; | |
192 uDesc.fWidth = yuvSizes[1].fWidth; | |
193 uDesc.fHeight = yuvSizes[1].fHeight; | |
194 | |
195 GrBackendTextureDesc vDesc; | |
196 vDesc.fConfig = kConfig; | |
197 vDesc.fOrigin = origin; | |
198 vDesc.fSampleCnt = 0; | |
199 vDesc.fTextureHandle = yuvTextureHandles[2]; | |
200 vDesc.fWidth = yuvSizes[2].fWidth; | |
201 vDesc.fHeight = yuvSizes[2].fHeight; | |
202 | |
203 SkAutoTUnref<GrTexture> yTex(ctx->textureProvider()->wrapBackendTexture(yDes c)); | |
204 SkAutoTUnref<GrTexture> uTex(ctx->textureProvider()->wrapBackendTexture(uDes c)); | |
205 SkAutoTUnref<GrTexture> vTex(ctx->textureProvider()->wrapBackendTexture(vDes c)); | |
206 if (!yTex || !uTex || !vTex) { | |
207 return NULL; | |
208 } | |
209 | |
210 GrSurfaceDesc dstDesc; | |
211 // Needs to be a render target in order to draw to it for the yuv->rgb conve rsion. | |
212 dstDesc.fFlags = kRenderTarget_GrSurfaceFlag; | |
213 dstDesc.fOrigin = origin; | |
214 dstDesc.fWidth = yuvSizes[0].fWidth; | |
215 dstDesc.fHeight = yuvSizes[0].fHeight; | |
216 dstDesc.fConfig = kRGBA_8888_GrPixelConfig; | |
217 dstDesc.fSampleCnt = 0; | |
218 | |
219 SkAutoTUnref<GrTexture> dst(ctx->textureProvider()->createTexture( | |
Daniele Castagna
2015/05/27 05:28:56
Should this be refScratchTexture?
We'd be requesti
bsalomon
2015/05/27 16:46:41
Yes you're right. Will fix. I want createTexture t
| |
220 dstDesc, isBud geted, NULL, 0)); | |
221 if (!dst) { | |
222 return NULL; | |
223 } | |
224 | |
225 GrPaint paint; | |
226 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | |
227 paint.addColorProcessor(GrYUVtoRGBEffect::Create(yTex, uTex, vTex, yuvSizes, | |
228 colorSpace))->unref(); | |
229 | |
230 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), | |
231 SkIntToScalar(dstDesc.fHeight)); | |
232 ctx->drawContext()->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), pain t, SkMatrix::I(), | |
233 rect); | |
234 ctx->flushSurfaceWrites(dst); | |
235 return SkNEW_ARGS(SkImage_Gpu, (dstDesc.fWidth, dstDesc.fHeight, kOpaque_SkA lphaType, dst, 0, | |
236 budgeted)); | |
237 } | |
OLD | NEW |