| 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 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * source can generate a texture that represents some content (e.g. cpu pixels,
SkPicture, ...). | 27 * source can generate a texture that represents some content (e.g. cpu pixels,
SkPicture, ...). |
| 28 */ | 28 */ |
| 29 class GrTextureProducer : public SkNoncopyable { | 29 class GrTextureProducer : public SkNoncopyable { |
| 30 public: | 30 public: |
| 31 struct CopyParams { | 31 struct CopyParams { |
| 32 GrTextureParams::FilterMode fFilter; | 32 GrTextureParams::FilterMode fFilter; |
| 33 int fWidth; | 33 int fWidth; |
| 34 int fHeight; | 34 int fHeight; |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 enum FilterConstraint { |
| 38 kYes_FilterConstraint, |
| 39 kNo_FilterConstraint, |
| 40 }; |
| 41 |
| 42 /** |
| 43 * Helper for creating a fragment processor to sample the texture with a giv
en filtering mode. |
| 44 * It attempts to avoid making texture copies or using domains whenever poss
ible. |
| 45 * |
| 46 * @param textureMatrix Matrix used to access the texture
. It is applied to |
| 47 * the local coords. The post-transf
ormed coords should |
| 48 * be in texel units (rather than no
rmalized) with |
| 49 * respect to this Producer's bounds
(width()/height()). |
| 50 * @param constraintRect A rect that represents the area o
f the texture to be |
| 51 * sampled. It must be contained in
the Producer's bounds |
| 52 * as defined by width()/height(). |
| 53 * @param filterConstriant Indicates whether filtering is li
mited to |
| 54 * constraintRect. |
| 55 * @param coordsLimitedToConstraintRect Is it known that textureMatrix*lo
calCoords is bound |
| 56 * by the portion of the texture ind
icated by |
| 57 * constraintRect (without considera
tion of filter |
| 58 * width, just the raw coords). |
| 59 * @param filterOrNullForBicubic If non-null indicates the filter
mode. If null means |
| 60 * use bicubic filtering. |
| 61 **/ |
| 62 virtual const GrFragmentProcessor* createFragmentProcessor( |
| 63 const SkMatrix& textureMatrix, |
| 64 const SkRect& constraintRect, |
| 65 FilterConstraint filterConstraint, |
| 66 bool coordsLimitedToConstraintRect, |
| 67 const GrTextureParams::FilterMode* filterOrN
ullForBicubic) = 0; |
| 68 |
| 37 virtual ~GrTextureProducer() {} | 69 virtual ~GrTextureProducer() {} |
| 38 | 70 |
| 39 int width() const { return fWidth; } | 71 int width() const { return fWidth; } |
| 40 int height() const { return fHeight; } | 72 int height() const { return fHeight; } |
| 41 | 73 |
| 42 protected: | 74 protected: |
| 43 GrTextureProducer(int width, int height) : fWidth(width), fHeight(height) {} | 75 GrTextureProducer(int width, int height) : fWidth(width), fHeight(height) {} |
| 44 | 76 |
| 45 /** Helper for creating a key for a copy from an original key. */ | 77 /** Helper for creating a key for a copy from an original key. */ |
| 46 static void MakeCopyKeyFromOrigKey(const GrUniqueKey& origKey, | 78 static void MakeCopyKeyFromOrigKey(const GrUniqueKey& origKey, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 * the SkCanvas::SrcRectConstraint used for subrect draws. | 117 * the SkCanvas::SrcRectConstraint used for subrect draws. |
| 86 */ | 118 */ |
| 87 class GrTextureAdjuster : public GrTextureProducer { | 119 class GrTextureAdjuster : public GrTextureProducer { |
| 88 public: | 120 public: |
| 89 /** Makes the subset of the texture safe to use with the given texture param
eters. | 121 /** Makes the subset of the texture safe to use with the given texture param
eters. |
| 90 outOffset will be the top-left corner of the subset if a copy is not mad
e. Otherwise, | 122 outOffset will be the top-left corner of the subset if a copy is not mad
e. Otherwise, |
| 91 the copy will be tight to the contents and outOffset will be (0, 0). If
the copy's size | 123 the copy will be tight to the contents and outOffset will be (0, 0). If
the copy's size |
| 92 does not match subset's dimensions then the contents are scaled to fit t
he copy.*/ | 124 does not match subset's dimensions then the contents are scaled to fit t
he copy.*/ |
| 93 GrTexture* refTextureSafeForParams(const GrTextureParams&, SkIPoint* outOffs
et); | 125 GrTexture* refTextureSafeForParams(const GrTextureParams&, SkIPoint* outOffs
et); |
| 94 | 126 |
| 95 enum FilterConstraint { | |
| 96 kYes_FilterConstraint, | |
| 97 kNo_FilterConstraint, | |
| 98 }; | |
| 99 | |
| 100 /** | |
| 101 * Helper for creating a fragment processor to sample the texture with a giv
en filtering mode. | |
| 102 * It attempts to avoids making a copy of the texture and avoid using a text
ure domain unless | |
| 103 * necessary. | |
| 104 * | |
| 105 * @param textureMatrix Matrix to apply to local coordina
tes to compute | |
| 106 * texel coordinates. The post-trans
formed coordinates | |
| 107 * should be in texels (relative to
this->width() and | |
| 108 * this->height()) and not be normal
ized. | |
| 109 * @param constraintRect Subrect of content area to be ren
dered. The | |
| 110 * constraint rect is relative to th
e content area. | |
| 111 * @param filterConstriant Indicates whether filtering is li
mited to | |
| 112 * constraintRect. | |
| 113 * @param coordsLimitedToConstraintRect Is it known that textureMatrix*lo
calCoords is bound | |
| 114 * by the portion of the texture ind
icated by | |
| 115 * constraintRect (without considera
tion of filter | |
| 116 * width, just the raw coords). | |
| 117 * @param filterOrNullForBicubic If non-null indicates the filter
mode. If null means | |
| 118 * use bicubic filtering. | |
| 119 **/ | |
| 120 const GrFragmentProcessor* createFragmentProcessor( | 127 const GrFragmentProcessor* createFragmentProcessor( |
| 121 const SkMatrix& textureMatrix, | 128 const SkMatrix& textureMatrix, |
| 122 const SkRect& constraintRect, | 129 const SkRect& constraintRect, |
| 123 FilterConstraint filterConstraint, | 130 FilterConstraint, |
| 124 bool coordsLimitedToConstraintRect, | 131 bool coordsLimitedToConstraintRect, |
| 125 const GrTextureParams::FilterMode* filterOrNullForBicubic); | 132 const GrTextureParams::FilterMode* filterOrNullF
orBicubic) override; |
| 126 | 133 |
| 127 protected: | 134 protected: |
| 128 /** The whole texture is content. */ | 135 /** The whole texture is content. */ |
| 129 explicit GrTextureAdjuster(GrTexture* original) | 136 explicit GrTextureAdjuster(GrTexture* original) |
| 130 : INHERITED(original->width(), original->height()) | 137 : INHERITED(original->width(), original->height()) |
| 131 , fOriginal(original) {} | 138 , fOriginal(original) {} |
| 132 | 139 |
| 133 GrTextureAdjuster(GrTexture* original, const SkIRect& contentArea); | 140 GrTextureAdjuster(GrTexture* original, const SkIRect& contentArea); |
| 134 | 141 |
| 135 GrTexture* originalTexture() const { return fOriginal; } | 142 GrTexture* originalTexture() const { return fOriginal; } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 146 | 153 |
| 147 /** | 154 /** |
| 148 * Base class for sources that start out as something other than a texture (enco
ded image, | 155 * Base class for sources that start out as something other than a texture (enco
ded image, |
| 149 * picture, ...). | 156 * picture, ...). |
| 150 */ | 157 */ |
| 151 class GrTextureMaker : public GrTextureProducer { | 158 class GrTextureMaker : public GrTextureProducer { |
| 152 public: | 159 public: |
| 153 /** Returns a texture that is safe for use with the params. If the size of t
he returned texture | 160 /** Returns a texture that is safe for use with the params. If the size of t
he returned texture |
| 154 does not match width()/height() then the contents of the original must b
e scaled to fit | 161 does not match width()/height() then the contents of the original must b
e scaled to fit |
| 155 the texture. */ | 162 the texture. */ |
| 156 GrTexture* refTextureForParams(GrContext*, const GrTextureParams&); | 163 GrTexture* refTextureForParams(const GrTextureParams&); |
| 164 |
| 165 const GrFragmentProcessor* createFragmentProcessor( |
| 166 const SkMatrix& textureMatrix, |
| 167 const SkRect& constraintRect, |
| 168 FilterConstraint filterConstraint, |
| 169 bool coordsLimitedToConstraintRect, |
| 170 const GrTextureParams::FilterMode* filterOrNullF
orBicubic) override; |
| 157 | 171 |
| 158 protected: | 172 protected: |
| 159 GrTextureMaker(int width, int height) : INHERITED(width, height) {} | 173 GrTextureMaker(GrContext* context, int width, int height) |
| 174 : INHERITED(width, height) |
| 175 , fContext(context) {} |
| 160 | 176 |
| 161 /** | 177 /** |
| 162 * Return the maker's "original" texture. It is the responsibility of the m
aker | 178 * Return the maker's "original" texture. It is the responsibility of the m
aker to handle any |
| 163 * to make this efficient ... if the texture is being generated, the maker
must handle | 179 * caching of the original if desired. |
| 164 * caching it (if desired). | |
| 165 */ | 180 */ |
| 166 virtual GrTexture* refOriginalTexture(GrContext*) = 0; | 181 virtual GrTexture* refOriginalTexture() = 0; |
| 167 | |
| 168 /** | |
| 169 * If we need to copy the producer's original texture, the producer is aske
d to return a key | |
| 170 * that identifies its original + the CopyParms parameter. If the maker doe
s not want to cache | |
| 171 * the stretched version (e.g. the producer is volatile), this should simpl
y return without | |
| 172 * initializing the copyKey. | |
| 173 */ | |
| 174 virtual void makeCopyKey(const CopyParams&, GrUniqueKey* copyKey) = 0; | |
| 175 | 182 |
| 176 /** | 183 /** |
| 177 * Return a new (uncached) texture that is the stretch of the maker's origi
nal. | 184 * Return a new (uncached) texture that is the stretch of the maker's origi
nal. |
| 178 * | 185 * |
| 179 * The base-class handles general logic for this, and only needs access to
the following | 186 * The base-class handles general logic for this, and only needs access to
the following |
| 180 * method: | 187 * method: |
| 181 * - refOriginalTexture() | 188 * - refOriginalTexture() |
| 182 * | 189 * |
| 183 * Subclass may override this if they can handle creating the texture more
directly than | 190 * Subclass may override this if they can handle creating the texture more
directly than |
| 184 * by copying. | 191 * by copying. |
| 185 */ | 192 */ |
| 186 virtual GrTexture* generateTextureForParams(GrContext*, const CopyParams&); | 193 virtual GrTexture* generateTextureForParams(const CopyParams&); |
| 194 |
| 195 GrContext* context() const { return fContext; } |
| 187 | 196 |
| 188 private: | 197 private: |
| 198 GrContext* fContext; |
| 199 |
| 189 typedef GrTextureProducer INHERITED; | 200 typedef GrTextureProducer INHERITED; |
| 190 }; | 201 }; |
| 191 | 202 |
| 192 #endif | 203 #endif |
| OLD | NEW |