blob: 732811615f874b952a143e08e4ad7186fe57e1f1 [file] [log] [blame]
Brian Osman3b66ab62016-11-28 09:26:31 -05001/*
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 Osman3b66ab62016-11-28 09:26:31 -05009#include "GrContext.h"
Brian Salomonc7fe0f72018-05-11 10:14:21 -040010#include "GrContextPriv.h"
Brian Osman3b66ab62016-11-28 09:26:31 -050011#include "GrGpuResourcePriv.h"
Brian Osman3b655982017-03-07 16:58:08 -050012#include "SkGr.h"
Brian Osman3b66ab62016-11-28 09:26:31 -050013#include "SkImageCacherator.h"
Brian Salomonc7fe0f72018-05-11 10:14:21 -040014#include "SkImage_Base.h"
Brian Osman3b66ab62016-11-28 09:26:31 -050015#include "SkPixelRef.h"
16
Brian Osmandf7e0752017-04-26 16:20:28 -040017GrImageTextureMaker::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 Osman3b66ab62016-11-28 09:26:31 -050026}
27
Robert Phillips0c984a02017-03-16 07:51:56 -040028sk_sp<GrTextureProxy> GrImageTextureMaker::refOriginalTextureProxy(bool willBeMipped,
Stan Ilievba81af22017-06-08 15:16:53 -040029 SkColorSpace* dstColorSpace,
30 AllowedTexGenType onlyIfFast) {
Brian Osmandf7e0752017-04-26 16:20:28 -040031 return fCacher->lockTextureProxy(this->context(), fOriginalKey, fCachingHint,
Stan Ilievba81af22017-06-08 15:16:53 -040032 willBeMipped, dstColorSpace, onlyIfFast);
Robert Phillips0c984a02017-03-16 07:51:56 -040033}
34
Brian Osman3b66ab62016-11-28 09:26:31 -050035void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey,
Brian Osman61624f02016-12-09 14:51:59 -050036 SkColorSpace* dstColorSpace) {
Brian Osman3b66ab62016-11-28 09:26:31 -050037 if (fOriginalKey.isValid() && SkImage::kAllow_CachingHint == fCachingHint) {
Brian Osmanc87cfb62018-07-11 09:08:46 -040038 SkImageCacherator::CachedFormat cacheFormat = SkImageCacherator::kLegacy_CachedFormat;
Brian Osman3b66ab62016-11-28 09:26:31 -050039 GrUniqueKey cacheKey;
40 fCacher->makeCacheKeyFromOrigKey(fOriginalKey, cacheFormat, &cacheKey);
41 MakeCopyKeyFromOrigKey(cacheKey, stretch, paramsCopyKey);
42 }
43}
44
45void GrImageTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) {
Brian Osmandf7e0752017-04-26 16:20:28 -040046 as_IB(fClient)->notifyAddedToCache();
Brian Osman3b66ab62016-11-28 09:26:31 -050047}
48
49SkAlphaType GrImageTextureMaker::alphaType() const {
Brian Osmandf7e0752017-04-26 16:20:28 -040050 return fClient->alphaType();
Brian Osman3b66ab62016-11-28 09:26:31 -050051}
Brian Osman61624f02016-12-09 14:51:59 -050052sk_sp<SkColorSpace> GrImageTextureMaker::getColorSpace(SkColorSpace* dstColorSpace) {
53 return fCacher->getColorSpace(this->context(), dstColorSpace);
Brian Osman3b66ab62016-11-28 09:26:31 -050054}