Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: src/gpu/GrTextureParamsAdjuster.h

Issue 1438663004: API changes to GrTextureAdjuster. (Closed) Base URL: https://skia.googlesource.com/skia.git@dividemat
Patch Set: back away from lambdas Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/gpu/GrTextureParamsAdjuster.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "GrTexture.h" 13 #include "GrTexture.h"
14 #include "SkFunction.h"
14 #include "SkTLazy.h" 15 #include "SkTLazy.h"
15 16
16 class GrContext; 17 class GrContext;
17 class GrTextureParams; 18 class GrTextureParams;
18 class GrUniqueKey; 19 class GrUniqueKey;
19 class SkBitmap; 20 class SkBitmap;
20 21
21 /** 22 /**
22 * Different GPUs and API extensions have different requirements with respect to what texture 23 * Different GPUs and API extensions have different requirements with respect to what texture
23 * sampling parameters may be used with textures of various types. This class fa cilitates making 24 * sampling parameters may be used with textures of various types. This class fa cilitates making
24 * texture compatible with a given GrTextureParams. There are two immediate subc lasses defined 25 * texture compatible with a given GrTextureParams. There are two immediate subc lasses defined
25 * below. One is a base class for sources that are inherently texture-backed (e. g. a texture-backed 26 * below. One is a base class for sources that are inherently texture-backed (e. g. a texture-backed
26 * SkImage). It supports subsetting the original texture. The other is for use c ases where the 27 * SkImage). It supports subsetting the original texture. The other is for use c ases where the
27 * source can generate a texture that represents some content (e.g. cpu pixels, SkPicture, ...). 28 * source can generate a texture that represents some content (e.g. cpu pixels, SkPicture, ...).
28 */ 29 */
29 class GrTextureProducer : public SkNoncopyable { 30 class GrTextureProducer : public SkNoncopyable {
30 public: 31 public:
31 struct CopyParams { 32 struct CopyParams {
32 GrTextureParams::FilterMode fFilter; 33 GrTextureParams::FilterMode fFilter;
33 int fWidth; 34 int fWidth;
34 int fHeight; 35 int fHeight;
35 }; 36 };
36 37
37 virtual ~GrTextureProducer() {} 38 virtual ~GrTextureProducer() {}
38 39
40 int width() const { return fWidth; }
41 int height() const { return fHeight; }
42
39 protected: 43 protected:
44 GrTextureProducer(int width, int height) : fWidth(width), fHeight(height) {}
45
40 /** Helper for creating a key for a copy from an original key. */ 46 /** Helper for creating a key for a copy from an original key. */
41 static void MakeCopyKeyFromOrigKey(const GrUniqueKey& origKey, 47 static void MakeCopyKeyFromOrigKey(const GrUniqueKey& origKey,
42 const CopyParams& copyParams, 48 const CopyParams& copyParams,
43 GrUniqueKey* copyKey) { 49 GrUniqueKey* copyKey) {
44 SkASSERT(!copyKey->isValid()); 50 SkASSERT(!copyKey->isValid());
45 if (origKey.isValid()) { 51 if (origKey.isValid()) {
46 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDoma in(); 52 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDoma in();
47 GrUniqueKey::Builder builder(copyKey, origKey, kDomain, 3); 53 GrUniqueKey::Builder builder(copyKey, origKey, kDomain, 3);
48 builder[0] = copyParams.fFilter; 54 builder[0] = copyParams.fFilter;
49 builder[1] = copyParams.fWidth; 55 builder[1] = copyParams.fWidth;
50 builder[2] = copyParams.fHeight; 56 builder[2] = copyParams.fHeight;
51 } 57 }
52 } 58 }
53 59
54 /** 60 /**
55 * If we need to make a copy in order to be compatible with GrTextureParams producer is asked to 61 * 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 62 * 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 producer is volati le), this should 63 * does not want to cache the stretched version (e.g. the producer is volati le), this should
58 * simply return without initializing the copyKey. 64 * simply return without initializing the copyKey.
59 */ 65 */
60 virtual void makeCopyKey(const CopyParams&, GrUniqueKey* copyKey) = 0; 66 virtual void makeCopyKey(const CopyParams&, GrUniqueKey* copyKey) = 0;
61 67
62 /** 68 /**
63 * If a stretched version of the texture is generated, it may be cached (ass uming that 69 * If a stretched version of the texture is generated, it may be cached (ass uming that
64 * makeCopyKey() returns true). In that case, the maker is notified in case it 70 * makeCopyKey() returns true). In that case, the maker is notified in case it
65 * wants to note that for when the maker is destroyed. 71 * wants to note that for when the maker is destroyed.
66 */ 72 */
67 virtual void didCacheCopy(const GrUniqueKey& copyKey) = 0; 73 virtual void didCacheCopy(const GrUniqueKey& copyKey) = 0;
68 74
75 private:
76 const int fWidth;
77 const int fHeight;
78
69 typedef SkNoncopyable INHERITED; 79 typedef SkNoncopyable INHERITED;
70 }; 80 };
71 81
72 /** 82 /**
73 * Base class for sources that start out as textures. Optionally allows for a co ntent area subrect. 83 * Base class for sources that start out as textures. Optionally allows for a co ntent area subrect.
74 * The intent is not to use content area for subrect rendering. Rather, the pixe ls outside the 84 * The intent is not to use content area for subrect rendering. Rather, the pixe ls outside the
75 * content area have undefined values and shouldn't be read *regardless* of filt ering mode or 85 * content area have undefined values and shouldn't be read *regardless* of filt ering mode or
76 * the SkCanvas::SrcRectConstraint used for subrect draws. 86 * the SkCanvas::SrcRectConstraint used for subrect draws.
77 */ 87 */
78 class GrTextureAdjuster : public GrTextureProducer { 88 class GrTextureAdjuster : public GrTextureProducer {
79 public: 89 public:
80 /** Makes the subset of the texture safe to use with the given texture param eters. 90 /** Makes the subset of the texture safe to use with the given texture param eters.
81 outOffset will be the top-left corner of the subset if a copy is not mad e. Otherwise, 91 outOffset will be the top-left corner of the subset if a copy is not mad e. Otherwise,
82 the copy will be tight to the contents and outOffset will be (0, 0). If the copy's size 92 the copy will be tight to the contents and outOffset will be (0, 0). If the copy's size
83 does not match subset's dimensions then the contents are scaled to fit t he copy.*/ 93 does not match subset's dimensions then the contents are scaled to fit t he copy.*/
84 GrTexture* refTextureSafeForParams(const GrTextureParams&, SkIPoint* outOffs et); 94 GrTexture* refTextureSafeForParams(const GrTextureParams&, SkIPoint* outOffs et);
85 95
86 enum FilterConstraint { 96 enum FilterConstraint {
87 kYes_FilterConstraint, 97 kYes_FilterConstraint,
88 kNo_FilterConstraint, 98 kNo_FilterConstraint,
89 }; 99 };
90 100
91 /** 101 /**
92 * Helper for creating a fragment processor to sample the texture with a giv en filtering mode. 102 * Helper for creating a fragment processor to sample the texture with a giv en filtering mode.
93 * It attempts to avoids making a copy of the texture and avoid using a text ure domain unless 103 * It attempts to avoids making a copy of the texture and avoid using a text ure domain unless
94 * necessary. 104 * necessary.
95 * 105 *
96 * @param textureMatrix Matrix to transform local coords by to compute 106 * @param textureMatrix Matrix to apply to local coordina tes to compute
97 * texture coords. 107 * texel coordinates. The post-trans formed coordinates
98 * @param constraintRect Subrect of content area to be ren dered. Must be 108 * should be in texels (relative to this->width() and
99 * clipped to the content area alrea dy. 109 * this->height()) and not be normal ized.
110 * @param constraintRect Subrect of content area to be ren dered. The
111 * constraint rect is relative to th e content area.
robertphillips 2015/11/11 22:44:04 and is in texel coordinates ?
bsalomon 2015/11/12 00:40:42 In a follow-up CL this function gets promoted to t
100 * @param filterConstriant Indicates whether filtering is li mited to 112 * @param filterConstriant Indicates whether filtering is li mited to
101 * constraintRect. 113 * constraintRect.
102 * @param coordsLimitedToConstraintRect Is it known that textureMatrix*lo calCoords is bound 114 * @param coordsLimitedToConstraintRect Is it known that textureMatrix*lo calCoords is bound
103 * by the portion of the texture ind icated by 115 * by the portion of the texture ind icated by
104 * constraintRect (without considera tion of filter 116 * constraintRect (without considera tion of filter
105 * width, just the raw coords). 117 * width, just the raw coords).
106 * @param filterOrNullForBicubic If non-null indicates the filter mode. If null means 118 * @param filterOrNullForBicubic If non-null indicates the filter mode. If null means
107 * use bicubic filtering. 119 * use bicubic filtering.
108 **/ 120 **/
109 const GrFragmentProcessor* createFragmentProcessor( 121 const GrFragmentProcessor* createFragmentProcessor(
110 const SkMatrix& textureMatrix, 122 const SkMatrix& textureMatrix,
111 const SkRect& constraintRect, 123 const SkRect& constraintRect,
112 FilterConstraint filterConstraint, 124 FilterConstraint filterConstraint,
113 bool coordsLimitedToConstraintRect, 125 bool coordsLimitedToConstraintRect,
114 const GrTextureParams::FilterMode* filterOrNullForBicubic); 126 const GrTextureParams::FilterMode* filterOrNullForBicubic);
115 127
116 GrTexture* originalTexture() const { return fOriginal; }
117
118 void getContentArea(SkIRect* contentArea) const {
119 if (fContentArea.isValid()) {
120 *contentArea = *fContentArea.get();
121 } else {
122 *contentArea = SkIRect::MakeWH(fOriginal->width(), fOriginal->height ());
123 }
124 }
125
126 protected: 128 protected:
127 /** The whole texture is content. */ 129 /** The whole texture is content. */
128 explicit GrTextureAdjuster(GrTexture* original): fOriginal(original) {} 130 explicit GrTextureAdjuster(GrTexture* original)
131 : INHERITED(original->width(), original->height())
132 , fOriginal(original) {}
129 133
130 GrTextureAdjuster(GrTexture* original, const SkIRect& contentArea); 134 GrTextureAdjuster(GrTexture* original, const SkIRect& contentArea);
131 135
136 GrTexture* originalTexture() const { return fOriginal; }
137
132 /** Returns the content area or null for the whole original texture */ 138 /** Returns the content area or null for the whole original texture */
133 const SkIRect* contentAreaOrNull() { return fContentArea.getMaybeNull(); } 139 const SkIRect* contentAreaOrNull() { return fContentArea.getMaybeNull(); }
134 140
135 private: 141 private:
136 SkTLazy<SkIRect> fContentArea; 142 SkTLazy<SkIRect> fContentArea;
137 GrTexture* fOriginal; 143 GrTexture* fOriginal;
138 144
139 typedef GrTextureProducer INHERITED; 145 typedef GrTextureProducer INHERITED;
140 }; 146 };
141 147
142 /** 148 /**
143 * Base class for sources that start out as something other than a texture (enco ded image, 149 * Base class for sources that start out as something other than a texture (enco ded image,
144 * picture, ...). 150 * picture, ...).
145 */ 151 */
146 class GrTextureMaker : public GrTextureProducer { 152 class GrTextureMaker : public GrTextureProducer {
147 public: 153 public:
148
149 GrTextureMaker(int width, int height) : fWidth(width), fHeight(height) {}
150
151 int width() const { return fWidth; }
152 int height() const { return fHeight; }
153
154 /** Returns a texture that is safe for use with the params. If the size of t he returned texture 154 /** Returns a texture that is safe for use with the params. If the size of t he returned texture
155 does not match width()/height() then the contents of the original must b e scaled to fit 155 does not match width()/height() then the contents of the original must b e scaled to fit
156 the texture. */ 156 the texture. */
157 GrTexture* refTextureForParams(GrContext*, const GrTextureParams&); 157 GrTexture* refTextureForParams(GrContext*, const GrTextureParams&);
158 158
159 protected: 159 protected:
160 GrTextureMaker(int width, int height) : INHERITED(width, height) {}
161
160 /** 162 /**
161 * Return the maker's "original" texture. It is the responsibility of the m aker 163 * Return the maker's "original" texture. It is the responsibility of the m aker
162 * to make this efficient ... if the texture is being generated, the maker must handle 164 * to make this efficient ... if the texture is being generated, the maker must handle
163 * caching it (if desired). 165 * caching it (if desired).
164 */ 166 */
165 virtual GrTexture* refOriginalTexture(GrContext*) = 0; 167 virtual GrTexture* refOriginalTexture(GrContext*) = 0;
166 168
167 /** 169 /**
168 * If we need to copy the producer's original texture, the producer is aske d to return a key 170 * If we need to copy the producer's original texture, the producer is aske d to return a key
169 * that identifies its original + the CopyParms parameter. If the maker doe s not want to cache 171 * that identifies its original + the CopyParms parameter. If the maker doe s not want to cache
170 * the stretched version (e.g. the producer is volatile), this should simpl y return without 172 * the stretched version (e.g. the producer is volatile), this should simpl y return without
171 * initializing the copyKey. 173 * initializing the copyKey.
172 */ 174 */
173 virtual void makeCopyKey(const CopyParams&, GrUniqueKey* copyKey) = 0; 175 virtual void makeCopyKey(const CopyParams&, GrUniqueKey* copyKey) = 0;
174 176
175 /** 177 /**
176 * Return a new (uncached) texture that is the stretch of the maker's origi nal. 178 * Return a new (uncached) texture that is the stretch of the maker's origi nal.
177 * 179 *
178 * The base-class handles general logic for this, and only needs access to the following 180 * The base-class handles general logic for this, and only needs access to the following
179 * method: 181 * method:
180 * - refOriginalTexture() 182 * - refOriginalTexture()
181 * 183 *
182 * Subclass may override this if they can handle creating the texture more directly than 184 * Subclass may override this if they can handle creating the texture more directly than
183 * by copying. 185 * by copying.
184 */ 186 */
185 virtual GrTexture* generateTextureForParams(GrContext*, const CopyParams&); 187 virtual GrTexture* generateTextureForParams(GrContext*, const CopyParams&);
186 188
187 private: 189 private:
188 const int fWidth;
189 const int fHeight;
190
191 typedef GrTextureProducer INHERITED; 190 typedef GrTextureProducer INHERITED;
192 }; 191 };
193 192
194 #endif 193 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrTextureParamsAdjuster.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698