| 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 "GrCaps.h" |
| 10 #include "GrContext.h" | 11 #include "GrContext.h" |
| 11 #include "GrDrawContext.h" | 12 #include "GrDrawContext.h" |
| 12 #include "effects/GrYUVtoRGBEffect.h" | 13 #include "effects/GrYUVtoRGBEffect.h" |
| 13 #include "SkCanvas.h" | 14 #include "SkCanvas.h" |
| 14 #include "SkGpuDevice.h" | 15 #include "SkGpuDevice.h" |
| 15 #include "SkPixelRef.h" | 16 #include "SkPixelRef.h" |
| 16 | 17 |
| 17 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText
ure* tex, | 18 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText
ure* tex, |
| 18 int sampleCountForNewSurfaces, SkSurface::Budgeted budg
eted) | 19 int sampleCountForNewSurfaces, SkSurface::Budgeted budg
eted) |
| 19 : INHERITED(w, h, uniqueID, nullptr) | 20 : INHERITED(w, h, uniqueID, nullptr) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 42 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; | 43 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; |
| 43 return SkSurface::NewRenderTarget(ctx, budgeted, info, fSampleCountForNewSur
faces, &props); | 44 return SkSurface::NewRenderTarget(ctx, budgeted, info, fSampleCountForNewSur
faces, &props); |
| 44 } | 45 } |
| 45 | 46 |
| 46 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { | 47 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { |
| 47 if (as_IB(image)->getTexture()) { | 48 if (as_IB(image)->getTexture()) { |
| 48 ((SkImage_Gpu*)image)->applyBudgetDecision(); | 49 ((SkImage_Gpu*)image)->applyBudgetDecision(); |
| 49 } | 50 } |
| 50 } | 51 } |
| 51 | 52 |
| 52 SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, SkShader::TileMode
tileY, | |
| 53 const SkMatrix* localMatrix) const { | |
| 54 SkBitmap bm; | |
| 55 GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isOpaqu
e(), &bm); | |
| 56 return SkShader::CreateBitmapShader(bm, tileX, tileY, localMatrix); | |
| 57 } | |
| 58 | |
| 59 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { | 53 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { |
| 60 if (SkBitmapCache::Find(this->uniqueID(), dst)) { | 54 if (SkBitmapCache::Find(this->uniqueID(), dst)) { |
| 61 SkASSERT(dst->getGenerationID() == this->uniqueID()); | 55 SkASSERT(dst->getGenerationID() == this->uniqueID()); |
| 62 SkASSERT(dst->isImmutable()); | 56 SkASSERT(dst->isImmutable()); |
| 63 SkASSERT(dst->getPixels()); | 57 SkASSERT(dst->getPixels()); |
| 64 return true; | 58 return true; |
| 65 } | 59 } |
| 66 | 60 |
| 67 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp
e; | 61 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp
e; |
| 68 if (!dst->tryAllocPixels(SkImageInfo::MakeN32(this->width(), this->height(),
at))) { | 62 if (!dst->tryAllocPixels(SkImageInfo::MakeN32(this->width(), this->height(),
at))) { |
| 69 return false; | 63 return false; |
| 70 } | 64 } |
| 71 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPix
elConfig, | 65 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPix
elConfig, |
| 72 dst->getPixels(), dst->rowBytes())) { | 66 dst->getPixels(), dst->rowBytes())) { |
| 73 return false; | 67 return false; |
| 74 } | 68 } |
| 75 | 69 |
| 76 dst->pixelRef()->setImmutableWithID(this->uniqueID()); | 70 dst->pixelRef()->setImmutableWithID(this->uniqueID()); |
| 77 SkBitmapCache::Add(this->uniqueID(), *dst); | 71 SkBitmapCache::Add(this->uniqueID(), *dst); |
| 78 fAddedRasterVersionToCache.store(true); | 72 fAddedRasterVersionToCache.store(true); |
| 79 return true; | 73 return true; |
| 80 } | 74 } |
| 81 | 75 |
| 82 GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, SkImageUsageType usage) con
st { | 76 GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, SkImageUsageType usage) con
st { |
| 77 const bool is_pow2 = SkIsPow2(this->width()) && SkIsPow2(this->height()); |
| 78 const bool npot_tex_supported = false; // ctx->caps()->npotTextureTileSuppo
rt() |
| 79 if (!is_pow2 && kUntiled_SkImageUsageType != usage && !npot_tex_supported) { |
| 80 // load as bitmap, since the GPU can support tiling a non-pow2 texture |
| 81 // related to skbug.com/4365 |
| 82 SkBitmap bitmap; |
| 83 if (this->getROPixels(&bitmap)) { |
| 84 return GrRefCachedBitmapTexture(ctx, bitmap, usage); |
| 85 } else { |
| 86 return nullptr; |
| 87 } |
| 88 } |
| 89 |
| 83 fTexture->ref(); | 90 fTexture->ref(); |
| 84 return fTexture; | 91 return fTexture; |
| 85 } | 92 } |
| 86 | 93 |
| 87 bool SkImage_Gpu::isOpaque() const { | 94 bool SkImage_Gpu::isOpaque() const { |
| 88 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaque_Sk
AlphaType; | 95 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaque_Sk
AlphaType; |
| 89 } | 96 } |
| 90 | 97 |
| 91 static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes)
{ | 98 static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes)
{ |
| 92 switch (info.colorType()) { | 99 switch (info.colorType()) { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 if (!dst) { | 287 if (!dst) { |
| 281 return nullptr; | 288 return nullptr; |
| 282 } | 289 } |
| 283 | 290 |
| 284 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 291 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
| 285 const SkIPoint dstP = SkIPoint::Make(0, 0); | 292 const SkIPoint dstP = SkIPoint::Make(0, 0); |
| 286 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); | 293 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); |
| 287 return dst; | 294 return dst; |
| 288 } | 295 } |
| 289 | 296 |
| OLD | NEW |