| 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 SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; | 
|  | 171 | 
|  | 172     if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || | 
|  | 173         yuvSizes[1].fWidth <= 0 || yuvSizes[1].fHeight <= 0 || | 
|  | 174         yuvSizes[2].fWidth <= 0 || yuvSizes[2].fHeight <= 0) { | 
|  | 175         return NULL; | 
|  | 176     } | 
|  | 177     static const GrPixelConfig kConfig = kAlpha_8_GrPixelConfig; | 
|  | 178     GrBackendTextureDesc yDesc; | 
|  | 179     yDesc.fConfig = kConfig; | 
|  | 180     yDesc.fOrigin = origin; | 
|  | 181     yDesc.fSampleCnt = 0; | 
|  | 182     yDesc.fTextureHandle = yuvTextureHandles[0]; | 
|  | 183     yDesc.fWidth = yuvSizes[0].fWidth; | 
|  | 184     yDesc.fHeight = yuvSizes[0].fHeight; | 
|  | 185 | 
|  | 186     GrBackendTextureDesc uDesc; | 
|  | 187     uDesc.fConfig = kConfig; | 
|  | 188     uDesc.fOrigin = origin; | 
|  | 189     uDesc.fSampleCnt = 0; | 
|  | 190     uDesc.fTextureHandle = yuvTextureHandles[1]; | 
|  | 191     uDesc.fWidth = yuvSizes[1].fWidth; | 
|  | 192     uDesc.fHeight = yuvSizes[1].fHeight; | 
|  | 193 | 
|  | 194     GrBackendTextureDesc vDesc; | 
|  | 195     vDesc.fConfig = kConfig; | 
|  | 196     vDesc.fOrigin = origin; | 
|  | 197     vDesc.fSampleCnt = 0; | 
|  | 198     vDesc.fTextureHandle = yuvTextureHandles[2]; | 
|  | 199     vDesc.fWidth = yuvSizes[2].fWidth; | 
|  | 200     vDesc.fHeight = yuvSizes[2].fHeight; | 
|  | 201 | 
|  | 202     SkAutoTUnref<GrTexture> yTex(ctx->textureProvider()->wrapBackendTexture(yDes
     c)); | 
|  | 203     SkAutoTUnref<GrTexture> uTex(ctx->textureProvider()->wrapBackendTexture(uDes
     c)); | 
|  | 204     SkAutoTUnref<GrTexture> vTex(ctx->textureProvider()->wrapBackendTexture(vDes
     c)); | 
|  | 205     if (!yTex || !uTex || !vTex) { | 
|  | 206         return NULL; | 
|  | 207     } | 
|  | 208 | 
|  | 209     GrSurfaceDesc dstDesc; | 
|  | 210     // Needs to be a render target in order to draw to it for the yuv->rgb conve
     rsion. | 
|  | 211     dstDesc.fFlags = kRenderTarget_GrSurfaceFlag; | 
|  | 212     dstDesc.fOrigin = origin; | 
|  | 213     dstDesc.fWidth = yuvSizes[0].fWidth; | 
|  | 214     dstDesc.fHeight = yuvSizes[0].fHeight; | 
|  | 215     dstDesc.fConfig = kRGBA_8888_GrPixelConfig; | 
|  | 216     dstDesc.fSampleCnt = 0; | 
|  | 217 | 
|  | 218     SkAutoTUnref<GrTexture> dst(ctx->textureProvider()->refScratchTexture( | 
|  | 219         dstDesc, GrTextureProvider::kExact_ScratchTexMatch)); | 
|  | 220     if (!dst) { | 
|  | 221         return NULL; | 
|  | 222     } | 
|  | 223 | 
|  | 224     GrPaint paint; | 
|  | 225     paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 
|  | 226     paint.addColorProcessor(GrYUVtoRGBEffect::Create(yTex, uTex, vTex, yuvSizes, | 
|  | 227                                                      colorSpace))->unref(); | 
|  | 228 | 
|  | 229     const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), | 
|  | 230                                        SkIntToScalar(dstDesc.fHeight)); | 
|  | 231     ctx->drawContext()->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), pain
     t, SkMatrix::I(), | 
|  | 232                                  rect); | 
|  | 233     ctx->flushSurfaceWrites(dst); | 
|  | 234     return SkNEW_ARGS(SkImage_Gpu, (dstDesc.fWidth, dstDesc.fHeight, kOpaque_SkA
     lphaType, dst, 0, | 
|  | 235                                     budgeted)); | 
|  | 236 } | 
| OLD | NEW | 
|---|