Chromium Code Reviews| Index: src/image/SkImage_Gpu.cpp |
| diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp |
| index eec0d1976001a7a3fddc23f797ca46089cde020d..bc357fb9f9d2540f713214875a0a7a9f7df618f4 100644 |
| --- a/src/image/SkImage_Gpu.cpp |
| +++ b/src/image/SkImage_Gpu.cpp |
| @@ -8,57 +8,89 @@ |
| #include "SkImage_Gpu.h" |
| #include "SkCanvas.h" |
| #include "GrContext.h" |
| +#include "SkGpuDevice.h" |
| -SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap, int sampleCountForNewSurfaces, |
| +SkImage_Gpu::SkImage_Gpu(int w, int h, GrTexture* tex, int sampleCountForNewSurfaces, |
| SkSurface::Budgeted budgeted) |
| - : INHERITED(bitmap.width(), bitmap.height(), NULL) |
| - , fBitmap(bitmap) |
| + : INHERITED(w, h, NULL) |
| + , fTexture(SkRef(tex)) |
| , fSampleCountForNewSurfaces(sampleCountForNewSurfaces) |
| , fBudgeted(budgeted) |
| -{ |
| - SkASSERT(fBitmap.getTexture()); |
| -} |
| - |
| -SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, |
| - SkShader::TileMode tileY, |
| - const SkMatrix* localMatrix) const |
| -{ |
| - return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); |
| -} |
| + {} |
| SkSurface* SkImage_Gpu::onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props) const { |
| - GrContext* ctx = this->getTexture()->getContext(); |
| + GrTexture* tex = this->getTexture(); |
| + SkASSERT(tex); |
| + GrContext* ctx = tex->getContext(); |
|
bsalomon
2015/05/07 17:05:56
This actually can fail if the GrContext was told t
reed1
2015/05/07 17:49:11
Done.
|
| + SkASSERT(ctx); |
| // TODO: Change signature of onNewSurface to take a budgeted param. |
| static const SkSurface::Budgeted kBudgeted = SkSurface::kNo_Budgeted; |
| return SkSurface::NewRenderTarget(ctx, kBudgeted, info, fSampleCountForNewSurfaces, &props); |
| } |
| -GrTexture* SkImage_Gpu::onGetTexture() const { |
| - return fBitmap.getTexture(); |
| +extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { |
| + if (image->getTexture()) { |
| + ((SkImage_Gpu*)image)->applyBudgetDecision(); |
| + } |
| +} |
| + |
| +SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, |
|
robertphillips
2015/05/07 16:50:04
line these guys up?
reed1
2015/05/07 17:49:11
Done.
|
| + SkShader::TileMode tileY, |
| + const SkMatrix* localMatrix) const |
| +{ |
| + SkBitmap bm; |
| + GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isOpaque(), &bm); |
| + return SkShader::CreateBitmapShader(bm, tileX, tileY, localMatrix); |
| } |
| bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { |
| - return fBitmap.copyTo(dst, kN32_SkColorType); |
| + SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
| + if (!dst->tryAllocPixels(SkImageInfo::MakeN32(this->width(), this->height(), at))) { |
| + return false; |
| + } |
| + if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPixelConfig, |
| + dst->getPixels(), dst->rowBytes())) { |
| + return false; |
| + } |
| + return true; |
| } |
| bool SkImage_Gpu::isOpaque() const { |
| - return fBitmap.isOpaque(); |
| + return GrPixelConfigIsOpaque(fTexture->config()); |
| } |
| -/////////////////////////////////////////////////////////////////////////////// |
| - |
| -SkImage* SkNewImageFromBitmapTexture(const SkBitmap& bitmap, int sampleCountForNewSurfaces, |
| - SkSurface::Budgeted budgeted) { |
| - if (0 == bitmap.width() || 0 == bitmap.height() || NULL == bitmap.getTexture()) { |
| +SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc) { |
| + if (desc.fWidth <= 0 || desc.fHeight <= 0) { |
| + return NULL; |
| + } |
| + SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc)); |
| + if (!tex) { |
| return NULL; |
| } |
| - return SkNEW_ARGS(SkImage_Gpu, (bitmap, sampleCountForNewSurfaces, budgeted)); |
| + return SkNEW_ARGS(SkImage_Gpu, (desc.fWidth, desc.fHeight, tex, 0, SkSurface::kNo_Budgeted)); |
| } |
| -GrTexture* SkTextureImageGetTexture(SkImage* image) { |
| - return ((SkImage_Gpu*)image)->getTexture(); |
| -} |
| +SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc& srcDesc) { |
| + if (srcDesc.fWidth <= 0 || srcDesc.fHeight <= 0) { |
| + return NULL; |
| + } |
| + SkAutoTUnref<GrTexture> src(ctx->textureProvider()->wrapBackendTexture(srcDesc)); |
| + if (!src) { |
| + return NULL; |
| + } |
| -extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { |
| - ((SkImage_Gpu*)image)->applyBudgetDecision(); |
| + GrSurfaceDesc dstDesc; |
| + dstDesc.fFlags = kNone_GrSurfaceFlags; |
| + dstDesc.fOrigin = srcDesc.fOrigin; |
| + dstDesc.fWidth = srcDesc.fWidth; |
| + dstDesc.fHeight = srcDesc.fHeight; |
| + dstDesc.fConfig = srcDesc.fConfig; |
| + dstDesc.fSampleCnt = srcDesc.fSampleCnt; |
| + |
|
robertphillips
2015/05/07 16:50:04
So, where is the copy happening?
reed1
2015/05/07 17:49:12
Done.
|
| + SkAutoTUnref<GrTexture> dst(ctx->textureProvider()->createTexture(dstDesc, true, NULL, 0)); |
| + if (!dst) { |
| + return NULL; |
| + } |
|
bsalomon
2015/05/07 17:05:56
Yeah, I think you need a GrContext::copySurface ca
reed1
2015/05/07 17:49:12
Done.
|
| + return SkNEW_ARGS(SkImage_Gpu, |
| + (dstDesc.fWidth, dstDesc.fHeight, dst, 0, SkSurface::kYes_Budgeted)); |
| } |