| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 GrTextureAccess_DEFINED | 8 #ifndef GrTextureAccess_DEFINED |
| 9 #define GrTextureAccess_DEFINED | 9 #define GrTextureAccess_DEFINED |
| 10 | 10 |
| 11 #include "GrGpuResourceRef.h" | 11 #include "GrGpuResourceRef.h" |
| 12 #include "GrTexture.h" | 12 #include "GrTexture.h" |
| 13 #include "GrTextureParams.h" | 13 #include "GrTextureParams.h" |
| 14 #include "SkRefCnt.h" | 14 #include "SkRefCnt.h" |
| 15 #include "SkShader.h" | 15 #include "SkShader.h" |
| 16 | 16 |
| 17 /** A class representing the swizzle access pattern for a texture. Note that if
the texture is | 17 /** |
| 18 * an alpha-only texture then the alpha channel is substituted for other compon
ents. Any mangling | 18 * Used to represent a texture that is required by a GrProcessor. It holds a GrT
exture along with |
| 19 * to handle the r,g,b->a conversions for alpha textures is automatically inclu
ded in the stage | 19 * an associated GrTextureParams |
| 20 * key. However, if a GrProcessor uses different swizzles based on its input th
en it must | |
| 21 * consider that variation in its key-generation. | |
| 22 */ | 20 */ |
| 23 class GrTextureAccess : public SkNoncopyable { | 21 class GrTextureAccess : public SkNoncopyable { |
| 24 public: | 22 public: |
| 25 /** | 23 /** |
| 26 * A default GrTextureAccess must have reset() called on it in a GrProcessor
subclass's | 24 * Must be initialized before adding to a GrProcessor's texture access list. |
| 27 * constructor if it will be accessible via GrProcessor::textureAccess(). | |
| 28 */ | 25 */ |
| 29 GrTextureAccess(); | 26 GrTextureAccess(); |
| 30 | 27 |
| 31 /** | |
| 32 * Uses the default swizzle, "rgba". | |
| 33 */ | |
| 34 GrTextureAccess(GrTexture*, const GrTextureParams&); | 28 GrTextureAccess(GrTexture*, const GrTextureParams&); |
| 29 |
| 35 explicit GrTextureAccess(GrTexture*, | 30 explicit GrTextureAccess(GrTexture*, |
| 36 GrTextureParams::FilterMode = GrTextureParams::kNon
e_FilterMode, | 31 GrTextureParams::FilterMode = GrTextureParams::kNon
e_FilterMode, |
| 37 SkShader::TileMode tileXAndY = SkShader::kClamp_Til
eMode); | 32 SkShader::TileMode tileXAndY = SkShader::kClamp_Til
eMode); |
| 38 | 33 |
| 39 /** | |
| 40 * swizzle must be a string between one and four (inclusive) characters cont
aining only 'r', | |
| 41 * 'g', 'b', and/or 'a'. | |
| 42 */ | |
| 43 GrTextureAccess(GrTexture*, const char* swizzle, const GrTextureParams&); | |
| 44 GrTextureAccess(GrTexture*, | |
| 45 const char* swizzle, | |
| 46 GrTextureParams::FilterMode = GrTextureParams::kNone_FilterM
ode, | |
| 47 SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode); | |
| 48 | |
| 49 void reset(GrTexture*, const GrTextureParams&); | 34 void reset(GrTexture*, const GrTextureParams&); |
| 50 void reset(GrTexture*, | 35 void reset(GrTexture*, |
| 51 GrTextureParams::FilterMode = GrTextureParams::kNone_FilterMode, | 36 GrTextureParams::FilterMode = GrTextureParams::kNone_FilterMode, |
| 52 SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode); | 37 SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode); |
| 53 void reset(GrTexture*, const char* swizzle, const GrTextureParams&); | |
| 54 void reset(GrTexture*, | |
| 55 const char* swizzle, | |
| 56 GrTextureParams::FilterMode = GrTextureParams::kNone_FilterMode, | |
| 57 SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode); | |
| 58 | 38 |
| 59 bool operator== (const GrTextureAccess& other) const { | 39 bool operator==(const GrTextureAccess& that) const { |
| 60 #ifdef SK_DEBUG | 40 return this->getTexture() == that.getTexture() && fParams == that.fParam
s; |
| 61 // below assumes all chars in fSwizzle are initialized even if string is
< 4 chars long. | |
| 62 SkASSERT(memcmp(fSwizzle, other.fSwizzle, sizeof(fSwizzle)-1) == | |
| 63 strcmp(fSwizzle, other.fSwizzle)); | |
| 64 #endif | |
| 65 return fParams == other.fParams && | |
| 66 (this->getTexture() == other.getTexture()) && | |
| 67 (0 == memcmp(fSwizzle, other.fSwizzle, sizeof(fSwizzle)-1)); | |
| 68 } | 41 } |
| 69 | 42 |
| 70 bool operator!= (const GrTextureAccess& other) const { return !(*this == oth
er); } | 43 bool operator!=(const GrTextureAccess& other) const { return !(*this == othe
r); } |
| 71 | 44 |
| 72 GrTexture* getTexture() const { return fTexture.get(); } | 45 GrTexture* getTexture() const { return fTexture.get(); } |
| 73 | 46 |
| 74 /** | 47 /** |
| 75 * For internal use by GrProcessor. | 48 * For internal use by GrProcessor. |
| 76 */ | 49 */ |
| 77 const GrGpuResourceRef* getProgramTexture() const { return &fTexture; } | 50 const GrGpuResourceRef* getProgramTexture() const { return &fTexture; } |
| 78 | 51 |
| 79 /** | |
| 80 * Returns a string representing the swizzle. The string is is null-terminat
ed. | |
| 81 */ | |
| 82 const char* getSwizzle() const { return fSwizzle; } | |
| 83 | |
| 84 /** Returns a mask indicating which components are referenced in the swizzle
. The return | |
| 85 is a bitfield of GrColorComponentFlags. */ | |
| 86 uint32_t swizzleMask() const { return fSwizzleMask; } | |
| 87 | |
| 88 const GrTextureParams& getParams() const { return fParams; } | 52 const GrTextureParams& getParams() const { return fParams; } |
| 89 | 53 |
| 90 private: | 54 private: |
| 91 void setSwizzle(const char*); | |
| 92 | 55 |
| 93 typedef GrTGpuResourceRef<GrTexture> ProgramTexture; | 56 typedef GrTGpuResourceRef<GrTexture> ProgramTexture; |
| 94 | 57 |
| 95 ProgramTexture fTexture; | 58 ProgramTexture fTexture; |
| 96 GrTextureParams fParams; | 59 GrTextureParams fParams; |
| 97 uint32_t fSwizzleMask; | |
| 98 char fSwizzle[5]; | |
| 99 | 60 |
| 100 typedef SkNoncopyable INHERITED; | 61 typedef SkNoncopyable INHERITED; |
| 101 }; | 62 }; |
| 102 | 63 |
| 103 #endif | 64 #endif |
| OLD | NEW |