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" |
Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 12 | #include "SkGr.h" |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 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 | |
Robert Phillips | 0c984a0 | 2017-03-16 07:51:56 -0400 | [diff] [blame] | 34 | sk_sp<GrTextureProxy> GrImageTextureMaker::refOriginalTextureProxy(bool willBeMipped, |
| 35 | SkColorSpace* dstColorSpace) { |
Robert Phillips | 4f358be | 2017-03-23 08:21:00 -0400 | [diff] [blame] | 36 | return fCacher->lockTextureProxy(this->context(), fOriginalKey, fClient, fCachingHint, |
| 37 | willBeMipped, dstColorSpace); |
Robert Phillips | 0c984a0 | 2017-03-16 07:51:56 -0400 | [diff] [blame] | 38 | } |
| 39 | |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 40 | void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey, |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 41 | SkColorSpace* dstColorSpace) { |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 42 | if (fOriginalKey.isValid() && SkImage::kAllow_CachingHint == fCachingHint) { |
| 43 | SkImageCacherator::CachedFormat cacheFormat = |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 44 | fCacher->chooseCacheFormat(dstColorSpace, this->context()->caps()); |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 45 | GrUniqueKey cacheKey; |
| 46 | fCacher->makeCacheKeyFromOrigKey(fOriginalKey, cacheFormat, &cacheKey); |
| 47 | MakeCopyKeyFromOrigKey(cacheKey, stretch, paramsCopyKey); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | void GrImageTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) { |
| 52 | if (fClient) { |
| 53 | as_IB(fClient)->notifyAddedToCache(); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | SkAlphaType GrImageTextureMaker::alphaType() const { |
| 58 | return fCacher->info().alphaType(); |
| 59 | } |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 60 | sk_sp<SkColorSpace> GrImageTextureMaker::getColorSpace(SkColorSpace* dstColorSpace) { |
| 61 | return fCacher->getColorSpace(this->context(), dstColorSpace); |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 62 | } |