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" |
Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 9 | #include "SkGr.h" |
Brian Osman | bd65955 | 2018-09-11 10:03:19 -0400 | [diff] [blame] | 10 | #include "SkImage_Lazy.h" |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 11 | |
Brian Osman | df7e075 | 2017-04-26 16:20:28 -0400 | [diff] [blame] | 12 | GrImageTextureMaker::GrImageTextureMaker(GrContext* context, const SkImage* client, |
| 13 | SkImage::CachingHint chint) |
| 14 | : INHERITED(context, client->width(), client->height(), client->isAlphaOnly()) |
Brian Osman | bd65955 | 2018-09-11 10:03:19 -0400 | [diff] [blame] | 15 | , fImage(static_cast<const SkImage_Lazy*>(client)) |
Brian Osman | df7e075 | 2017-04-26 16:20:28 -0400 | [diff] [blame] | 16 | , fCachingHint(chint) { |
Brian Osman | bd65955 | 2018-09-11 10:03:19 -0400 | [diff] [blame] | 17 | SkASSERT(client->isLazyGenerated()); |
Brian Osman | df7e075 | 2017-04-26 16:20:28 -0400 | [diff] [blame] | 18 | GrMakeKeyFromImageID(&fOriginalKey, client->uniqueID(), |
| 19 | SkIRect::MakeWH(this->width(), this->height())); |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 20 | } |
| 21 | |
Robert Phillips | 0c984a0 | 2017-03-16 07:51:56 -0400 | [diff] [blame] | 22 | sk_sp<GrTextureProxy> GrImageTextureMaker::refOriginalTextureProxy(bool willBeMipped, |
Stan Iliev | ba81af2 | 2017-06-08 15:16:53 -0400 | [diff] [blame] | 23 | AllowedTexGenType onlyIfFast) { |
Brian Osman | bd65955 | 2018-09-11 10:03:19 -0400 | [diff] [blame] | 24 | return fImage->lockTextureProxy(this->context(), fOriginalKey, fCachingHint, |
Brian Osman | e7fd8c3 | 2018-10-19 13:30:39 -0400 | [diff] [blame^] | 25 | willBeMipped, onlyIfFast); |
Robert Phillips | 0c984a0 | 2017-03-16 07:51:56 -0400 | [diff] [blame] | 26 | } |
| 27 | |
Brian Osman | b3f3830 | 2018-09-07 15:24:44 -0400 | [diff] [blame] | 28 | void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) { |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 29 | if (fOriginalKey.isValid() && SkImage::kAllow_CachingHint == fCachingHint) { |
Brian Osman | 10494e3 | 2018-09-10 12:45:18 -0400 | [diff] [blame] | 30 | GrUniqueKey cacheKey; |
Brian Osman | bd65955 | 2018-09-11 10:03:19 -0400 | [diff] [blame] | 31 | fImage->makeCacheKeyFromOrigKey(fOriginalKey, &cacheKey); |
Brian Osman | 10494e3 | 2018-09-10 12:45:18 -0400 | [diff] [blame] | 32 | MakeCopyKeyFromOrigKey(cacheKey, stretch, paramsCopyKey); |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 33 | } |
| 34 | } |
| 35 | |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 36 | SkAlphaType GrImageTextureMaker::alphaType() const { |
Brian Osman | bd65955 | 2018-09-11 10:03:19 -0400 | [diff] [blame] | 37 | return fImage->alphaType(); |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 38 | } |
Brian Osman | e7fd8c3 | 2018-10-19 13:30:39 -0400 | [diff] [blame^] | 39 | sk_sp<SkColorSpace> GrImageTextureMaker::getColorSpace() { |
Brian Osman | bd65955 | 2018-09-11 10:03:19 -0400 | [diff] [blame] | 40 | return fImage->refColorSpace(); |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 41 | } |