Line data Source code
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 :
17 0 : static bool cacher_is_alpha_only(const SkImageCacherator& cacher) {
18 0 : return kAlpha_8_SkColorType == cacher.info().colorType();
19 : }
20 :
21 0 : GrImageTextureMaker::GrImageTextureMaker(GrContext* context, SkImageCacherator* cacher,
22 0 : const SkImage* client, SkImage::CachingHint chint)
23 0 : : INHERITED(context, cacher->info().width(), cacher->info().height(),
24 0 : cacher_is_alpha_only(*cacher))
25 : , fCacher(cacher)
26 : , fClient(client)
27 0 : , fCachingHint(chint) {
28 0 : if (client) {
29 0 : GrMakeKeyFromImageID(&fOriginalKey, client->uniqueID(),
30 0 : SkIRect::MakeWH(this->width(), this->height()));
31 : }
32 0 : }
33 :
34 0 : sk_sp<GrTextureProxy> GrImageTextureMaker::refOriginalTextureProxy(bool willBeMipped,
35 : SkColorSpace* dstColorSpace) {
36 0 : return fCacher->lockTextureProxy(this->context(), fOriginalKey, fClient, fCachingHint,
37 0 : willBeMipped, dstColorSpace);
38 : }
39 :
40 0 : void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey,
41 : SkColorSpace* dstColorSpace) {
42 0 : if (fOriginalKey.isValid() && SkImage::kAllow_CachingHint == fCachingHint) {
43 : SkImageCacherator::CachedFormat cacheFormat =
44 0 : fCacher->chooseCacheFormat(dstColorSpace, this->context()->caps());
45 0 : GrUniqueKey cacheKey;
46 0 : fCacher->makeCacheKeyFromOrigKey(fOriginalKey, cacheFormat, &cacheKey);
47 0 : MakeCopyKeyFromOrigKey(cacheKey, stretch, paramsCopyKey);
48 : }
49 0 : }
50 :
51 0 : void GrImageTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) {
52 0 : if (fClient) {
53 0 : as_IB(fClient)->notifyAddedToCache();
54 : }
55 0 : }
56 :
57 0 : SkAlphaType GrImageTextureMaker::alphaType() const {
58 0 : return fCacher->info().alphaType();
59 : }
60 0 : sk_sp<SkColorSpace> GrImageTextureMaker::getColorSpace(SkColorSpace* dstColorSpace) {
61 0 : return fCacher->getColorSpace(this->context(), dstColorSpace);
62 : }
|