| 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 "SkBitmapCache.h" | 8 #include "SkBitmapCache.h" |
| 9 #include "SkImage_Gpu.h" | 9 #include "SkImage_Gpu.h" |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 142 } |
| 143 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc,
ownership)); | 143 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc,
ownership)); |
| 144 if (!tex) { | 144 if (!tex) { |
| 145 return NULL; | 145 return NULL; |
| 146 } | 146 } |
| 147 if (releaseProc) { | 147 if (releaseProc) { |
| 148 tex->setRelease(releaseProc, releaseCtx); | 148 tex->setRelease(releaseProc, releaseCtx); |
| 149 } | 149 } |
| 150 | 150 |
| 151 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; | 151 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; |
| 152 return SkNEW_ARGS(SkImage_Gpu, | 152 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at,
tex, 0, budgeted); |
| 153 (desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, tex
, 0, budgeted)); | |
| 154 | |
| 155 } | 153 } |
| 156 | 154 |
| 157 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des
c, SkAlphaType at, | 155 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des
c, SkAlphaType at, |
| 158 TextureReleaseProc releaseP, ReleaseContext rel
easeC) { | 156 TextureReleaseProc releaseP, ReleaseContext rel
easeC) { |
| 159 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, re
leaseP, releaseC); | 157 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, re
leaseP, releaseC); |
| 160 } | 158 } |
| 161 | 159 |
| 162 SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDe
sc& desc, | 160 SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDe
sc& desc, |
| 163 SkAlphaType at) { | 161 SkAlphaType at) { |
| 164 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, NUL
L, NULL); | 162 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, NUL
L, NULL); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 177 } | 175 } |
| 178 | 176 |
| 179 const bool isBudgeted = true; | 177 const bool isBudgeted = true; |
| 180 SkAutoTUnref<GrTexture> dst(GrDeepCopyTexture(src, isBudgeted)); | 178 SkAutoTUnref<GrTexture> dst(GrDeepCopyTexture(src, isBudgeted)); |
| 181 if (!dst) { | 179 if (!dst) { |
| 182 return NULL; | 180 return NULL; |
| 183 } | 181 } |
| 184 | 182 |
| 185 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; | 183 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; |
| 186 const int sampleCount = 0; // todo: make this an explicit parameter to newS
urface()? | 184 const int sampleCount = 0; // todo: make this an explicit parameter to newS
urface()? |
| 187 return SkNEW_ARGS(SkImage_Gpu, (desc.fWidth, desc.fHeight, kNeedNewImageUniq
ueID, | 185 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at,
dst, sampleCount, |
| 188 at, dst, sampleCount, budgeted)); | 186 budgeted); |
| 189 } | 187 } |
| 190 | 188 |
| 191 SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS
pace, | 189 SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS
pace, |
| 192 const GrBackendObject yuvTextureHandles
[3], | 190 const GrBackendObject yuvTextureHandles
[3], |
| 193 const SkISize yuvSizes[3], | 191 const SkISize yuvSizes[3], |
| 194 GrSurfaceOrigin origin) { | 192 GrSurfaceOrigin origin) { |
| 195 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; | 193 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; |
| 196 | 194 |
| 197 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || | 195 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || |
| 198 yuvSizes[1].fWidth <= 0 || yuvSizes[1].fHeight <= 0 || | 196 yuvSizes[1].fWidth <= 0 || yuvSizes[1].fHeight <= 0 || |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 GrPaint paint; | 249 GrPaint paint; |
| 252 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 250 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
| 253 paint.addColorProcessor(GrYUVtoRGBEffect::Create(paint.getProcessorDataManag
er(), yTex, uTex, | 251 paint.addColorProcessor(GrYUVtoRGBEffect::Create(paint.getProcessorDataManag
er(), yTex, uTex, |
| 254 vTex, yuvSizes, colorSpace)
)->unref(); | 252 vTex, yuvSizes, colorSpace)
)->unref(); |
| 255 | 253 |
| 256 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), | 254 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), |
| 257 SkIntToScalar(dstDesc.fHeight)); | 255 SkIntToScalar(dstDesc.fHeight)); |
| 258 GrDrawContext* drawContext = ctx->drawContext(); | 256 GrDrawContext* drawContext = ctx->drawContext(); |
| 259 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMa
trix::I(), rect); | 257 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMa
trix::I(), rect); |
| 260 ctx->flushSurfaceWrites(dst); | 258 ctx->flushSurfaceWrites(dst); |
| 261 return SkNEW_ARGS(SkImage_Gpu, (dstDesc.fWidth, dstDesc.fHeight, kNeedNewIma
geUniqueID, | 259 return new SkImage_Gpu(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueI
D, |
| 262 kOpaque_SkAlphaType, dst, 0, budgeted)); | 260 kOpaque_SkAlphaType, dst, 0, budgeted); |
| 263 } | 261 } |
| 264 | 262 |
| 265 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 263 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 266 | 264 |
| 267 GrTexture* GrDeepCopyTexture(GrTexture* src, bool budgeted) { | 265 GrTexture* GrDeepCopyTexture(GrTexture* src, bool budgeted) { |
| 268 GrContext* ctx = src->getContext(); | 266 GrContext* ctx = src->getContext(); |
| 269 | 267 |
| 270 GrSurfaceDesc desc = src->desc(); | 268 GrSurfaceDesc desc = src->desc(); |
| 271 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, NULL,
0); | 269 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, NULL,
0); |
| 272 if (!dst) { | 270 if (!dst) { |
| 273 return NULL; | 271 return NULL; |
| 274 } | 272 } |
| 275 | 273 |
| 276 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 274 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
| 277 const SkIPoint dstP = SkIPoint::Make(0, 0); | 275 const SkIPoint dstP = SkIPoint::Make(0, 0); |
| 278 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); | 276 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); |
| 279 return dst; | 277 return dst; |
| 280 } | 278 } |
| 281 | 279 |
| OLD | NEW |