blob: b5d68bf865993b0b2480d91fa7a9d7dfdc1adf4c [file] [log] [blame]
reed@google.com6997ebb2012-07-30 19:50:31 +00001/*
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
reed@google.comf6627b72012-07-27 18:02:50 +00008#include "SkBitmap.h"
fmalita3b0d5322015-09-18 08:07:31 -07009#include "SkBitmapCache.h"
mike@reedtribe.org70e35902012-07-29 20:38:16 +000010#include "SkCanvas.h"
Mike Klein919cc452017-03-18 15:36:52 +000011#include "SkColorSpace_Base.h"
reed871872f2015-06-22 12:48:26 -070012#include "SkData.h"
halcanaryf2848b62015-12-10 12:40:23 -080013#include "SkImageEncoder.h"
senorblanco5878dbd2016-05-19 14:50:29 -070014#include "SkImageFilter.h"
brianosman04a44d02016-09-21 09:46:57 -070015#include "SkImageFilterCache.h"
reed5965c8a2015-01-07 18:04:45 -080016#include "SkImageGenerator.h"
scroggo@google.com7def5e12013-05-31 14:00:10 +000017#include "SkImagePriv.h"
reed856e9d92015-09-30 12:21:45 -070018#include "SkImageShader.h"
scroggo@google.com7def5e12013-05-31 14:00:10 +000019#include "SkImage_Base.h"
reed80c772b2015-07-30 18:58:23 -070020#include "SkNextID.h"
reed7fb4f8b2016-03-11 04:33:52 -080021#include "SkPicture.h"
reed56179002015-07-07 06:11:19 -070022#include "SkPixelRef.h"
reed96472de2014-12-10 09:53:42 -080023#include "SkReadPixelsRec.h"
senorblanco5878dbd2016-05-19 14:50:29 -070024#include "SkSpecialImage.h"
reedf8d18742015-01-02 20:45:37 -080025#include "SkString.h"
reed4af267b2014-11-21 08:46:37 -080026#include "SkSurface.h"
reed56179002015-07-07 06:11:19 -070027
bsalomon55812362015-06-10 08:49:28 -070028#if SK_SUPPORT_GPU
29#include "GrTexture.h"
30#include "GrContext.h"
reed56179002015-07-07 06:11:19 -070031#include "SkImage_Gpu.h"
bsalomon55812362015-06-10 08:49:28 -070032#endif
scroggo@google.com7def5e12013-05-31 14:00:10 +000033
reed80c772b2015-07-30 18:58:23 -070034SkImage::SkImage(int width, int height, uint32_t uniqueID)
35 : fWidth(width)
36 , fHeight(height)
37 , fUniqueID(kNeedNewImageUniqueID == uniqueID ? SkNextID::ImageID() : uniqueID)
38{
39 SkASSERT(width > 0);
40 SkASSERT(height > 0);
reed@google.comf6627b72012-07-27 18:02:50 +000041}
42
reed6ceeebd2016-03-09 14:26:26 -080043bool SkImage::peekPixels(SkPixmap* pm) const {
44 SkPixmap tmp;
45 if (!pm) {
46 pm = &tmp;
reed@google.com4f7c6152014-02-06 14:11:56 +000047 }
reed6ceeebd2016-03-09 14:26:26 -080048 return as_IB(this)->onPeekPixels(pm);
reed@google.com4f7c6152014-02-06 14:11:56 +000049}
50
reed96472de2014-12-10 09:53:42 -080051bool SkImage::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
reed09553032015-11-23 12:32:16 -080052 int srcX, int srcY, CachingHint chint) const {
Matt Sarett03dd6d52017-01-23 12:15:09 -050053 return as_IB(this)->onReadPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY, chint);
reed09553032015-11-23 12:32:16 -080054}
55
56bool SkImage::scalePixels(const SkPixmap& dst, SkFilterQuality quality, CachingHint chint) const {
reed6868c3f2015-11-24 11:44:47 -080057 if (this->width() == dst.width() && this->height() == dst.height()) {
58 return this->readPixels(dst, 0, 0, chint);
59 }
60
reed09553032015-11-23 12:32:16 -080061 // Idea: If/when SkImageGenerator supports a native-scaling API (where the generator itself
62 // can scale more efficiently) we should take advantage of it here.
63 //
64 SkBitmap bm;
Brian Osman61624f02016-12-09 14:51:59 -050065 if (as_IB(this)->getROPixels(&bm, dst.info().colorSpace(), chint)) {
reed09553032015-11-23 12:32:16 -080066 SkPixmap pmap;
67 // Note: By calling the pixmap scaler, we never cache the final result, so the chint
68 // is (currently) only being applied to the getROPixels. If we get a request to
69 // also attempt to cache the final (scaled) result, we would add that logic here.
70 //
71 return bm.peekPixels(&pmap) && pmap.scalePixels(dst, quality);
72 }
73 return false;
reed@google.com4f7c6152014-02-06 14:11:56 +000074}
75
reed88d064d2015-10-12 11:30:02 -070076///////////////////////////////////////////////////////////////////////////////////////////////////
77
brianosman69c166d2016-08-17 14:01:05 -070078SkAlphaType SkImage::alphaType() const {
79 return as_IB(this)->onAlphaType();
80}
81
Matt Sarett5b4599f2017-03-02 12:42:35 -050082SkColorSpace* SkImage::colorSpace() const {
83 return as_IB(this)->onImageInfo().colorSpace();
84}
85
86sk_sp<SkColorSpace> SkImage::refColorSpace() const {
87 return as_IB(this)->onImageInfo().refColorSpace();
88}
89
reed5671c5b2016-03-09 14:47:34 -080090sk_sp<SkShader> SkImage::makeShader(SkShader::TileMode tileX, SkShader::TileMode tileY,
91 const SkMatrix* localMatrix) const {
reed6b2d7ac2016-08-11 06:42:26 -070092 return SkImageShader::Make(sk_ref_sp(const_cast<SkImage*>(this)), tileX, tileY, localMatrix);
piotaixrcef04f82014-07-14 07:48:04 -070093}
94
Mike Reed6409f842017-07-11 16:03:13 -040095sk_sp<SkData> SkImage::encodeToData(SkEncodedImageFormat type, int quality) const {
Leon Scroggins294c1c42016-11-08 14:29:46 +000096 SkBitmap bm;
Brian Osman61624f02016-12-09 14:51:59 -050097 SkColorSpace* legacyColorSpace = nullptr;
98 if (as_IB(this)->getROPixels(&bm, legacyColorSpace)) {
Mike Reed25eef6b2017-12-08 16:20:58 -050099 return SkEncodeBitmap(bm, type, quality);
Leon Scroggins294c1c42016-11-08 14:29:46 +0000100 }
101 return nullptr;
102}
103
Mike Reedef038482017-12-16 08:41:28 -0500104sk_sp<SkData> SkImage::encodeToData() const {
105 if (auto encoded = this->refEncodedData()) {
Mike Reed6409f842017-07-11 16:03:13 -0400106 return encoded;
fmalita2be71252015-09-03 07:17:25 -0700107 }
108
109 SkBitmap bm;
Mike Reed4edb5d22017-04-17 11:02:51 -0400110 SkPixmap pmap;
Brian Osman61624f02016-12-09 14:51:59 -0500111 SkColorSpace* legacyColorSpace = nullptr;
Mike Reed4edb5d22017-04-17 11:02:51 -0400112 if (as_IB(this)->getROPixels(&bm, legacyColorSpace) && bm.peekPixels(&pmap)) {
Mike Reedef038482017-12-16 08:41:28 -0500113 return SkEncodePixmap(pmap, SkEncodedImageFormat::kPNG, 100);
fmalita2be71252015-09-03 07:17:25 -0700114 }
fmalita2be71252015-09-03 07:17:25 -0700115 return nullptr;
116}
117
Mike Reed6409f842017-07-11 16:03:13 -0400118sk_sp<SkData> SkImage::refEncodedData() const {
119 return sk_sp<SkData>(as_IB(this)->onRefEncoded());
reed871872f2015-06-22 12:48:26 -0700120}
121
reed7fb4f8b2016-03-11 04:33:52 -0800122sk_sp<SkImage> SkImage::MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset) {
halcanary96fcdcc2015-08-27 07:41:13 -0700123 if (nullptr == encoded || 0 == encoded->size()) {
124 return nullptr;
reed5965c8a2015-01-07 18:04:45 -0800125 }
Mike Reed185130c2017-02-15 15:14:16 -0500126 return SkImage::MakeFromGenerator(SkImageGenerator::MakeFromEncoded(encoded), subset);
reed5965c8a2015-01-07 18:04:45 -0800127}
128
Mike Reed6409f842017-07-11 16:03:13 -0400129///////////////////////////////////////////////////////////////////////////////////////////////////
130
reedf8d18742015-01-02 20:45:37 -0800131const char* SkImage::toString(SkString* str) const {
132 str->appendf("image: (id:%d (%d, %d) %s)", this->uniqueID(), this->width(), this->height(),
133 this->isOpaque() ? "opaque" : "");
134 return str->c_str();
135}
136
reed7fb4f8b2016-03-11 04:33:52 -0800137sk_sp<SkImage> SkImage::makeSubset(const SkIRect& subset) const {
reed7b6945b2015-09-24 00:50:58 -0700138 if (subset.isEmpty()) {
139 return nullptr;
140 }
141
142 const SkIRect bounds = SkIRect::MakeWH(this->width(), this->height());
143 if (!bounds.contains(subset)) {
144 return nullptr;
145 }
146
147 // optimization : return self if the subset == our bounds
148 if (bounds == subset) {
reed7fb4f8b2016-03-11 04:33:52 -0800149 return sk_ref_sp(const_cast<SkImage*>(this));
reed7b6945b2015-09-24 00:50:58 -0700150 }
reed7fb4f8b2016-03-11 04:33:52 -0800151 return as_IB(this)->onMakeSubset(subset);
reedf803da12015-01-23 05:58:07 -0800152}
153
bsalomon55812362015-06-10 08:49:28 -0700154#if SK_SUPPORT_GPU
155
156GrTexture* SkImage::getTexture() const {
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400157 return as_IB(this)->onGetTexture();
bsalomon55812362015-06-10 08:49:28 -0700158}
159
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400160bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->peekProxy()); }
bsalomon55812362015-06-10 08:49:28 -0700161
Robert Phillips3390e152017-01-31 17:53:34 -0500162GrBackendObject SkImage::getTextureHandle(bool flushPendingGrContextIO,
163 GrSurfaceOrigin* origin) const {
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400164 return as_IB(this)->onGetTextureHandle(flushPendingGrContextIO, origin);
bsalomon55812362015-06-10 08:49:28 -0700165}
166
Brian Osman5bbd0762017-05-08 11:07:42 -0400167bool SkImage::isValid(GrContext* context) const {
168 if (context && context->abandoned()) {
169 return false;
170 }
171 return as_IB(this)->onIsValid(context);
172}
173
bsalomon55812362015-06-10 08:49:28 -0700174#else
175
halcanary96fcdcc2015-08-27 07:41:13 -0700176GrTexture* SkImage::getTexture() const { return nullptr; }
bsalomon55812362015-06-10 08:49:28 -0700177
178bool SkImage::isTextureBacked() const { return false; }
179
Robert Phillips3390e152017-01-31 17:53:34 -0500180GrBackendObject SkImage::getTextureHandle(bool, GrSurfaceOrigin*) const { return 0; }
bsalomon55812362015-06-10 08:49:28 -0700181
Brian Osman5bbd0762017-05-08 11:07:42 -0400182bool SkImage::isValid(GrContext* context) const {
183 if (context) {
184 return false;
185 }
186 return as_IB(this)->onIsValid(context);
187}
188
bsalomon55812362015-06-10 08:49:28 -0700189#endif
190
reed@google.com4f7c6152014-02-06 14:11:56 +0000191///////////////////////////////////////////////////////////////////////////////
192
reedaf3fbfc2015-10-04 11:28:36 -0700193SkImage_Base::SkImage_Base(int width, int height, uint32_t uniqueID)
fmalita3b0d5322015-09-18 08:07:31 -0700194 : INHERITED(width, height, uniqueID)
fmalita3b0d5322015-09-18 08:07:31 -0700195 , fAddedToCache(false)
reedaf3fbfc2015-10-04 11:28:36 -0700196{}
fmalita3b0d5322015-09-18 08:07:31 -0700197
198SkImage_Base::~SkImage_Base() {
199 if (fAddedToCache.load()) {
200 SkNotifyBitmapGenIDIsStale(this->uniqueID());
201 }
202}
203
reed09553032015-11-23 12:32:16 -0800204bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY, CachingHint chint) const {
205 return this->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(), srcX, srcY, chint);
reed871872f2015-06-22 12:48:26 -0700206}
207
208///////////////////////////////////////////////////////////////////////////////////////////////////
reedf803da12015-01-23 05:58:07 -0800209
reed7fb4f8b2016-03-11 04:33:52 -0800210sk_sp<SkImage> SkImage::MakeFromBitmap(const SkBitmap& bm) {
reed56179002015-07-07 06:11:19 -0700211 SkPixelRef* pr = bm.pixelRef();
halcanary96fcdcc2015-08-27 07:41:13 -0700212 if (nullptr == pr) {
213 return nullptr;
reed56179002015-07-07 06:11:19 -0700214 }
215
reed1ec04d92016-08-05 12:07:41 -0700216 return SkMakeImageFromRasterBitmap(bm, kIfMutable_SkCopyPixelsMode);
reed56179002015-07-07 06:11:19 -0700217}
218
reed3c065112015-07-08 12:46:22 -0700219bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {
220 return as_IB(this)->onAsLegacyBitmap(bitmap, mode);
221}
222
223bool SkImage_Base::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {
224 // As the base-class, all we can do is make a copy (regardless of mode).
225 // Subclasses that want to be more optimal should override.
Brian Osman7992da32016-11-18 11:28:24 -0500226 SkImageInfo info = this->onImageInfo().makeColorType(kN32_SkColorType).makeColorSpace(nullptr);
reed3c065112015-07-08 12:46:22 -0700227 if (!bitmap->tryAllocPixels(info)) {
228 return false;
229 }
230 if (!this->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(), 0, 0)) {
231 bitmap->reset();
232 return false;
233 }
234
235 if (kRO_LegacyBitmapMode == mode) {
236 bitmap->setImmutable();
237 }
238 return true;
239}
240
Brian Osman138ea972016-12-16 11:55:18 -0500241sk_sp<SkImage> SkImage::MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
Matt Sarette94255d2017-01-09 12:38:59 -0500242 const SkMatrix* matrix, const SkPaint* paint,
243 BitDepth bitDepth, sk_sp<SkColorSpace> colorSpace) {
Mike Reed185130c2017-02-15 15:14:16 -0500244 return MakeFromGenerator(SkImageGenerator::MakeFromPicture(dimensions, std::move(picture),
245 matrix, paint, bitDepth,
246 std::move(colorSpace)));
Matt Sarette94255d2017-01-09 12:38:59 -0500247}
Robert Phillipsa5fdc972017-02-18 16:58:09 -0500248
senorblanco5878dbd2016-05-19 14:50:29 -0700249sk_sp<SkImage> SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRect& subset,
250 const SkIRect& clipBounds, SkIRect* outSubset,
251 SkIPoint* offset) const {
brianosman04a44d02016-09-21 09:46:57 -0700252 if (!filter || !outSubset || !offset || !this->bounds().contains(subset)) {
253 return nullptr;
254 }
Brian Osman7992da32016-11-18 11:28:24 -0500255 SkColorSpace* colorSpace = as_IB(this)->onImageInfo().colorSpace();
brianosman04a44d02016-09-21 09:46:57 -0700256 sk_sp<SkSpecialImage> srcSpecialImage = SkSpecialImage::MakeFromImage(
Brian Osman61624f02016-12-09 14:51:59 -0500257 subset, sk_ref_sp(const_cast<SkImage*>(this)), colorSpace);
brianosman04a44d02016-09-21 09:46:57 -0700258 if (!srcSpecialImage) {
259 return nullptr;
260 }
senorblanco5878dbd2016-05-19 14:50:29 -0700261
Hal Canary67b39de2016-11-07 11:47:44 -0500262 sk_sp<SkImageFilterCache> cache(
brianosman04a44d02016-09-21 09:46:57 -0700263 SkImageFilterCache::Create(SkImageFilterCache::kDefaultTransientSize));
Brian Osman7992da32016-11-18 11:28:24 -0500264 SkImageFilter::OutputProperties outputProperties(colorSpace);
brianosman2a75e5d2016-09-22 07:15:37 -0700265 SkImageFilter::Context context(SkMatrix::I(), clipBounds, cache.get(), outputProperties);
266
Robert Phillipsa5fdc972017-02-18 16:58:09 -0500267 sk_sp<SkSpecialImage> result = filter->filterImage(srcSpecialImage.get(), context, offset);
brianosman04a44d02016-09-21 09:46:57 -0700268 if (!result) {
269 return nullptr;
270 }
senorblanco5878dbd2016-05-19 14:50:29 -0700271
brianosman04a44d02016-09-21 09:46:57 -0700272 *outSubset = SkIRect::MakeWH(result->width(), result->height());
273 if (!outSubset->intersect(clipBounds.makeOffset(-offset->x(), -offset->y()))) {
274 return nullptr;
275 }
276 offset->fX += outSubset->x();
277 offset->fY += outSubset->y();
Robert Phillipsa5fdc972017-02-18 16:58:09 -0500278
279 // Note that here we're returning the special image's entire backing store, loose padding
280 // and all!
281 return result->asImage();
senorblanco5878dbd2016-05-19 14:50:29 -0700282}
283
fmalitaddbbdda2015-08-20 08:47:26 -0700284bool SkImage::isLazyGenerated() const {
285 return as_IB(this)->onIsLazyGenerated();
286}
287
reed9e2ed832016-10-31 05:27:28 -0700288bool SkImage::isAlphaOnly() const {
289 return as_IB(this)->onImageInfo().colorType() == kAlpha_8_SkColorType;
290}
291
Matt Sarettcb874232017-04-05 11:41:27 -0400292sk_sp<SkImage> SkImage::makeColorSpace(sk_sp<SkColorSpace> target,
293 SkTransferFunctionBehavior premulBehavior) const {
Matt Sarett6de13102017-03-14 14:10:48 -0400294 SkColorSpaceTransferFn fn;
295 if (!target || !target->isNumericalTransferFn(&fn)) {
296 return nullptr;
297 }
298
Matt Sarett73879eb2017-03-22 10:07:50 -0400299 // No need to create a new image if:
Matt Sarettd3df9ec2017-06-05 10:45:30 -0400300 // (1) The color spaces are equal.
Matt Sarett73879eb2017-03-22 10:07:50 -0400301 // (2) The color type is kAlpha8.
Matt Sarettd3df9ec2017-06-05 10:45:30 -0400302 if (SkColorSpace::Equals(this->colorSpace(), target.get()) ||
Matt Sarettcb874232017-04-05 11:41:27 -0400303 kAlpha_8_SkColorType == as_IB(this)->onImageInfo().colorType()) {
304 return sk_ref_sp(const_cast<SkImage*>(this));
Matt Sarett6de13102017-03-14 14:10:48 -0400305 }
306
Matt Sarett9f3dcb32017-05-04 08:53:32 -0400307 SkColorType targetColorType = kN32_SkColorType;
308 if (SkTransferFunctionBehavior::kRespect == premulBehavior && target->gammaIsLinear()) {
309 targetColorType = kRGBA_F16_SkColorType;
310 }
311
Matt Sarettcb874232017-04-05 11:41:27 -0400312 // TODO: We might consider making this a deferred conversion?
Matt Sarett9f3dcb32017-05-04 08:53:32 -0400313 return as_IB(this)->onMakeColorSpace(std::move(target), targetColorType, premulBehavior);
Matt Sarett6de13102017-03-14 14:10:48 -0400314}
315
Mike Reedb950b592018-01-02 10:16:12 -0500316sk_sp<SkImage> SkImage::makeNonTextureImage() const {
317 if (!this->isTextureBacked()) {
318 return sk_ref_sp(const_cast<SkImage*>(this));
319 }
320 return this->makeRasterImage();
321}
322
Mike Reedf7ee95c2017-12-04 14:27:01 -0500323sk_sp<SkImage> SkImage::makeRasterImage() const {
324 SkPixmap pm;
325 if (this->peekPixels(&pm)) {
326 return sk_ref_sp(const_cast<SkImage*>(this));
327 }
328
329 const SkImageInfo info = as_IB(this)->onImageInfo();
330 const size_t rowBytes = info.minRowBytes();
331 size_t size = info.computeByteSize(rowBytes);
332 if (SkImageInfo::ByteSizeOverflowed(size)) {
333 return nullptr;
334 }
335
336 sk_sp<SkData> data = SkData::MakeUninitialized(size);
Mike Klein98e38e22018-01-12 15:59:53 +0000337 pm = { info.makeColorSpace(nullptr), data->writable_data(), info.minRowBytes() };
Mike Reedf7ee95c2017-12-04 14:27:01 -0500338 if (!this->readPixels(pm, 0, 0)) {
339 return nullptr;
340 }
341
342 return SkImage::MakeRasterData(info, std::move(data), rowBytes);
343}
344
reed56179002015-07-07 06:11:19 -0700345//////////////////////////////////////////////////////////////////////////////////////
346
reed8b26b992015-05-07 15:36:17 -0700347#if !SK_SUPPORT_GPU
348
Robert Phillips590533f2017-07-11 14:22:35 -0400349sk_sp<SkImage> MakeTextureFromMipMap(GrContext*, const SkImageInfo&, const GrMipLevel texels[],
Brian Osman7b8400d2016-11-08 17:08:54 -0500350 int mipLevelCount, SkBudgeted, SkDestinationSurfaceColorMode) {
cblume33e0cb52016-08-30 12:09:23 -0700351 return nullptr;
352}
353
Greg Daniel94403452017-04-18 15:52:36 -0400354sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx,
355 const GrBackendTexture& tex, GrSurfaceOrigin origin,
356 SkAlphaType at, sk_sp<SkColorSpace> cs,
357 TextureReleaseProc releaseP, ReleaseContext releaseC) {
358 return nullptr;
359}
360
Eric Karlaae533e2017-12-15 23:37:45 +0000361size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy&,
362 const DeferredTextureImageUsageParams[],
363 int paramCnt, void* buffer,
364 SkColorSpace* dstColorSpace,
365 SkColorType dstColorType) const {
366 return 0;
367}
368
369sk_sp<SkImage> SkImage::MakeFromDeferredTextureImageData(GrContext* context, const void*,
370 SkBudgeted) {
371 return nullptr;
372}
373
Greg Danielf5d87582017-12-18 14:48:15 -0500374sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx,
375 const GrBackendTexture& tex, GrSurfaceOrigin origin,
376 SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs,
377 TextureReleaseProc releaseP, ReleaseContext releaseC) {
378 return nullptr;
379}
380
Eric Karl914a36b2017-10-12 12:44:50 -0700381bool SkImage::MakeBackendTextureFromSkImage(GrContext*,
382 sk_sp<SkImage>,
383 GrBackendTexture*,
384 BackendTextureReleaseProc*) {
385 return false;
386}
387
Greg Daniel94403452017-04-18 15:52:36 -0400388sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx,
389 const GrBackendTexture& tex, GrSurfaceOrigin origin,
390 SkAlphaType at, sk_sp<SkColorSpace> cs) {
391 return nullptr;
392}
393
Greg Danielf5d87582017-12-18 14:48:15 -0500394sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx,
395 const GrBackendTexture& tex, GrSurfaceOrigin origin,
396 SkColorType ct, SkAlphaType at,
397 sk_sp<SkColorSpace> cs) {
398 return nullptr;
399}
400
reed7fb4f8b2016-03-11 04:33:52 -0800401sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace space,
402 const GrBackendObject yuvTextureHandles[3],
403 const SkISize yuvSizes[3],
brianosmandddbe382016-07-20 13:55:39 -0700404 GrSurfaceOrigin origin,
405 sk_sp<SkColorSpace> imageColorSpace) {
bsalomon8e74f802016-01-30 10:01:40 -0800406 return nullptr;
407}
408
Robert Phillipsc25db632017-12-13 09:22:45 -0500409sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace space,
410 const GrBackendTexture yuvTextureHandles[3],
411 const SkISize yuvSizes[3],
412 GrSurfaceOrigin origin,
413 sk_sp<SkColorSpace> imageColorSpace) {
414 return nullptr;
415}
416
Brian Osman041f7df2017-02-07 11:23:28 -0500417sk_sp<SkImage> SkImage::makeTextureImage(GrContext*, SkColorSpace* dstColorSpace) const {
418 return nullptr;
419}
420
reed7fb4f8b2016-03-11 04:33:52 -0800421#endif
422
423///////////////////////////////////////////////////////////////////////////////////////////////////
424
Robert Phillips590533f2017-07-11 14:22:35 -0400425sk_sp<SkImage> MakeTextureFromMipMap(GrContext*, const SkImageInfo&, const GrMipLevel texels[],
cblume186d2d42016-06-03 11:17:42 -0700426 int mipLevelCount, SkBudgeted) {
427 return nullptr;
428}
reeda9ca05c2016-08-11 03:55:15 -0700429
430///////////////////////////////////////////////////////////////////////////////////////////////////
reed2d5b7142016-08-17 11:12:33 -0700431
Derek Sollenbergerd3ea9b72016-11-09 11:25:13 -0500432bool SkImage_pinAsTexture(const SkImage* image, GrContext* ctx) {
reed2d5b7142016-08-17 11:12:33 -0700433 SkASSERT(image);
434 SkASSERT(ctx);
Derek Sollenbergerd3ea9b72016-11-09 11:25:13 -0500435 return as_IB(image)->onPinAsTexture(ctx);
reed2d5b7142016-08-17 11:12:33 -0700436}
437
438void SkImage_unpinAsTexture(const SkImage* image, GrContext* ctx) {
439 SkASSERT(image);
440 SkASSERT(ctx);
441 as_IB(image)->onUnpinAsTexture(ctx);
442}
Brian Osman0d4ff6c2017-01-17 16:10:07 -0500443
444///////////////////////////////////////////////////////////////////////////////////////////////////
445
446sk_sp<SkImage> SkImageMakeRasterCopyAndAssignColorSpace(const SkImage* src,
447 SkColorSpace* colorSpace) {
448 // Read the pixels out of the source image, with no conversion
449 SkImageInfo info = as_IB(src)->onImageInfo();
450 if (kUnknown_SkColorType == info.colorType()) {
451 SkDEBUGFAIL("Unexpected color type");
452 return nullptr;
453 }
454
455 size_t rowBytes = info.minRowBytes();
Mike Reedf0ffb892017-10-03 14:47:21 -0400456 size_t size = info.computeByteSize(rowBytes);
Mike Reedc5eb97d2017-10-09 10:42:51 -0400457 if (SkImageInfo::ByteSizeOverflowed(size)) {
Mike Reedf0ffb892017-10-03 14:47:21 -0400458 return nullptr;
459 }
Brian Osman0d4ff6c2017-01-17 16:10:07 -0500460 auto data = SkData::MakeUninitialized(size);
461 if (!data) {
462 return nullptr;
463 }
464
465 SkPixmap pm(info, data->writable_data(), rowBytes);
466 if (!src->readPixels(pm, 0, 0, SkImage::kDisallow_CachingHint)) {
467 return nullptr;
468 }
469
470 // Wrap them in a new image with a different color space
471 return SkImage::MakeRasterData(info.makeColorSpace(sk_ref_sp(colorSpace)), data, rowBytes);
472}