reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
| 8 | #include "SkBitmap.h" |
| 9 | #include "SkBitmapCache.h" |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 10 | #include "SkColorSpace_Base.h" |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 11 | #include "SkImage_Base.h" |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 12 | #include "SkImageCacherator.h" |
reed | 935d6cf | 2015-08-18 11:16:09 -0700 | [diff] [blame] | 13 | #include "SkMallocPixelRef.h" |
| 14 | #include "SkNextID.h" |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 15 | #include "SkPixelRef.h" |
reed | 4b3d3be | 2015-09-17 13:35:19 -0700 | [diff] [blame] | 16 | #include "SkResourceCache.h" |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 17 | |
| 18 | #if SK_SUPPORT_GPU |
| 19 | #include "GrContext.h" |
Brian Osman | 46da1cc | 2017-02-14 14:15:48 -0500 | [diff] [blame] | 20 | #include "GrContextPriv.h" |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 21 | #include "GrGpuResourcePriv.h" |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 22 | #include "GrImageTextureMaker.h" |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 23 | #include "GrResourceKey.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 24 | #include "GrResourceProvider.h" |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 25 | #include "GrSamplerParams.h" |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 26 | #include "GrYUVProvider.h" |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 27 | #include "SkGr.h" |
| 28 | #include "SkGrPriv.h" |
| 29 | #endif |
| 30 | |
reed | 93eeadf | 2016-05-11 08:06:11 -0700 | [diff] [blame] | 31 | // Until we actually have codecs/etc. that can contain/support a GPU texture format |
| 32 | // skip this step, since for some generators, returning their encoded data as a SkData |
| 33 | // can be somewhat expensive, and this call doesn't indicate to the generator that we're |
| 34 | // only interested in GPU datas... |
| 35 | // see skbug.com/ 4971, 5128, ... |
| 36 | //#define SK_SUPPORT_COMPRESSED_TEXTURES_IN_CACHERATOR |
| 37 | |
fmalita | f0c38f5 | 2016-10-27 14:22:41 -0700 | [diff] [blame] | 38 | // Helper for exclusive access to a shared generator. |
| 39 | class SkImageCacherator::ScopedGenerator { |
| 40 | public: |
| 41 | ScopedGenerator(const sk_sp<SharedGenerator>& gen) |
| 42 | : fSharedGenerator(gen) |
| 43 | , fAutoAquire(gen->fMutex) {} |
| 44 | |
| 45 | SkImageGenerator* operator->() const { |
| 46 | fSharedGenerator->fMutex.assertHeld(); |
| 47 | return fSharedGenerator->fGenerator.get(); |
| 48 | } |
| 49 | |
| 50 | operator SkImageGenerator*() const { |
| 51 | fSharedGenerator->fMutex.assertHeld(); |
| 52 | return fSharedGenerator->fGenerator.get(); |
| 53 | } |
| 54 | |
| 55 | private: |
| 56 | const sk_sp<SharedGenerator>& fSharedGenerator; |
| 57 | SkAutoExclusive fAutoAquire; |
| 58 | }; |
| 59 | |
fmalita | 8bd45cd | 2016-11-04 11:36:31 -0700 | [diff] [blame] | 60 | SkImageCacherator::Validator::Validator(sk_sp<SharedGenerator> gen, const SkIRect* subset) |
| 61 | : fSharedGenerator(std::move(gen)) { |
reed | 3a100d3 | 2015-09-14 09:59:28 -0700 | [diff] [blame] | 62 | |
fmalita | f0c38f5 | 2016-10-27 14:22:41 -0700 | [diff] [blame] | 63 | if (!fSharedGenerator) { |
fmalita | 7929e3a | 2016-10-27 08:15:44 -0700 | [diff] [blame] | 64 | return; |
| 65 | } |
reed | 3a100d3 | 2015-09-14 09:59:28 -0700 | [diff] [blame] | 66 | |
fmalita | 8bd45cd | 2016-11-04 11:36:31 -0700 | [diff] [blame] | 67 | // The following generator accessors are safe without acquiring the mutex (const getters). |
| 68 | // TODO: refactor to use a ScopedGenerator instead, for clarity. |
| 69 | const SkImageInfo& info = fSharedGenerator->fGenerator->getInfo(); |
reed | 935d6cf | 2015-08-18 11:16:09 -0700 | [diff] [blame] | 70 | if (info.isEmpty()) { |
fmalita | f0c38f5 | 2016-10-27 14:22:41 -0700 | [diff] [blame] | 71 | fSharedGenerator.reset(); |
fmalita | 7929e3a | 2016-10-27 08:15:44 -0700 | [diff] [blame] | 72 | return; |
reed | 935d6cf | 2015-08-18 11:16:09 -0700 | [diff] [blame] | 73 | } |
| 74 | |
fmalita | 8bd45cd | 2016-11-04 11:36:31 -0700 | [diff] [blame] | 75 | fUniqueID = fSharedGenerator->fGenerator->uniqueID(); |
reed | 935d6cf | 2015-08-18 11:16:09 -0700 | [diff] [blame] | 76 | const SkIRect bounds = SkIRect::MakeWH(info.width(), info.height()); |
| 77 | if (subset) { |
| 78 | if (!bounds.contains(*subset)) { |
fmalita | f0c38f5 | 2016-10-27 14:22:41 -0700 | [diff] [blame] | 79 | fSharedGenerator.reset(); |
fmalita | 7929e3a | 2016-10-27 08:15:44 -0700 | [diff] [blame] | 80 | return; |
reed | 935d6cf | 2015-08-18 11:16:09 -0700 | [diff] [blame] | 81 | } |
| 82 | if (*subset != bounds) { |
| 83 | // we need a different uniqueID since we really are a subset of the raw generator |
fmalita | 7929e3a | 2016-10-27 08:15:44 -0700 | [diff] [blame] | 84 | fUniqueID = SkNextID::ImageID(); |
reed | 935d6cf | 2015-08-18 11:16:09 -0700 | [diff] [blame] | 85 | } |
| 86 | } else { |
| 87 | subset = &bounds; |
| 88 | } |
| 89 | |
Brian Osman | 57ae6cf | 2016-11-15 18:07:26 +0000 | [diff] [blame] | 90 | fInfo = info.makeWH(subset->width(), subset->height()); |
fmalita | 7929e3a | 2016-10-27 08:15:44 -0700 | [diff] [blame] | 91 | fOrigin = SkIPoint::Make(subset->x(), subset->y()); |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 92 | |
| 93 | // If the encoded data is in a strange color space (it's not an XYZ matrix space), we won't be |
| 94 | // able to preserve the gamut of the encoded data when we decode it. Instead, we'll have to |
| 95 | // decode to a known color space (linear sRGB is a good choice). But we need to adjust the |
| 96 | // stored color space, because drawing code will ask the SkImage for its color space, which |
| 97 | // will in turn ask the cacherator. If we return the A2B color space, then we will be unable to |
| 98 | // construct a source-to-dest gamut transformation matrix. |
| 99 | if (fInfo.colorSpace() && |
| 100 | SkColorSpace_Base::Type::kXYZ != as_CSB(fInfo.colorSpace())->type()) { |
Matt Sarett | 77a7a1b | 2017-02-07 13:56:11 -0500 | [diff] [blame] | 101 | fInfo = fInfo.makeColorSpace(SkColorSpace::MakeSRGBLinear()); |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 102 | } |
reed | 8f4fe37 | 2015-08-13 14:06:46 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Mike Reed | 185130c | 2017-02-15 15:14:16 -0500 | [diff] [blame] | 105 | SkImageCacherator* SkImageCacherator::NewFromGenerator(std::unique_ptr<SkImageGenerator> gen, |
fmalita | 7929e3a | 2016-10-27 08:15:44 -0700 | [diff] [blame] | 106 | const SkIRect* subset) { |
Mike Reed | 185130c | 2017-02-15 15:14:16 -0500 | [diff] [blame] | 107 | Validator validator(SharedGenerator::Make(std::move(gen)), subset); |
fmalita | 7929e3a | 2016-10-27 08:15:44 -0700 | [diff] [blame] | 108 | |
| 109 | return validator ? new SkImageCacherator(&validator) : nullptr; |
| 110 | } |
| 111 | |
| 112 | SkImageCacherator::SkImageCacherator(Validator* validator) |
fmalita | f0c38f5 | 2016-10-27 14:22:41 -0700 | [diff] [blame] | 113 | : fSharedGenerator(std::move(validator->fSharedGenerator)) // we take ownership |
fmalita | 7929e3a | 2016-10-27 08:15:44 -0700 | [diff] [blame] | 114 | , fInfo(validator->fInfo) |
| 115 | , fOrigin(validator->fOrigin) |
fmalita | 7929e3a | 2016-10-27 08:15:44 -0700 | [diff] [blame] | 116 | { |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 117 | fUniqueIDs[kLegacy_CachedFormat] = validator->fUniqueID; |
| 118 | for (int i = 1; i < kNumCachedFormats; ++i) { |
| 119 | // We lazily allocate IDs for non-default caching cases |
| 120 | fUniqueIDs[i] = kNeedNewImageUniqueID; |
| 121 | } |
fmalita | f0c38f5 | 2016-10-27 14:22:41 -0700 | [diff] [blame] | 122 | SkASSERT(fSharedGenerator); |
fmalita | 7929e3a | 2016-10-27 08:15:44 -0700 | [diff] [blame] | 123 | } |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 124 | |
fmalita | f0c38f5 | 2016-10-27 14:22:41 -0700 | [diff] [blame] | 125 | SkImageCacherator::~SkImageCacherator() {} |
| 126 | |
reed | 05dd251 | 2016-01-05 09:16:19 -0800 | [diff] [blame] | 127 | SkData* SkImageCacherator::refEncoded(GrContext* ctx) { |
fmalita | f0c38f5 | 2016-10-27 14:22:41 -0700 | [diff] [blame] | 128 | ScopedGenerator generator(fSharedGenerator); |
reed | 05dd251 | 2016-01-05 09:16:19 -0800 | [diff] [blame] | 129 | return generator->refEncodedData(ctx); |
reed | d5c448f | 2015-08-26 14:16:43 -0700 | [diff] [blame] | 130 | } |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 131 | |
| 132 | static bool check_output_bitmap(const SkBitmap& bitmap, uint32_t expectedID) { |
| 133 | SkASSERT(bitmap.getGenerationID() == expectedID); |
| 134 | SkASSERT(bitmap.isImmutable()); |
| 135 | SkASSERT(bitmap.getPixels()); |
| 136 | return true; |
| 137 | } |
| 138 | |
reed | 995b4bd | 2015-09-14 10:27:57 -0700 | [diff] [blame] | 139 | // Note, this returns a new, mutable, bitmap, with a new genID. |
| 140 | // If you want the immutable bitmap with the same ID as our cacherator, call tryLockAsBitmap() |
| 141 | // |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 142 | bool SkImageCacherator::generateBitmap(SkBitmap* bitmap, const SkImageInfo& decodeInfo) { |
reed | 4b3d3be | 2015-09-17 13:35:19 -0700 | [diff] [blame] | 143 | SkBitmap::Allocator* allocator = SkResourceCache::GetAllocator(); |
| 144 | |
fmalita | f0c38f5 | 2016-10-27 14:22:41 -0700 | [diff] [blame] | 145 | ScopedGenerator generator(fSharedGenerator); |
reed | 935d6cf | 2015-08-18 11:16:09 -0700 | [diff] [blame] | 146 | const SkImageInfo& genInfo = generator->getInfo(); |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 147 | if (decodeInfo.dimensions() == genInfo.dimensions()) { |
reed | d5c448f | 2015-08-26 14:16:43 -0700 | [diff] [blame] | 148 | SkASSERT(fOrigin.x() == 0 && fOrigin.y() == 0); |
reed | 935d6cf | 2015-08-18 11:16:09 -0700 | [diff] [blame] | 149 | // fast-case, no copy needed |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 150 | return generator->tryGenerateBitmap(bitmap, decodeInfo, allocator); |
reed | 935d6cf | 2015-08-18 11:16:09 -0700 | [diff] [blame] | 151 | } else { |
reed | c4a83e2 | 2015-09-11 11:47:27 -0700 | [diff] [blame] | 152 | // need to handle subsetting, so we first generate the full size version, and then |
halcanary | 6950de6 | 2015-11-07 05:29:00 -0800 | [diff] [blame] | 153 | // "read" from it to get our subset. See https://bug.skia.org/4213 |
reed | c4a83e2 | 2015-09-11 11:47:27 -0700 | [diff] [blame] | 154 | |
reed | 935d6cf | 2015-08-18 11:16:09 -0700 | [diff] [blame] | 155 | SkBitmap full; |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 156 | if (!generator->tryGenerateBitmap(&full, |
| 157 | decodeInfo.makeWH(genInfo.width(), genInfo.height()), |
| 158 | allocator)) { |
reed | 935d6cf | 2015-08-18 11:16:09 -0700 | [diff] [blame] | 159 | return false; |
| 160 | } |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 161 | if (!bitmap->tryAllocPixels(decodeInfo, nullptr, full.getColorTable())) { |
reed | 935d6cf | 2015-08-18 11:16:09 -0700 | [diff] [blame] | 162 | return false; |
| 163 | } |
reed | c4a83e2 | 2015-09-11 11:47:27 -0700 | [diff] [blame] | 164 | return full.readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(), |
| 165 | fOrigin.x(), fOrigin.y()); |
reed | 935d6cf | 2015-08-18 11:16:09 -0700 | [diff] [blame] | 166 | } |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 167 | } |
| 168 | |
reed | 6868c3f | 2015-11-24 11:44:47 -0800 | [diff] [blame] | 169 | bool SkImageCacherator::directGeneratePixels(const SkImageInfo& info, void* pixels, size_t rb, |
| 170 | int srcX, int srcY) { |
fmalita | f0c38f5 | 2016-10-27 14:22:41 -0700 | [diff] [blame] | 171 | ScopedGenerator generator(fSharedGenerator); |
reed | 6868c3f | 2015-11-24 11:44:47 -0800 | [diff] [blame] | 172 | const SkImageInfo& genInfo = generator->getInfo(); |
| 173 | // Currently generators do not natively handle subsets, so check that first. |
| 174 | if (srcX || srcY || genInfo.width() != info.width() || genInfo.height() != info.height()) { |
| 175 | return false; |
| 176 | } |
| 177 | return generator->getPixels(info, pixels, rb); |
| 178 | } |
| 179 | |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 180 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
| 181 | |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 182 | bool SkImageCacherator::lockAsBitmapOnlyIfAlreadyCached(SkBitmap* bitmap, CachedFormat format) { |
| 183 | return kNeedNewImageUniqueID != fUniqueIDs[format] && |
| 184 | SkBitmapCache::Find(fUniqueIDs[format], bitmap) && |
| 185 | check_output_bitmap(*bitmap, fUniqueIDs[format]); |
reed | 6868c3f | 2015-11-24 11:44:47 -0800 | [diff] [blame] | 186 | } |
| 187 | |
reed | 0955303 | 2015-11-23 12:32:16 -0800 | [diff] [blame] | 188 | bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap, const SkImage* client, |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 189 | SkImage::CachingHint chint, CachedFormat format, |
| 190 | const SkImageInfo& info) { |
| 191 | if (this->lockAsBitmapOnlyIfAlreadyCached(bitmap, format)) { |
reed | 6868c3f | 2015-11-24 11:44:47 -0800 | [diff] [blame] | 192 | return true; |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 193 | } |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 194 | if (!this->generateBitmap(bitmap, info)) { |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 195 | return false; |
| 196 | } |
| 197 | |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 198 | if (kNeedNewImageUniqueID == fUniqueIDs[format]) { |
| 199 | fUniqueIDs[format] = SkNextID::ImageID(); |
| 200 | } |
| 201 | bitmap->pixelRef()->setImmutableWithID(fUniqueIDs[format]); |
reed | 0955303 | 2015-11-23 12:32:16 -0800 | [diff] [blame] | 202 | if (SkImage::kAllow_CachingHint == chint) { |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 203 | SkBitmapCache::Add(fUniqueIDs[format], *bitmap); |
reed | 0955303 | 2015-11-23 12:32:16 -0800 | [diff] [blame] | 204 | if (client) { |
| 205 | as_IB(client)->notifyAddedToCache(); |
| 206 | } |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 207 | } |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 208 | return true; |
| 209 | } |
| 210 | |
Robert Phillips | 4447b64 | 2017-03-03 11:10:18 -0500 | [diff] [blame] | 211 | bool SkImageCacherator::lockAsBitmap(GrContext* context, SkBitmap* bitmap, const SkImage* client, |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 212 | SkColorSpace* dstColorSpace, |
reed | 0955303 | 2015-11-23 12:32:16 -0800 | [diff] [blame] | 213 | SkImage::CachingHint chint) { |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 214 | CachedFormat format = this->chooseCacheFormat(dstColorSpace); |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 215 | SkImageInfo cacheInfo = this->buildCacheInfo(format); |
| 216 | |
| 217 | if (kNeedNewImageUniqueID == fUniqueIDs[format]) { |
| 218 | fUniqueIDs[format] = SkNextID::ImageID(); |
| 219 | } |
| 220 | |
| 221 | if (this->tryLockAsBitmap(bitmap, client, chint, format, cacheInfo)) { |
| 222 | return check_output_bitmap(*bitmap, fUniqueIDs[format]); |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | #if SK_SUPPORT_GPU |
Robert Phillips | 4447b64 | 2017-03-03 11:10:18 -0500 | [diff] [blame] | 226 | if (!context) { |
| 227 | bitmap->reset(); |
| 228 | return false; |
| 229 | } |
| 230 | |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 231 | // Try to get a texture and read it back to raster (and then cache that with our ID) |
Robert Phillips | 4447b64 | 2017-03-03 11:10:18 -0500 | [diff] [blame] | 232 | sk_sp<GrTextureProxy> proxy; |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 233 | |
reed | d5c448f | 2015-08-26 14:16:43 -0700 | [diff] [blame] | 234 | { |
fmalita | f0c38f5 | 2016-10-27 14:22:41 -0700 | [diff] [blame] | 235 | ScopedGenerator generator(fSharedGenerator); |
Robert Phillips | 4447b64 | 2017-03-03 11:10:18 -0500 | [diff] [blame] | 236 | proxy = generator->generateTexture(context, cacheInfo, fOrigin); |
reed | d5c448f | 2015-08-26 14:16:43 -0700 | [diff] [blame] | 237 | } |
Robert Phillips | 4447b64 | 2017-03-03 11:10:18 -0500 | [diff] [blame] | 238 | if (!proxy) { |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 239 | bitmap->reset(); |
| 240 | return false; |
| 241 | } |
| 242 | |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 243 | if (!bitmap->tryAllocPixels(cacheInfo)) { |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 244 | bitmap->reset(); |
| 245 | return false; |
| 246 | } |
| 247 | |
Robert Phillips | 4447b64 | 2017-03-03 11:10:18 -0500 | [diff] [blame] | 248 | sk_sp<GrSurfaceContext> sContext(context->contextPriv().makeWrappedSurfaceContext( |
| 249 | proxy, |
| 250 | fInfo.refColorSpace())); // src colorSpace |
| 251 | if (!sContext) { |
| 252 | bitmap->reset(); |
| 253 | return false; |
| 254 | } |
| 255 | |
| 256 | if (!sContext->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(), 0, 0)) { |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 257 | bitmap->reset(); |
| 258 | return false; |
| 259 | } |
| 260 | |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 261 | bitmap->pixelRef()->setImmutableWithID(fUniqueIDs[format]); |
reed | 0955303 | 2015-11-23 12:32:16 -0800 | [diff] [blame] | 262 | if (SkImage::kAllow_CachingHint == chint) { |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 263 | SkBitmapCache::Add(fUniqueIDs[format], *bitmap); |
reed | 0955303 | 2015-11-23 12:32:16 -0800 | [diff] [blame] | 264 | if (client) { |
| 265 | as_IB(client)->notifyAddedToCache(); |
| 266 | } |
fmalita | 3b0d532 | 2015-09-18 08:07:31 -0700 | [diff] [blame] | 267 | } |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 268 | return check_output_bitmap(*bitmap, fUniqueIDs[format]); |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 269 | #else |
| 270 | return false; |
| 271 | #endif |
| 272 | } |
| 273 | |
| 274 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
| 275 | |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 276 | // Abstraction of GrCaps that handles the cases where we don't have a caps pointer (because |
| 277 | // we're in raster mode), or where GPU support is entirely missing. In theory, we only need the |
| 278 | // chosen format to be texturable, but that lets us choose F16 on GLES implemenations where we |
| 279 | // won't be able to read the texture back. We'd like to ensure that SkImake::makeNonTextureImage |
| 280 | // works, so we require that the formats we choose are renderable (as a proxy for being readable). |
| 281 | struct CacheCaps { |
| 282 | CacheCaps(const GrCaps* caps) : fCaps(caps) {} |
| 283 | |
Brian Osman | d601087 | 2016-11-15 18:06:18 +0000 | [diff] [blame] | 284 | #if SK_SUPPORT_GPU |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 285 | bool supportsHalfFloat() const { |
| 286 | return !fCaps || |
| 287 | (fCaps->isConfigTexturable(kRGBA_half_GrPixelConfig) && |
| 288 | fCaps->isConfigRenderable(kRGBA_half_GrPixelConfig, false)); |
| 289 | } |
| 290 | |
| 291 | bool supportsSRGB() const { |
| 292 | return !fCaps || |
| 293 | (fCaps->srgbSupport() && fCaps->isConfigTexturable(kSRGBA_8888_GrPixelConfig)); |
| 294 | } |
| 295 | |
| 296 | bool supportsSBGR() const { |
| 297 | return !fCaps || fCaps->srgbSupport(); |
| 298 | } |
| 299 | #else |
| 300 | bool supportsHalfFloat() const { return true; } |
| 301 | bool supportsSRGB() const { return true; } |
| 302 | bool supportsSBGR() const { return true; } |
| 303 | #endif |
| 304 | |
| 305 | const GrCaps* fCaps; |
| 306 | }; |
| 307 | |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 308 | SkImageCacherator::CachedFormat SkImageCacherator::chooseCacheFormat(SkColorSpace* dstColorSpace, |
| 309 | const GrCaps* grCaps) { |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 310 | SkColorSpace* cs = fInfo.colorSpace(); |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 311 | if (!cs || !dstColorSpace) { |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 312 | return kLegacy_CachedFormat; |
| 313 | } |
| 314 | |
| 315 | CacheCaps caps(grCaps); |
| 316 | switch (fInfo.colorType()) { |
| 317 | case kUnknown_SkColorType: |
| 318 | case kAlpha_8_SkColorType: |
| 319 | case kRGB_565_SkColorType: |
| 320 | case kARGB_4444_SkColorType: |
| 321 | // We don't support color space on these formats, so always decode in legacy mode: |
| 322 | // TODO: Ask the codec to decode these to something else (at least sRGB 8888)? |
| 323 | return kLegacy_CachedFormat; |
| 324 | |
| 325 | case kIndex_8_SkColorType: |
| 326 | // We can't draw from indexed textures with a color space, so ask the codec to expand |
| 327 | if (cs->gammaCloseToSRGB()) { |
| 328 | if (caps.supportsSRGB()) { |
| 329 | return kSRGB8888_CachedFormat; |
| 330 | } else if (caps.supportsHalfFloat()) { |
| 331 | return kLinearF16_CachedFormat; |
| 332 | } else { |
| 333 | return kLegacy_CachedFormat; |
| 334 | } |
| 335 | } else { |
| 336 | if (caps.supportsHalfFloat()) { |
| 337 | return kLinearF16_CachedFormat; |
| 338 | } else if (caps.supportsSRGB()) { |
| 339 | return kSRGB8888_CachedFormat; |
| 340 | } else { |
| 341 | return kLegacy_CachedFormat; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | case kGray_8_SkColorType: |
| 346 | // TODO: What do we do with grayscale sources that have strange color spaces attached? |
| 347 | // The codecs and color space xform don't handle this correctly (yet), so drop it on |
| 348 | // the floor. (Also, inflating by a factor of 8 is going to be unfortunate). |
| 349 | // As it is, we don't directly support sRGB grayscale, so ask the codec to convert |
| 350 | // it for us. This bypasses some really sketchy code GrUploadPixmapToTexture. |
| 351 | if (cs->gammaCloseToSRGB() && caps.supportsSRGB()) { |
| 352 | return kSRGB8888_CachedFormat; |
| 353 | } else { |
| 354 | return kLegacy_CachedFormat; |
| 355 | } |
| 356 | |
| 357 | case kRGBA_8888_SkColorType: |
| 358 | if (cs->gammaCloseToSRGB()) { |
| 359 | if (caps.supportsSRGB()) { |
| 360 | return kAsIs_CachedFormat; |
| 361 | } else if (caps.supportsHalfFloat()) { |
| 362 | return kLinearF16_CachedFormat; |
| 363 | } else { |
| 364 | return kLegacy_CachedFormat; |
| 365 | } |
| 366 | } else { |
| 367 | if (caps.supportsHalfFloat()) { |
| 368 | return kLinearF16_CachedFormat; |
| 369 | } else if (caps.supportsSRGB()) { |
| 370 | return kSRGB8888_CachedFormat; |
| 371 | } else { |
| 372 | return kLegacy_CachedFormat; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | case kBGRA_8888_SkColorType: |
| 377 | // Odd case. sBGRA isn't a real thing, so we may not have this texturable. |
| 378 | if (caps.supportsSBGR()) { |
| 379 | if (cs->gammaCloseToSRGB()) { |
| 380 | return kAsIs_CachedFormat; |
| 381 | } else if (caps.supportsHalfFloat()) { |
| 382 | return kLinearF16_CachedFormat; |
| 383 | } else if (caps.supportsSRGB()) { |
| 384 | return kSRGB8888_CachedFormat; |
| 385 | } else { |
| 386 | // sBGRA support without sRGBA is highly unlikely (impossible?) Nevertheless. |
| 387 | return kLegacy_CachedFormat; |
| 388 | } |
| 389 | } else { |
| 390 | if (cs->gammaCloseToSRGB()) { |
| 391 | if (caps.supportsSRGB()) { |
| 392 | return kSRGB8888_CachedFormat; |
| 393 | } else if (caps.supportsHalfFloat()) { |
| 394 | return kLinearF16_CachedFormat; |
| 395 | } else { |
| 396 | return kLegacy_CachedFormat; |
| 397 | } |
| 398 | } else { |
| 399 | if (caps.supportsHalfFloat()) { |
| 400 | return kLinearF16_CachedFormat; |
| 401 | } else if (caps.supportsSRGB()) { |
| 402 | return kSRGB8888_CachedFormat; |
| 403 | } else { |
| 404 | return kLegacy_CachedFormat; |
| 405 | } |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | case kRGBA_F16_SkColorType: |
| 410 | if (!caps.supportsHalfFloat()) { |
| 411 | if (caps.supportsSRGB()) { |
| 412 | return kSRGB8888_CachedFormat; |
| 413 | } else { |
| 414 | return kLegacy_CachedFormat; |
| 415 | } |
| 416 | } else if (cs->gammaIsLinear()) { |
| 417 | return kAsIs_CachedFormat; |
| 418 | } else { |
| 419 | return kLinearF16_CachedFormat; |
| 420 | } |
| 421 | } |
| 422 | SkDEBUGFAIL("Unreachable"); |
| 423 | return kLegacy_CachedFormat; |
| 424 | } |
| 425 | |
| 426 | SkImageInfo SkImageCacherator::buildCacheInfo(CachedFormat format) { |
| 427 | switch (format) { |
| 428 | case kLegacy_CachedFormat: |
| 429 | return fInfo.makeColorSpace(nullptr); |
| 430 | case kAsIs_CachedFormat: |
| 431 | return fInfo; |
| 432 | case kLinearF16_CachedFormat: |
| 433 | return fInfo |
| 434 | .makeColorType(kRGBA_F16_SkColorType) |
| 435 | .makeColorSpace(as_CSB(fInfo.colorSpace())->makeLinearGamma()); |
| 436 | case kSRGB8888_CachedFormat: |
| 437 | return fInfo |
| 438 | .makeColorType(kRGBA_8888_SkColorType) |
| 439 | .makeColorSpace(as_CSB(fInfo.colorSpace())->makeSRGBGamma()); |
| 440 | default: |
| 441 | SkDEBUGFAIL("Invalid cached format"); |
| 442 | return fInfo; |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
| 447 | |
| 448 | #if SK_SUPPORT_GPU |
| 449 | |
| 450 | void SkImageCacherator::makeCacheKeyFromOrigKey(const GrUniqueKey& origKey, CachedFormat format, |
| 451 | GrUniqueKey* cacheKey) { |
| 452 | SkASSERT(!cacheKey->isValid()); |
| 453 | if (origKey.isValid()) { |
| 454 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| 455 | GrUniqueKey::Builder builder(cacheKey, origKey, kDomain, 1); |
| 456 | builder[0] = format; |
| 457 | } |
| 458 | } |
Brian Osman | d601087 | 2016-11-15 18:06:18 +0000 | [diff] [blame] | 459 | |
| 460 | #ifdef SK_SUPPORT_COMPRESSED_TEXTURES_IN_CACHERATOR |
| 461 | static GrTexture* load_compressed_into_texture(GrContext* ctx, SkData* data, GrSurfaceDesc desc) { |
| 462 | const void* rawStart; |
| 463 | GrPixelConfig config = GrIsCompressedTextureDataSupported(ctx, data, desc.fWidth, desc.fHeight, |
| 464 | &rawStart); |
| 465 | if (kUnknown_GrPixelConfig == config) { |
| 466 | return nullptr; |
| 467 | } |
| 468 | |
| 469 | desc.fConfig = config; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 470 | return ctx->resourceProvider()->createTexture(desc, SkBudgeted::kYes, rawStart, 0); |
Brian Osman | d601087 | 2016-11-15 18:06:18 +0000 | [diff] [blame] | 471 | } |
| 472 | #endif |
| 473 | |
| 474 | class Generator_GrYUVProvider : public GrYUVProvider { |
| 475 | SkImageGenerator* fGen; |
| 476 | |
| 477 | public: |
| 478 | Generator_GrYUVProvider(SkImageGenerator* gen) : fGen(gen) {} |
| 479 | |
| 480 | uint32_t onGetID() override { return fGen->uniqueID(); } |
| 481 | bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override { |
| 482 | return fGen->queryYUV8(sizeInfo, colorSpace); |
| 483 | } |
| 484 | bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override { |
| 485 | return fGen->getYUV8Planes(sizeInfo, planes); |
| 486 | } |
| 487 | }; |
| 488 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 489 | static GrTexture* set_key_and_return(GrResourceProvider* resourceProvider, |
Robert Phillips | f7cf81a | 2017-03-02 10:23:52 -0500 | [diff] [blame] | 490 | GrTexture* tex, const GrUniqueKey& key) { |
Brian Osman | d601087 | 2016-11-15 18:06:18 +0000 | [diff] [blame] | 491 | if (key.isValid()) { |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 492 | resourceProvider->assignUniqueKeyToTexture(key, tex); |
Brian Osman | d601087 | 2016-11-15 18:06:18 +0000 | [diff] [blame] | 493 | } |
| 494 | return tex; |
| 495 | } |
| 496 | |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 497 | sk_sp<SkColorSpace> SkImageCacherator::getColorSpace(GrContext* ctx, SkColorSpace* dstColorSpace) { |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 498 | // TODO: This isn't always correct. Picture generator currently produces textures in N32, |
| 499 | // and will (soon) emit them in an arbitrary (destination) space. We will need to stash that |
| 500 | // information in/on the key so we can return the correct space in case #1 of lockTexture. |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 501 | CachedFormat format = this->chooseCacheFormat(dstColorSpace, ctx->caps()); |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 502 | SkImageInfo cacheInfo = this->buildCacheInfo(format); |
| 503 | return sk_ref_sp(cacheInfo.colorSpace()); |
| 504 | } |
| 505 | |
reed | d5c448f | 2015-08-26 14:16:43 -0700 | [diff] [blame] | 506 | /* |
| 507 | * We have a 5 ways to try to return a texture (in sorted order) |
| 508 | * |
| 509 | * 1. Check the cache for a pre-existing one |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 510 | * 2. Ask the generator to natively create one |
reed | d5c448f | 2015-08-26 14:16:43 -0700 | [diff] [blame] | 511 | * 3. Ask the generator to return a compressed form that the GPU might support |
| 512 | * 4. Ask the generator to return YUV planes, which the GPU can convert |
| 513 | * 5. Ask the generator to return RGB(A) data, which the GPU can convert |
| 514 | */ |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 515 | GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& origKey, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 516 | const SkImage* client, SkImage::CachingHint chint, |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 517 | bool willBeMipped, SkColorSpace* dstColorSpace) { |
ericrk | 369e937 | 2016-02-05 15:32:36 -0800 | [diff] [blame] | 518 | // Values representing the various texture lock paths we can take. Used for logging the path |
| 519 | // taken to a histogram. |
| 520 | enum LockTexturePath { |
| 521 | kFailure_LockTexturePath, |
| 522 | kPreExisting_LockTexturePath, |
| 523 | kNative_LockTexturePath, |
| 524 | kCompressed_LockTexturePath, |
| 525 | kYUV_LockTexturePath, |
| 526 | kRGBA_LockTexturePath, |
| 527 | }; |
| 528 | |
| 529 | enum { kLockTexturePathCount = kRGBA_LockTexturePath + 1 }; |
| 530 | |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 531 | // Determine which cached format we're going to use (which may involve decoding to a different |
| 532 | // info than the generator provides). |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 533 | CachedFormat format = this->chooseCacheFormat(dstColorSpace, ctx->caps()); |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 534 | |
| 535 | // Fold the cache format into our texture key |
| 536 | GrUniqueKey key; |
| 537 | this->makeCacheKeyFromOrigKey(origKey, format, &key); |
| 538 | |
Brian Salomon | bc0bcc0 | 2015-10-19 15:12:32 -0400 | [diff] [blame] | 539 | // 1. Check the cache for a pre-existing one |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 540 | if (key.isValid()) { |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 541 | if (GrTexture* tex = ctx->resourceProvider()->findAndRefTextureByUniqueKey(key)) { |
ericrk | 369e937 | 2016-02-05 15:32:36 -0800 | [diff] [blame] | 542 | SK_HISTOGRAM_ENUMERATION("LockTexturePath", kPreExisting_LockTexturePath, |
| 543 | kLockTexturePathCount); |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 544 | return tex; |
| 545 | } |
Brian Salomon | bc0bcc0 | 2015-10-19 15:12:32 -0400 | [diff] [blame] | 546 | } |
| 547 | |
Brian Osman | 222e9ad | 2016-12-14 15:42:36 -0500 | [diff] [blame] | 548 | // The CachedFormat is both an index for which cache "slot" we'll use to store this particular |
| 549 | // decoded variant of the encoded data, and also a recipe for how to transform the original |
| 550 | // info to get the one that we're going to decode to. |
| 551 | SkImageInfo cacheInfo = this->buildCacheInfo(format); |
| 552 | |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 553 | // 2. Ask the generator to natively create one |
reed | d5c448f | 2015-08-26 14:16:43 -0700 | [diff] [blame] | 554 | { |
fmalita | f0c38f5 | 2016-10-27 14:22:41 -0700 | [diff] [blame] | 555 | ScopedGenerator generator(fSharedGenerator); |
Robert Phillips | 4447b64 | 2017-03-03 11:10:18 -0500 | [diff] [blame] | 556 | if (sk_sp<GrTextureProxy> proxy = generator->generateTexture(ctx, cacheInfo, fOrigin)) { |
ericrk | 369e937 | 2016-02-05 15:32:36 -0800 | [diff] [blame] | 557 | SK_HISTOGRAM_ENUMERATION("LockTexturePath", kNative_LockTexturePath, |
| 558 | kLockTexturePathCount); |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 559 | GrTexture* tex2 = proxy->instantiate(ctx->resourceProvider()); |
Robert Phillips | 4447b64 | 2017-03-03 11:10:18 -0500 | [diff] [blame] | 560 | if (tex2) { |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 561 | return set_key_and_return(ctx->resourceProvider(), SkSafeRef(tex2), key); |
Robert Phillips | 4447b64 | 2017-03-03 11:10:18 -0500 | [diff] [blame] | 562 | } |
reed | d5c448f | 2015-08-26 14:16:43 -0700 | [diff] [blame] | 563 | } |
| 564 | } |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 565 | |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 566 | const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(cacheInfo, *ctx->caps()); |
reed | 3322a81 | 2015-09-16 10:09:24 -0700 | [diff] [blame] | 567 | |
reed | 93eeadf | 2016-05-11 08:06:11 -0700 | [diff] [blame] | 568 | #ifdef SK_SUPPORT_COMPRESSED_TEXTURES_IN_CACHERATOR |
reed | d5c448f | 2015-08-26 14:16:43 -0700 | [diff] [blame] | 569 | // 3. Ask the generator to return a compressed form that the GPU might support |
bungeman | ffae30d | 2016-08-03 13:32:32 -0700 | [diff] [blame] | 570 | sk_sp<SkData> data(this->refEncoded(ctx)); |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 571 | if (data) { |
| 572 | GrTexture* tex = load_compressed_into_texture(ctx, data, desc); |
| 573 | if (tex) { |
ericrk | 369e937 | 2016-02-05 15:32:36 -0800 | [diff] [blame] | 574 | SK_HISTOGRAM_ENUMERATION("LockTexturePath", kCompressed_LockTexturePath, |
| 575 | kLockTexturePathCount); |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 576 | return set_key_and_return(tex, key); |
| 577 | } |
| 578 | } |
reed | 93eeadf | 2016-05-11 08:06:11 -0700 | [diff] [blame] | 579 | #endif |
reed | d5c448f | 2015-08-26 14:16:43 -0700 | [diff] [blame] | 580 | |
| 581 | // 4. Ask the generator to return YUV planes, which the GPU can convert |
Brian Osman | 46da1cc | 2017-02-14 14:15:48 -0500 | [diff] [blame] | 582 | if (!ctx->contextPriv().disableGpuYUVConversion()) { |
fmalita | f0c38f5 | 2016-10-27 14:22:41 -0700 | [diff] [blame] | 583 | ScopedGenerator generator(fSharedGenerator); |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 584 | Generator_GrYUVProvider provider(generator); |
robertphillips | 677da9d | 2016-05-11 05:15:55 -0700 | [diff] [blame] | 585 | sk_sp<GrTexture> tex = provider.refAsTexture(ctx, desc, true); |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 586 | if (tex) { |
ericrk | 369e937 | 2016-02-05 15:32:36 -0800 | [diff] [blame] | 587 | SK_HISTOGRAM_ENUMERATION("LockTexturePath", kYUV_LockTexturePath, |
| 588 | kLockTexturePathCount); |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 589 | return set_key_and_return(ctx->resourceProvider(), tex.release(), key); |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 590 | } |
| 591 | } |
reed | d5c448f | 2015-08-26 14:16:43 -0700 | [diff] [blame] | 592 | |
| 593 | // 5. Ask the generator to return RGB(A) data, which the GPU can convert |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 594 | SkBitmap bitmap; |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 595 | if (this->tryLockAsBitmap(&bitmap, client, chint, format, cacheInfo)) { |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 596 | GrTexture* tex = nullptr; |
| 597 | if (willBeMipped) { |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 598 | tex = GrGenerateMipMapsAndUploadToTexture(ctx, bitmap, dstColorSpace); |
brianosman | eb3429c | 2016-03-25 13:03:03 -0700 | [diff] [blame] | 599 | } |
| 600 | if (!tex) { |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 601 | tex = GrUploadBitmapToTexture(ctx, bitmap); |
| 602 | } |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 603 | if (tex) { |
ericrk | 369e937 | 2016-02-05 15:32:36 -0800 | [diff] [blame] | 604 | SK_HISTOGRAM_ENUMERATION("LockTexturePath", kRGBA_LockTexturePath, |
| 605 | kLockTexturePathCount); |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 606 | return set_key_and_return(ctx->resourceProvider(), tex, key); |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 607 | } |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 608 | } |
ericrk | 369e937 | 2016-02-05 15:32:36 -0800 | [diff] [blame] | 609 | SK_HISTOGRAM_ENUMERATION("LockTexturePath", kFailure_LockTexturePath, |
| 610 | kLockTexturePathCount); |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 611 | return nullptr; |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 612 | } |
| 613 | |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 614 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 615 | |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 616 | GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrSamplerParams& params, |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 617 | SkColorSpace* dstColorSpace, |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 618 | sk_sp<SkColorSpace>* texColorSpace, |
Robert Phillips | 67c18d6 | 2017-01-20 12:44:06 -0500 | [diff] [blame] | 619 | const SkImage* client, |
| 620 | SkScalar scaleAdjust[2], |
| 621 | SkImage::CachingHint chint) { |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 622 | if (!ctx) { |
| 623 | return nullptr; |
| 624 | } |
| 625 | |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 626 | return GrImageTextureMaker(ctx, this, client, chint).refTextureForParams(params, dstColorSpace, |
Robert Phillips | 67c18d6 | 2017-01-20 12:44:06 -0500 | [diff] [blame] | 627 | texColorSpace, |
| 628 | scaleAdjust); |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | #else |
| 632 | |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 633 | GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrSamplerParams&, |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 634 | SkColorSpace* dstColorSpace, |
Brian Osman | 7992da3 | 2016-11-18 11:28:24 -0500 | [diff] [blame] | 635 | sk_sp<SkColorSpace>* texColorSpace, |
Robert Phillips | 67c18d6 | 2017-01-20 12:44:06 -0500 | [diff] [blame] | 636 | const SkImage* client, |
| 637 | SkScalar scaleAdjust[2], SkImage::CachingHint) { |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 638 | return nullptr; |
| 639 | } |
| 640 | |
| 641 | #endif |