• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
12 #include "SkGr.h"
13 #include "SkImage_Base.h"
14 #include "SkImageCacherator.h"
15 #include "SkPixelRef.h"
16 
GrImageTextureMaker(GrContext * context,const SkImage * client,SkImage::CachingHint chint)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()));
26 }
27 
refOriginalTextureProxy(bool willBeMipped,SkColorSpace * dstColorSpace,AllowedTexGenType onlyIfFast)28 sk_sp<GrTextureProxy> GrImageTextureMaker::refOriginalTextureProxy(bool willBeMipped,
29                                                                    SkColorSpace* dstColorSpace,
30                                                                    AllowedTexGenType onlyIfFast) {
31     return fCacher->lockTextureProxy(this->context(), fOriginalKey, fCachingHint,
32                                      willBeMipped, dstColorSpace, onlyIfFast);
33 }
34 
makeCopyKey(const CopyParams & stretch,GrUniqueKey * paramsCopyKey,SkColorSpace * dstColorSpace)35 void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey,
36                                       SkColorSpace* dstColorSpace) {
37     if (fOriginalKey.isValid() && SkImage::kAllow_CachingHint == fCachingHint) {
38         SkImageCacherator::CachedFormat cacheFormat =
39             fCacher->chooseCacheFormat(dstColorSpace, this->context()->caps());
40         GrUniqueKey cacheKey;
41         fCacher->makeCacheKeyFromOrigKey(fOriginalKey, cacheFormat, &cacheKey);
42         MakeCopyKeyFromOrigKey(cacheKey, stretch, paramsCopyKey);
43     }
44 }
45 
didCacheCopy(const GrUniqueKey & copyKey)46 void GrImageTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) {
47     as_IB(fClient)->notifyAddedToCache();
48 }
49 
alphaType() const50 SkAlphaType GrImageTextureMaker::alphaType() const {
51     return fClient->alphaType();
52 }
getColorSpace(SkColorSpace * dstColorSpace)53 sk_sp<SkColorSpace> GrImageTextureMaker::getColorSpace(SkColorSpace* dstColorSpace) {
54     return fCacher->getColorSpace(this->context(), dstColorSpace);
55 }
56