| 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, fBudgeted); |
| 132 if (!subTx) { |
| 133 return nullptr; |
| 134 } |
| 135 ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0)); |
| 136 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, fAl
phaType, subTx, |
| 137 fBudgeted); |
| 138 } |
| 139 |
| 139 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 140 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 140 | 141 |
| 141 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur
eDesc& desc, | 142 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur
eDesc& desc, |
| 142 SkAlphaType at, GrWrapOwnership owner
ship, | 143 SkAlphaType at, GrWrapOwnership owner
ship, |
| 143 SkImage::TextureReleaseProc releasePr
oc, | 144 SkImage::TextureReleaseProc releasePr
oc, |
| 144 SkImage::ReleaseContext releaseCtx) { | 145 SkImage::ReleaseContext releaseCtx) { |
| 145 if (desc.fWidth <= 0 || desc.fHeight <= 0) { | 146 if (desc.fWidth <= 0 || desc.fHeight <= 0) { |
| 146 return nullptr; | 147 return nullptr; |
| 147 } | 148 } |
| 148 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc,
ownership)); | 149 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc,
ownership)); |
| 149 if (!tex) { | 150 if (!tex) { |
| 150 return nullptr; | 151 return nullptr; |
| 151 } | 152 } |
| 152 if (releaseProc) { | 153 if (releaseProc) { |
| 153 tex->setRelease(releaseProc, releaseCtx); | 154 tex->setRelease(releaseProc, releaseCtx); |
| 154 } | 155 } |
| 155 | 156 |
| 156 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; | 157 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; |
| 157 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at,
tex, 0, budgeted); | 158 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at,
tex, budgeted); |
| 158 } | 159 } |
| 159 | 160 |
| 160 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des
c, SkAlphaType at, | 161 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des
c, SkAlphaType at, |
| 161 TextureReleaseProc releaseP, ReleaseContext rel
easeC) { | 162 TextureReleaseProc releaseP, ReleaseContext rel
easeC) { |
| 162 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, re
leaseP, releaseC); | 163 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, re
leaseP, releaseC); |
| 163 } | 164 } |
| 164 | 165 |
| 165 SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDe
sc& desc, | 166 SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDe
sc& desc, |
| 166 SkAlphaType at) { | 167 SkAlphaType at) { |
| 167 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, nul
lptr, nullptr); | 168 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, nul
lptr, nullptr); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 179 return nullptr; | 180 return nullptr; |
| 180 } | 181 } |
| 181 | 182 |
| 182 const bool isBudgeted = true; | 183 const bool isBudgeted = true; |
| 183 SkAutoTUnref<GrTexture> dst(GrDeepCopyTexture(src, isBudgeted)); | 184 SkAutoTUnref<GrTexture> dst(GrDeepCopyTexture(src, isBudgeted)); |
| 184 if (!dst) { | 185 if (!dst) { |
| 185 return nullptr; | 186 return nullptr; |
| 186 } | 187 } |
| 187 | 188 |
| 188 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; | 189 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; |
| 189 const int sampleCount = 0; // todo: make this an explicit parameter to newS
urface()? | 190 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); | 191 budgeted); |
| 192 } | 192 } |
| 193 | 193 |
| 194 SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS
pace, | 194 SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS
pace, |
| 195 const GrBackendObject yuvTextureHandles
[3], | 195 const GrBackendObject yuvTextureHandles
[3], |
| 196 const SkISize yuvSizes[3], | 196 const SkISize yuvSizes[3], |
| 197 GrSurfaceOrigin origin) { | 197 GrSurfaceOrigin origin) { |
| 198 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; | 198 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; |
| 199 | 199 |
| 200 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || | 200 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), | 260 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), |
| 261 SkIntToScalar(dstDesc.fHeight)); | 261 SkIntToScalar(dstDesc.fHeight)); |
| 262 SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext()); | 262 SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext()); |
| 263 if (!drawContext) { | 263 if (!drawContext) { |
| 264 return nullptr; | 264 return nullptr; |
| 265 } | 265 } |
| 266 | 266 |
| 267 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMa
trix::I(), rect); | 267 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMa
trix::I(), rect); |
| 268 ctx->flushSurfaceWrites(dst); | 268 ctx->flushSurfaceWrites(dst); |
| 269 return new SkImage_Gpu(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueI
D, | 269 return new SkImage_Gpu(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueI
D, |
| 270 kOpaque_SkAlphaType, dst, 0, budgeted); | 270 kOpaque_SkAlphaType, dst, budgeted); |
| 271 } | 271 } |
| 272 | 272 |
| 273 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 273 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 274 | 274 |
| 275 GrTexture* GrDeepCopyTexture(GrTexture* src, bool budgeted) { | 275 GrTexture* GrDeepCopyTexture(GrTexture* src, bool budgeted) { |
| 276 GrContext* ctx = src->getContext(); | 276 GrContext* ctx = src->getContext(); |
| 277 | 277 |
| 278 GrSurfaceDesc desc = src->desc(); | 278 GrSurfaceDesc desc = src->desc(); |
| 279 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp
tr, 0); | 279 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp
tr, 0); |
| 280 if (!dst) { | 280 if (!dst) { |
| 281 return nullptr; | 281 return nullptr; |
| 282 } | 282 } |
| 283 | 283 |
| 284 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 284 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
| 285 const SkIPoint dstP = SkIPoint::Make(0, 0); | 285 const SkIPoint dstP = SkIPoint::Make(0, 0); |
| 286 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); | 286 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); |
| 287 return dst; | 287 return dst; |
| 288 } | 288 } |
| 289 | 289 |
| OLD | NEW |