reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 8 | #include "SkAutoPixmapStorage.h" |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 9 | #include "GrCaps.h" |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 10 | #include "GrContext.h" |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 11 | #include "GrDrawContext.h" |
bsalomon | f1ecd21 | 2015-12-09 17:06:02 -0800 | [diff] [blame] | 12 | #include "GrImageIDTextureAdjuster.h" |
bsalomon | f267c1e | 2016-02-01 13:16:14 -0800 | [diff] [blame] | 13 | #include "effects/GrYUVEffect.h" |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 14 | #include "SkCanvas.h" |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 15 | #include "SkBitmapCache.h" |
bsalomon | 89fe56b | 2015-10-29 10:49:28 -0700 | [diff] [blame] | 16 | #include "SkGrPriv.h" |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 17 | #include "SkImage_Gpu.h" |
ericrk | b4da01d | 2016-06-13 11:18:14 -0700 | [diff] [blame] | 18 | #include "SkMipMap.h" |
reed | 6f1216a | 2015-08-04 08:10:13 -0700 | [diff] [blame] | 19 | #include "SkPixelRef.h" |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 20 | |
reed | 80c772b | 2015-07-30 18:58:23 -0700 | [diff] [blame] | 21 | SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrTexture* tex, |
brianosman | dddbe38 | 2016-07-20 13:55:39 -0700 | [diff] [blame] | 22 | sk_sp<SkColorSpace> colorSpace, SkBudgeted budgeted) |
reed | af3fbfc | 2015-10-04 11:28:36 -0700 | [diff] [blame] | 23 | : INHERITED(w, h, uniqueID) |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 24 | , fTexture(SkRef(tex)) |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 25 | , fAlphaType(at) |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 26 | , fBudgeted(budgeted) |
brianosman | dddbe38 | 2016-07-20 13:55:39 -0700 | [diff] [blame] | 27 | , fColorSpace(std::move(colorSpace)) |
bsalomon | 1cd6311 | 2015-08-05 06:58:39 -0700 | [diff] [blame] | 28 | , fAddedRasterVersionToCache(false) |
reed | c9b5f8b | 2015-10-22 13:20:20 -0700 | [diff] [blame] | 29 | { |
| 30 | SkASSERT(tex->width() == w); |
| 31 | SkASSERT(tex->height() == h); |
| 32 | } |
piotaixr | cef04f8 | 2014-07-14 07:48:04 -0700 | [diff] [blame] | 33 | |
reed | 6f1216a | 2015-08-04 08:10:13 -0700 | [diff] [blame] | 34 | SkImage_Gpu::~SkImage_Gpu() { |
| 35 | if (fAddedRasterVersionToCache.load()) { |
| 36 | SkNotifyBitmapGenIDIsStale(this->uniqueID()); |
| 37 | } |
| 38 | } |
| 39 | |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 40 | extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { |
robertphillips | ea70c4b | 2016-07-20 08:54:31 -0700 | [diff] [blame] | 41 | if (image->isTextureBacked()) { |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 42 | ((SkImage_Gpu*)image)->applyBudgetDecision(); |
| 43 | } |
| 44 | } |
| 45 | |
brianosman | 396fcdb | 2016-07-22 06:26:11 -0700 | [diff] [blame] | 46 | SkImageInfo SkImage_Gpu::onImageInfo() const { |
| 47 | SkColorType ct; |
| 48 | if (!GrPixelConfigToColorType(fTexture->config(), &ct)) { |
| 49 | ct = kUnknown_SkColorType; |
| 50 | } |
| 51 | return SkImageInfo::Make(fTexture->width(), fTexture->height(), ct, fAlphaType, fColorSpace); |
| 52 | } |
| 53 | |
brianosman | 69c166d | 2016-08-17 14:01:05 -0700 | [diff] [blame^] | 54 | static SkImageInfo make_info(int w, int h, SkAlphaType at, sk_sp<SkColorSpace> colorSpace) { |
| 55 | return SkImageInfo::MakeN32(w, h, at, std::move(colorSpace)); |
reed | 88d064d | 2015-10-12 11:30:02 -0700 | [diff] [blame] | 56 | } |
| 57 | |
reed | 0955303 | 2015-11-23 12:32:16 -0800 | [diff] [blame] | 58 | bool SkImage_Gpu::getROPixels(SkBitmap* dst, CachingHint chint) const { |
reed | 6f1216a | 2015-08-04 08:10:13 -0700 | [diff] [blame] | 59 | if (SkBitmapCache::Find(this->uniqueID(), dst)) { |
| 60 | SkASSERT(dst->getGenerationID() == this->uniqueID()); |
| 61 | SkASSERT(dst->isImmutable()); |
| 62 | SkASSERT(dst->getPixels()); |
| 63 | return true; |
| 64 | } |
| 65 | |
brianosman | 69c166d | 2016-08-17 14:01:05 -0700 | [diff] [blame^] | 66 | if (!dst->tryAllocPixels(make_info(this->width(), this->height(), this->alphaType(), |
brianosman | dddbe38 | 2016-07-20 13:55:39 -0700 | [diff] [blame] | 67 | this->fColorSpace))) { |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 68 | return false; |
| 69 | } |
| 70 | if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPixelConfig, |
| 71 | dst->getPixels(), dst->rowBytes())) { |
| 72 | return false; |
| 73 | } |
reed | 6f1216a | 2015-08-04 08:10:13 -0700 | [diff] [blame] | 74 | |
| 75 | dst->pixelRef()->setImmutableWithID(this->uniqueID()); |
reed | 0955303 | 2015-11-23 12:32:16 -0800 | [diff] [blame] | 76 | if (kAllow_CachingHint == chint) { |
| 77 | SkBitmapCache::Add(this->uniqueID(), *dst); |
| 78 | fAddedRasterVersionToCache.store(true); |
| 79 | } |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 80 | return true; |
| 81 | } |
| 82 | |
brianosman | 982eb7f | 2016-06-06 13:10:58 -0700 | [diff] [blame] | 83 | GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrTextureParams& params, |
| 84 | SkSourceGammaTreatment gammaTreatment) const { |
reed | 2d5b714 | 2016-08-17 11:12:33 -0700 | [diff] [blame] | 85 | GrTextureAdjuster adjuster(this->peekTexture(), this->bounds(), this->uniqueID(), |
| 86 | this->onImageInfo().colorSpace()); |
| 87 | return adjuster.refTextureSafeForParams(params, gammaTreatment, nullptr); |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 88 | } |
| 89 | |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 90 | static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes) { |
| 91 | switch (info.colorType()) { |
| 92 | case kRGBA_8888_SkColorType: |
| 93 | case kBGRA_8888_SkColorType: |
| 94 | break; |
| 95 | default: |
| 96 | return; // nothing to do |
| 97 | } |
| 98 | |
| 99 | // SkColor is not necesarily RGBA or BGRA, but it is one of them on little-endian, |
| 100 | // and in either case, the alpha-byte is always in the same place, so we can safely call |
| 101 | // SkPreMultiplyColor() |
| 102 | // |
| 103 | SkColor* row = (SkColor*)pixels; |
| 104 | for (int y = 0; y < info.height(); ++y) { |
| 105 | for (int x = 0; x < info.width(); ++x) { |
| 106 | row[x] = SkPreMultiplyColor(row[x]); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | bool SkImage_Gpu::onReadPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, |
reed | 0955303 | 2015-11-23 12:32:16 -0800 | [diff] [blame] | 112 | int srcX, int srcY, CachingHint) const { |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 113 | GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fTexture->getContext()->caps()); |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 114 | uint32_t flags = 0; |
| 115 | if (kUnpremul_SkAlphaType == info.alphaType() && kPremul_SkAlphaType == fAlphaType) { |
| 116 | // let the GPU perform this transformation for us |
| 117 | flags = GrContext::kUnpremul_PixelOpsFlag; |
| 118 | } |
| 119 | if (!fTexture->readPixels(srcX, srcY, info.width(), info.height(), config, |
| 120 | pixels, rowBytes, flags)) { |
| 121 | return false; |
| 122 | } |
| 123 | // do we have to manually fix-up the alpha channel? |
| 124 | // src dst |
| 125 | // unpremul premul fix manually |
| 126 | // premul unpremul done by kUnpremul_PixelOpsFlag |
| 127 | // all other combos need to change. |
| 128 | // |
| 129 | // Should this be handled by Ganesh? todo:? |
| 130 | // |
| 131 | if (kPremul_SkAlphaType == info.alphaType() && kUnpremul_SkAlphaType == fAlphaType) { |
| 132 | apply_premul(info, pixels, rowBytes); |
| 133 | } |
| 134 | return true; |
| 135 | } |
| 136 | |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 137 | sk_sp<SkImage> SkImage_Gpu::onMakeSubset(const SkIRect& subset) const { |
reed | 7b6945b | 2015-09-24 00:50:58 -0700 | [diff] [blame] | 138 | GrContext* ctx = fTexture->getContext(); |
| 139 | GrSurfaceDesc desc = fTexture->desc(); |
| 140 | desc.fWidth = subset.width(); |
| 141 | desc.fHeight = subset.height(); |
| 142 | |
senorblanco | 8775112 | 2016-05-20 07:27:38 -0700 | [diff] [blame] | 143 | sk_sp<GrTexture> subTx(ctx->textureProvider()->createTexture(desc, fBudgeted)); |
reed | 7b6945b | 2015-09-24 00:50:58 -0700 | [diff] [blame] | 144 | if (!subTx) { |
| 145 | return nullptr; |
| 146 | } |
senorblanco | 8775112 | 2016-05-20 07:27:38 -0700 | [diff] [blame] | 147 | ctx->copySurface(subTx.get(), fTexture, subset, SkIPoint::Make(0, 0)); |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 148 | return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, |
brianosman | dddbe38 | 2016-07-20 13:55:39 -0700 | [diff] [blame] | 149 | fAlphaType, subTx.get(), fColorSpace, fBudgeted); |
reed | 7b6945b | 2015-09-24 00:50:58 -0700 | [diff] [blame] | 150 | } |
| 151 | |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 152 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 153 | |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 154 | static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackendTextureDesc& desc, |
brianosman | dddbe38 | 2016-07-20 13:55:39 -0700 | [diff] [blame] | 155 | SkAlphaType at, sk_sp<SkColorSpace> colorSpace, |
| 156 | GrWrapOwnership ownership, |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 157 | SkImage::TextureReleaseProc releaseProc, |
| 158 | SkImage::ReleaseContext releaseCtx) { |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 159 | if (desc.fWidth <= 0 || desc.fHeight <= 0) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 160 | return nullptr; |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 161 | } |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 162 | SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc, ownership)); |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 163 | if (!tex) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 164 | return nullptr; |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 165 | } |
reed | de49988 | 2015-06-18 13:41:40 -0700 | [diff] [blame] | 166 | if (releaseProc) { |
| 167 | tex->setRelease(releaseProc, releaseCtx); |
| 168 | } |
| 169 | |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 170 | const SkBudgeted budgeted = SkBudgeted::kNo; |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 171 | return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, |
brianosman | dddbe38 | 2016-07-20 13:55:39 -0700 | [diff] [blame] | 172 | at, tex, colorSpace, budgeted); |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 173 | } |
| 174 | |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 175 | sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc, |
brianosman | dddbe38 | 2016-07-20 13:55:39 -0700 | [diff] [blame] | 176 | SkAlphaType at, sk_sp<SkColorSpace> cs, |
| 177 | TextureReleaseProc releaseP, ReleaseContext releaseC) { |
| 178 | return new_wrapped_texture_common(ctx, desc, at, std::move(cs), kBorrow_GrWrapOwnership, |
| 179 | releaseP, releaseC); |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 180 | } |
| 181 | |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 182 | sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDesc& desc, |
brianosman | dddbe38 | 2016-07-20 13:55:39 -0700 | [diff] [blame] | 183 | SkAlphaType at, sk_sp<SkColorSpace> cs) { |
| 184 | return new_wrapped_texture_common(ctx, desc, at, std::move(cs), kAdopt_GrWrapOwnership, |
| 185 | nullptr, nullptr); |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 186 | } |
| 187 | |
jbauman | b445a57 | 2016-06-09 13:24:48 -0700 | [diff] [blame] | 188 | static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpace colorSpace, |
| 189 | bool nv12, |
| 190 | const GrBackendObject yuvTextureHandles[], |
| 191 | const SkISize yuvSizes[], |
brianosman | dddbe38 | 2016-07-20 13:55:39 -0700 | [diff] [blame] | 192 | GrSurfaceOrigin origin, |
| 193 | sk_sp<SkColorSpace> imageColorSpace) { |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 194 | const SkBudgeted budgeted = SkBudgeted::kYes; |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 195 | |
jbauman | b445a57 | 2016-06-09 13:24:48 -0700 | [diff] [blame] | 196 | if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || yuvSizes[1].fWidth <= 0 || |
| 197 | yuvSizes[1].fHeight <= 0) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 198 | return nullptr; |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 199 | } |
jbauman | b445a57 | 2016-06-09 13:24:48 -0700 | [diff] [blame] | 200 | if (!nv12 && (yuvSizes[2].fWidth <= 0 || yuvSizes[2].fHeight <= 0)) { |
| 201 | return nullptr; |
| 202 | } |
| 203 | |
| 204 | const GrPixelConfig kConfig = nv12 ? kRGBA_8888_GrPixelConfig : kAlpha_8_GrPixelConfig; |
| 205 | |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 206 | GrBackendTextureDesc yDesc; |
| 207 | yDesc.fConfig = kConfig; |
| 208 | yDesc.fOrigin = origin; |
| 209 | yDesc.fSampleCnt = 0; |
| 210 | yDesc.fTextureHandle = yuvTextureHandles[0]; |
| 211 | yDesc.fWidth = yuvSizes[0].fWidth; |
| 212 | yDesc.fHeight = yuvSizes[0].fHeight; |
| 213 | |
| 214 | GrBackendTextureDesc uDesc; |
| 215 | uDesc.fConfig = kConfig; |
| 216 | uDesc.fOrigin = origin; |
| 217 | uDesc.fSampleCnt = 0; |
| 218 | uDesc.fTextureHandle = yuvTextureHandles[1]; |
| 219 | uDesc.fWidth = yuvSizes[1].fWidth; |
| 220 | uDesc.fHeight = yuvSizes[1].fHeight; |
| 221 | |
jbauman | b445a57 | 2016-06-09 13:24:48 -0700 | [diff] [blame] | 222 | sk_sp<GrTexture> yTex( |
| 223 | ctx->textureProvider()->wrapBackendTexture(yDesc, kBorrow_GrWrapOwnership)); |
| 224 | sk_sp<GrTexture> uTex( |
| 225 | ctx->textureProvider()->wrapBackendTexture(uDesc, kBorrow_GrWrapOwnership)); |
| 226 | sk_sp<GrTexture> vTex; |
| 227 | if (nv12) { |
| 228 | vTex = uTex; |
| 229 | } else { |
| 230 | GrBackendTextureDesc vDesc; |
| 231 | vDesc.fConfig = kConfig; |
| 232 | vDesc.fOrigin = origin; |
| 233 | vDesc.fSampleCnt = 0; |
| 234 | vDesc.fTextureHandle = yuvTextureHandles[2]; |
| 235 | vDesc.fWidth = yuvSizes[2].fWidth; |
| 236 | vDesc.fHeight = yuvSizes[2].fHeight; |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 237 | |
jbauman | b445a57 | 2016-06-09 13:24:48 -0700 | [diff] [blame] | 238 | vTex = sk_sp<GrTexture>( |
| 239 | ctx->textureProvider()->wrapBackendTexture(vDesc, kBorrow_GrWrapOwnership)); |
| 240 | } |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 241 | if (!yTex || !uTex || !vTex) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 242 | return nullptr; |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 243 | } |
| 244 | |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 245 | const int width = yuvSizes[0].fWidth; |
| 246 | const int height = yuvSizes[0].fHeight; |
robertphillips | aa19a5f | 2016-04-28 06:21:55 -0700 | [diff] [blame] | 247 | |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 248 | // Needs to be a render target in order to draw to it for the yuv->rgb conversion. |
robertphillips | 6738c70 | 2016-07-27 12:13:51 -0700 | [diff] [blame] | 249 | sk_sp<GrDrawContext> drawContext(ctx->makeDrawContext(SkBackingFit::kExact, |
| 250 | width, height, |
| 251 | kRGBA_8888_GrPixelConfig, |
| 252 | std::move(imageColorSpace), |
| 253 | 0, |
| 254 | origin)); |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 255 | if (!drawContext) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 256 | return nullptr; |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | GrPaint paint; |
| 260 | paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
jbauman | b445a57 | 2016-06-09 13:24:48 -0700 | [diff] [blame] | 261 | paint.addColorFragmentProcessor( |
| 262 | GrYUVEffect::MakeYUVToRGB(yTex.get(), uTex.get(), vTex.get(), yuvSizes, colorSpace, nv12)); |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 263 | |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 264 | const SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); |
robertphillips | c9a3706 | 2015-09-01 08:34:28 -0700 | [diff] [blame] | 265 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 266 | drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect); |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 267 | ctx->flushSurfaceWrites(drawContext->accessRenderTarget()); |
| 268 | return sk_make_sp<SkImage_Gpu>(width, height, kNeedNewImageUniqueID, |
brianosman | dddbe38 | 2016-07-20 13:55:39 -0700 | [diff] [blame] | 269 | kOpaque_SkAlphaType, drawContext->asTexture().get(), |
brianosman | dfe4f2e | 2016-07-21 13:28:36 -0700 | [diff] [blame] | 270 | sk_ref_sp(drawContext->getColorSpace()), budgeted); |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 271 | } |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 272 | |
jbauman | b445a57 | 2016-06-09 13:24:48 -0700 | [diff] [blame] | 273 | sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace, |
| 274 | const GrBackendObject yuvTextureHandles[3], |
brianosman | dddbe38 | 2016-07-20 13:55:39 -0700 | [diff] [blame] | 275 | const SkISize yuvSizes[3], GrSurfaceOrigin origin, |
| 276 | sk_sp<SkColorSpace> imageColorSpace) { |
| 277 | return make_from_yuv_textures_copy(ctx, colorSpace, false, yuvTextureHandles, yuvSizes, origin, |
| 278 | std::move(imageColorSpace)); |
jbauman | b445a57 | 2016-06-09 13:24:48 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace, |
| 282 | const GrBackendObject yuvTextureHandles[2], |
| 283 | const SkISize yuvSizes[2], |
brianosman | dddbe38 | 2016-07-20 13:55:39 -0700 | [diff] [blame] | 284 | GrSurfaceOrigin origin, |
| 285 | sk_sp<SkColorSpace> imageColorSpace) { |
| 286 | return make_from_yuv_textures_copy(ctx, colorSpace, true, yuvTextureHandles, yuvSizes, origin, |
| 287 | std::move(imageColorSpace)); |
jbauman | b445a57 | 2016-06-09 13:24:48 -0700 | [diff] [blame] | 288 | } |
| 289 | |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 290 | static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) { |
brianosman | 982eb7f | 2016-06-06 13:10:58 -0700 | [diff] [blame] | 291 | SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams::ClampNoFilter(), |
| 292 | SkSourceGammaTreatment::kRespect)); |
bsalomon | 8e74f80 | 2016-01-30 10:01:40 -0800 | [diff] [blame] | 293 | if (!texture) { |
| 294 | return nullptr; |
| 295 | } |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 296 | return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at, texture, |
brianosman | dddbe38 | 2016-07-20 13:55:39 -0700 | [diff] [blame] | 297 | sk_ref_sp(maker->getColorSpace()), SkBudgeted::kNo); |
bsalomon | 8e74f80 | 2016-01-30 10:01:40 -0800 | [diff] [blame] | 298 | } |
| 299 | |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 300 | sk_sp<SkImage> SkImage::makeTextureImage(GrContext *context) const { |
bsalomon | 8e74f80 | 2016-01-30 10:01:40 -0800 | [diff] [blame] | 301 | if (!context) { |
| 302 | return nullptr; |
| 303 | } |
| 304 | if (GrTexture* peek = as_IB(this)->peekTexture()) { |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 305 | return peek->getContext() == context ? sk_ref_sp(const_cast<SkImage*>(this)) : nullptr; |
bsalomon | 8e74f80 | 2016-01-30 10:01:40 -0800 | [diff] [blame] | 306 | } |
bsalomon | 8e74f80 | 2016-01-30 10:01:40 -0800 | [diff] [blame] | 307 | |
| 308 | if (SkImageCacherator* cacher = as_IB(this)->peekCacherator()) { |
| 309 | GrImageTextureMaker maker(context, cacher, this, kDisallow_CachingHint); |
brianosman | 69c166d | 2016-08-17 14:01:05 -0700 | [diff] [blame^] | 310 | return create_image_from_maker(&maker, this->alphaType(), this->uniqueID()); |
bsalomon | 8e74f80 | 2016-01-30 10:01:40 -0800 | [diff] [blame] | 311 | } |
reed | 9a5a201 | 2016-08-08 09:00:29 -0700 | [diff] [blame] | 312 | |
| 313 | if (const SkBitmap* bmp = as_IB(this)->onPeekBitmap()) { |
| 314 | GrBitmapTextureMaker maker(context, *bmp); |
brianosman | 69c166d | 2016-08-17 14:01:05 -0700 | [diff] [blame^] | 315 | return create_image_from_maker(&maker, this->alphaType(), this->uniqueID()); |
bsalomon | 8e74f80 | 2016-01-30 10:01:40 -0800 | [diff] [blame] | 316 | } |
reed | 9a5a201 | 2016-08-08 09:00:29 -0700 | [diff] [blame] | 317 | return nullptr; |
bsalomon | 8e74f80 | 2016-01-30 10:01:40 -0800 | [diff] [blame] | 318 | } |
| 319 | |
bsalomon | 634b430 | 2016-07-12 18:11:17 -0700 | [diff] [blame] | 320 | sk_sp<SkImage> SkImage::makeNonTextureImage() const { |
brianosman | 396fcdb | 2016-07-22 06:26:11 -0700 | [diff] [blame] | 321 | if (!this->isTextureBacked()) { |
bsalomon | 634b430 | 2016-07-12 18:11:17 -0700 | [diff] [blame] | 322 | return sk_ref_sp(const_cast<SkImage*>(this)); |
| 323 | } |
brianosman | 396fcdb | 2016-07-22 06:26:11 -0700 | [diff] [blame] | 324 | SkImageInfo info = as_IB(this)->onImageInfo(); |
bsalomon | 634b430 | 2016-07-12 18:11:17 -0700 | [diff] [blame] | 325 | size_t rowBytes = info.minRowBytes(); |
| 326 | size_t size = info.getSafeSize(rowBytes); |
| 327 | auto data = SkData::MakeUninitialized(size); |
| 328 | if (!data) { |
| 329 | return nullptr; |
| 330 | } |
| 331 | SkPixmap pm(info, data->writable_data(), rowBytes); |
| 332 | if (!this->readPixels(pm, 0, 0, kDisallow_CachingHint)) { |
| 333 | return nullptr; |
| 334 | } |
| 335 | return MakeRasterData(info, data, rowBytes); |
| 336 | } |
| 337 | |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 338 | sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext* ctx, const SkPixmap& pixmap, |
| 339 | SkBudgeted budgeted) { |
bsalomon | 0d99686 | 2016-03-09 18:44:43 -0800 | [diff] [blame] | 340 | if (!ctx) { |
| 341 | return nullptr; |
| 342 | } |
ericrk | 8bea890 | 2016-03-18 11:52:20 -0700 | [diff] [blame] | 343 | SkAutoTUnref<GrTexture> texture(GrUploadPixmapToTexture(ctx, pixmap, budgeted)); |
bsalomon | 0d99686 | 2016-03-09 18:44:43 -0800 | [diff] [blame] | 344 | if (!texture) { |
| 345 | return nullptr; |
| 346 | } |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 347 | return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNewImageUniqueID, |
brianosman | dddbe38 | 2016-07-20 13:55:39 -0700 | [diff] [blame] | 348 | pixmap.alphaType(), texture, |
| 349 | sk_ref_sp(pixmap.info().colorSpace()), budgeted); |
bsalomon | 0d99686 | 2016-03-09 18:44:43 -0800 | [diff] [blame] | 350 | } |
| 351 | |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 352 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 353 | |
bsalomon | 4d516a6 | 2016-07-28 13:37:31 -0700 | [diff] [blame] | 354 | namespace { |
| 355 | struct MipMapLevelData { |
| 356 | void* fPixelData; |
| 357 | size_t fRowBytes; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 358 | }; |
| 359 | |
bsalomon | 4d516a6 | 2016-07-28 13:37:31 -0700 | [diff] [blame] | 360 | struct DeferredTextureImage { |
halcanary | e9d55c5 | 2016-08-09 17:46:25 -0700 | [diff] [blame] | 361 | uint32_t fContextUniqueID; |
bsalomon | 4d516a6 | 2016-07-28 13:37:31 -0700 | [diff] [blame] | 362 | // We don't store a SkImageInfo because it contains a ref-counted SkColorSpace. |
halcanary | e9d55c5 | 2016-08-09 17:46:25 -0700 | [diff] [blame] | 363 | int fWidth; |
| 364 | int fHeight; |
| 365 | SkColorType fColorType; |
| 366 | SkAlphaType fAlphaType; |
| 367 | void* fColorSpace; |
| 368 | size_t fColorSpaceSize; |
| 369 | int fColorTableCnt; |
| 370 | uint32_t* fColorTableData; |
| 371 | int fMipMapLevelCount; |
bsalomon | 4d516a6 | 2016-07-28 13:37:31 -0700 | [diff] [blame] | 372 | // The fMipMapLevelData array may contain more than 1 element. |
| 373 | // It contains fMipMapLevelCount elements. |
| 374 | // That means this struct's size is not known at compile-time. |
halcanary | e9d55c5 | 2016-08-09 17:46:25 -0700 | [diff] [blame] | 375 | MipMapLevelData fMipMapLevelData[1]; |
bsalomon | 4d516a6 | 2016-07-28 13:37:31 -0700 | [diff] [blame] | 376 | }; |
| 377 | } // anonymous namespace |
| 378 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 379 | size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& proxy, |
ericrk | b4da01d | 2016-06-13 11:18:14 -0700 | [diff] [blame] | 380 | const DeferredTextureImageUsageParams params[], |
halcanary | e9d55c5 | 2016-08-09 17:46:25 -0700 | [diff] [blame] | 381 | int paramCnt, void* buffer) const { |
ericrk | b4da01d | 2016-06-13 11:18:14 -0700 | [diff] [blame] | 382 | // Extract relevant min/max values from the params array. |
| 383 | int lowestPreScaleMipLevel = params[0].fPreScaleMipLevel; |
| 384 | SkFilterQuality highestFilterQuality = params[0].fQuality; |
| 385 | for (int i = 1; i < paramCnt; ++i) { |
| 386 | if (lowestPreScaleMipLevel > params[i].fPreScaleMipLevel) |
| 387 | lowestPreScaleMipLevel = params[i].fPreScaleMipLevel; |
| 388 | if (highestFilterQuality < params[i].fQuality) |
| 389 | highestFilterQuality = params[i].fQuality; |
| 390 | } |
| 391 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 392 | const bool fillMode = SkToBool(buffer); |
| 393 | if (fillMode && !SkIsAlign8(reinterpret_cast<intptr_t>(buffer))) { |
| 394 | return 0; |
| 395 | } |
| 396 | |
ericrk | b4da01d | 2016-06-13 11:18:14 -0700 | [diff] [blame] | 397 | // Calculate scaling parameters. |
| 398 | bool isScaled = lowestPreScaleMipLevel != 0; |
| 399 | |
| 400 | SkISize scaledSize; |
| 401 | if (isScaled) { |
| 402 | // SkMipMap::ComputeLevelSize takes an index into an SkMipMap. SkMipMaps don't contain the |
| 403 | // base level, so to get an SkMipMap index we must subtract one from the GL MipMap level. |
| 404 | scaledSize = SkMipMap::ComputeLevelSize(this->width(), this->height(), |
| 405 | lowestPreScaleMipLevel - 1); |
| 406 | } else { |
| 407 | scaledSize = SkISize::Make(this->width(), this->height()); |
| 408 | } |
| 409 | |
| 410 | // We never want to scale at higher than SW medium quality, as SW medium matches GPU high. |
| 411 | SkFilterQuality scaleFilterQuality = highestFilterQuality; |
| 412 | if (scaleFilterQuality > kMedium_SkFilterQuality) { |
| 413 | scaleFilterQuality = kMedium_SkFilterQuality; |
| 414 | } |
| 415 | |
ericrk | c429baf | 2016-03-24 15:35:45 -0700 | [diff] [blame] | 416 | const int maxTextureSize = proxy.fCaps->maxTextureSize(); |
ericrk | b4da01d | 2016-06-13 11:18:14 -0700 | [diff] [blame] | 417 | if (scaledSize.width() > maxTextureSize || scaledSize.height() > maxTextureSize) { |
ericrk | c429baf | 2016-03-24 15:35:45 -0700 | [diff] [blame] | 418 | return 0; |
| 419 | } |
| 420 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 421 | SkAutoPixmapStorage pixmap; |
| 422 | SkImageInfo info; |
| 423 | size_t pixelSize = 0; |
| 424 | size_t ctSize = 0; |
| 425 | int ctCount = 0; |
ericrk | b4da01d | 2016-06-13 11:18:14 -0700 | [diff] [blame] | 426 | if (!isScaled && this->peekPixels(&pixmap)) { |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 427 | info = pixmap.info(); |
| 428 | pixelSize = SkAlign8(pixmap.getSafeSize()); |
| 429 | if (pixmap.ctable()) { |
| 430 | ctCount = pixmap.ctable()->count(); |
| 431 | ctSize = SkAlign8(pixmap.ctable()->count() * 4); |
| 432 | } |
| 433 | } else { |
| 434 | // Here we're just using presence of data to know whether there is a codec behind the image. |
| 435 | // In the future we will access the cacherator and get the exact data that we want to (e.g. |
| 436 | // yuv planes) upload. |
bungeman | ffae30d | 2016-08-03 13:32:32 -0700 | [diff] [blame] | 437 | sk_sp<SkData> data(this->refEncoded()); |
ericrk | b4da01d | 2016-06-13 11:18:14 -0700 | [diff] [blame] | 438 | if (!data && !this->peekPixels(nullptr)) { |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 439 | return 0; |
| 440 | } |
brianosman | 69c166d | 2016-08-17 14:01:05 -0700 | [diff] [blame^] | 441 | info = SkImageInfo::MakeN32(scaledSize.width(), scaledSize.height(), this->alphaType()); |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 442 | pixelSize = SkAlign8(SkAutoPixmapStorage::AllocSize(info, nullptr)); |
| 443 | if (fillMode) { |
| 444 | pixmap.alloc(info); |
ericrk | b4da01d | 2016-06-13 11:18:14 -0700 | [diff] [blame] | 445 | if (isScaled) { |
| 446 | if (!this->scalePixels(pixmap, scaleFilterQuality, |
| 447 | SkImage::kDisallow_CachingHint)) { |
| 448 | return 0; |
| 449 | } |
| 450 | } else { |
| 451 | if (!this->readPixels(pixmap, 0, 0, SkImage::kDisallow_CachingHint)) { |
| 452 | return 0; |
| 453 | } |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 454 | } |
| 455 | SkASSERT(!pixmap.ctable()); |
| 456 | } |
| 457 | } |
cblume | 2c05280 | 2016-05-31 09:55:08 -0700 | [diff] [blame] | 458 | int mipMapLevelCount = 1; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 459 | size_t size = 0; |
| 460 | size_t dtiSize = SkAlign8(sizeof(DeferredTextureImage)); |
| 461 | size += dtiSize; |
bsalomon | 4d516a6 | 2016-07-28 13:37:31 -0700 | [diff] [blame] | 462 | size += mipMapLevelCount * sizeof(MipMapLevelData); |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 463 | size_t pixelOffset = size; |
| 464 | size += pixelSize; |
| 465 | size_t ctOffset = size; |
| 466 | size += ctSize; |
bsalomon | 4d516a6 | 2016-07-28 13:37:31 -0700 | [diff] [blame] | 467 | size_t colorSpaceOffset = 0; |
| 468 | size_t colorSpaceSize = 0; |
| 469 | if (info.colorSpace()) { |
| 470 | colorSpaceOffset = size; |
| 471 | colorSpaceSize = info.colorSpace()->writeToMemory(nullptr); |
| 472 | size += colorSpaceSize; |
| 473 | } |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 474 | if (!fillMode) { |
| 475 | return size; |
| 476 | } |
| 477 | intptr_t bufferAsInt = reinterpret_cast<intptr_t>(buffer); |
| 478 | void* pixels = reinterpret_cast<void*>(bufferAsInt + pixelOffset); |
| 479 | SkPMColor* ct = nullptr; |
| 480 | if (ctSize) { |
| 481 | ct = reinterpret_cast<SkPMColor*>(bufferAsInt + ctOffset); |
| 482 | } |
| 483 | |
| 484 | memcpy(pixels, pixmap.addr(), pixmap.getSafeSize()); |
| 485 | if (ctSize) { |
| 486 | memcpy(ct, pixmap.ctable()->readColors(), ctSize); |
| 487 | } |
| 488 | |
| 489 | SkASSERT(info == pixmap.info()); |
| 490 | size_t rowBytes = pixmap.rowBytes(); |
| 491 | DeferredTextureImage* dti = new (buffer) DeferredTextureImage(); |
| 492 | dti->fContextUniqueID = proxy.fContextUniqueID; |
bsalomon | 4d516a6 | 2016-07-28 13:37:31 -0700 | [diff] [blame] | 493 | dti->fWidth = info.width(); |
| 494 | dti->fHeight = info.height(); |
| 495 | dti->fColorType = info.colorType(); |
| 496 | dti->fAlphaType = info.alphaType(); |
| 497 | dti->fColorTableCnt = ctCount; |
| 498 | dti->fColorTableData = ct; |
| 499 | dti->fMipMapLevelCount = mipMapLevelCount; |
| 500 | dti->fMipMapLevelData[0].fPixelData = pixels; |
| 501 | dti->fMipMapLevelData[0].fRowBytes = rowBytes; |
| 502 | if (colorSpaceSize) { |
| 503 | dti->fColorSpace = reinterpret_cast<void*>(bufferAsInt + colorSpaceOffset); |
| 504 | dti->fColorSpaceSize = colorSpaceSize; |
| 505 | info.colorSpace()->writeToMemory(dti->fColorSpace); |
| 506 | } else { |
| 507 | dti->fColorSpace = nullptr; |
| 508 | dti->fColorSpaceSize = 0; |
| 509 | } |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 510 | return size; |
| 511 | } |
| 512 | |
| 513 | sk_sp<SkImage> SkImage::MakeFromDeferredTextureImageData(GrContext* context, const void* data, |
| 514 | SkBudgeted budgeted) { |
| 515 | if (!data) { |
| 516 | return nullptr; |
| 517 | } |
| 518 | const DeferredTextureImage* dti = reinterpret_cast<const DeferredTextureImage*>(data); |
| 519 | |
| 520 | if (!context || context->uniqueID() != dti->fContextUniqueID) { |
| 521 | return nullptr; |
| 522 | } |
| 523 | SkAutoTUnref<SkColorTable> colorTable; |
bsalomon | 4d516a6 | 2016-07-28 13:37:31 -0700 | [diff] [blame] | 524 | if (dti->fColorTableCnt) { |
| 525 | SkASSERT(dti->fColorTableData); |
| 526 | colorTable.reset(new SkColorTable(dti->fColorTableData, dti->fColorTableCnt)); |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 527 | } |
halcanary | e9d55c5 | 2016-08-09 17:46:25 -0700 | [diff] [blame] | 528 | SkASSERT(dti->fMipMapLevelCount == 1); |
bsalomon | 4d516a6 | 2016-07-28 13:37:31 -0700 | [diff] [blame] | 529 | sk_sp<SkColorSpace> colorSpace; |
| 530 | if (dti->fColorSpaceSize) { |
| 531 | colorSpace = SkColorSpace::Deserialize(dti->fColorSpace, dti->fColorSpaceSize); |
| 532 | } |
| 533 | SkImageInfo info = SkImageInfo::Make(dti->fWidth, dti->fHeight, |
| 534 | dti->fColorType, dti->fAlphaType, colorSpace); |
halcanary | e9d55c5 | 2016-08-09 17:46:25 -0700 | [diff] [blame] | 535 | SkPixmap pixmap; |
| 536 | pixmap.reset(info, dti->fMipMapLevelData[0].fPixelData, |
| 537 | dti->fMipMapLevelData[0].fRowBytes, colorTable.get()); |
| 538 | return SkImage::MakeTextureFromPixmap(context, pixmap, budgeted); |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 542 | |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 543 | GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted budgeted) { |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 544 | GrContext* ctx = src->getContext(); |
| 545 | |
| 546 | GrSurfaceDesc desc = src->desc(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 547 | GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullptr, 0); |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 548 | if (!dst) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 549 | return nullptr; |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 550 | } |
cblume | 6121405 | 2016-01-26 09:10:48 -0800 | [diff] [blame] | 551 | |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 552 | const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
| 553 | const SkIPoint dstP = SkIPoint::Make(0, 0); |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 554 | ctx->copySurface(dst, src, srcR, dstP); |
| 555 | ctx->flushSurfaceWrites(dst); |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 556 | return dst; |
| 557 | } |
| 558 | |
cblume | 186d2d4 | 2016-06-03 11:17:42 -0700 | [diff] [blame] | 559 | sk_sp<SkImage> SkImage::MakeTextureFromMipMap(GrContext* ctx, const SkImageInfo& info, |
| 560 | const GrMipLevel* texels, int mipLevelCount, |
halcanary | e9d55c5 | 2016-08-09 17:46:25 -0700 | [diff] [blame] | 561 | SkBudgeted budgeted) { |
cblume | 186d2d4 | 2016-06-03 11:17:42 -0700 | [diff] [blame] | 562 | if (!ctx) { |
| 563 | return nullptr; |
| 564 | } |
| 565 | SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, mipLevelCount)); |
| 566 | if (!texture) { |
| 567 | return nullptr; |
| 568 | } |
| 569 | return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNewImageUniqueID, |
brianosman | dddbe38 | 2016-07-20 13:55:39 -0700 | [diff] [blame] | 570 | info.alphaType(), texture, sk_ref_sp(info.colorSpace()), |
| 571 | budgeted); |
cblume | 186d2d4 | 2016-06-03 11:17:42 -0700 | [diff] [blame] | 572 | } |