OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrTextureMaker_DEFINED | 8 #ifndef GrTextureMaker_DEFINED |
9 #define GrTextureMaker_DEFINED | 9 #define GrTextureMaker_DEFINED |
10 | 10 |
11 #include "GrTextureParams.h" | 11 #include "GrTextureParams.h" |
12 #include "GrResourceKey.h" | 12 #include "GrResourceKey.h" |
13 #include "SkTLazy.h" | |
13 | 14 |
14 class GrContext; | 15 class GrContext; |
15 class GrTexture; | 16 class GrTexture; |
16 class GrTextureParams; | 17 class GrTextureParams; |
17 class GrUniqueKey; | 18 class GrUniqueKey; |
18 class SkBitmap; | 19 class SkBitmap; |
19 | 20 |
20 /** | 21 /** |
21 * Different GPUs and API extensions have different requirements with respect to what texture | 22 * Different GPUs and API extensions have different requirements with respect to what texture |
22 * sampling parameters may be used with textures of various types. This class fa cilitates making | 23 * sampling parameters may be used with textures of various types. This class fa cilitates making |
23 * texture compatible with a given GrTextureParams. It abstracts the source of t he original data | 24 * texture compatible with a given GrTextureParams. There are two immediate subc lasses defined |
24 * which may be an already existing texture, CPU pixels, a codec, ... so that va rious sources can | 25 * below. One is a base class for sources that are inherently texture-backed (e. g. a texture-backed |
25 * be used with common code that scales or copies the data to make it compatible with a | 26 * SkImage). It supports subsetting the original texture. The other is for use c ases where the |
26 * GrTextureParams. | 27 * source can generate a texture that represents some content (e.g. cpu pixels, SkPicture, ...). |
27 */ | 28 */ |
28 class GrTextureParamsAdjuster { | 29 class GrTextureProducer : public SkNoncopyable { |
29 public: | 30 public: |
30 struct CopyParams { | 31 struct CopyParams { |
31 GrTextureParams::FilterMode fFilter; | 32 GrTextureParams::FilterMode fFilter; |
32 int fWidth; | 33 int fWidth; |
33 int fHeight; | 34 int fHeight; |
34 }; | 35 }; |
35 | 36 |
36 GrTextureParamsAdjuster(int width, int height) : fWidth(width), fHeight(heig ht) {} | 37 virtual ~GrTextureProducer() {} |
37 virtual ~GrTextureParamsAdjuster() {} | 38 |
39 protected: | |
40 /** Helper for creating a key for a copy from an original key. */ | |
41 static void MakeCopyKeyFromOrigKey(const GrUniqueKey& origKey, | |
42 const CopyParams& copyParams, | |
43 GrUniqueKey* copyKey) { | |
44 SkASSERT(!copyKey->isValid()); | |
45 if (origKey.isValid()) { | |
46 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDoma in(); | |
47 GrUniqueKey::Builder builder(copyKey, origKey, kDomain, 3); | |
48 builder[0] = copyParams.fFilter; | |
49 builder[1] = copyParams.fWidth; | |
50 builder[2] = copyParams.fHeight; | |
51 } | |
52 } | |
53 | |
54 /** | |
55 * If we need to make a copy in order to be compatible with GrTextureParams producer is asked to | |
56 * return a key that identifies its original content + the CopyParms paramet er. If the producer | |
57 * does not want to cache the stretched version (e.g. the maker is volatile) , this should simply | |
58 * return without initializing the copyKey. | |
59 */ | |
60 virtual void makeCopyKey(const CopyParams&, GrUniqueKey* copyKey) = 0; | |
61 | |
62 /** | |
63 * If a stretched version of the texture is generated, it may be cached (ass uming that | |
robertphillips
2015/10/29 16:57:54
onMakeParamsKey ?
bsalomon
2015/10/29 17:36:22
Done.
| |
64 * onMakeParamsKey() returns true). In that case, the maker is notified in c ase it | |
65 * wants to note that for when the maker is destroyed. | |
66 */ | |
67 virtual void didCacheCopy(const GrUniqueKey& copyKey) = 0; | |
68 | |
69 typedef SkNoncopyable INHERITED; | |
70 }; | |
71 | |
72 /** Base class for sources that start out as textures */ | |
73 class GrTextureAdjuster : public GrTextureProducer { | |
74 public: | |
75 /** Makes the subset of the texture safe to use with the given texture param eters. | |
76 outOffset will be the top-left corner of the subset if a copy is not mad e. Otherwise, | |
77 the copy will be tight to the contents and outOffset will be (0, 0). If the copy's size | |
78 does not match subset's dimensions then the contents are scaled to fit t he copy.*/ | |
79 GrTexture* refTextureSafeForParams(const GrTextureParams&, SkIPoint* outOffs et); | |
80 | |
81 protected: | |
82 /** No subset, use the whole texture */ | |
83 explicit GrTextureAdjuster(GrTexture* original): fOriginal(original) {} | |
84 | |
85 GrTextureAdjuster(GrTexture* original, const SkIRect& subset); | |
86 | |
87 GrTexture* originalTexture() { return fOriginal; } | |
88 | |
89 /** Returns the subset or null for the whole original texture */ | |
90 const SkIRect* subset() { return fSubset.getMaybeNull(); } | |
91 | |
92 private: | |
93 GrTexture* internalRefTextureSafeForParams(GrTexture*, const SkIRect* subset , | |
94 const GrTextureParams&, SkIPoint* outOffset); | |
95 SkTLazy<SkIRect> fSubset; | |
96 GrTexture* fOriginal; | |
97 | |
98 typedef GrTextureProducer INHERITED; | |
99 }; | |
100 | |
101 /** | |
102 * Base class for sources that start out as something other than a texture (enco ded image, | |
103 * picture, ...). | |
104 */ | |
105 class GrTextureMaker : public GrTextureProducer { | |
106 public: | |
107 | |
108 GrTextureMaker(int width, int height) : fWidth(width), fHeight(height) {} | |
robertphillips
2015/10/29 16:57:54
override ?
bsalomon
2015/10/29 17:36:22
rm'ed the function
| |
109 virtual ~GrTextureMaker() {} | |
38 | 110 |
39 int width() const { return fWidth; } | 111 int width() const { return fWidth; } |
40 int height() const { return fHeight; } | 112 int height() const { return fHeight; } |
41 | 113 |
42 /** Returns a texture that is safe for use with the params */ | 114 /** Returns a texture that is safe for use with the params. If the size of t he returned texture |
115 does not match width()/height() then the contents of the original must b e scaled to fit | |
116 the texture. */ | |
43 GrTexture* refTextureForParams(GrContext*, const GrTextureParams&); | 117 GrTexture* refTextureForParams(GrContext*, const GrTextureParams&); |
44 | 118 |
45 protected: | 119 protected: |
46 /** | 120 /** |
47 * Return the maker's "original" texture. It is the responsibility of the m aker | 121 * Return the maker's "original" texture. It is the responsibility of the m aker |
48 * to make this efficient ... if the texture is being generated, the maker must handle | 122 * to make this efficient ... if the texture is being generated, the maker must handle |
49 * caching it (if desired). | 123 * caching it (if desired). |
50 */ | 124 */ |
51 virtual GrTexture* refOriginalTexture(GrContext*) = 0; | 125 virtual GrTexture* refOriginalTexture(GrContext*) = 0; |
52 | 126 |
(...skipping 10 matching lines...) Expand all Loading... | |
63 * | 137 * |
64 * The base-class handles general logic for this, and only needs access to the following | 138 * The base-class handles general logic for this, and only needs access to the following |
65 * method: | 139 * method: |
66 * - refOriginalTexture() | 140 * - refOriginalTexture() |
67 * | 141 * |
68 * Subclass may override this if they can handle creating the texture more directly than | 142 * Subclass may override this if they can handle creating the texture more directly than |
69 * by copying. | 143 * by copying. |
70 */ | 144 */ |
71 virtual GrTexture* generateTextureForParams(GrContext*, const CopyParams&); | 145 virtual GrTexture* generateTextureForParams(GrContext*, const CopyParams&); |
72 | 146 |
73 /** | |
74 * If a stretched version of the texture is generated, it may be cached (as suming that | |
75 * onMakeParamsKey() returns true). In that case, the maker is notified in case it | |
76 * wants to note that for when the maker is destroyed. | |
77 */ | |
78 virtual void didCacheCopy(const GrUniqueKey& copyKey) = 0; | |
79 | |
80 /** Helper for creating a key for a copy from an original key. */ | |
81 static void MakeCopyKeyFromOrigKey(const GrUniqueKey& origKey, | |
82 const CopyParams& copyParams, | |
83 GrUniqueKey* copyKey) { | |
84 SkASSERT(!copyKey->isValid()); | |
85 if (origKey.isValid()) { | |
86 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDoma in(); | |
87 GrUniqueKey::Builder builder(copyKey, origKey, kDomain, 3); | |
88 builder[0] = copyParams.fFilter; | |
89 builder[1] = copyParams.fWidth; | |
90 builder[2] = copyParams.fHeight; | |
91 } | |
92 } | |
93 | |
94 private: | 147 private: |
95 const int fWidth; | 148 const int fWidth; |
96 const int fHeight; | 149 const int fHeight; |
150 | |
151 typedef GrTextureProducer INHERITED; | |
97 }; | 152 }; |
98 | 153 |
99 #endif | 154 #endif |
OLD | NEW |