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 | |
Brian Osman | df7e075 | 2017-04-26 16:20:28 -0400 | [diff] [blame] | 17 | GrImageTextureMaker::GrImageTextureMaker(GrContext* context, const SkImage* client, |
| 18 | SkImage::CachingHint chint) |
| 19 | : INHERITED(context, client->width(), client->height(), client->isAlphaOnly()) |
| 20 | , fCacher(as_IB(client)->peekCacherator()) |
| 21 | , fClient(client) |
| 22 | , fCachingHint(chint) { |
| 23 | SkASSERT(fCacher); |
| 24 | GrMakeKeyFromImageID(&fOriginalKey, client->uniqueID(), |
| 25 | SkIRect::MakeWH(this->width(), this->height())); |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 26 | } |
| 27 | |
Robert Phillips | 0c984a0 | 2017-03-16 07:51:56 -0400 | [diff] [blame] | 28 | sk_sp<GrTextureProxy> GrImageTextureMaker::refOriginalTextureProxy(bool willBeMipped, |
Stan Iliev | ba81af2 | 2017-06-08 15:16:53 -0400 | [diff] [blame] | 29 | SkColorSpace* dstColorSpace, |
| 30 | AllowedTexGenType onlyIfFast) { |
Brian Osman | df7e075 | 2017-04-26 16:20:28 -0400 | [diff] [blame] | 31 | return fCacher->lockTextureProxy(this->context(), fOriginalKey, fCachingHint, |
Stan Iliev | ba81af2 | 2017-06-08 15:16:53 -0400 | [diff] [blame] | 32 | willBeMipped, dstColorSpace, onlyIfFast); |
Robert Phillips | 0c984a0 | 2017-03-16 07:51:56 -0400 | [diff] [blame] | 33 | } |
| 34 | |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 35 | void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey, |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 36 | SkColorSpace* dstColorSpace) { |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 37 | if (fOriginalKey.isValid() && SkImage::kAllow_CachingHint == fCachingHint) { |
| 38 | SkImageCacherator::CachedFormat cacheFormat = |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 39 | fCacher->chooseCacheFormat(dstColorSpace, this->context()->caps()); |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 40 | GrUniqueKey cacheKey; |
| 41 | fCacher->makeCacheKeyFromOrigKey(fOriginalKey, cacheFormat, &cacheKey); |
| 42 | MakeCopyKeyFromOrigKey(cacheKey, stretch, paramsCopyKey); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | void GrImageTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) { |
Brian Osman | df7e075 | 2017-04-26 16:20:28 -0400 | [diff] [blame] | 47 | as_IB(fClient)->notifyAddedToCache(); |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | SkAlphaType GrImageTextureMaker::alphaType() const { |
Brian Osman | df7e075 | 2017-04-26 16:20:28 -0400 | [diff] [blame] | 51 | return fClient->alphaType(); |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 52 | } |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 53 | sk_sp<SkColorSpace> GrImageTextureMaker::getColorSpace(SkColorSpace* dstColorSpace) { |
| 54 | return fCacher->getColorSpace(this->context(), dstColorSpace); |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 55 | } |