Revert "Remove SkImage::MakeTextureFromPixmap"
This reverts commit 8ccbbb455c6ef194920c47e846b95b50f5017138.
Reason for revert: Chrome perf regression
BUG=chrome:684483
Original change's description:
> Remove SkImage::MakeTextureFromPixmap
>
> Another step towards reducing the number of texture upload paths.
>
> BUG=skia:
>
> Change-Id: Ica185e7334f52dc9ebf87e21fe6f60589ef87bb3
> Reviewed-on: https://skia-review.googlesource.com/7346
> Commit-Queue: Brian Osman <brianosman@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>
>
TBR=bsalomon@google.com,robertphillips@google.com,brianosman@google.com,cblume@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
BUG=skia:
Change-Id: I8bf6970b764018f3ebcac8123e4d6a8ad05317ff
Reviewed-on: https://skia-review.googlesource.com/7484
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index a1ecf5b..ec1968f 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -371,6 +371,20 @@
return MakeRasterData(info, data, rowBytes);
}
+sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext* ctx, const SkPixmap& pixmap,
+ SkBudgeted budgeted) {
+ if (!ctx) {
+ return nullptr;
+ }
+ sk_sp<GrTexture> texture(GrUploadPixmapToTexture(ctx, pixmap, budgeted));
+ if (!texture) {
+ return nullptr;
+ }
+ return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNewImageUniqueID,
+ pixmap.alphaType(), std::move(texture),
+ sk_ref_sp(pixmap.info().colorSpace()), budgeted);
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace {
@@ -666,14 +680,21 @@
}
SkImageInfo info = SkImageInfo::Make(dti->fWidth, dti->fHeight,
dti->fColorType, dti->fAlphaType, colorSpace);
- SkAutoSTArray<16, GrMipLevel> texels(mipLevelCount);
- for (int i = 0; i < mipLevelCount; i++) {
- texels[i].fPixels = dti->fMipMapLevelData[i].fPixelData;
- texels[i].fRowBytes = dti->fMipMapLevelData[i].fRowBytes;
- }
+ if (mipLevelCount == 1) {
+ SkPixmap pixmap;
+ pixmap.reset(info, dti->fMipMapLevelData[0].fPixelData, dti->fMipMapLevelData[0].fRowBytes);
+ return SkImage::MakeTextureFromPixmap(context, pixmap, budgeted);
+ } else {
+ std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[mipLevelCount]);
+ for (int i = 0; i < mipLevelCount; i++) {
+ texels[i].fPixels = dti->fMipMapLevelData[i].fPixelData;
+ texels[i].fRowBytes = dti->fMipMapLevelData[i].fRowBytes;
+ }
- return SkImage::MakeTextureFromMipMap(context, info, texels.get(), mipLevelCount,
- SkBudgeted::kYes, dti->fColorMode);
+ return SkImage::MakeTextureFromMipMap(context, info, texels.get(),
+ mipLevelCount, SkBudgeted::kYes,
+ dti->fColorMode);
+ }
}
///////////////////////////////////////////////////////////////////////////////////////////////////