Chromium Code Reviews| 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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| 11 #include "SkGpuDevice.h" | |
| 11 | 12 |
| 12 SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap, int sampleCountForNewSurfaces, | 13 SkImage_Gpu::SkImage_Gpu(int w, int h, GrTexture* tex, int sampleCountForNewSurf aces, |
| 13 SkSurface::Budgeted budgeted) | 14 SkSurface::Budgeted budgeted) |
| 14 : INHERITED(bitmap.width(), bitmap.height(), NULL) | 15 : INHERITED(w, h, NULL) |
| 15 , fBitmap(bitmap) | 16 , fTexture(SkRef(tex)) |
| 16 , fSampleCountForNewSurfaces(sampleCountForNewSurfaces) | 17 , fSampleCountForNewSurfaces(sampleCountForNewSurfaces) |
| 17 , fBudgeted(budgeted) | 18 , fBudgeted(budgeted) |
| 18 { | 19 {} |
| 19 SkASSERT(fBitmap.getTexture()); | |
| 20 } | |
| 21 | |
| 22 SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, | |
| 23 SkShader::TileMode tileY, | |
| 24 const SkMatrix* localMatrix) const | |
| 25 { | |
| 26 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); | |
| 27 } | |
| 28 | 20 |
| 29 SkSurface* SkImage_Gpu::onNewSurface(const SkImageInfo& info, const SkSurfacePro ps& props) const { | 21 SkSurface* SkImage_Gpu::onNewSurface(const SkImageInfo& info, const SkSurfacePro ps& props) const { |
| 30 GrContext* ctx = this->getTexture()->getContext(); | 22 GrTexture* tex = this->getTexture(); |
| 23 SkASSERT(tex); | |
| 24 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.
| |
| 25 SkASSERT(ctx); | |
| 31 // TODO: Change signature of onNewSurface to take a budgeted param. | 26 // TODO: Change signature of onNewSurface to take a budgeted param. |
| 32 static const SkSurface::Budgeted kBudgeted = SkSurface::kNo_Budgeted; | 27 static const SkSurface::Budgeted kBudgeted = SkSurface::kNo_Budgeted; |
| 33 return SkSurface::NewRenderTarget(ctx, kBudgeted, info, fSampleCountForNewSu rfaces, &props); | 28 return SkSurface::NewRenderTarget(ctx, kBudgeted, info, fSampleCountForNewSu rfaces, &props); |
| 34 } | 29 } |
| 35 | 30 |
| 36 GrTexture* SkImage_Gpu::onGetTexture() const { | 31 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { |
| 37 return fBitmap.getTexture(); | 32 if (image->getTexture()) { |
| 33 ((SkImage_Gpu*)image)->applyBudgetDecision(); | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 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.
| |
| 38 SkShader::TileMode tileY, | |
| 39 const SkMatrix* localMatrix) const | |
| 40 { | |
| 41 SkBitmap bm; | |
| 42 GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isOpaqu e(), &bm); | |
| 43 return SkShader::CreateBitmapShader(bm, tileX, tileY, localMatrix); | |
| 38 } | 44 } |
| 39 | 45 |
| 40 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { | 46 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { |
| 41 return fBitmap.copyTo(dst, kN32_SkColorType); | 47 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp e; |
| 48 if (!dst->tryAllocPixels(SkImageInfo::MakeN32(this->width(), this->height(), at))) { | |
| 49 return false; | |
| 50 } | |
| 51 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPix elConfig, | |
| 52 dst->getPixels(), dst->rowBytes())) { | |
| 53 return false; | |
| 54 } | |
| 55 return true; | |
| 42 } | 56 } |
| 43 | 57 |
| 44 bool SkImage_Gpu::isOpaque() const { | 58 bool SkImage_Gpu::isOpaque() const { |
| 45 return fBitmap.isOpaque(); | 59 return GrPixelConfigIsOpaque(fTexture->config()); |
| 46 } | 60 } |
| 47 | 61 |
| 48 /////////////////////////////////////////////////////////////////////////////// | 62 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des c) { |
| 49 | 63 if (desc.fWidth <= 0 || desc.fHeight <= 0) { |
| 50 SkImage* SkNewImageFromBitmapTexture(const SkBitmap& bitmap, int sampleCountForN ewSurfaces, | |
| 51 SkSurface::Budgeted budgeted) { | |
| 52 if (0 == bitmap.width() || 0 == bitmap.height() || NULL == bitmap.getTexture ()) { | |
| 53 return NULL; | 64 return NULL; |
| 54 } | 65 } |
| 55 return SkNEW_ARGS(SkImage_Gpu, (bitmap, sampleCountForNewSurfaces, budgeted) ); | 66 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc) ); |
| 67 if (!tex) { | |
| 68 return NULL; | |
| 69 } | |
| 70 return SkNEW_ARGS(SkImage_Gpu, (desc.fWidth, desc.fHeight, tex, 0, SkSurface ::kNo_Budgeted)); | |
| 56 } | 71 } |
| 57 | 72 |
| 58 GrTexture* SkTextureImageGetTexture(SkImage* image) { | 73 SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc& srcDesc) { |
| 59 return ((SkImage_Gpu*)image)->getTexture(); | 74 if (srcDesc.fWidth <= 0 || srcDesc.fHeight <= 0) { |
| 75 return NULL; | |
| 76 } | |
| 77 SkAutoTUnref<GrTexture> src(ctx->textureProvider()->wrapBackendTexture(srcDe sc)); | |
| 78 if (!src) { | |
| 79 return NULL; | |
| 80 } | |
| 81 | |
| 82 GrSurfaceDesc dstDesc; | |
| 83 dstDesc.fFlags = kNone_GrSurfaceFlags; | |
| 84 dstDesc.fOrigin = srcDesc.fOrigin; | |
| 85 dstDesc.fWidth = srcDesc.fWidth; | |
| 86 dstDesc.fHeight = srcDesc.fHeight; | |
| 87 dstDesc.fConfig = srcDesc.fConfig; | |
| 88 dstDesc.fSampleCnt = srcDesc.fSampleCnt; | |
| 89 | |
|
robertphillips
2015/05/07 16:50:04
So, where is the copy happening?
reed1
2015/05/07 17:49:12
Done.
| |
| 90 SkAutoTUnref<GrTexture> dst(ctx->textureProvider()->createTexture(dstDesc, t rue, NULL, 0)); | |
| 91 if (!dst) { | |
| 92 return NULL; | |
| 93 } | |
|
bsalomon
2015/05/07 17:05:56
Yeah, I think you need a GrContext::copySurface ca
reed1
2015/05/07 17:49:12
Done.
| |
| 94 return SkNEW_ARGS(SkImage_Gpu, | |
| 95 (dstDesc.fWidth, dstDesc.fHeight, dst, 0, SkSurface::kYes_ Budgeted)); | |
| 60 } | 96 } |
| 61 | |
| 62 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { | |
| 63 ((SkImage_Gpu*)image)->applyBudgetDecision(); | |
| 64 } | |
| OLD | NEW |