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 | |
cblume | 33e0cb5 | 2016-08-30 12:09:23 -0700 | [diff] [blame] | 8 | #include <cstddef> |
| 9 | #include <cstring> |
| 10 | #include <type_traits> |
| 11 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkCanvas.h" |
| 13 | #include "include/gpu/GrBackendSurface.h" |
| 14 | #include "include/gpu/GrContext.h" |
| 15 | #include "include/gpu/GrTexture.h" |
| 16 | #include "include/private/GrRecordingContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "include/private/SkImageInfoPriv.h" |
| 18 | #include "src/core/SkAutoPixmapStorage.h" |
| 19 | #include "src/core/SkBitmapCache.h" |
| 20 | #include "src/core/SkMipMap.h" |
| 21 | #include "src/core/SkScopeExit.h" |
| 22 | #include "src/core/SkTraceEvent.h" |
| 23 | #include "src/gpu/GrAHardwareBufferImageGenerator.h" |
| 24 | #include "src/gpu/GrAHardwareBufferUtils.h" |
| 25 | #include "src/gpu/GrBackendTextureImageGenerator.h" |
| 26 | #include "src/gpu/GrBitmapTextureMaker.h" |
| 27 | #include "src/gpu/GrCaps.h" |
| 28 | #include "src/gpu/GrClip.h" |
| 29 | #include "src/gpu/GrColorSpaceXform.h" |
| 30 | #include "src/gpu/GrContextPriv.h" |
| 31 | #include "src/gpu/GrDrawingManager.h" |
| 32 | #include "src/gpu/GrGpu.h" |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 33 | #include "src/gpu/GrImageInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 34 | #include "src/gpu/GrImageTextureMaker.h" |
| 35 | #include "src/gpu/GrProxyProvider.h" |
| 36 | #include "src/gpu/GrRecordingContextPriv.h" |
| 37 | #include "src/gpu/GrRenderTargetContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 38 | #include "src/gpu/GrSemaphore.h" |
| 39 | #include "src/gpu/GrSurfacePriv.h" |
| 40 | #include "src/gpu/GrTextureAdjuster.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 41 | #include "src/gpu/GrTexturePriv.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 42 | #include "src/gpu/GrTextureProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 43 | #include "src/gpu/GrTextureProxyPriv.h" |
| 44 | #include "src/gpu/SkGr.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 45 | #include "src/gpu/gl/GrGLTexture.h" |
| 46 | #include "src/image/SkImage_Gpu.h" |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 47 | |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 48 | SkImage_Gpu::SkImage_Gpu(sk_sp<GrContext> context, uint32_t uniqueID, GrSurfaceProxyView view, |
| 49 | SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> colorSpace) |
Greg Daniel | 81b9897 | 2019-12-13 11:09:43 -0500 | [diff] [blame] | 50 | : INHERITED(std::move(context), view.proxy()->backingStoreDimensions(), uniqueID, |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 51 | ct, at, colorSpace) |
| 52 | , fView(std::move(view)) { |
| 53 | #ifdef SK_DEBUG |
| 54 | const GrBackendFormat& format = fView.proxy()->backendFormat(); |
| 55 | GrColorType grCT = SkColorTypeToGrColorType(ct); |
| 56 | const GrCaps* caps = this->context()->priv().caps(); |
| 57 | if (caps->isFormatSRGB(format)) { |
| 58 | SkASSERT(grCT == GrColorType::kRGBA_8888); |
| 59 | grCT = GrColorType::kRGBA_8888_SRGB; |
| 60 | } |
| 61 | SkASSERT(caps->isFormatCompressed(format) || |
| 62 | caps->areColorTypeAndFormatCompatible(grCT, format)); |
| 63 | #endif |
| 64 | } |
piotaixr | cef04f8 | 2014-07-14 07:48:04 -0700 | [diff] [blame] | 65 | |
Brian Salomon | 729fc0c | 2019-09-30 16:33:11 +0000 | [diff] [blame] | 66 | SkImage_Gpu::~SkImage_Gpu() {} |
| 67 | |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 68 | GrSemaphoresSubmitted SkImage_Gpu::onFlush(GrContext* context, const GrFlushInfo& info) { |
| 69 | if (!context || !fContext->priv().matches(context) || fContext->abandoned()) { |
| 70 | return GrSemaphoresSubmitted::kNo; |
| 71 | } |
| 72 | |
Greg Daniel | 81b9897 | 2019-12-13 11:09:43 -0500 | [diff] [blame] | 73 | GrSurfaceProxy* p[1] = {fView.proxy()}; |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 74 | return context->priv().flushSurfaces(p, 1, info); |
| 75 | } |
| 76 | |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 77 | sk_sp<SkImage> SkImage_Gpu::onMakeColorTypeAndColorSpace(GrRecordingContext* context, |
| 78 | SkColorType targetCT, |
Brian Osman | f48c996 | 2019-01-14 11:15:50 -0500 | [diff] [blame] | 79 | sk_sp<SkColorSpace> targetCS) const { |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 80 | if (!context || !fContext->priv().matches(context)) { |
| 81 | return nullptr; |
| 82 | } |
| 83 | |
Brian Salomon | 5ad6fd3 | 2019-03-21 15:30:08 -0400 | [diff] [blame] | 84 | auto xform = GrColorSpaceXformEffect::Make(this->colorSpace(), this->alphaType(), |
| 85 | targetCS.get(), this->alphaType()); |
Brian Osman | f48c996 | 2019-01-14 11:15:50 -0500 | [diff] [blame] | 86 | SkASSERT(xform || targetCT != this->colorType()); |
Jim Van Verth | 3e4c2f3 | 2019-01-11 13:32:45 -0500 | [diff] [blame] | 87 | |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 88 | auto renderTargetContext = GrRenderTargetContext::MakeWithFallback( |
| 89 | context, SkColorTypeToGrColorType(targetCT), nullptr, SkBackingFit::kExact, |
| 90 | this->dimensions()); |
Jim Van Verth | 3e4c2f3 | 2019-01-11 13:32:45 -0500 | [diff] [blame] | 91 | if (!renderTargetContext) { |
| 92 | return nullptr; |
| 93 | } |
| 94 | |
| 95 | GrPaint paint; |
| 96 | paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
Greg Daniel | 81b9897 | 2019-12-13 11:09:43 -0500 | [diff] [blame] | 97 | sk_sp<GrTextureProxy> proxy = this->asTextureProxyRef(context); |
Brian Salomon | bfb7211 | 2020-01-13 10:51:50 -0500 | [diff] [blame] | 98 | paint.addColorFragmentProcessor(GrTextureEffect::Make(std::move(proxy), this->alphaType())); |
Brian Osman | f48c996 | 2019-01-14 11:15:50 -0500 | [diff] [blame] | 99 | if (xform) { |
| 100 | paint.addColorFragmentProcessor(std::move(xform)); |
| 101 | } |
Jim Van Verth | 3e4c2f3 | 2019-01-11 13:32:45 -0500 | [diff] [blame] | 102 | |
| 103 | renderTargetContext->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), |
| 104 | SkRect::MakeIWH(this->width(), this->height())); |
| 105 | if (!renderTargetContext->asTextureProxy()) { |
| 106 | return nullptr; |
| 107 | } |
| 108 | |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 109 | targetCT = GrColorTypeToSkColorType(renderTargetContext->colorInfo().colorType()); |
Jim Van Verth | 3e4c2f3 | 2019-01-11 13:32:45 -0500 | [diff] [blame] | 110 | // MDB: this call is okay bc we know 'renderTargetContext' was exact |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 111 | return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, |
| 112 | renderTargetContext->readSurfaceView(), targetCT, |
| 113 | this->alphaType(), std::move(targetCS)); |
Jim Van Verth | 3e4c2f3 | 2019-01-11 13:32:45 -0500 | [diff] [blame] | 114 | } |
| 115 | |
Brian Osman | d514837 | 2019-08-14 16:14:51 -0400 | [diff] [blame] | 116 | sk_sp<SkImage> SkImage_Gpu::onReinterpretColorSpace(sk_sp<SkColorSpace> newCS) const { |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 117 | return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, fView, this->colorType(), |
| 118 | this->alphaType(), std::move(newCS)); |
Brian Osman | d514837 | 2019-08-14 16:14:51 -0400 | [diff] [blame] | 119 | } |
| 120 | |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 121 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 122 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 123 | static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, |
| 124 | const GrBackendTexture& backendTex, |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 125 | GrColorType colorType, GrSurfaceOrigin origin, |
brianosman | dddbe38 | 2016-07-20 13:55:39 -0700 | [diff] [blame] | 126 | SkAlphaType at, sk_sp<SkColorSpace> colorSpace, |
| 127 | GrWrapOwnership ownership, |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 128 | SkImage::TextureReleaseProc releaseProc, |
| 129 | SkImage::ReleaseContext releaseCtx) { |
Greg Daniel | 66aebf3 | 2018-04-09 09:15:56 -0400 | [diff] [blame] | 130 | if (!backendTex.isValid() || backendTex.width() <= 0 || backendTex.height() <= 0) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 131 | return nullptr; |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 132 | } |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 133 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 134 | GrProxyProvider* proxyProvider = ctx->priv().proxyProvider(); |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 135 | sk_sp<GrTextureProxy> proxy = |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 136 | proxyProvider->wrapBackendTexture(backendTex, colorType, origin, ownership, |
| 137 | GrWrapCacheable::kNo, kRead_GrIOType, |
| 138 | releaseProc, releaseCtx); |
Robert Phillips | adbe132 | 2018-01-17 13:35:46 -0500 | [diff] [blame] | 139 | if (!proxy) { |
Robert Phillips | e201ebc | 2018-01-17 18:12:50 +0000 | [diff] [blame] | 140 | return nullptr; |
| 141 | } |
Greg Daniel | 81b9897 | 2019-12-13 11:09:43 -0500 | [diff] [blame] | 142 | |
Greg Daniel | 14b5721 | 2019-12-17 16:18:06 -0500 | [diff] [blame] | 143 | GrSwizzle swizzle = ctx->priv().caps()->getReadSwizzle(proxy->backendFormat(), colorType); |
Greg Daniel | 81b9897 | 2019-12-13 11:09:43 -0500 | [diff] [blame] | 144 | GrSurfaceProxyView view(std::move(proxy), origin, swizzle); |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 145 | return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, std::move(view), |
| 146 | GrColorTypeToSkColorType(colorType), at, std::move(colorSpace)); |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 149 | sk_sp<SkImage> SkImage::MakeFromCompressedTexture(GrContext* ctx, |
| 150 | const GrBackendTexture& tex, |
| 151 | GrSurfaceOrigin origin, |
| 152 | SkAlphaType at, |
| 153 | sk_sp<SkColorSpace> cs, |
| 154 | TextureReleaseProc releaseP, |
| 155 | ReleaseContext releaseC) { |
Robert Phillips | ead321b | 2019-12-19 10:16:32 -0500 | [diff] [blame] | 156 | if (!ctx) { |
| 157 | return nullptr; |
| 158 | } |
| 159 | |
| 160 | const GrCaps* caps = ctx->priv().caps(); |
| 161 | |
| 162 | if (!SkImage_GpuBase::ValidateCompressedBackendTexture(caps, tex, at)) { |
| 163 | return nullptr; |
| 164 | } |
| 165 | |
| 166 | GrProxyProvider* proxyProvider = ctx->priv().proxyProvider(); |
| 167 | sk_sp<GrTextureProxy> proxy = |
| 168 | proxyProvider->wrapCompressedBackendTexture(tex, origin, kBorrow_GrWrapOwnership, |
| 169 | GrWrapCacheable::kNo, releaseP, releaseC); |
| 170 | if (!proxy) { |
| 171 | return nullptr; |
| 172 | } |
| 173 | |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 174 | CompressionType type = caps->compressionType(tex.getBackendFormat()); |
| 175 | SkColorType ct = GrCompressionTypeToSkColorType(type); |
| 176 | |
Robert Phillips | ead321b | 2019-12-19 10:16:32 -0500 | [diff] [blame] | 177 | GrSurfaceProxyView view(std::move(proxy), origin, GrSwizzle::RGBA()); |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 178 | return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, std::move(view), ct, at, |
Robert Phillips | ead321b | 2019-12-19 10:16:32 -0500 | [diff] [blame] | 179 | std::move(cs)); |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 180 | } |
| 181 | |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 182 | sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx, |
| 183 | const GrBackendTexture& tex, GrSurfaceOrigin origin, |
| 184 | SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs, |
| 185 | TextureReleaseProc releaseP, ReleaseContext releaseC) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 186 | if (!ctx) { |
| 187 | return nullptr; |
| 188 | } |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 189 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 190 | const GrCaps* caps = ctx->priv().caps(); |
| 191 | |
| 192 | GrColorType grColorType = SkColorTypeAndFormatToGrColorType(caps, ct, tex.getBackendFormat()); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 193 | if (GrColorType::kUnknown == grColorType) { |
Robert Phillips | 9725638 | 2019-07-17 15:26:36 -0400 | [diff] [blame] | 194 | return nullptr; |
| 195 | } |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 196 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 197 | if (!SkImage_GpuBase::ValidateBackendTexture(caps, tex, grColorType, ct, at, cs)) { |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 198 | return nullptr; |
| 199 | } |
| 200 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 201 | return new_wrapped_texture_common(ctx, tex, grColorType, origin, at, std::move(cs), |
Brian Salomon | bfd2749 | 2018-03-19 14:08:51 -0400 | [diff] [blame] | 202 | kBorrow_GrWrapOwnership, releaseP, releaseC); |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 203 | } |
| 204 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 205 | sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx, |
| 206 | const GrBackendTexture& tex, GrSurfaceOrigin origin, |
Brian Salomon | 42409c2 | 2018-03-20 13:48:41 -0400 | [diff] [blame] | 207 | SkColorType ct, SkAlphaType at, |
| 208 | sk_sp<SkColorSpace> cs) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 209 | if (!ctx || !ctx->priv().resourceProvider()) { |
Greg Daniel | f2336e4 | 2018-01-23 16:38:14 -0500 | [diff] [blame] | 210 | // We have a DDL context and we don't support adopted textures for them. |
| 211 | return nullptr; |
| 212 | } |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 213 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 214 | const GrCaps* caps = ctx->priv().caps(); |
| 215 | |
| 216 | GrColorType grColorType = SkColorTypeAndFormatToGrColorType(caps, ct, tex.getBackendFormat()); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 217 | if (GrColorType::kUnknown == grColorType) { |
Robert Phillips | 9725638 | 2019-07-17 15:26:36 -0400 | [diff] [blame] | 218 | return nullptr; |
| 219 | } |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 220 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 221 | if (!SkImage_GpuBase::ValidateBackendTexture(caps, tex, grColorType, ct, at, cs)) { |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 222 | return nullptr; |
| 223 | } |
| 224 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 225 | return new_wrapped_texture_common(ctx, tex, grColorType, origin, at, std::move(cs), |
Brian Salomon | 42409c2 | 2018-03-20 13:48:41 -0400 | [diff] [blame] | 226 | kAdopt_GrWrapOwnership, nullptr, nullptr); |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 227 | } |
| 228 | |
Jim Van Verth | ee06b33 | 2019-01-18 10:36:32 -0500 | [diff] [blame] | 229 | sk_sp<SkImage> SkImage::MakeFromCompressed(GrContext* context, sk_sp<SkData> data, |
Robert Phillips | e4720c6 | 2020-01-14 14:33:24 -0500 | [diff] [blame] | 230 | int width, int height, CompressionType type, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame^] | 231 | GrMipMapped mipMapped, GrProtected isProtected) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 232 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 233 | sk_sp<GrTextureProxy> proxy = proxyProvider->createCompressedTextureProxy( |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame^] | 234 | {width, height}, SkBudgeted::kYes, mipMapped, isProtected, type, std::move(data)); |
Jim Van Verth | ee06b33 | 2019-01-18 10:36:32 -0500 | [diff] [blame] | 235 | if (!proxy) { |
| 236 | return nullptr; |
| 237 | } |
Greg Daniel | 81b9897 | 2019-12-13 11:09:43 -0500 | [diff] [blame] | 238 | // TODO: remove asserts when proxy doesn't hold origin or swizzle |
| 239 | SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin); |
| 240 | SkASSERT(proxy->textureSwizzle() == GrSwizzle()); |
| 241 | GrSurfaceProxyView view(std::move(proxy)); |
Brian Salomon | 729fc0c | 2019-09-30 16:33:11 +0000 | [diff] [blame] | 242 | |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 243 | SkColorType colorType = GrCompressionTypeToSkColorType(type); |
| 244 | |
| 245 | return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, std::move(view), |
| 246 | colorType, kOpaque_SkAlphaType, nullptr); |
Jim Van Verth | ee06b33 | 2019-01-18 10:36:32 -0500 | [diff] [blame] | 247 | } |
| 248 | |
Brian Salomon | f05e6d3 | 2018-12-20 08:41:41 -0500 | [diff] [blame] | 249 | sk_sp<SkImage> SkImage_Gpu::ConvertYUVATexturesToRGB(GrContext* ctx, SkYUVColorSpace yuvColorSpace, |
| 250 | const GrBackendTexture yuvaTextures[], |
| 251 | const SkYUVAIndex yuvaIndices[4], SkISize size, |
| 252 | GrSurfaceOrigin origin, |
| 253 | GrRenderTargetContext* renderTargetContext) { |
Brian Salomon | d2fcfb5 | 2018-09-17 21:57:11 -0400 | [diff] [blame] | 254 | SkASSERT(renderTargetContext); |
| 255 | |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 256 | int numTextures; |
| 257 | if (!SkYUVAIndex::AreValidIndices(yuvaIndices, &numTextures)) { |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 258 | return nullptr; |
| 259 | } |
Robert Phillips | ba5c439 | 2018-07-25 12:37:14 -0400 | [diff] [blame] | 260 | |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 261 | sk_sp<GrTextureProxy> tempTextureProxies[4]; |
Jim Van Verth | 5327536 | 2018-11-09 15:42:35 -0500 | [diff] [blame] | 262 | if (!SkImage_GpuBase::MakeTempTextureProxies(ctx, yuvaTextures, numTextures, yuvaIndices, |
| 263 | origin, tempTextureProxies)) { |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 264 | return nullptr; |
| 265 | } |
| 266 | |
| 267 | const SkRect rect = SkRect::MakeIWH(size.width(), size.height()); |
Brian Osman | e956049 | 2019-02-05 17:00:03 -0500 | [diff] [blame] | 268 | if (!RenderYUVAToRGBA(ctx, renderTargetContext, rect, yuvColorSpace, nullptr, |
Jim Van Verth | 0e67194 | 2018-11-09 12:03:57 -0500 | [diff] [blame] | 269 | tempTextureProxies, yuvaIndices)) { |
| 270 | return nullptr; |
| 271 | } |
Robert Phillips | b726d58 | 2017-03-09 16:36:32 -0500 | [diff] [blame] | 272 | |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 273 | SkColorType ct = GrColorTypeToSkColorType(renderTargetContext->colorInfo().colorType()); |
Jim Van Verth | 5327536 | 2018-11-09 15:42:35 -0500 | [diff] [blame] | 274 | SkAlphaType at = GetAlphaTypeFromYUVAIndices(yuvaIndices); |
Robert Phillips | b726d58 | 2017-03-09 16:36:32 -0500 | [diff] [blame] | 275 | // MDB: this call is okay bc we know 'renderTargetContext' was exact |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 276 | return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, |
| 277 | renderTargetContext->readSurfaceView(), ct, at, |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 278 | renderTargetContext->colorInfo().refColorSpace()); |
Brian Salomon | d2fcfb5 | 2018-09-17 21:57:11 -0400 | [diff] [blame] | 279 | } |
| 280 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 281 | sk_sp<SkImage> SkImage::MakeFromYUVATexturesCopy(GrContext* ctx, |
| 282 | SkYUVColorSpace yuvColorSpace, |
| 283 | const GrBackendTexture yuvaTextures[], |
| 284 | const SkYUVAIndex yuvaIndices[4], |
| 285 | SkISize imageSize, |
| 286 | GrSurfaceOrigin imageOrigin, |
| 287 | sk_sp<SkColorSpace> imageColorSpace) { |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 288 | auto renderTargetContext = GrRenderTargetContext::Make( |
| 289 | ctx, GrColorType::kRGBA_8888, std::move(imageColorSpace), SkBackingFit::kExact, |
| 290 | imageSize, 1, GrMipMapped::kNo, GrProtected::kNo, imageOrigin); |
Brian Salomon | d2fcfb5 | 2018-09-17 21:57:11 -0400 | [diff] [blame] | 291 | if (!renderTargetContext) { |
| 292 | return nullptr; |
| 293 | } |
| 294 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 295 | return SkImage_Gpu::ConvertYUVATexturesToRGB(ctx, yuvColorSpace, yuvaTextures, yuvaIndices, |
Brian Salomon | f05e6d3 | 2018-12-20 08:41:41 -0500 | [diff] [blame] | 296 | imageSize, imageOrigin, renderTargetContext.get()); |
Brian Salomon | d2fcfb5 | 2018-09-17 21:57:11 -0400 | [diff] [blame] | 297 | } |
| 298 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 299 | sk_sp<SkImage> SkImage::MakeFromYUVATexturesCopyWithExternalBackend( |
Brian Salomon | d2fcfb5 | 2018-09-17 21:57:11 -0400 | [diff] [blame] | 300 | GrContext* ctx, |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 301 | SkYUVColorSpace yuvColorSpace, |
Brian Salomon | d2fcfb5 | 2018-09-17 21:57:11 -0400 | [diff] [blame] | 302 | const GrBackendTexture yuvaTextures[], |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 303 | const SkYUVAIndex yuvaIndices[4], |
| 304 | SkISize imageSize, |
| 305 | GrSurfaceOrigin imageOrigin, |
| 306 | const GrBackendTexture& backendTexture, |
Robert Phillips | eb3eb98 | 2019-08-19 13:35:48 -0400 | [diff] [blame] | 307 | sk_sp<SkColorSpace> imageColorSpace, |
| 308 | TextureReleaseProc textureReleaseProc, |
| 309 | ReleaseContext releaseContext) { |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 310 | const GrCaps* caps = ctx->priv().caps(); |
Robert Phillips | dd39980 | 2019-07-18 12:28:00 +0000 | [diff] [blame] | 311 | |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 312 | GrColorType grColorType = SkColorTypeAndFormatToGrColorType(caps, kRGBA_8888_SkColorType, |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 313 | backendTexture.getBackendFormat()); |
| 314 | if (GrColorType::kUnknown == grColorType) { |
| 315 | return nullptr; |
| 316 | } |
| 317 | |
Jim Van Verth | 5327536 | 2018-11-09 15:42:35 -0500 | [diff] [blame] | 318 | SkAlphaType at = SkImage_GpuBase::GetAlphaTypeFromYUVAIndices(yuvaIndices); |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 319 | if (!SkImage_Gpu::ValidateBackendTexture(caps, backendTexture, grColorType, |
| 320 | kRGBA_8888_SkColorType, at, nullptr)) { |
Brian Salomon | d2fcfb5 | 2018-09-17 21:57:11 -0400 | [diff] [blame] | 321 | return nullptr; |
| 322 | } |
| 323 | |
| 324 | // Needs to create a render target with external texture |
| 325 | // in order to draw to it for the yuv->rgb conversion. |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 326 | auto renderTargetContext = GrRenderTargetContext::MakeFromBackendTexture( |
| 327 | ctx, grColorType, std::move(imageColorSpace), backendTexture, 1, imageOrigin, |
| 328 | nullptr, textureReleaseProc, releaseContext); |
Brian Salomon | d2fcfb5 | 2018-09-17 21:57:11 -0400 | [diff] [blame] | 329 | if (!renderTargetContext) { |
| 330 | return nullptr; |
| 331 | } |
| 332 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 333 | return SkImage_Gpu::ConvertYUVATexturesToRGB(ctx, yuvColorSpace, yuvaTextures, yuvaIndices, |
Brian Salomon | f05e6d3 | 2018-12-20 08:41:41 -0500 | [diff] [blame] | 334 | imageSize, imageOrigin, renderTargetContext.get()); |
Robert Phillips | c25db63 | 2017-12-13 09:22:45 -0500 | [diff] [blame] | 335 | } |
| 336 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 337 | sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace yuvColorSpace, |
Brian Salomon | 6a426c1 | 2018-03-15 12:16:02 -0400 | [diff] [blame] | 338 | const GrBackendTexture yuvTextures[3], |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 339 | GrSurfaceOrigin imageOrigin, |
Brian Salomon | 6a426c1 | 2018-03-15 12:16:02 -0400 | [diff] [blame] | 340 | sk_sp<SkColorSpace> imageColorSpace) { |
Weiliang Chen | bed9d5e | 2018-05-22 18:44:02 -0400 | [diff] [blame] | 341 | // TODO: SkImageSourceChannel input is being ingored right now. Setup correctly in the future. |
| 342 | SkYUVAIndex yuvaIndices[4] = { |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame] | 343 | SkYUVAIndex{0, SkColorChannel::kR}, |
| 344 | SkYUVAIndex{1, SkColorChannel::kR}, |
| 345 | SkYUVAIndex{2, SkColorChannel::kR}, |
Robert Phillips | 66a9734 | 2018-10-04 09:10:29 -0400 | [diff] [blame] | 346 | SkYUVAIndex{-1, SkColorChannel::kA}}; |
Weiliang Chen | bed9d5e | 2018-05-22 18:44:02 -0400 | [diff] [blame] | 347 | SkISize size{yuvTextures[0].width(), yuvTextures[0].height()}; |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 348 | return SkImage_Gpu::MakeFromYUVATexturesCopy(ctx, yuvColorSpace, yuvTextures, yuvaIndices, |
| 349 | size, imageOrigin, std::move(imageColorSpace)); |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 350 | } |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 351 | |
Brian Salomon | d2fcfb5 | 2018-09-17 21:57:11 -0400 | [diff] [blame] | 352 | sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopyWithExternalBackend( |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 353 | GrContext* ctx, SkYUVColorSpace yuvColorSpace, const GrBackendTexture yuvTextures[3], |
| 354 | GrSurfaceOrigin imageOrigin, const GrBackendTexture& backendTexture, |
Brian Salomon | d2fcfb5 | 2018-09-17 21:57:11 -0400 | [diff] [blame] | 355 | sk_sp<SkColorSpace> imageColorSpace) { |
| 356 | SkYUVAIndex yuvaIndices[4] = { |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame] | 357 | SkYUVAIndex{0, SkColorChannel::kR}, |
| 358 | SkYUVAIndex{1, SkColorChannel::kR}, |
| 359 | SkYUVAIndex{2, SkColorChannel::kR}, |
Robert Phillips | 66a9734 | 2018-10-04 09:10:29 -0400 | [diff] [blame] | 360 | SkYUVAIndex{-1, SkColorChannel::kA}}; |
Brian Salomon | d2fcfb5 | 2018-09-17 21:57:11 -0400 | [diff] [blame] | 361 | SkISize size{yuvTextures[0].width(), yuvTextures[0].height()}; |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 362 | return SkImage_Gpu::MakeFromYUVATexturesCopyWithExternalBackend( |
| 363 | ctx, yuvColorSpace, yuvTextures, yuvaIndices, size, imageOrigin, backendTexture, |
Robert Phillips | eb3eb98 | 2019-08-19 13:35:48 -0400 | [diff] [blame] | 364 | std::move(imageColorSpace), nullptr, nullptr); |
Brian Salomon | d2fcfb5 | 2018-09-17 21:57:11 -0400 | [diff] [blame] | 365 | } |
| 366 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 367 | sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace yuvColorSpace, |
Brian Salomon | 6a426c1 | 2018-03-15 12:16:02 -0400 | [diff] [blame] | 368 | const GrBackendTexture nv12Textures[2], |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 369 | GrSurfaceOrigin imageOrigin, |
brianosman | dddbe38 | 2016-07-20 13:55:39 -0700 | [diff] [blame] | 370 | sk_sp<SkColorSpace> imageColorSpace) { |
Weiliang Chen | bed9d5e | 2018-05-22 18:44:02 -0400 | [diff] [blame] | 371 | // TODO: SkImageSourceChannel input is being ingored right now. Setup correctly in the future. |
| 372 | SkYUVAIndex yuvaIndices[4] = { |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame] | 373 | SkYUVAIndex{0, SkColorChannel::kR}, |
| 374 | SkYUVAIndex{1, SkColorChannel::kR}, |
| 375 | SkYUVAIndex{1, SkColorChannel::kG}, |
Robert Phillips | 66a9734 | 2018-10-04 09:10:29 -0400 | [diff] [blame] | 376 | SkYUVAIndex{-1, SkColorChannel::kA}}; |
Weiliang Chen | bed9d5e | 2018-05-22 18:44:02 -0400 | [diff] [blame] | 377 | SkISize size{nv12Textures[0].width(), nv12Textures[0].height()}; |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 378 | return SkImage_Gpu::MakeFromYUVATexturesCopy(ctx, yuvColorSpace, nv12Textures, yuvaIndices, |
| 379 | size, imageOrigin, std::move(imageColorSpace)); |
Robert Phillips | c25db63 | 2017-12-13 09:22:45 -0500 | [diff] [blame] | 380 | } |
| 381 | |
Brian Salomon | d2fcfb5 | 2018-09-17 21:57:11 -0400 | [diff] [blame] | 382 | sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopyWithExternalBackend( |
| 383 | GrContext* ctx, |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 384 | SkYUVColorSpace yuvColorSpace, |
Brian Salomon | d2fcfb5 | 2018-09-17 21:57:11 -0400 | [diff] [blame] | 385 | const GrBackendTexture nv12Textures[2], |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 386 | GrSurfaceOrigin imageOrigin, |
| 387 | const GrBackendTexture& backendTexture, |
Robert Phillips | eb3eb98 | 2019-08-19 13:35:48 -0400 | [diff] [blame] | 388 | sk_sp<SkColorSpace> imageColorSpace, |
| 389 | TextureReleaseProc textureReleaseProc, |
| 390 | ReleaseContext releaseContext) { |
Brian Salomon | d2fcfb5 | 2018-09-17 21:57:11 -0400 | [diff] [blame] | 391 | SkYUVAIndex yuvaIndices[4] = { |
Robert Phillips | 94ade75 | 2018-10-09 12:32:31 -0400 | [diff] [blame] | 392 | SkYUVAIndex{0, SkColorChannel::kR}, |
| 393 | SkYUVAIndex{1, SkColorChannel::kR}, |
| 394 | SkYUVAIndex{1, SkColorChannel::kG}, |
Robert Phillips | 66a9734 | 2018-10-04 09:10:29 -0400 | [diff] [blame] | 395 | SkYUVAIndex{-1, SkColorChannel::kA}}; |
Brian Salomon | d2fcfb5 | 2018-09-17 21:57:11 -0400 | [diff] [blame] | 396 | SkISize size{nv12Textures[0].width(), nv12Textures[0].height()}; |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 397 | return SkImage_Gpu::MakeFromYUVATexturesCopyWithExternalBackend( |
| 398 | ctx, yuvColorSpace, nv12Textures, yuvaIndices, size, imageOrigin, backendTexture, |
Robert Phillips | eb3eb98 | 2019-08-19 13:35:48 -0400 | [diff] [blame] | 399 | std::move(imageColorSpace), textureReleaseProc, releaseContext); |
Brian Salomon | d2fcfb5 | 2018-09-17 21:57:11 -0400 | [diff] [blame] | 400 | } |
| 401 | |
Greg Daniel | 5f4b09d | 2018-06-12 16:39:59 -0400 | [diff] [blame] | 402 | static sk_sp<SkImage> create_image_from_producer(GrContext* context, GrTextureProducer* producer, |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 403 | uint32_t id, GrMipMapped mipMapped) { |
Greg Daniel | 81b9897 | 2019-12-13 11:09:43 -0500 | [diff] [blame] | 404 | // TODO: have texture producer return a GrSurfaceProxyView |
Greg Daniel | 82c6b10 | 2020-01-21 10:33:22 -0500 | [diff] [blame] | 405 | auto [proxy, colorType] = producer->refTextureProxy(mipMapped); |
Robert Phillips | 3798c86 | 2017-03-27 11:08:16 -0400 | [diff] [blame] | 406 | if (!proxy) { |
Brian Osman | 041f7df | 2017-02-07 11:23:28 -0500 | [diff] [blame] | 407 | return nullptr; |
| 408 | } |
Greg Daniel | 81b9897 | 2019-12-13 11:09:43 -0500 | [diff] [blame] | 409 | GrSurfaceOrigin origin = proxy->origin(); |
| 410 | const GrSwizzle& swizzle = proxy->textureSwizzle(); |
| 411 | GrSurfaceProxyView view(std::move(proxy), origin, swizzle); |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 412 | return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), id, std::move(view), |
| 413 | GrColorTypeToSkColorType(colorType), |
| 414 | producer->alphaType(), sk_ref_sp(producer->colorSpace())); |
Brian Osman | 041f7df | 2017-02-07 11:23:28 -0500 | [diff] [blame] | 415 | } |
| 416 | |
Brian Osman | d566e2e | 2019-08-14 13:19:04 -0400 | [diff] [blame] | 417 | sk_sp<SkImage> SkImage::makeTextureImage(GrContext* context, GrMipMapped mipMapped) const { |
Brian Osman | 041f7df | 2017-02-07 11:23:28 -0500 | [diff] [blame] | 418 | if (!context) { |
| 419 | return nullptr; |
| 420 | } |
Robert Phillips | fe0963c | 2019-02-07 13:25:07 -0500 | [diff] [blame] | 421 | |
| 422 | if (this->isTextureBacked()) { |
| 423 | if (!as_IB(this)->context()->priv().matches(context)) { |
Greg Daniel | 5f4b09d | 2018-06-12 16:39:59 -0400 | [diff] [blame] | 424 | return nullptr; |
| 425 | } |
Robert Phillips | fe0963c | 2019-02-07 13:25:07 -0500 | [diff] [blame] | 426 | |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 427 | sk_sp<GrTextureProxy> proxy = as_IB(this)->asTextureProxyRef(context); |
Greg Daniel | 5f4b09d | 2018-06-12 16:39:59 -0400 | [diff] [blame] | 428 | SkASSERT(proxy); |
| 429 | if (GrMipMapped::kNo == mipMapped || proxy->mipMapped() == mipMapped) { |
| 430 | return sk_ref_sp(const_cast<SkImage*>(this)); |
| 431 | } |
Brian Salomon | 1a217eb | 2019-10-24 10:50:36 -0400 | [diff] [blame] | 432 | GrTextureAdjuster adjuster(context, std::move(proxy), this->imageInfo().colorInfo(), |
| 433 | this->uniqueID()); |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 434 | return create_image_from_producer(context, &adjuster, this->uniqueID(), mipMapped); |
Brian Osman | 041f7df | 2017-02-07 11:23:28 -0500 | [diff] [blame] | 435 | } |
| 436 | |
Brian Osman | df7e075 | 2017-04-26 16:20:28 -0400 | [diff] [blame] | 437 | if (this->isLazyGenerated()) { |
| 438 | GrImageTextureMaker maker(context, this, kDisallow_CachingHint); |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 439 | return create_image_from_producer(context, &maker, this->uniqueID(), mipMapped); |
Brian Osman | 041f7df | 2017-02-07 11:23:28 -0500 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | if (const SkBitmap* bmp = as_IB(this)->onPeekBitmap()) { |
| 443 | GrBitmapTextureMaker maker(context, *bmp); |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 444 | return create_image_from_producer(context, &maker, this->uniqueID(), mipMapped); |
Brian Osman | 041f7df | 2017-02-07 11:23:28 -0500 | [diff] [blame] | 445 | } |
| 446 | return nullptr; |
| 447 | } |
| 448 | |
Greg Daniel | 7278d68 | 2018-03-16 14:57:21 -0400 | [diff] [blame] | 449 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 450 | |
Greg Daniel | a8d9211 | 2018-03-09 12:05:04 -0500 | [diff] [blame] | 451 | sk_sp<SkImage> SkImage_Gpu::MakePromiseTexture(GrContext* context, |
| 452 | const GrBackendFormat& backendFormat, |
| 453 | int width, |
| 454 | int height, |
| 455 | GrMipMapped mipMapped, |
| 456 | GrSurfaceOrigin origin, |
| 457 | SkColorType colorType, |
| 458 | SkAlphaType alphaType, |
| 459 | sk_sp<SkColorSpace> colorSpace, |
Brian Salomon | cdd8a0a | 2019-01-10 12:09:52 -0500 | [diff] [blame] | 460 | PromiseImageTextureFulfillProc textureFulfillProc, |
| 461 | PromiseImageTextureReleaseProc textureReleaseProc, |
Brian Salomon | f55e8d5 | 2019-01-30 17:28:20 -0500 | [diff] [blame] | 462 | PromiseImageTextureDoneProc textureDoneProc, |
Brian Salomon | 0cc5754 | 2019-03-08 13:28:46 -0500 | [diff] [blame] | 463 | PromiseImageTextureContext textureContext, |
| 464 | PromiseImageApiVersion version) { |
Robert Phillips | ef85d19 | 2018-10-09 11:24:09 -0400 | [diff] [blame] | 465 | // The contract here is that if 'promiseDoneProc' is passed in it should always be called, |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 466 | // even if creation of the SkImage fails. Once we call MakePromiseImageLazyProxy it takes |
| 467 | // responsibility for calling the done proc. |
Brian Salomon | f55e8d5 | 2019-01-30 17:28:20 -0500 | [diff] [blame] | 468 | if (!textureDoneProc) { |
Robert Phillips | ef85d19 | 2018-10-09 11:24:09 -0400 | [diff] [blame] | 469 | return nullptr; |
| 470 | } |
Brian Salomon | f55e8d5 | 2019-01-30 17:28:20 -0500 | [diff] [blame] | 471 | SkScopeExit callDone([textureDoneProc, textureContext]() { textureDoneProc(textureContext); }); |
Robert Phillips | ef85d19 | 2018-10-09 11:24:09 -0400 | [diff] [blame] | 472 | |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 473 | SkImageInfo info = SkImageInfo::Make(width, height, colorType, alphaType, colorSpace); |
| 474 | if (!SkImageInfoIsValid(info)) { |
| 475 | return nullptr; |
| 476 | } |
Robert Phillips | ef85d19 | 2018-10-09 11:24:09 -0400 | [diff] [blame] | 477 | |
Greg Daniel | a8d9211 | 2018-03-09 12:05:04 -0500 | [diff] [blame] | 478 | if (!context) { |
| 479 | return nullptr; |
| 480 | } |
| 481 | |
| 482 | if (width <= 0 || height <= 0) { |
| 483 | return nullptr; |
| 484 | } |
| 485 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 486 | GrColorType grColorType = SkColorTypeAndFormatToGrColorType(context->priv().caps(), |
| 487 | colorType, |
| 488 | backendFormat); |
| 489 | if (GrColorType::kUnknown == grColorType) { |
Greg Daniel | a8d9211 | 2018-03-09 12:05:04 -0500 | [diff] [blame] | 490 | return nullptr; |
| 491 | } |
| 492 | |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 493 | callDone.clear(); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 494 | auto proxy = MakePromiseImageLazyProxy(context, width, height, origin, |
| 495 | grColorType, backendFormat, |
Brian Salomon | be5a093 | 2018-12-10 10:03:26 -0500 | [diff] [blame] | 496 | mipMapped, textureFulfillProc, textureReleaseProc, |
Brian Salomon | 0cc5754 | 2019-03-08 13:28:46 -0500 | [diff] [blame] | 497 | textureDoneProc, textureContext, version); |
Greg Daniel | a8d9211 | 2018-03-09 12:05:04 -0500 | [diff] [blame] | 498 | if (!proxy) { |
| 499 | return nullptr; |
| 500 | } |
Greg Daniel | 14b5721 | 2019-12-17 16:18:06 -0500 | [diff] [blame] | 501 | GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(backendFormat, grColorType); |
Greg Daniel | 81b9897 | 2019-12-13 11:09:43 -0500 | [diff] [blame] | 502 | GrSurfaceProxyView view(std::move(proxy), origin, swizzle); |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 503 | return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, std::move(view), |
| 504 | colorType, alphaType, std::move(colorSpace)); |
Greg Daniel | a8d9211 | 2018-03-09 12:05:04 -0500 | [diff] [blame] | 505 | } |
| 506 | |
Greg Daniel | 7278d68 | 2018-03-16 14:57:21 -0400 | [diff] [blame] | 507 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 508 | |
Brian Osman | 584b501 | 2018-04-13 15:48:26 -0400 | [diff] [blame] | 509 | sk_sp<SkImage> SkImage::MakeCrossContextFromPixmap(GrContext* context, |
| 510 | const SkPixmap& originalPixmap, bool buildMips, |
Brian Osman | 584b501 | 2018-04-13 15:48:26 -0400 | [diff] [blame] | 511 | bool limitToMaxTextureSize) { |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 512 | // Some backends or drivers don't support (safely) moving resources between contexts |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 513 | if (!context || !context->priv().caps()->crossContextTextureSupport()) { |
Brian Osman | 584b501 | 2018-04-13 15:48:26 -0400 | [diff] [blame] | 514 | return SkImage::MakeRasterCopy(originalPixmap); |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 515 | } |
| 516 | |
Greg Daniel | 9e78811 | 2018-02-08 14:29:37 -0500 | [diff] [blame] | 517 | // If we don't have access to the resource provider and gpu (i.e. in a DDL context) we will not |
| 518 | // be able to make everything needed for a GPU CrossContext image. Thus return a raster copy |
| 519 | // instead. |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 520 | if (!context->priv().resourceProvider()) { |
Brian Osman | 584b501 | 2018-04-13 15:48:26 -0400 | [diff] [blame] | 521 | return SkImage::MakeRasterCopy(originalPixmap); |
Greg Daniel | 9e78811 | 2018-02-08 14:29:37 -0500 | [diff] [blame] | 522 | } |
| 523 | |
Brian Osman | 0471a93 | 2019-02-07 13:36:56 -0500 | [diff] [blame] | 524 | // If non-power-of-two mipmapping isn't supported, ignore the client's request |
| 525 | if (!context->priv().caps()->mipMapSupport()) { |
| 526 | buildMips = false; |
| 527 | } |
| 528 | |
Brian Osman | 584b501 | 2018-04-13 15:48:26 -0400 | [diff] [blame] | 529 | const SkPixmap* pixmap = &originalPixmap; |
| 530 | SkAutoPixmapStorage resized; |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 531 | int maxTextureSize = context->priv().caps()->maxTextureSize(); |
Brian Osman | 584b501 | 2018-04-13 15:48:26 -0400 | [diff] [blame] | 532 | int maxDim = SkTMax(originalPixmap.width(), originalPixmap.height()); |
| 533 | if (limitToMaxTextureSize && maxDim > maxTextureSize) { |
| 534 | float scale = static_cast<float>(maxTextureSize) / maxDim; |
| 535 | int newWidth = SkTMin(static_cast<int>(originalPixmap.width() * scale), maxTextureSize); |
| 536 | int newHeight = SkTMin(static_cast<int>(originalPixmap.height() * scale), maxTextureSize); |
| 537 | SkImageInfo info = originalPixmap.info().makeWH(newWidth, newHeight); |
| 538 | if (!resized.tryAlloc(info) || !originalPixmap.scalePixels(resized, kLow_SkFilterQuality)) { |
| 539 | return nullptr; |
| 540 | } |
| 541 | pixmap = &resized; |
| 542 | } |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 543 | // Turn the pixmap into a GrTextureProxy |
Brian Osman | 7dcc616 | 2019-03-25 10:12:57 -0400 | [diff] [blame] | 544 | SkBitmap bmp; |
| 545 | bmp.installPixels(*pixmap); |
Greg Daniel | 82c6b10 | 2020-01-21 10:33:22 -0500 | [diff] [blame] | 546 | GrBitmapTextureMaker bitmapMaker(context, bmp, false, false); |
Brian Osman | 7dcc616 | 2019-03-25 10:12:57 -0400 | [diff] [blame] | 547 | GrMipMapped mipMapped = buildMips ? GrMipMapped::kYes : GrMipMapped::kNo; |
Greg Daniel | 82c6b10 | 2020-01-21 10:33:22 -0500 | [diff] [blame] | 548 | auto [proxy, grCT] = bitmapMaker.refTextureProxy(mipMapped); |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 549 | if (!proxy) { |
Brian Osman | 584b501 | 2018-04-13 15:48:26 -0400 | [diff] [blame] | 550 | return SkImage::MakeRasterCopy(*pixmap); |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 551 | } |
| 552 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 553 | sk_sp<GrTexture> texture = sk_ref_sp(proxy->peekTexture()); |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 554 | |
| 555 | // Flush any writes or uploads |
Greg Daniel | 4aa13e7 | 2019-04-15 14:42:20 -0400 | [diff] [blame] | 556 | context->priv().flushSurface(proxy.get()); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 557 | GrGpu* gpu = context->priv().getGpu(); |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 558 | |
Greg Daniel | 301015c | 2019-11-18 14:06:46 -0500 | [diff] [blame] | 559 | std::unique_ptr<GrSemaphore> sema = gpu->prepareTextureForCrossContextUsage(texture.get()); |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 560 | |
Greg Daniel | 82c6b10 | 2020-01-21 10:33:22 -0500 | [diff] [blame] | 561 | SkColorType skCT = GrColorTypeToSkColorType(grCT); |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 562 | auto gen = GrBackendTextureImageGenerator::Make(std::move(texture), proxy->origin(), |
Greg Daniel | 82c6b10 | 2020-01-21 10:33:22 -0500 | [diff] [blame] | 563 | std::move(sema), skCT, |
Brian Osman | 584b501 | 2018-04-13 15:48:26 -0400 | [diff] [blame] | 564 | pixmap->alphaType(), |
| 565 | pixmap->info().refColorSpace()); |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 566 | return SkImage::MakeFromGenerator(std::move(gen)); |
| 567 | } |
| 568 | |
Derek Sollenberger | 7a86987 | 2017-06-27 15:37:25 -0400 | [diff] [blame] | 569 | #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 |
Stan Iliev | 7e910df | 2017-06-02 10:29:21 -0400 | [diff] [blame] | 570 | sk_sp<SkImage> SkImage::MakeFromAHardwareBuffer(AHardwareBuffer* graphicBuffer, SkAlphaType at, |
Stan Iliev | 505dd57 | 2018-09-13 14:20:03 -0400 | [diff] [blame] | 571 | sk_sp<SkColorSpace> cs, |
| 572 | GrSurfaceOrigin surfaceOrigin) { |
| 573 | auto gen = GrAHardwareBufferImageGenerator::Make(graphicBuffer, at, cs, surfaceOrigin); |
Stan Iliev | 7e910df | 2017-06-02 10:29:21 -0400 | [diff] [blame] | 574 | return SkImage::MakeFromGenerator(std::move(gen)); |
| 575 | } |
Greg Daniel | b6c15ba | 2019-03-04 13:08:25 -0500 | [diff] [blame] | 576 | |
| 577 | sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context, |
| 578 | const SkPixmap& pixmap, |
| 579 | AHardwareBuffer* hardwareBuffer, |
| 580 | GrSurfaceOrigin surfaceOrigin) { |
| 581 | AHardwareBuffer_Desc bufferDesc; |
| 582 | AHardwareBuffer_describe(hardwareBuffer, &bufferDesc); |
| 583 | |
| 584 | if (!SkToBool(bufferDesc.usage & AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE)) { |
| 585 | return nullptr; |
| 586 | } |
| 587 | |
| 588 | GrBackendFormat backendFormat = GrAHardwareBufferUtils::GetBackendFormat(context, |
| 589 | hardwareBuffer, |
| 590 | bufferDesc.format, |
| 591 | true); |
| 592 | |
| 593 | if (!backendFormat.isValid()) { |
| 594 | return nullptr; |
| 595 | } |
| 596 | |
| 597 | GrAHardwareBufferUtils::DeleteImageProc deleteImageProc = nullptr; |
Stan Iliev | a56b04a | 2019-08-01 14:22:34 -0400 | [diff] [blame] | 598 | GrAHardwareBufferUtils::UpdateImageProc updateImageProc = nullptr; |
| 599 | GrAHardwareBufferUtils::TexImageCtx deleteImageCtx = nullptr; |
Greg Daniel | b6c15ba | 2019-03-04 13:08:25 -0500 | [diff] [blame] | 600 | |
| 601 | GrBackendTexture backendTexture = |
| 602 | GrAHardwareBufferUtils::MakeBackendTexture(context, hardwareBuffer, |
| 603 | bufferDesc.width, bufferDesc.height, |
Stan Iliev | a56b04a | 2019-08-01 14:22:34 -0400 | [diff] [blame] | 604 | &deleteImageProc, &updateImageProc, |
| 605 | &deleteImageCtx, false, backendFormat, true); |
Greg Daniel | b6c15ba | 2019-03-04 13:08:25 -0500 | [diff] [blame] | 606 | if (!backendTexture.isValid()) { |
| 607 | return nullptr; |
| 608 | } |
| 609 | SkASSERT(deleteImageProc); |
| 610 | |
| 611 | SkColorType colorType = |
| 612 | GrAHardwareBufferUtils::GetSkColorTypeFromBufferFormat(bufferDesc.format); |
| 613 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 614 | GrColorType grColorType = SkColorTypeToGrColorType(colorType); |
Greg Daniel | b6c15ba | 2019-03-04 13:08:25 -0500 | [diff] [blame] | 615 | |
| 616 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
| 617 | if (!proxyProvider) { |
| 618 | deleteImageProc(deleteImageCtx); |
| 619 | return nullptr; |
| 620 | } |
| 621 | |
| 622 | sk_sp<GrTextureProxy> proxy = |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 623 | proxyProvider->wrapBackendTexture(backendTexture, grColorType, surfaceOrigin, |
Greg Daniel | b6c15ba | 2019-03-04 13:08:25 -0500 | [diff] [blame] | 624 | kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, |
| 625 | kRW_GrIOType, deleteImageProc, deleteImageCtx); |
| 626 | if (!proxy) { |
| 627 | deleteImageProc(deleteImageCtx); |
| 628 | return nullptr; |
| 629 | } |
| 630 | |
| 631 | sk_sp<SkColorSpace> cs = pixmap.refColorSpace(); |
| 632 | SkAlphaType at = pixmap.alphaType(); |
| 633 | |
Greg Daniel | 14b5721 | 2019-12-17 16:18:06 -0500 | [diff] [blame] | 634 | GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(backendFormat, grColorType); |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 635 | GrSurfaceProxyView view(std::move(proxy), surfaceOrigin, swizzle); |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 636 | sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, view, |
| 637 | colorType, at, cs); |
Greg Daniel | b6c15ba | 2019-03-04 13:08:25 -0500 | [diff] [blame] | 638 | if (!image) { |
| 639 | return nullptr; |
| 640 | } |
| 641 | |
| 642 | GrDrawingManager* drawingManager = context->priv().drawingManager(); |
| 643 | if (!drawingManager) { |
| 644 | return nullptr; |
| 645 | } |
| 646 | |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 647 | GrSurfaceContext surfaceContext(context, std::move(view), |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 648 | SkColorTypeToGrColorType(pixmap.colorType()), |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 649 | pixmap.alphaType(), cs); |
Greg Daniel | b6c15ba | 2019-03-04 13:08:25 -0500 | [diff] [blame] | 650 | |
| 651 | SkImageInfo srcInfo = SkImageInfo::Make(bufferDesc.width, bufferDesc.height, colorType, at, |
| 652 | std::move(cs)); |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 653 | surfaceContext.writePixels(srcInfo, pixmap.addr(0, 0), pixmap.rowBytes(), {0, 0}); |
Greg Daniel | b6c15ba | 2019-03-04 13:08:25 -0500 | [diff] [blame] | 654 | |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 655 | GrFlushInfo info; |
| 656 | info.fFlags = kSyncCpu_GrFlushFlag; |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 657 | GrSurfaceProxy* p[1] = {surfaceContext.asSurfaceProxy()}; |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 658 | drawingManager->flush(p, 1, SkSurface::BackendSurfaceAccess::kNoAccess, info, |
| 659 | GrPrepareForExternalIORequests()); |
Greg Daniel | b6c15ba | 2019-03-04 13:08:25 -0500 | [diff] [blame] | 660 | |
| 661 | return image; |
| 662 | } |
Stan Iliev | 7e910df | 2017-06-02 10:29:21 -0400 | [diff] [blame] | 663 | #endif |
| 664 | |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 665 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 666 | |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 667 | bool SkImage::MakeBackendTextureFromSkImage(GrContext* ctx, |
| 668 | sk_sp<SkImage> image, |
| 669 | GrBackendTexture* backendTexture, |
| 670 | BackendTextureReleaseProc* releaseProc) { |
| 671 | if (!image || !ctx || !backendTexture || !releaseProc) { |
| 672 | return false; |
| 673 | } |
| 674 | |
| 675 | // Ensure we have a texture backed image. |
| 676 | if (!image->isTextureBacked()) { |
Brian Osman | d566e2e | 2019-08-14 13:19:04 -0400 | [diff] [blame] | 677 | image = image->makeTextureImage(ctx); |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 678 | if (!image) { |
| 679 | return false; |
| 680 | } |
| 681 | } |
| 682 | GrTexture* texture = image->getTexture(); |
Eric Karl | 36591e5 | 2018-01-19 13:45:02 -0800 | [diff] [blame] | 683 | if (!texture) { |
| 684 | // In context-loss cases, we may not have a texture. |
| 685 | return false; |
| 686 | } |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 687 | |
| 688 | // If the image's context doesn't match the provided context, fail. |
| 689 | if (texture->getContext() != ctx) { |
| 690 | return false; |
| 691 | } |
| 692 | |
| 693 | // Flush any pending IO on the texture. |
Greg Daniel | 4aa13e7 | 2019-04-15 14:42:20 -0400 | [diff] [blame] | 694 | ctx->priv().flushSurface(as_IB(image)->peekProxy()); |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 695 | |
| 696 | // We must make a copy of the image if the image is not unique, if the GrTexture owned by the |
| 697 | // image is not unique, or if the texture wraps an external object. |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 698 | if (!image->unique() || !texture->unique() || |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 699 | texture->resourcePriv().refsWrappedObjects()) { |
| 700 | // onMakeSubset will always copy the image. |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 701 | image = as_IB(image)->onMakeSubset(ctx, image->bounds()); |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 702 | if (!image) { |
| 703 | return false; |
| 704 | } |
| 705 | |
| 706 | texture = image->getTexture(); |
Eric Karl | 36591e5 | 2018-01-19 13:45:02 -0800 | [diff] [blame] | 707 | if (!texture) { |
| 708 | return false; |
| 709 | } |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 710 | |
| 711 | // Flush to ensure that the copy is completed before we return the texture. |
Greg Daniel | 4aa13e7 | 2019-04-15 14:42:20 -0400 | [diff] [blame] | 712 | ctx->priv().flushSurface(as_IB(image)->peekProxy()); |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | SkASSERT(!texture->resourcePriv().refsWrappedObjects()); |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 716 | SkASSERT(texture->unique()); |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 717 | SkASSERT(image->unique()); |
| 718 | |
| 719 | // Take a reference to the GrTexture and release the image. |
| 720 | sk_sp<GrTexture> textureRef(SkSafeRef(texture)); |
| 721 | image = nullptr; |
| 722 | |
| 723 | // Steal the backend texture from the GrTexture, releasing the GrTexture in the process. |
| 724 | return GrTexture::StealBackendTexture(std::move(textureRef), backendTexture, releaseProc); |
| 725 | } |