diff options
author | 2016-07-12 18:11:17 -0700 | |
---|---|---|
committer | 2016-07-12 18:11:17 -0700 | |
commit | 634b43008025d039f3f2f1f6c01e8044ffbb901f (patch) | |
tree | 377c7d7deda5bb20bdf4573580c9270b6f1db78e /src/image/SkImage_Gpu.cpp | |
parent | e504dbc092ec09c056ba3aa72693962a06d3aa4c (diff) |
Add a function to convert a texture backed SkImage to raster.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2147493004
Review-Url: https://codereview.chromium.org/2147493004
Diffstat (limited to 'src/image/SkImage_Gpu.cpp')
-rw-r--r-- | src/image/SkImage_Gpu.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 7ce6450058..21ef52e463 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -332,6 +332,31 @@ sk_sp<SkImage> SkImage::makeTextureImage(GrContext *context) const { return create_image_from_maker(&maker, at, this->uniqueID()); } +sk_sp<SkImage> SkImage::makeNonTextureImage() const { + GrTexture* texture = as_IB(this)->peekTexture(); + if (!texture) { + return sk_ref_sp(const_cast<SkImage*>(this)); + } + SkColorType ct; + sk_sp<SkColorSpace> cs; + if (!GrPixelConfigToColorAndColorSpace(texture->config(), &ct, &cs)) { + return nullptr; + } + SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType; + auto info = SkImageInfo::Make(this->width(), this->height(), ct, at, cs); + size_t rowBytes = info.minRowBytes(); + size_t size = info.getSafeSize(rowBytes); + auto data = SkData::MakeUninitialized(size); + if (!data) { + return nullptr; + } + SkPixmap pm(info, data->writable_data(), rowBytes); + if (!this->readPixels(pm, 0, 0, kDisallow_CachingHint)) { + return nullptr; + } + return MakeRasterData(info, data, rowBytes); +} + sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext* ctx, const SkPixmap& pixmap, SkBudgeted budgeted) { if (!ctx) { |