blob: 36ac0ad3e14e5274e3a0611e8d558c13ad9d893c [file] [log] [blame]
bsalomonc55271f2015-11-09 11:55:57 -08001/*
2 * Copyright 2015 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#ifndef GrImageIDTextureAdjuster_DEFINED
9#define GrImageIDTextureAdjuster_DEFINED
10
11#include "GrTextureParamsAdjuster.h"
bsalomon1cf6f9b2015-12-08 10:53:43 -080012#include "SkImage.h"
bsalomonc55271f2015-11-09 11:55:57 -080013
14class SkBitmap;
15class SkImage_Base;
bsalomon1cf6f9b2015-12-08 10:53:43 -080016class SkImageCacherator;
bsalomonc55271f2015-11-09 11:55:57 -080017
bsalomonb1b01992015-11-18 10:56:08 -080018/** This class manages the conversion of SW-backed bitmaps to GrTextures. If the input bitmap is
19 non-volatile the texture is cached using a key created from the pixels' image id and the
20 subset of the pixelref specified by the bitmap. */
21class GrBitmapTextureMaker : public GrTextureMaker {
22public:
23 GrBitmapTextureMaker(GrContext* context, const SkBitmap& bitmap);
24
25protected:
brianosman982eb7f2016-06-06 13:10:58 -070026 GrTexture* refOriginalTexture(bool willBeMipped, SkSourceGammaTreatment) override;
bsalomonb1b01992015-11-18 10:56:08 -080027
28 void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) override;
29
30 void didCacheCopy(const GrUniqueKey& copyKey) override;
31
brianosman5814b8a2016-08-18 06:43:03 -070032 SkAlphaType alphaType() const override;
brianosman42803662016-07-15 06:59:48 -070033 SkColorSpace* getColorSpace() override;
34
bsalomonb1b01992015-11-18 10:56:08 -080035private:
36 const SkBitmap fBitmap;
37 GrUniqueKey fOriginalKey;
38
39 typedef GrTextureMaker INHERITED;
40};
41
bsalomon1cf6f9b2015-12-08 10:53:43 -080042/** This class manages the conversion of generator-backed images to GrTextures. If the caching hint
43 is kAllow the image's ID is used for the cache key. */
44class GrImageTextureMaker : public GrTextureMaker {
45public:
46 GrImageTextureMaker(GrContext* context, SkImageCacherator* cacher, const SkImage* client,
47 SkImage::CachingHint chint);
48
49protected:
50 // TODO: consider overriding this, for the case where the underlying generator might be
51 // able to efficiently produce a "stretched" texture natively (e.g. picture-backed)
52 // GrTexture* generateTextureForParams(const CopyParams&) override;
53
brianosman982eb7f2016-06-06 13:10:58 -070054 GrTexture* refOriginalTexture(bool willBeMipped, SkSourceGammaTreatment) override;
bsalomon1cf6f9b2015-12-08 10:53:43 -080055 void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override;
56 void didCacheCopy(const GrUniqueKey& copyKey) override;
57
brianosman5814b8a2016-08-18 06:43:03 -070058 SkAlphaType alphaType() const override;
brianosman42803662016-07-15 06:59:48 -070059 SkColorSpace* getColorSpace() override;
60
bsalomon1cf6f9b2015-12-08 10:53:43 -080061private:
62 SkImageCacherator* fCacher;
63 const SkImage* fClient;
64 GrUniqueKey fOriginalKey;
65 SkImage::CachingHint fCachingHint;
66
67 typedef GrTextureMaker INHERITED;
68};
69
bsalomonc55271f2015-11-09 11:55:57 -080070#endif