| 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 "GrCaps.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { | 38 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { |
| 39 if (as_IB(image)->getTexture()) { | 39 if (as_IB(image)->getTexture()) { |
| 40 ((SkImage_Gpu*)image)->applyBudgetDecision(); | 40 ((SkImage_Gpu*)image)->applyBudgetDecision(); |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 static SkImageInfo make_info(int w, int h, bool isOpaque) { | 44 static SkImageInfo make_info(int w, int h, bool isOpaque) { |
| 45 return SkImageInfo::MakeN32(w, h, isOpaque ? kOpaque_SkAlphaType : kPremul_S
kAlphaType); | 45 return SkImageInfo::MakeN32(w, h, isOpaque ? kOpaque_SkAlphaType : kPremul_S
kAlphaType); |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { | 48 bool SkImage_Gpu::getROPixels(SkBitmap* dst, CachingHint chint) const { |
| 49 if (SkBitmapCache::Find(this->uniqueID(), dst)) { | 49 if (SkBitmapCache::Find(this->uniqueID(), dst)) { |
| 50 SkASSERT(dst->getGenerationID() == this->uniqueID()); | 50 SkASSERT(dst->getGenerationID() == this->uniqueID()); |
| 51 SkASSERT(dst->isImmutable()); | 51 SkASSERT(dst->isImmutable()); |
| 52 SkASSERT(dst->getPixels()); | 52 SkASSERT(dst->getPixels()); |
| 53 return true; | 53 return true; |
| 54 } | 54 } |
| 55 | 55 |
| 56 if (!dst->tryAllocPixels(make_info(this->width(), this->height(), this->isOp
aque()))) { | 56 if (!dst->tryAllocPixels(make_info(this->width(), this->height(), this->isOp
aque()))) { |
| 57 return false; | 57 return false; |
| 58 } | 58 } |
| 59 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPix
elConfig, | 59 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPix
elConfig, |
| 60 dst->getPixels(), dst->rowBytes())) { | 60 dst->getPixels(), dst->rowBytes())) { |
| 61 return false; | 61 return false; |
| 62 } | 62 } |
| 63 | 63 |
| 64 dst->pixelRef()->setImmutableWithID(this->uniqueID()); | 64 dst->pixelRef()->setImmutableWithID(this->uniqueID()); |
| 65 SkBitmapCache::Add(this->uniqueID(), *dst); | 65 if (kAllow_CachingHint == chint) { |
| 66 fAddedRasterVersionToCache.store(true); | 66 SkBitmapCache::Add(this->uniqueID(), *dst); |
| 67 fAddedRasterVersionToCache.store(true); |
| 68 } |
| 67 return true; | 69 return true; |
| 68 } | 70 } |
| 69 | 71 |
| 70 class GpuImage_GrTextureAdjuster : public GrTextureAdjuster { | 72 class GpuImage_GrTextureAdjuster : public GrTextureAdjuster { |
| 71 public: | 73 public: |
| 72 GpuImage_GrTextureAdjuster(const SkImage_Gpu* image) | 74 GpuImage_GrTextureAdjuster(const SkImage_Gpu* image) |
| 73 : INHERITED(image->peekTexture()) | 75 : INHERITED(image->peekTexture()) |
| 74 , fImage(image) | 76 , fImage(image) |
| 75 {} | 77 {} |
| 76 | 78 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // | 115 // |
| 114 SkColor* row = (SkColor*)pixels; | 116 SkColor* row = (SkColor*)pixels; |
| 115 for (int y = 0; y < info.height(); ++y) { | 117 for (int y = 0; y < info.height(); ++y) { |
| 116 for (int x = 0; x < info.width(); ++x) { | 118 for (int x = 0; x < info.width(); ++x) { |
| 117 row[x] = SkPreMultiplyColor(row[x]); | 119 row[x] = SkPreMultiplyColor(row[x]); |
| 118 } | 120 } |
| 119 } | 121 } |
| 120 } | 122 } |
| 121 | 123 |
| 122 bool SkImage_Gpu::onReadPixels(const SkImageInfo& info, void* pixels, size_t row
Bytes, | 124 bool SkImage_Gpu::onReadPixels(const SkImageInfo& info, void* pixels, size_t row
Bytes, |
| 123 int srcX, int srcY) const { | 125 int srcX, int srcY, CachingHint) const { |
| 124 GrPixelConfig config = SkImageInfo2GrPixelConfig(info.colorType(), info.alph
aType(), | 126 GrPixelConfig config = SkImageInfo2GrPixelConfig(info.colorType(), info.alph
aType(), |
| 125 info.profileType()); | 127 info.profileType()); |
| 126 uint32_t flags = 0; | 128 uint32_t flags = 0; |
| 127 if (kUnpremul_SkAlphaType == info.alphaType() && kPremul_SkAlphaType == fAlp
haType) { | 129 if (kUnpremul_SkAlphaType == info.alphaType() && kPremul_SkAlphaType == fAlp
haType) { |
| 128 // let the GPU perform this transformation for us | 130 // let the GPU perform this transformation for us |
| 129 flags = GrContext::kUnpremul_PixelOpsFlag; | 131 flags = GrContext::kUnpremul_PixelOpsFlag; |
| 130 } | 132 } |
| 131 if (!fTexture->readPixels(srcX, srcY, info.width(), info.height(), config, | 133 if (!fTexture->readPixels(srcX, srcY, info.width(), info.height(), config, |
| 132 pixels, rowBytes, flags)) { | 134 pixels, rowBytes, flags)) { |
| 133 return false; | 135 return false; |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 if (!dst) { | 385 if (!dst) { |
| 384 return nullptr; | 386 return nullptr; |
| 385 } | 387 } |
| 386 | 388 |
| 387 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 389 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
| 388 const SkIPoint dstP = SkIPoint::Make(0, 0); | 390 const SkIPoint dstP = SkIPoint::Make(0, 0); |
| 389 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); | 391 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); |
| 390 return dst; | 392 return dst; |
| 391 } | 393 } |
| 392 | 394 |
| OLD | NEW |