blob: 5bf81d2d8fbe6694288aa36e09dfc418a7eb2591 [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"
9
10#include "GrContext.h"
11#include "GrGpuResourcePriv.h"
Brian Osman3b655982017-03-07 16:58:08 -050012#include "SkGr.h"
Brian Osman3b66ab62016-11-28 09:26:31 -050013#include "SkImage_Base.h"
14#include "SkImageCacherator.h"
15#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) {
38 SkImageCacherator::CachedFormat cacheFormat =
Brian Osman61624f02016-12-09 14:51:59 -050039 fCacher->chooseCacheFormat(dstColorSpace, this->context()->caps());
Brian Osman3b66ab62016-11-28 09:26:31 -050040 GrUniqueKey cacheKey;
41 fCacher->makeCacheKeyFromOrigKey(fOriginalKey, cacheFormat, &cacheKey);
42 MakeCopyKeyFromOrigKey(cacheKey, stretch, paramsCopyKey);
43 }
44}
45
46void GrImageTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) {
Brian Osmandf7e0752017-04-26 16:20:28 -040047 as_IB(fClient)->notifyAddedToCache();
Brian Osman3b66ab62016-11-28 09:26:31 -050048}
49
50SkAlphaType GrImageTextureMaker::alphaType() const {
Brian Osmandf7e0752017-04-26 16:20:28 -040051 return fClient->alphaType();
Brian Osman3b66ab62016-11-28 09:26:31 -050052}
Brian Osman61624f02016-12-09 14:51:59 -050053sk_sp<SkColorSpace> GrImageTextureMaker::getColorSpace(SkColorSpace* dstColorSpace) {
54 return fCacher->getColorSpace(this->context(), dstColorSpace);
Brian Osman3b66ab62016-11-28 09:26:31 -050055}