blob: 6c7561974412a0a99cb9b8f21102bd3943d7c321 [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"
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
reed6ceeebd2016-03-09 14:26:26 -080051#ifdef SK_SUPPORT_LEGACY_PEEKPIXELS_PARMS
52const void* SkImage::peekPixels(SkImageInfo* info, size_t* rowBytes) const {
53 SkPixmap pm;
54 if (this->peekPixels(&pm)) {
55 if (info) {
56 *info = pm.info();
57 }
58 if (rowBytes) {
59 *rowBytes = pm.rowBytes();
60 }
61 return pm.addr();
62 }
63 return nullptr;
64}
65#endif
66
reed96472de2014-12-10 09:53:42 -080067bool SkImage::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
reed09553032015-11-23 12:32:16 -080068 int srcX, int srcY, CachingHint chint) const {
reed96472de2014-12-10 09:53:42 -080069 SkReadPixelsRec rec(dstInfo, dstPixels, dstRowBytes, srcX, srcY);
70 if (!rec.trim(this->width(), this->height())) {
reed@google.com4f7c6152014-02-06 14:11:56 +000071 return false;
72 }
reed09553032015-11-23 12:32:16 -080073 return as_IB(this)->onReadPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec.fX, rec.fY, chint);
74}
75
76bool SkImage::scalePixels(const SkPixmap& dst, SkFilterQuality quality, CachingHint chint) const {
reed6868c3f2015-11-24 11:44:47 -080077 if (this->width() == dst.width() && this->height() == dst.height()) {
78 return this->readPixels(dst, 0, 0, chint);
79 }
80
reed09553032015-11-23 12:32:16 -080081 // Idea: If/when SkImageGenerator supports a native-scaling API (where the generator itself
82 // can scale more efficiently) we should take advantage of it here.
83 //
84 SkBitmap bm;
85 if (as_IB(this)->getROPixels(&bm, chint)) {
86 bm.lockPixels();
87 SkPixmap pmap;
88 // Note: By calling the pixmap scaler, we never cache the final result, so the chint
89 // is (currently) only being applied to the getROPixels. If we get a request to
90 // also attempt to cache the final (scaled) result, we would add that logic here.
91 //
92 return bm.peekPixels(&pmap) && pmap.scalePixels(dst, quality);
93 }
94 return false;
reed@google.com4f7c6152014-02-06 14:11:56 +000095}
96
reedd6b30312015-09-02 07:06:23 -070097void SkImage::preroll(GrContext* ctx) const {
reedefd50da2015-09-14 11:17:23 -070098 // For now, and to maintain parity w/ previous pixelref behavior, we just force the image
99 // to produce a cached raster-bitmap form, so that drawing to a raster canvas should be fast.
100 //
101 SkBitmap bm;
102 if (as_IB(this)->getROPixels(&bm)) {
103 bm.lockPixels();
104 bm.unlockPixels();
105 }
reedd6b30312015-09-02 07:06:23 -0700106}
107
reed88d064d2015-10-12 11:30:02 -0700108///////////////////////////////////////////////////////////////////////////////////////////////////
109
brianosman69c166d2016-08-17 14:01:05 -0700110SkAlphaType SkImage::alphaType() const {
111 return as_IB(this)->onAlphaType();
112}
113
reed5671c5b2016-03-09 14:47:34 -0800114sk_sp<SkShader> SkImage::makeShader(SkShader::TileMode tileX, SkShader::TileMode tileY,
115 const SkMatrix* localMatrix) const {
reed6b2d7ac2016-08-11 06:42:26 -0700116 return SkImageShader::Make(sk_ref_sp(const_cast<SkImage*>(this)), tileX, tileY, localMatrix);
piotaixrcef04f82014-07-14 07:48:04 -0700117}
118
reed5671c5b2016-03-09 14:47:34 -0800119#ifdef SK_SUPPORT_LEGACY_CREATESHADER_PTR
120SkShader* SkImage::newShader(SkShader::TileMode tileX, SkShader::TileMode tileY,
121 const SkMatrix* localMatrix) const {
122 return this->makeShader(tileX, tileY, localMatrix).release();
123}
124#endif
125
scroggo@google.com7def5e12013-05-31 14:00:10 +0000126SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const {
127 SkBitmap bm;
128 if (as_IB(this)->getROPixels(&bm)) {
129 return SkImageEncoder::EncodeData(bm, type, quality);
130 }
halcanary96fcdcc2015-08-27 07:41:13 -0700131 return nullptr;
junov@chromium.orgda904742013-05-01 22:38:16 +0000132}
reed@google.com4f7c6152014-02-06 14:11:56 +0000133
halcanarya2e05672015-12-09 03:56:02 -0800134SkData* SkImage::encode(SkPixelSerializer* serializer) const {
halcanaryf2848b62015-12-10 12:40:23 -0800135 SkAutoTUnref<SkPixelSerializer> defaultSerializer;
136 SkPixelSerializer* effectiveSerializer = serializer;
137 if (!effectiveSerializer) {
138 defaultSerializer.reset(SkImageEncoder::CreatePixelSerializer());
139 SkASSERT(defaultSerializer.get());
140 effectiveSerializer = defaultSerializer.get();
141 }
bungemanffae30d2016-08-03 13:32:32 -0700142 sk_sp<SkData> encoded(this->refEncoded());
reedc9e190d2015-09-28 09:58:41 -0700143 if (encoded && effectiveSerializer->useEncodedData(encoded->data(), encoded->size())) {
mtklein18300a32016-03-16 13:53:35 -0700144 return encoded.release();
fmalita2be71252015-09-03 07:17:25 -0700145 }
146
147 SkBitmap bm;
148 SkAutoPixmapUnlock apu;
149 if (as_IB(this)->getROPixels(&bm) && bm.requestLock(&apu)) {
halcanary6b280172015-12-07 12:42:24 -0800150 return effectiveSerializer->encode(apu.pixmap());
fmalita2be71252015-09-03 07:17:25 -0700151 }
152
153 return nullptr;
154}
155
reed871872f2015-06-22 12:48:26 -0700156SkData* SkImage::refEncoded() const {
reed05dd2512016-01-05 09:16:19 -0800157 GrContext* ctx = nullptr; // should we allow the caller to pass in a ctx?
158 return as_IB(this)->onRefEncoded(ctx);
reed871872f2015-06-22 12:48:26 -0700159}
160
reed7fb4f8b2016-03-11 04:33:52 -0800161sk_sp<SkImage> SkImage::MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset) {
halcanary96fcdcc2015-08-27 07:41:13 -0700162 if (nullptr == encoded || 0 == encoded->size()) {
163 return nullptr;
reed5965c8a2015-01-07 18:04:45 -0800164 }
reed7fb4f8b2016-03-11 04:33:52 -0800165 SkImageGenerator* generator = SkImageGenerator::NewFromEncoded(encoded.get());
166 return SkImage::MakeFromGenerator(generator, subset);
reed5965c8a2015-01-07 18:04:45 -0800167}
168
reedf8d18742015-01-02 20:45:37 -0800169const char* SkImage::toString(SkString* str) const {
170 str->appendf("image: (id:%d (%d, %d) %s)", this->uniqueID(), this->width(), this->height(),
171 this->isOpaque() ? "opaque" : "");
172 return str->c_str();
173}
174
reed7fb4f8b2016-03-11 04:33:52 -0800175sk_sp<SkImage> SkImage::makeSubset(const SkIRect& subset) const {
reed7b6945b2015-09-24 00:50:58 -0700176 if (subset.isEmpty()) {
177 return nullptr;
178 }
179
180 const SkIRect bounds = SkIRect::MakeWH(this->width(), this->height());
181 if (!bounds.contains(subset)) {
182 return nullptr;
183 }
184
185 // optimization : return self if the subset == our bounds
186 if (bounds == subset) {
reed7fb4f8b2016-03-11 04:33:52 -0800187 return sk_ref_sp(const_cast<SkImage*>(this));
reed7b6945b2015-09-24 00:50:58 -0700188 }
reed7fb4f8b2016-03-11 04:33:52 -0800189 return as_IB(this)->onMakeSubset(subset);
reedf803da12015-01-23 05:58:07 -0800190}
191
bsalomon55812362015-06-10 08:49:28 -0700192#if SK_SUPPORT_GPU
193
194GrTexture* SkImage::getTexture() const {
reed85d91782015-09-10 14:33:38 -0700195 return as_IB(this)->peekTexture();
bsalomon55812362015-06-10 08:49:28 -0700196}
197
bsalomon84a4e5a2016-02-29 11:41:52 -0800198bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->peekTexture()); }
bsalomon55812362015-06-10 08:49:28 -0700199
bsalomonc49e8682015-06-30 11:37:35 -0700200GrBackendObject SkImage::getTextureHandle(bool flushPendingGrContextIO) const {
bsalomon84a4e5a2016-02-29 11:41:52 -0800201 GrTexture* texture = as_IB(this)->peekTexture();
bsalomon55812362015-06-10 08:49:28 -0700202 if (texture) {
203 GrContext* context = texture->getContext();
204 if (context) {
bsalomonc49e8682015-06-30 11:37:35 -0700205 if (flushPendingGrContextIO) {
206 context->prepareSurfaceForExternalIO(texture);
bsalomon55812362015-06-10 08:49:28 -0700207 }
208 }
209 return texture->getTextureHandle();
210 }
211 return 0;
212}
213
214#else
215
halcanary96fcdcc2015-08-27 07:41:13 -0700216GrTexture* SkImage::getTexture() const { return nullptr; }
bsalomon55812362015-06-10 08:49:28 -0700217
218bool SkImage::isTextureBacked() const { return false; }
219
bsalomonc49e8682015-06-30 11:37:35 -0700220GrBackendObject SkImage::getTextureHandle(bool) const { return 0; }
bsalomon55812362015-06-10 08:49:28 -0700221
222#endif
223
reed@google.com4f7c6152014-02-06 14:11:56 +0000224///////////////////////////////////////////////////////////////////////////////
225
226static bool raster_canvas_supports(const SkImageInfo& info) {
reede5ea5002014-09-03 11:54:58 -0700227 switch (info.colorType()) {
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000228 case kN32_SkColorType:
reede5ea5002014-09-03 11:54:58 -0700229 return kUnpremul_SkAlphaType != info.alphaType();
reed@google.com4f7c6152014-02-06 14:11:56 +0000230 case kRGB_565_SkColorType:
231 return true;
232 case kAlpha_8_SkColorType:
233 return true;
234 default:
235 break;
236 }
237 return false;
238}
239
reedaf3fbfc2015-10-04 11:28:36 -0700240SkImage_Base::SkImage_Base(int width, int height, uint32_t uniqueID)
fmalita3b0d5322015-09-18 08:07:31 -0700241 : INHERITED(width, height, uniqueID)
fmalita3b0d5322015-09-18 08:07:31 -0700242 , fAddedToCache(false)
reedaf3fbfc2015-10-04 11:28:36 -0700243{}
fmalita3b0d5322015-09-18 08:07:31 -0700244
245SkImage_Base::~SkImage_Base() {
246 if (fAddedToCache.load()) {
247 SkNotifyBitmapGenIDIsStale(this->uniqueID());
248 }
249}
250
reed96472de2014-12-10 09:53:42 -0800251bool SkImage_Base::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
reed09553032015-11-23 12:32:16 -0800252 int srcX, int srcY, CachingHint) const {
reed96472de2014-12-10 09:53:42 -0800253 if (!raster_canvas_supports(dstInfo)) {
254 return false;
reed@google.com4f7c6152014-02-06 14:11:56 +0000255 }
256
reed96472de2014-12-10 09:53:42 -0800257 SkBitmap bm;
258 bm.installPixels(dstInfo, dstPixels, dstRowBytes);
259 SkCanvas canvas(bm);
reed@google.com4f7c6152014-02-06 14:11:56 +0000260
261 SkPaint paint;
reed374772b2016-10-05 17:33:02 -0700262 paint.setBlendMode(SkBlendMode::kSrc);
reed96472de2014-12-10 09:53:42 -0800263 canvas.drawImage(this, -SkIntToScalar(srcX), -SkIntToScalar(srcY), &paint);
reed@google.com4f7c6152014-02-06 14:11:56 +0000264
reed@google.com4f7c6152014-02-06 14:11:56 +0000265 return true;
266}
reedf803da12015-01-23 05:58:07 -0800267
reed871872f2015-06-22 12:48:26 -0700268///////////////////////////////////////////////////////////////////////////////////////////////////
269
reed09553032015-11-23 12:32:16 -0800270bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY, CachingHint chint) const {
271 return this->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(), srcX, srcY, chint);
reed871872f2015-06-22 12:48:26 -0700272}
273
bsalomonf267c1e2016-02-01 13:16:14 -0800274#if SK_SUPPORT_GPU
275#include "GrTextureToYUVPlanes.h"
276#endif
277
278#include "SkRGBAToYUV.h"
279
280bool SkImage::readYUV8Planes(const SkISize sizes[3], void* const planes[3],
Brian Salomonde3a7262016-02-03 17:09:00 -0500281 const size_t rowBytes[3], SkYUVColorSpace colorSpace) const {
bsalomonf267c1e2016-02-01 13:16:14 -0800282#if SK_SUPPORT_GPU
283 if (GrTexture* texture = as_IB(this)->peekTexture()) {
284 if (GrTextureToYUVPlanes(texture, sizes, planes, rowBytes, colorSpace)) {
285 return true;
286 }
287 }
288#endif
289 return SkRGBAToYUV(this, sizes, planes, rowBytes, colorSpace);
290}
291
reed871872f2015-06-22 12:48:26 -0700292///////////////////////////////////////////////////////////////////////////////////////////////////
reedf803da12015-01-23 05:58:07 -0800293
reed7fb4f8b2016-03-11 04:33:52 -0800294sk_sp<SkImage> SkImage::MakeFromBitmap(const SkBitmap& bm) {
reed56179002015-07-07 06:11:19 -0700295 SkPixelRef* pr = bm.pixelRef();
halcanary96fcdcc2015-08-27 07:41:13 -0700296 if (nullptr == pr) {
297 return nullptr;
reed56179002015-07-07 06:11:19 -0700298 }
299
reed1ec04d92016-08-05 12:07:41 -0700300 return SkMakeImageFromRasterBitmap(bm, kIfMutable_SkCopyPixelsMode);
reed56179002015-07-07 06:11:19 -0700301}
302
reed3c065112015-07-08 12:46:22 -0700303bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {
304 return as_IB(this)->onAsLegacyBitmap(bitmap, mode);
305}
306
307bool SkImage_Base::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {
308 // As the base-class, all we can do is make a copy (regardless of mode).
309 // Subclasses that want to be more optimal should override.
msarettbe36d592016-06-13 11:25:03 -0700310 SkImageInfo info = this->onImageInfo().makeColorType(kN32_SkColorType)
brianosman69c166d2016-08-17 14:01:05 -0700311 .makeAlphaType(this->alphaType());
reed3c065112015-07-08 12:46:22 -0700312 if (!bitmap->tryAllocPixels(info)) {
313 return false;
314 }
315 if (!this->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(), 0, 0)) {
316 bitmap->reset();
317 return false;
318 }
319
320 if (kRO_LegacyBitmapMode == mode) {
321 bitmap->setImmutable();
322 }
323 return true;
324}
325
reed7fb4f8b2016-03-11 04:33:52 -0800326sk_sp<SkImage> SkImage::MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
327 const SkMatrix* matrix, const SkPaint* paint) {
reedd5b75632015-08-13 09:37:45 -0700328 if (!picture) {
329 return nullptr;
330 }
reed7fb4f8b2016-03-11 04:33:52 -0800331 return MakeFromGenerator(SkImageGenerator::NewFromPicture(dimensions, picture.get(),
332 matrix, paint));
reedd5b75632015-08-13 09:37:45 -0700333}
334
senorblanco5878dbd2016-05-19 14:50:29 -0700335sk_sp<SkImage> SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRect& subset,
336 const SkIRect& clipBounds, SkIRect* outSubset,
337 SkIPoint* offset) const {
brianosman04a44d02016-09-21 09:46:57 -0700338 if (!filter || !outSubset || !offset || !this->bounds().contains(subset)) {
339 return nullptr;
340 }
341 sk_sp<SkSpecialImage> srcSpecialImage = SkSpecialImage::MakeFromImage(
342 subset, sk_ref_sp(const_cast<SkImage*>(this)));
343 if (!srcSpecialImage) {
344 return nullptr;
345 }
senorblanco5878dbd2016-05-19 14:50:29 -0700346
brianosman04a44d02016-09-21 09:46:57 -0700347 SkAutoTUnref<SkImageFilterCache> cache(
348 SkImageFilterCache::Create(SkImageFilterCache::kDefaultTransientSize));
brianosman2a75e5d2016-09-22 07:15:37 -0700349 SkImageFilter::OutputProperties outputProperties(as_IB(this)->onImageInfo().colorSpace());
350 SkImageFilter::Context context(SkMatrix::I(), clipBounds, cache.get(), outputProperties);
351
brianosman04a44d02016-09-21 09:46:57 -0700352 sk_sp<SkSpecialImage> result =
353 filter->filterImage(srcSpecialImage.get(), context, offset);
senorblanco5878dbd2016-05-19 14:50:29 -0700354
brianosman04a44d02016-09-21 09:46:57 -0700355 if (!result) {
356 return nullptr;
357 }
senorblanco5878dbd2016-05-19 14:50:29 -0700358
brianosman04a44d02016-09-21 09:46:57 -0700359 SkIRect fullSize = SkIRect::MakeWH(result->width(), result->height());
senorblanco5878dbd2016-05-19 14:50:29 -0700360#if SK_SUPPORT_GPU
brianosman04a44d02016-09-21 09:46:57 -0700361 if (result->isTextureBacked()) {
362 GrContext* context = result->getContext();
363 sk_sp<GrTexture> texture = result->asTextureRef(context);
364 fullSize = SkIRect::MakeWH(texture->width(), texture->height());
365 }
senorblanco5878dbd2016-05-19 14:50:29 -0700366#endif
brianosman04a44d02016-09-21 09:46:57 -0700367 *outSubset = SkIRect::MakeWH(result->width(), result->height());
368 if (!outSubset->intersect(clipBounds.makeOffset(-offset->x(), -offset->y()))) {
369 return nullptr;
370 }
371 offset->fX += outSubset->x();
372 offset->fY += outSubset->y();
373 // This isn't really a "tight" subset, but includes any texture padding.
374 return result->makeTightSubset(fullSize);
senorblanco5878dbd2016-05-19 14:50:29 -0700375}
376
fmalitaddbbdda2015-08-20 08:47:26 -0700377bool SkImage::isLazyGenerated() const {
378 return as_IB(this)->onIsLazyGenerated();
379}
380
reed56179002015-07-07 06:11:19 -0700381//////////////////////////////////////////////////////////////////////////////////////
382
reed8b26b992015-05-07 15:36:17 -0700383#if !SK_SUPPORT_GPU
384
reed7fb4f8b2016-03-11 04:33:52 -0800385sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext*, const SkPixmap&, SkBudgeted budgeted) {
bsalomon0d996862016-03-09 18:44:43 -0800386 return nullptr;
387}
388
cblume33e0cb52016-08-30 12:09:23 -0700389sk_sp<SkImage> MakeTextureFromMipMap(GrContext*, const SkImageInfo&, const GrMipLevel* texels,
390 int mipLevelCount, SkBudgeted, SkSourceGammaTreatment) {
391 return nullptr;
392}
393
reed7fb4f8b2016-03-11 04:33:52 -0800394sk_sp<SkImage> SkImage::MakeFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType,
brianosmandddbe382016-07-20 13:55:39 -0700395 sk_sp<SkColorSpace>, TextureReleaseProc, ReleaseContext) {
halcanary96fcdcc2015-08-27 07:41:13 -0700396 return nullptr;
reed8b26b992015-05-07 15:36:17 -0700397}
398
bsalomon41b952c2016-03-11 06:46:33 -0800399size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy&,
400 const DeferredTextureImageUsageParams[],
cblume33e0cb52016-08-30 12:09:23 -0700401 int paramCnt, void* buffer,
Brian Osman6c15cc72016-10-17 09:51:37 -0400402 SkColorSpace* dstColorSpace) const {
bsalomon41b952c2016-03-11 06:46:33 -0800403 return 0;
404}
405
406sk_sp<SkImage> SkImage::MakeFromDeferredTextureImageData(GrContext* context, const void*,
407 SkBudgeted) {
408 return nullptr;
409}
410
reed7fb4f8b2016-03-11 04:33:52 -0800411sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
brianosmandddbe382016-07-20 13:55:39 -0700412 SkAlphaType, sk_sp<SkColorSpace>) {
halcanary96fcdcc2015-08-27 07:41:13 -0700413 return nullptr;
bsalomon6dc6f5f2015-06-18 09:12:16 -0700414}
415
reed7fb4f8b2016-03-11 04:33:52 -0800416sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace space,
417 const GrBackendObject yuvTextureHandles[3],
418 const SkISize yuvSizes[3],
brianosmandddbe382016-07-20 13:55:39 -0700419 GrSurfaceOrigin origin,
420 sk_sp<SkColorSpace> imageColorSpace) {
bsalomon8e74f802016-01-30 10:01:40 -0800421 return nullptr;
422}
423
reed7fb4f8b2016-03-11 04:33:52 -0800424sk_sp<SkImage> SkImage::makeTextureImage(GrContext*) const {
425 return nullptr;
426}
427
bsalomon634b4302016-07-12 18:11:17 -0700428sk_sp<SkImage> SkImage::makeNonTextureImage() const {
429 return sk_ref_sp(const_cast<SkImage*>(this));
430}
431
reed7fb4f8b2016-03-11 04:33:52 -0800432#endif
433
434///////////////////////////////////////////////////////////////////////////////////////////////////
435
436#ifdef SK_SUPPORT_LEGACY_IMAGEFACTORY
437SkImage* SkImage::NewRasterCopy(const Info& info, const void* pixels, size_t rowBytes,
438 SkColorTable* ctable) {
439 return MakeRasterCopy(SkPixmap(info, pixels, rowBytes, ctable)).release();
440}
441
442SkImage* SkImage::NewRasterData(const Info& info, SkData* pixels, size_t rowBytes) {
443 return MakeRasterData(info, sk_ref_sp(pixels), rowBytes).release();
444}
445
446SkImage* SkImage::NewFromRaster(const Info& info, const void* pixels, size_t rowBytes,
447 RasterReleaseProc proc, ReleaseContext releasectx) {
448 return MakeFromRaster(SkPixmap(info, pixels, rowBytes), proc, releasectx).release();
449}
450
451SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) {
452 return MakeFromBitmap(bm).release();
453}
454
455SkImage* SkImage::NewFromGenerator(SkImageGenerator* gen, const SkIRect* subset) {
456 return MakeFromGenerator(gen, subset).release();
457}
458
459SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) {
460 return MakeFromEncoded(sk_ref_sp(encoded), subset).release();
461}
462
463SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc, SkAlphaType at,
464 TextureReleaseProc proc, ReleaseContext releasectx) {
465 return MakeFromTexture(ctx, desc, at, proc, releasectx).release();
466}
467
468SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDesc& desc,
469 SkAlphaType at) {
470 return MakeFromAdoptedTexture(ctx, desc, at).release();
471}
472
reed7fb4f8b2016-03-11 04:33:52 -0800473SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace space,
474 const GrBackendObject yuvTextureHandles[3],
475 const SkISize yuvSizes[3],
476 GrSurfaceOrigin origin) {
477 return MakeFromYUVTexturesCopy(ctx, space, yuvTextureHandles, yuvSizes, origin).release();
478}
479
480SkImage* SkImage::NewFromPicture(const SkPicture* picture, const SkISize& dimensions,
481 const SkMatrix* matrix, const SkPaint* paint) {
482 return MakeFromPicture(sk_ref_sp(const_cast<SkPicture*>(picture)), dimensions,
483 matrix, paint).release();
484}
485
486SkImage* SkImage::NewTextureFromPixmap(GrContext* ctx, const SkPixmap& pmap, SkBudgeted budgeted) {
487 return MakeTextureFromPixmap(ctx, pmap, budgeted).release();
488}
bsalomon41b952c2016-03-11 06:46:33 -0800489
490SkImage* SkImage::NewFromDeferredTextureImageData(GrContext* ctx, const void* data,
491 SkBudgeted budgeted) {
492 return MakeFromDeferredTextureImageData(ctx, data, budgeted).release();
493}
reed8b26b992015-05-07 15:36:17 -0700494#endif
cblume186d2d42016-06-03 11:17:42 -0700495
496sk_sp<SkImage> MakeTextureFromMipMap(GrContext*, const SkImageInfo&, const GrMipLevel* texels,
497 int mipLevelCount, SkBudgeted) {
498 return nullptr;
499}
reeda9ca05c2016-08-11 03:55:15 -0700500
501///////////////////////////////////////////////////////////////////////////////////////////////////
502#include "SkImageDeserializer.h"
503
504sk_sp<SkImage> SkImageDeserializer::makeFromData(SkData* data, const SkIRect* subset) {
505 return SkImage::MakeFromEncoded(sk_ref_sp(data), subset);
506}
507sk_sp<SkImage> SkImageDeserializer::makeFromMemory(const void* data, size_t length,
508 const SkIRect* subset) {
509 return SkImage::MakeFromEncoded(SkData::MakeWithCopy(data, length), subset);
510}
reed2d5b7142016-08-17 11:12:33 -0700511
512///////////////////////////////////////////////////////////////////////////////////////////////////
513
514void SkImage_pinAsTexture(const SkImage* image, GrContext* ctx) {
515 SkASSERT(image);
516 SkASSERT(ctx);
517 as_IB(image)->onPinAsTexture(ctx);
518}
519
520void SkImage_unpinAsTexture(const SkImage* image, GrContext* ctx) {
521 SkASSERT(image);
522 SkASSERT(ctx);
523 as_IB(image)->onUnpinAsTexture(ctx);
524}