diff options
author | 2013-03-28 13:46:42 +0000 | |
---|---|---|
committer | 2013-03-28 13:46:42 +0000 | |
commit | b8eb2e89edf914caf5479baeffcb670d3e93f496 (patch) | |
tree | 328527b349cf6cc24c07be4f466ebe35a34c230f /include/gpu | |
parent | 51c81123afbf9a09fda43ca2d287fcf4f5593e9c (diff) |
Make GrGLShaderBuilder::TextureSampler extract only required info from GrTextureAccess.
This will make it possible to init a TextureSampler without a texture or a specific config.
Also unify two separate bitfields of color components in GPU code.
Review URL: https://codereview.chromium.org/13121002
git-svn-id: http://skia.googlecode.com/svn/trunk@8428 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/gpu')
-rw-r--r-- | include/gpu/GrColor.h | 40 | ||||
-rw-r--r-- | include/gpu/GrEffect.h | 21 | ||||
-rw-r--r-- | include/gpu/GrTextureAccess.h | 12 | ||||
-rw-r--r-- | include/gpu/GrTypes.h | 3 |
4 files changed, 48 insertions, 28 deletions
diff --git a/include/gpu/GrColor.h b/include/gpu/GrColor.h index af12ac69bc..43d932be0d 100644 --- a/include/gpu/GrColor.h +++ b/include/gpu/GrColor.h @@ -67,4 +67,44 @@ static inline void GrColorToRGBAFloat(GrColor color, float rgba[4]) { rgba[3] = GrColorUnpackA(color) * ONE_OVER_255; } +/** + * Flags used for bitfields of color components. They are defined so that the bit order reflects the + * GrColor shift order. + */ +enum GrColorComponentFlags { + kR_GrColorComponentFlag = 1 << (GrColor_SHIFT_R / 8), + kG_GrColorComponentFlag = 1 << (GrColor_SHIFT_G / 8), + kB_GrColorComponentFlag = 1 << (GrColor_SHIFT_B / 8), + kA_GrColorComponentFlag = 1 << (GrColor_SHIFT_A / 8), + + kRGB_GrColorComponentFlags = (kR_GrColorComponentFlag | kG_GrColorComponentFlag | + kB_GrColorComponentFlag), + + kRGBA_GrColorComponentFlags = (kR_GrColorComponentFlag | kG_GrColorComponentFlag | + kB_GrColorComponentFlag | kA_GrColorComponentFlag) +}; + +static inline uint32_t GrPixelConfigComponentMask(GrPixelConfig config) { + GrAssert(config >= 0 && config < kGrPixelConfigCnt); + static const uint32_t kFlags[] = { + 0, // kUnknown_GrPixelConfig + kA_GrColorComponentFlag, // kAlpha_8_GrPixelConfig + kRGBA_GrColorComponentFlags, // kIndex_8_GrPixelConfig + kRGB_GrColorComponentFlags, // kRGB_565_GrPixelConfig + kRGBA_GrColorComponentFlags, // kRGBA_4444_GrPixelConfig + kRGBA_GrColorComponentFlags, // kRGBA_8888_GrPixelConfig + kRGBA_GrColorComponentFlags, // kBGRA_8888_GrPixelConfig + }; + return kFlags[config]; + + GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig); + GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig); + GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig); + GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig); + GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig); + GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig); + GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig); + GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFlags) == kGrPixelConfigCnt); +} + #endif diff --git a/include/gpu/GrEffect.h b/include/gpu/GrEffect.h index 883438603d..de4b2a14fb 100644 --- a/include/gpu/GrEffect.h +++ b/include/gpu/GrEffect.h @@ -87,24 +87,11 @@ public: virtual ~GrEffect(); /** - * Flags for getConstantColorComponents. They are defined so that the bit order reflects the - * GrColor shift order. - */ - enum ValidComponentFlags { - kR_ValidComponentFlag = 1 << (GrColor_SHIFT_R / 8), - kG_ValidComponentFlag = 1 << (GrColor_SHIFT_G / 8), - kB_ValidComponentFlag = 1 << (GrColor_SHIFT_B / 8), - kA_ValidComponentFlag = 1 << (GrColor_SHIFT_A / 8), - - kAll_ValidComponentFlags = (kR_ValidComponentFlag | kG_ValidComponentFlag | - kB_ValidComponentFlag | kA_ValidComponentFlag) - }; - - /** * This function is used to perform optimizations. When called the color and validFlags params - * indicate whether the input components to this effect in the FS will have known values. The - * function updates both params to indicate known values of its output. A component of the color - * param only has meaning if the corresponding bit in validFlags is set. + * indicate whether the input components to this effect in the FS will have known values. + * validFlags is a bitfield of GrColorComponentFlags. The function updates both params to + * indicate known values of its output. A component of the color param only has meaning if the + * corresponding bit in validFlags is set. */ virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const = 0; diff --git a/include/gpu/GrTextureAccess.h b/include/gpu/GrTextureAccess.h index b03e6e6dc9..e5ea535d99 100644 --- a/include/gpu/GrTextureAccess.h +++ b/include/gpu/GrTextureAccess.h @@ -162,16 +162,8 @@ public: */ const char* getSwizzle() const { return fSwizzle; } - enum { - kR_SwizzleFlag = 0x1, - kG_SwizzleFlag = 0x2, - kB_SwizzleFlag = 0x4, - kA_SwizzleFlag = 0x8, - - kRGB_SwizzleMask = (kR_SwizzleFlag | kG_SwizzleFlag | kB_SwizzleFlag), - }; - - /** Returns a mask indicating which components are referenced in the swizzle. */ + /** Returns a mask indicating which components are referenced in the swizzle. The return + is a bitfield of GrColorComponentFlags. */ uint32_t swizzleMask() const { return fSwizzleMask; } const GrTextureParams& getParams() const { return fParams; } diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h index f0153dfc56..5e48dac460 100644 --- a/include/gpu/GrTypes.h +++ b/include/gpu/GrTypes.h @@ -284,8 +284,9 @@ enum GrPixelConfig { */ kBGRA_8888_GrPixelConfig, - kGrPixelConfigCount + kLast_GrPixelConfig = kBGRA_8888_GrPixelConfig }; +static const int kGrPixelConfigCnt = kLast_GrPixelConfig + 1; // Aliases for pixel configs that match skia's byte order. #ifndef SK_CPU_LENDIAN |