Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 "GrImageTextureMaker.h" |
| 9 | |
| 10 | #include "GrContext.h" |
| 11 | #include "GrGpuResourcePriv.h" |
| 12 | #include "SkGrPriv.h" |
| 13 | #include "SkImage_Base.h" |
| 14 | #include "SkImageCacherator.h" |
| 15 | #include "SkPixelRef.h" |
| 16 | |
| 17 | static bool cacher_is_alpha_only(const SkImageCacherator& cacher) { |
| 18 | return kAlpha_8_SkColorType == cacher.info().colorType(); |
| 19 | } |
| 20 | |
| 21 | GrImageTextureMaker::GrImageTextureMaker(GrContext* context, SkImageCacherator* cacher, |
| 22 | const SkImage* client, SkImage::CachingHint chint) |
| 23 | : INHERITED(context, cacher->info().width(), cacher->info().height(), |
| 24 | cacher_is_alpha_only(*cacher)) |
| 25 | , fCacher(cacher) |
| 26 | , fClient(client) |
| 27 | , fCachingHint(chint) { |
| 28 | if (client) { |
| 29 | GrMakeKeyFromImageID(&fOriginalKey, client->uniqueID(), |
| 30 | SkIRect::MakeWH(this->width(), this->height())); |
| 31 | } |
| 32 | } |
| 33 | |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 34 | GrTexture* GrImageTextureMaker::refOriginalTexture(bool willBeMipped, SkColorSpace* dstColorSpace) { |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 35 | return fCacher->lockTexture(this->context(), fOriginalKey, fClient, fCachingHint, willBeMipped, |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 36 | dstColorSpace); |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey, |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 40 | SkColorSpace* dstColorSpace) { |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 41 | if (fOriginalKey.isValid() && SkImage::kAllow_CachingHint == fCachingHint) { |
| 42 | SkImageCacherator::CachedFormat cacheFormat = |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 43 | fCacher->chooseCacheFormat(dstColorSpace, this->context()->caps()); |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 44 | GrUniqueKey cacheKey; |
| 45 | fCacher->makeCacheKeyFromOrigKey(fOriginalKey, cacheFormat, &cacheKey); |
| 46 | MakeCopyKeyFromOrigKey(cacheKey, stretch, paramsCopyKey); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void GrImageTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) { |
| 51 | if (fClient) { |
| 52 | as_IB(fClient)->notifyAddedToCache(); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | SkAlphaType GrImageTextureMaker::alphaType() const { |
| 57 | return fCacher->info().alphaType(); |
| 58 | } |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 59 | sk_sp<SkColorSpace> GrImageTextureMaker::getColorSpace(SkColorSpace* dstColorSpace) { |
| 60 | return fCacher->getColorSpace(this->context(), dstColorSpace); |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 61 | } |