| 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" |
| 11 #include "GrDrawContext.h" | 11 #include "GrDrawContext.h" |
| 12 #include "effects/GrYUVtoRGBEffect.h" | 12 #include "effects/GrYUVtoRGBEffect.h" |
| 13 #include "SkCanvas.h" | 13 #include "SkCanvas.h" |
| 14 #include "SkGpuDevice.h" | 14 #include "SkGpuDevice.h" |
| 15 #include "SkPixelRef.h" | 15 #include "SkPixelRef.h" |
| 16 | 16 |
| 17 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText
ure* tex, | 17 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText
ure* tex, |
| 18 int sampleCountForNewSurfaces, SkSurface::Budgeted budg
eted) | 18 SkSurface::Budgeted budgeted) |
| 19 : INHERITED(w, h, uniqueID, nullptr) | 19 : INHERITED(w, h, uniqueID, nullptr) |
| 20 , fTexture(SkRef(tex)) | 20 , fTexture(SkRef(tex)) |
| 21 , fSampleCountForNewSurfaces(sampleCountForNewSurfaces) | |
| 22 , fAlphaType(at) | 21 , fAlphaType(at) |
| 23 , fBudgeted(budgeted) | 22 , fBudgeted(budgeted) |
| 24 , fAddedRasterVersionToCache(false) | 23 , fAddedRasterVersionToCache(false) |
| 25 {} | 24 {} |
| 26 | 25 |
| 27 SkImage_Gpu::~SkImage_Gpu() { | 26 SkImage_Gpu::~SkImage_Gpu() { |
| 28 if (fAddedRasterVersionToCache.load()) { | 27 if (fAddedRasterVersionToCache.load()) { |
| 29 SkNotifyBitmapGenIDIsStale(this->uniqueID()); | 28 SkNotifyBitmapGenIDIsStale(this->uniqueID()); |
| 30 } | 29 } |
| 31 } | 30 } |
| 32 | 31 |
| 33 SkSurface* SkImage_Gpu::onNewSurface(const SkImageInfo& info, const SkSurfacePro
ps& props) const { | |
| 34 GrTexture* tex = this->getTexture(); | |
| 35 SkASSERT(tex); | |
| 36 GrContext* ctx = tex->getContext(); | |
| 37 if (!ctx) { | |
| 38 // the texture may have been abandoned, so we have to check | |
| 39 return nullptr; | |
| 40 } | |
| 41 // TODO: Change signature of onNewSurface to take a budgeted param. | |
| 42 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; | |
| 43 return SkSurface::NewRenderTarget(ctx, budgeted, info, fSampleCountForNewSur
faces, &props); | |
| 44 } | |
| 45 | |
| 46 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { | 32 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { |
| 47 if (as_IB(image)->getTexture()) { | 33 if (as_IB(image)->getTexture()) { |
| 48 ((SkImage_Gpu*)image)->applyBudgetDecision(); | 34 ((SkImage_Gpu*)image)->applyBudgetDecision(); |
| 49 } | 35 } |
| 50 } | 36 } |
| 51 | 37 |
| 52 SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, SkShader::TileMode
tileY, | 38 SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, SkShader::TileMode
tileY, |
| 53 const SkMatrix* localMatrix) const { | 39 const SkMatrix* localMatrix) const { |
| 54 SkBitmap bm; | 40 SkBitmap bm; |
| 55 GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isOpaqu
e(), &bm); | 41 GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isOpaqu
e(), &bm); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 // all other combos need to change. | 115 // all other combos need to change. |
| 130 // | 116 // |
| 131 // Should this be handled by Ganesh? todo:? | 117 // Should this be handled by Ganesh? todo:? |
| 132 // | 118 // |
| 133 if (kPremul_SkAlphaType == info.alphaType() && kUnpremul_SkAlphaType == fAlp
haType) { | 119 if (kPremul_SkAlphaType == info.alphaType() && kUnpremul_SkAlphaType == fAlp
haType) { |
| 134 apply_premul(info, pixels, rowBytes); | 120 apply_premul(info, pixels, rowBytes); |
| 135 } | 121 } |
| 136 return true; | 122 return true; |
| 137 } | 123 } |
| 138 | 124 |
| 125 SkImage* SkImage_Gpu::onNewSubset(const SkIRect& subset) const { |
| 126 GrContext* ctx = fTexture->getContext(); |
| 127 GrSurfaceDesc desc = fTexture->desc(); |
| 128 desc.fWidth = subset.width(); |
| 129 desc.fHeight = subset.height(); |
| 130 |
| 131 GrTexture* subTx = ctx->textureProvider()->createTexture(desc, |
| 132 SkSurface::kYes_Bud
geted == fBudgeted); |
| 133 if (!subTx) { |
| 134 return nullptr; |
| 135 } |
| 136 ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0)); |
| 137 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, fAl
phaType, subTx, |
| 138 fBudgeted); |
| 139 } |
| 140 |
| 139 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 141 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 140 | 142 |
| 141 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur
eDesc& desc, | 143 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur
eDesc& desc, |
| 142 SkAlphaType at, GrWrapOwnership owner
ship, | 144 SkAlphaType at, GrWrapOwnership owner
ship, |
| 143 SkImage::TextureReleaseProc releasePr
oc, | 145 SkImage::TextureReleaseProc releasePr
oc, |
| 144 SkImage::ReleaseContext releaseCtx) { | 146 SkImage::ReleaseContext releaseCtx) { |
| 145 if (desc.fWidth <= 0 || desc.fHeight <= 0) { | 147 if (desc.fWidth <= 0 || desc.fHeight <= 0) { |
| 146 return nullptr; | 148 return nullptr; |
| 147 } | 149 } |
| 148 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc,
ownership)); | 150 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc,
ownership)); |
| 149 if (!tex) { | 151 if (!tex) { |
| 150 return nullptr; | 152 return nullptr; |
| 151 } | 153 } |
| 152 if (releaseProc) { | 154 if (releaseProc) { |
| 153 tex->setRelease(releaseProc, releaseCtx); | 155 tex->setRelease(releaseProc, releaseCtx); |
| 154 } | 156 } |
| 155 | 157 |
| 156 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; | 158 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; |
| 157 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at,
tex, 0, budgeted); | 159 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at,
tex, budgeted); |
| 158 } | 160 } |
| 159 | 161 |
| 160 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des
c, SkAlphaType at, | 162 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des
c, SkAlphaType at, |
| 161 TextureReleaseProc releaseP, ReleaseContext rel
easeC) { | 163 TextureReleaseProc releaseP, ReleaseContext rel
easeC) { |
| 162 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, re
leaseP, releaseC); | 164 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, re
leaseP, releaseC); |
| 163 } | 165 } |
| 164 | 166 |
| 165 SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDe
sc& desc, | 167 SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDe
sc& desc, |
| 166 SkAlphaType at) { | 168 SkAlphaType at) { |
| 167 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, nul
lptr, nullptr); | 169 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, nul
lptr, nullptr); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 179 return nullptr; | 181 return nullptr; |
| 180 } | 182 } |
| 181 | 183 |
| 182 const bool isBudgeted = true; | 184 const bool isBudgeted = true; |
| 183 SkAutoTUnref<GrTexture> dst(GrDeepCopyTexture(src, isBudgeted)); | 185 SkAutoTUnref<GrTexture> dst(GrDeepCopyTexture(src, isBudgeted)); |
| 184 if (!dst) { | 186 if (!dst) { |
| 185 return nullptr; | 187 return nullptr; |
| 186 } | 188 } |
| 187 | 189 |
| 188 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; | 190 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; |
| 189 const int sampleCount = 0; // todo: make this an explicit parameter to newS
urface()? | 191 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at,
dst, |
| 190 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at,
dst, sampleCount, | |
| 191 budgeted); | 192 budgeted); |
| 192 } | 193 } |
| 193 | 194 |
| 194 SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS
pace, | 195 SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS
pace, |
| 195 const GrBackendObject yuvTextureHandles
[3], | 196 const GrBackendObject yuvTextureHandles
[3], |
| 196 const SkISize yuvSizes[3], | 197 const SkISize yuvSizes[3], |
| 197 GrSurfaceOrigin origin) { | 198 GrSurfaceOrigin origin) { |
| 198 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; | 199 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; |
| 199 | 200 |
| 200 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || | 201 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), | 261 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), |
| 261 SkIntToScalar(dstDesc.fHeight)); | 262 SkIntToScalar(dstDesc.fHeight)); |
| 262 SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext()); | 263 SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext()); |
| 263 if (!drawContext) { | 264 if (!drawContext) { |
| 264 return nullptr; | 265 return nullptr; |
| 265 } | 266 } |
| 266 | 267 |
| 267 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMa
trix::I(), rect); | 268 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMa
trix::I(), rect); |
| 268 ctx->flushSurfaceWrites(dst); | 269 ctx->flushSurfaceWrites(dst); |
| 269 return new SkImage_Gpu(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueI
D, | 270 return new SkImage_Gpu(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueI
D, |
| 270 kOpaque_SkAlphaType, dst, 0, budgeted); | 271 kOpaque_SkAlphaType, dst, budgeted); |
| 271 } | 272 } |
| 272 | 273 |
| 273 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 274 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 274 | 275 |
| 275 GrTexture* GrDeepCopyTexture(GrTexture* src, bool budgeted) { | 276 GrTexture* GrDeepCopyTexture(GrTexture* src, bool budgeted) { |
| 276 GrContext* ctx = src->getContext(); | 277 GrContext* ctx = src->getContext(); |
| 277 | 278 |
| 278 GrSurfaceDesc desc = src->desc(); | 279 GrSurfaceDesc desc = src->desc(); |
| 279 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp
tr, 0); | 280 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp
tr, 0); |
| 280 if (!dst) { | 281 if (!dst) { |
| 281 return nullptr; | 282 return nullptr; |
| 282 } | 283 } |
| 283 | 284 |
| 284 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 285 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
| 285 const SkIPoint dstP = SkIPoint::Make(0, 0); | 286 const SkIPoint dstP = SkIPoint::Make(0, 0); |
| 286 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); | 287 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); |
| 287 return dst; | 288 return dst; |
| 288 } | 289 } |
| 289 | 290 |
| OLD | NEW |