blob: 66301341d379a1c9fd2a09a2b63738be9fa19d01 [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"
reed871872f2015-06-22 12:48:26 -070011#include "SkData.h"
halcanaryf2848b62015-12-10 12:40:23 -080012#include "SkImageEncoder.h"
senorblanco5878dbd2016-05-19 14:50:29 -070013#include "SkImageFilter.h"
brianosman04a44d02016-09-21 09:46:57 -070014#include "SkImageFilterCache.h"
reed5965c8a2015-01-07 18:04:45 -080015#include "SkImageGenerator.h"
scroggo@google.com7def5e12013-05-31 14:00:10 +000016#include "SkImagePriv.h"
reed856e9d92015-09-30 12:21:45 -070017#include "SkImageShader.h"
scroggo@google.com7def5e12013-05-31 14:00:10 +000018#include "SkImage_Base.h"
reed80c772b2015-07-30 18:58:23 -070019#include "SkNextID.h"
reed7fb4f8b2016-03-11 04:33:52 -080020#include "SkPicture.h"
reed56179002015-07-07 06:11:19 -070021#include "SkPixelRef.h"
fmalita2be71252015-09-03 07:17:25 -070022#include "SkPixelSerializer.h"
reed96472de2014-12-10 09:53:42 -080023#include "SkReadPixelsRec.h"
senorblanco5878dbd2016-05-19 14:50:29 -070024#include "SkSpecialImage.h"
Hal Canary1fcc4042016-11-30 17:07:59 -050025#include "SkStream.h"
reedf8d18742015-01-02 20:45:37 -080026#include "SkString.h"
reed4af267b2014-11-21 08:46:37 -080027#include "SkSurface.h"
reed56179002015-07-07 06:11:19 -070028
bsalomon55812362015-06-10 08:49:28 -070029#if SK_SUPPORT_GPU
30#include "GrTexture.h"
31#include "GrContext.h"
reed56179002015-07-07 06:11:19 -070032#include "SkImage_Gpu.h"
bsalomon55812362015-06-10 08:49:28 -070033#endif
scroggo@google.com7def5e12013-05-31 14:00:10 +000034
reed80c772b2015-07-30 18:58:23 -070035SkImage::SkImage(int width, int height, uint32_t uniqueID)
36 : fWidth(width)
37 , fHeight(height)
38 , fUniqueID(kNeedNewImageUniqueID == uniqueID ? SkNextID::ImageID() : uniqueID)
39{
40 SkASSERT(width > 0);
41 SkASSERT(height > 0);
reed@google.comf6627b72012-07-27 18:02:50 +000042}
43
reed6ceeebd2016-03-09 14:26:26 -080044bool SkImage::peekPixels(SkPixmap* pm) const {
45 SkPixmap tmp;
46 if (!pm) {
47 pm = &tmp;
reed@google.com4f7c6152014-02-06 14:11:56 +000048 }
reed6ceeebd2016-03-09 14:26:26 -080049 return as_IB(this)->onPeekPixels(pm);
reed@google.com4f7c6152014-02-06 14:11:56 +000050}
51
reed96472de2014-12-10 09:53:42 -080052bool SkImage::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
reed09553032015-11-23 12:32:16 -080053 int srcX, int srcY, CachingHint chint) const {
reed96472de2014-12-10 09:53:42 -080054 SkReadPixelsRec rec(dstInfo, dstPixels, dstRowBytes, srcX, srcY);
55 if (!rec.trim(this->width(), this->height())) {
reed@google.com4f7c6152014-02-06 14:11:56 +000056 return false;
57 }
reed09553032015-11-23 12:32:16 -080058 return as_IB(this)->onReadPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec.fX, rec.fY, chint);
59}
60
61bool SkImage::scalePixels(const SkPixmap& dst, SkFilterQuality quality, CachingHint chint) const {
reed6868c3f2015-11-24 11:44:47 -080062 if (this->width() == dst.width() && this->height() == dst.height()) {
63 return this->readPixels(dst, 0, 0, chint);
64 }
65
reed09553032015-11-23 12:32:16 -080066 // Idea: If/when SkImageGenerator supports a native-scaling API (where the generator itself
67 // can scale more efficiently) we should take advantage of it here.
68 //
69 SkBitmap bm;
Brian Osman61624f02016-12-09 14:51:59 -050070 if (as_IB(this)->getROPixels(&bm, dst.info().colorSpace(), chint)) {
reed09553032015-11-23 12:32:16 -080071 bm.lockPixels();
72 SkPixmap pmap;
73 // Note: By calling the pixmap scaler, we never cache the final result, so the chint
74 // is (currently) only being applied to the getROPixels. If we get a request to
75 // also attempt to cache the final (scaled) result, we would add that logic here.
76 //
77 return bm.peekPixels(&pmap) && pmap.scalePixels(dst, quality);
78 }
79 return false;
reed@google.com4f7c6152014-02-06 14:11:56 +000080}
81
reed88d064d2015-10-12 11:30:02 -070082///////////////////////////////////////////////////////////////////////////////////////////////////
83
brianosman69c166d2016-08-17 14:01:05 -070084SkAlphaType SkImage::alphaType() const {
85 return as_IB(this)->onAlphaType();
86}
87
reed5671c5b2016-03-09 14:47:34 -080088sk_sp<SkShader> SkImage::makeShader(SkShader::TileMode tileX, SkShader::TileMode tileY,
89 const SkMatrix* localMatrix) const {
reed6b2d7ac2016-08-11 06:42:26 -070090 return SkImageShader::Make(sk_ref_sp(const_cast<SkImage*>(this)), tileX, tileY, localMatrix);
piotaixrcef04f82014-07-14 07:48:04 -070091}
92
Hal Canarydb683012016-11-23 08:55:18 -070093SkData* SkImage::encode(SkEncodedImageFormat type, int quality) const {
Leon Scroggins294c1c42016-11-08 14:29:46 +000094 SkBitmap bm;
Brian Osman7992da32016-11-18 11:28:24 -050095 // TODO: Right now, the encoders don't handle F16 or linearly premultiplied data. Once they do,
96 // we should decode in "color space aware" mode, then re-encode that. For now, work around this
97 // by asking for a legacy decode (which gives us the raw data in N32).
Brian Osman61624f02016-12-09 14:51:59 -050098 SkColorSpace* legacyColorSpace = nullptr;
99 if (as_IB(this)->getROPixels(&bm, legacyColorSpace)) {
Hal Canarydb683012016-11-23 08:55:18 -0700100 SkDynamicMemoryWStream buf;
101 return SkEncodeImage(&buf, bm, type, quality) ? buf.detachAsData().release() : nullptr;
Leon Scroggins294c1c42016-11-08 14:29:46 +0000102 }
103 return nullptr;
104}
105
halcanarya2e05672015-12-09 03:56:02 -0800106SkData* SkImage::encode(SkPixelSerializer* serializer) const {
bungemanffae30d2016-08-03 13:32:32 -0700107 sk_sp<SkData> encoded(this->refEncoded());
Hal Canarydb683012016-11-23 08:55:18 -0700108 if (encoded &&
109 (!serializer || serializer->useEncodedData(encoded->data(), encoded->size()))) {
mtklein18300a32016-03-16 13:53:35 -0700110 return encoded.release();
fmalita2be71252015-09-03 07:17:25 -0700111 }
112
113 SkBitmap bm;
114 SkAutoPixmapUnlock apu;
Brian Osman7992da32016-11-18 11:28:24 -0500115 // TODO: Right now, the encoders don't handle F16 or linearly premultiplied data. Once they do,
116 // we should decode in "color space aware" mode, then re-encode that. For now, work around this
117 // by asking for a legacy decode (which gives us the raw data in N32).
Brian Osman61624f02016-12-09 14:51:59 -0500118 SkColorSpace* legacyColorSpace = nullptr;
119 if (as_IB(this)->getROPixels(&bm, legacyColorSpace) &&
Brian Osman7992da32016-11-18 11:28:24 -0500120 bm.requestLock(&apu)) {
Hal Canarydb683012016-11-23 08:55:18 -0700121 if (serializer) {
122 return serializer->encode(apu.pixmap());
123 } else {
124 SkDynamicMemoryWStream buf;
125 return SkEncodeImage(&buf, apu.pixmap(), SkEncodedImageFormat::kPNG, 100)
126 ? buf.detachAsData().release() : nullptr;
127 }
fmalita2be71252015-09-03 07:17:25 -0700128 }
129
130 return nullptr;
131}
132
reed871872f2015-06-22 12:48:26 -0700133SkData* SkImage::refEncoded() const {
reed05dd2512016-01-05 09:16:19 -0800134 GrContext* ctx = nullptr; // should we allow the caller to pass in a ctx?
135 return as_IB(this)->onRefEncoded(ctx);
reed871872f2015-06-22 12:48:26 -0700136}
137
reed7fb4f8b2016-03-11 04:33:52 -0800138sk_sp<SkImage> SkImage::MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset) {
halcanary96fcdcc2015-08-27 07:41:13 -0700139 if (nullptr == encoded || 0 == encoded->size()) {
140 return nullptr;
reed5965c8a2015-01-07 18:04:45 -0800141 }
reed7fb4f8b2016-03-11 04:33:52 -0800142 SkImageGenerator* generator = SkImageGenerator::NewFromEncoded(encoded.get());
143 return SkImage::MakeFromGenerator(generator, subset);
reed5965c8a2015-01-07 18:04:45 -0800144}
145
reedf8d18742015-01-02 20:45:37 -0800146const char* SkImage::toString(SkString* str) const {
147 str->appendf("image: (id:%d (%d, %d) %s)", this->uniqueID(), this->width(), this->height(),
148 this->isOpaque() ? "opaque" : "");
149 return str->c_str();
150}
151
reed7fb4f8b2016-03-11 04:33:52 -0800152sk_sp<SkImage> SkImage::makeSubset(const SkIRect& subset) const {
reed7b6945b2015-09-24 00:50:58 -0700153 if (subset.isEmpty()) {
154 return nullptr;
155 }
156
157 const SkIRect bounds = SkIRect::MakeWH(this->width(), this->height());
158 if (!bounds.contains(subset)) {
159 return nullptr;
160 }
161
162 // optimization : return self if the subset == our bounds
163 if (bounds == subset) {
reed7fb4f8b2016-03-11 04:33:52 -0800164 return sk_ref_sp(const_cast<SkImage*>(this));
reed7b6945b2015-09-24 00:50:58 -0700165 }
reed7fb4f8b2016-03-11 04:33:52 -0800166 return as_IB(this)->onMakeSubset(subset);
reedf803da12015-01-23 05:58:07 -0800167}
168
bsalomon55812362015-06-10 08:49:28 -0700169#if SK_SUPPORT_GPU
170
171GrTexture* SkImage::getTexture() const {
reed85d91782015-09-10 14:33:38 -0700172 return as_IB(this)->peekTexture();
bsalomon55812362015-06-10 08:49:28 -0700173}
174
bsalomon84a4e5a2016-02-29 11:41:52 -0800175bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->peekTexture()); }
bsalomon55812362015-06-10 08:49:28 -0700176
bsalomonc49e8682015-06-30 11:37:35 -0700177GrBackendObject SkImage::getTextureHandle(bool flushPendingGrContextIO) const {
bsalomon84a4e5a2016-02-29 11:41:52 -0800178 GrTexture* texture = as_IB(this)->peekTexture();
bsalomon55812362015-06-10 08:49:28 -0700179 if (texture) {
180 GrContext* context = texture->getContext();
Hal Canarydb683012016-11-23 08:55:18 -0700181 if (context) {
bsalomonc49e8682015-06-30 11:37:35 -0700182 if (flushPendingGrContextIO) {
183 context->prepareSurfaceForExternalIO(texture);
bsalomon55812362015-06-10 08:49:28 -0700184 }
185 }
186 return texture->getTextureHandle();
187 }
188 return 0;
189}
190
191#else
192
halcanary96fcdcc2015-08-27 07:41:13 -0700193GrTexture* SkImage::getTexture() const { return nullptr; }
bsalomon55812362015-06-10 08:49:28 -0700194
195bool SkImage::isTextureBacked() const { return false; }
196
bsalomonc49e8682015-06-30 11:37:35 -0700197GrBackendObject SkImage::getTextureHandle(bool) const { return 0; }
bsalomon55812362015-06-10 08:49:28 -0700198
199#endif
200
reed@google.com4f7c6152014-02-06 14:11:56 +0000201///////////////////////////////////////////////////////////////////////////////
202
203static bool raster_canvas_supports(const SkImageInfo& info) {
reede5ea5002014-09-03 11:54:58 -0700204 switch (info.colorType()) {
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000205 case kN32_SkColorType:
reede5ea5002014-09-03 11:54:58 -0700206 return kUnpremul_SkAlphaType != info.alphaType();
reed@google.com4f7c6152014-02-06 14:11:56 +0000207 case kRGB_565_SkColorType:
208 return true;
209 case kAlpha_8_SkColorType:
210 return true;
211 default:
212 break;
213 }
214 return false;
215}
216
reedaf3fbfc2015-10-04 11:28:36 -0700217SkImage_Base::SkImage_Base(int width, int height, uint32_t uniqueID)
fmalita3b0d5322015-09-18 08:07:31 -0700218 : INHERITED(width, height, uniqueID)
fmalita3b0d5322015-09-18 08:07:31 -0700219 , fAddedToCache(false)
reedaf3fbfc2015-10-04 11:28:36 -0700220{}
fmalita3b0d5322015-09-18 08:07:31 -0700221
222SkImage_Base::~SkImage_Base() {
223 if (fAddedToCache.load()) {
224 SkNotifyBitmapGenIDIsStale(this->uniqueID());
225 }
226}
227
reed96472de2014-12-10 09:53:42 -0800228bool SkImage_Base::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
reed09553032015-11-23 12:32:16 -0800229 int srcX, int srcY, CachingHint) const {
reed96472de2014-12-10 09:53:42 -0800230 if (!raster_canvas_supports(dstInfo)) {
231 return false;
reed@google.com4f7c6152014-02-06 14:11:56 +0000232 }
233
reed96472de2014-12-10 09:53:42 -0800234 SkBitmap bm;
235 bm.installPixels(dstInfo, dstPixels, dstRowBytes);
236 SkCanvas canvas(bm);
reed@google.com4f7c6152014-02-06 14:11:56 +0000237
238 SkPaint paint;
reed374772b2016-10-05 17:33:02 -0700239 paint.setBlendMode(SkBlendMode::kSrc);
reed96472de2014-12-10 09:53:42 -0800240 canvas.drawImage(this, -SkIntToScalar(srcX), -SkIntToScalar(srcY), &paint);
reed@google.com4f7c6152014-02-06 14:11:56 +0000241
reed@google.com4f7c6152014-02-06 14:11:56 +0000242 return true;
243}
reedf803da12015-01-23 05:58:07 -0800244
reed871872f2015-06-22 12:48:26 -0700245///////////////////////////////////////////////////////////////////////////////////////////////////
246
reed09553032015-11-23 12:32:16 -0800247bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY, CachingHint chint) const {
248 return this->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(), srcX, srcY, chint);
reed871872f2015-06-22 12:48:26 -0700249}
250
bsalomonf267c1e2016-02-01 13:16:14 -0800251#if SK_SUPPORT_GPU
252#include "GrTextureToYUVPlanes.h"
253#endif
254
255#include "SkRGBAToYUV.h"
256
257bool SkImage::readYUV8Planes(const SkISize sizes[3], void* const planes[3],
Brian Salomonde3a7262016-02-03 17:09:00 -0500258 const size_t rowBytes[3], SkYUVColorSpace colorSpace) const {
bsalomonf267c1e2016-02-01 13:16:14 -0800259#if SK_SUPPORT_GPU
260 if (GrTexture* texture = as_IB(this)->peekTexture()) {
261 if (GrTextureToYUVPlanes(texture, sizes, planes, rowBytes, colorSpace)) {
262 return true;
263 }
264 }
265#endif
266 return SkRGBAToYUV(this, sizes, planes, rowBytes, colorSpace);
267}
268
reed871872f2015-06-22 12:48:26 -0700269///////////////////////////////////////////////////////////////////////////////////////////////////
reedf803da12015-01-23 05:58:07 -0800270
reed7fb4f8b2016-03-11 04:33:52 -0800271sk_sp<SkImage> SkImage::MakeFromBitmap(const SkBitmap& bm) {
reed56179002015-07-07 06:11:19 -0700272 SkPixelRef* pr = bm.pixelRef();
halcanary96fcdcc2015-08-27 07:41:13 -0700273 if (nullptr == pr) {
274 return nullptr;
reed56179002015-07-07 06:11:19 -0700275 }
276
reed1ec04d92016-08-05 12:07:41 -0700277 return SkMakeImageFromRasterBitmap(bm, kIfMutable_SkCopyPixelsMode);
reed56179002015-07-07 06:11:19 -0700278}
279
reed3c065112015-07-08 12:46:22 -0700280bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {
281 return as_IB(this)->onAsLegacyBitmap(bitmap, mode);
282}
283
284bool SkImage_Base::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {
285 // As the base-class, all we can do is make a copy (regardless of mode).
286 // Subclasses that want to be more optimal should override.
Brian Osman7992da32016-11-18 11:28:24 -0500287 SkImageInfo info = this->onImageInfo().makeColorType(kN32_SkColorType).makeColorSpace(nullptr);
reed3c065112015-07-08 12:46:22 -0700288 if (!bitmap->tryAllocPixels(info)) {
289 return false;
290 }
291 if (!this->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(), 0, 0)) {
292 bitmap->reset();
293 return false;
294 }
295
296 if (kRO_LegacyBitmapMode == mode) {
297 bitmap->setImmutable();
298 }
299 return true;
300}
301
Brian Osman138ea972016-12-16 11:55:18 -0500302sk_sp<SkImage> SkImage::MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
303 const SkMatrix* matrix, const SkPaint* paint) {
Matt Sarette94255d2017-01-09 12:38:59 -0500304 return SkImage::MakeFromPicture(std::move(picture), dimensions, matrix, paint, BitDepth::kU8,
Matt Sarettf9436b82017-01-09 15:59:17 -0500305 nullptr);
reedd5b75632015-08-13 09:37:45 -0700306}
307
Matt Sarette94255d2017-01-09 12:38:59 -0500308sk_sp<SkImage> SkImage::MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
309 const SkMatrix* matrix, const SkPaint* paint,
310 BitDepth bitDepth, sk_sp<SkColorSpace> colorSpace) {
311 return MakeFromGenerator(SkImageGenerator::NewFromPicture(dimensions, picture.get(), matrix,
312 paint, bitDepth,
313 std::move(colorSpace)));
314}
senorblanco5878dbd2016-05-19 14:50:29 -0700315sk_sp<SkImage> SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRect& subset,
316 const SkIRect& clipBounds, SkIRect* outSubset,
317 SkIPoint* offset) const {
brianosman04a44d02016-09-21 09:46:57 -0700318 if (!filter || !outSubset || !offset || !this->bounds().contains(subset)) {
319 return nullptr;
320 }
Brian Osman7992da32016-11-18 11:28:24 -0500321 SkColorSpace* colorSpace = as_IB(this)->onImageInfo().colorSpace();
brianosman04a44d02016-09-21 09:46:57 -0700322 sk_sp<SkSpecialImage> srcSpecialImage = SkSpecialImage::MakeFromImage(
Brian Osman61624f02016-12-09 14:51:59 -0500323 subset, sk_ref_sp(const_cast<SkImage*>(this)), colorSpace);
brianosman04a44d02016-09-21 09:46:57 -0700324 if (!srcSpecialImage) {
325 return nullptr;
326 }
senorblanco5878dbd2016-05-19 14:50:29 -0700327
Hal Canary67b39de2016-11-07 11:47:44 -0500328 sk_sp<SkImageFilterCache> cache(
brianosman04a44d02016-09-21 09:46:57 -0700329 SkImageFilterCache::Create(SkImageFilterCache::kDefaultTransientSize));
Brian Osman7992da32016-11-18 11:28:24 -0500330 SkImageFilter::OutputProperties outputProperties(colorSpace);
brianosman2a75e5d2016-09-22 07:15:37 -0700331 SkImageFilter::Context context(SkMatrix::I(), clipBounds, cache.get(), outputProperties);
332
brianosman04a44d02016-09-21 09:46:57 -0700333 sk_sp<SkSpecialImage> result =
334 filter->filterImage(srcSpecialImage.get(), context, offset);
senorblanco5878dbd2016-05-19 14:50:29 -0700335
brianosman04a44d02016-09-21 09:46:57 -0700336 if (!result) {
337 return nullptr;
338 }
senorblanco5878dbd2016-05-19 14:50:29 -0700339
brianosman04a44d02016-09-21 09:46:57 -0700340 SkIRect fullSize = SkIRect::MakeWH(result->width(), result->height());
senorblanco5878dbd2016-05-19 14:50:29 -0700341#if SK_SUPPORT_GPU
brianosman04a44d02016-09-21 09:46:57 -0700342 if (result->isTextureBacked()) {
343 GrContext* context = result->getContext();
344 sk_sp<GrTexture> texture = result->asTextureRef(context);
brianosman818d8a92016-11-22 12:03:53 -0800345 if (!texture) {
346 return nullptr;
347 }
brianosman04a44d02016-09-21 09:46:57 -0700348 fullSize = SkIRect::MakeWH(texture->width(), texture->height());
349 }
senorblanco5878dbd2016-05-19 14:50:29 -0700350#endif
brianosman04a44d02016-09-21 09:46:57 -0700351 *outSubset = SkIRect::MakeWH(result->width(), result->height());
352 if (!outSubset->intersect(clipBounds.makeOffset(-offset->x(), -offset->y()))) {
353 return nullptr;
354 }
355 offset->fX += outSubset->x();
356 offset->fY += outSubset->y();
357 // This isn't really a "tight" subset, but includes any texture padding.
358 return result->makeTightSubset(fullSize);
senorblanco5878dbd2016-05-19 14:50:29 -0700359}
360
fmalitaddbbdda2015-08-20 08:47:26 -0700361bool SkImage::isLazyGenerated() const {
362 return as_IB(this)->onIsLazyGenerated();
363}
364
reed9e2ed832016-10-31 05:27:28 -0700365bool SkImage::isAlphaOnly() const {
366 return as_IB(this)->onImageInfo().colorType() == kAlpha_8_SkColorType;
367}
368
reed56179002015-07-07 06:11:19 -0700369//////////////////////////////////////////////////////////////////////////////////////
370
reed8b26b992015-05-07 15:36:17 -0700371#if !SK_SUPPORT_GPU
372
reed7fb4f8b2016-03-11 04:33:52 -0800373sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext*, const SkPixmap&, SkBudgeted budgeted) {
bsalomon0d996862016-03-09 18:44:43 -0800374 return nullptr;
375}
376
cblume33e0cb52016-08-30 12:09:23 -0700377sk_sp<SkImage> MakeTextureFromMipMap(GrContext*, const SkImageInfo&, const GrMipLevel* texels,
Brian Osman7b8400d2016-11-08 17:08:54 -0500378 int mipLevelCount, SkBudgeted, SkDestinationSurfaceColorMode) {
cblume33e0cb52016-08-30 12:09:23 -0700379 return nullptr;
380}
381
reed7fb4f8b2016-03-11 04:33:52 -0800382sk_sp<SkImage> SkImage::MakeFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType,
brianosmandddbe382016-07-20 13:55:39 -0700383 sk_sp<SkColorSpace>, TextureReleaseProc, ReleaseContext) {
halcanary96fcdcc2015-08-27 07:41:13 -0700384 return nullptr;
reed8b26b992015-05-07 15:36:17 -0700385}
386
bsalomon41b952c2016-03-11 06:46:33 -0800387size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy&,
388 const DeferredTextureImageUsageParams[],
cblume33e0cb52016-08-30 12:09:23 -0700389 int paramCnt, void* buffer,
Brian Osman6c15cc72016-10-17 09:51:37 -0400390 SkColorSpace* dstColorSpace) const {
bsalomon41b952c2016-03-11 06:46:33 -0800391 return 0;
392}
393
394sk_sp<SkImage> SkImage::MakeFromDeferredTextureImageData(GrContext* context, const void*,
395 SkBudgeted) {
396 return nullptr;
397}
398
reed7fb4f8b2016-03-11 04:33:52 -0800399sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
brianosmandddbe382016-07-20 13:55:39 -0700400 SkAlphaType, sk_sp<SkColorSpace>) {
halcanary96fcdcc2015-08-27 07:41:13 -0700401 return nullptr;
bsalomon6dc6f5f2015-06-18 09:12:16 -0700402}
403
reed7fb4f8b2016-03-11 04:33:52 -0800404sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace space,
405 const GrBackendObject yuvTextureHandles[3],
406 const SkISize yuvSizes[3],
brianosmandddbe382016-07-20 13:55:39 -0700407 GrSurfaceOrigin origin,
408 sk_sp<SkColorSpace> imageColorSpace) {
bsalomon8e74f802016-01-30 10:01:40 -0800409 return nullptr;
410}
411
bsalomon634b4302016-07-12 18:11:17 -0700412sk_sp<SkImage> SkImage::makeNonTextureImage() const {
413 return sk_ref_sp(const_cast<SkImage*>(this));
414}
415
reed7fb4f8b2016-03-11 04:33:52 -0800416#endif
417
418///////////////////////////////////////////////////////////////////////////////////////////////////
419
cblume186d2d42016-06-03 11:17:42 -0700420sk_sp<SkImage> MakeTextureFromMipMap(GrContext*, const SkImageInfo&, const GrMipLevel* texels,
421 int mipLevelCount, SkBudgeted) {
422 return nullptr;
423}
reeda9ca05c2016-08-11 03:55:15 -0700424
425///////////////////////////////////////////////////////////////////////////////////////////////////
426#include "SkImageDeserializer.h"
427
428sk_sp<SkImage> SkImageDeserializer::makeFromData(SkData* data, const SkIRect* subset) {
429 return SkImage::MakeFromEncoded(sk_ref_sp(data), subset);
430}
431sk_sp<SkImage> SkImageDeserializer::makeFromMemory(const void* data, size_t length,
432 const SkIRect* subset) {
433 return SkImage::MakeFromEncoded(SkData::MakeWithCopy(data, length), subset);
434}
reed2d5b7142016-08-17 11:12:33 -0700435
436///////////////////////////////////////////////////////////////////////////////////////////////////
437
Derek Sollenbergerd3ea9b72016-11-09 11:25:13 -0500438bool SkImage_pinAsTexture(const SkImage* image, GrContext* ctx) {
reed2d5b7142016-08-17 11:12:33 -0700439 SkASSERT(image);
440 SkASSERT(ctx);
Derek Sollenbergerd3ea9b72016-11-09 11:25:13 -0500441 return as_IB(image)->onPinAsTexture(ctx);
reed2d5b7142016-08-17 11:12:33 -0700442}
443
444void SkImage_unpinAsTexture(const SkImage* image, GrContext* ctx) {
445 SkASSERT(image);
446 SkASSERT(ctx);
447 as_IB(image)->onUnpinAsTexture(ctx);
448}