bsalomon@google.com | 047696c | 2012-09-11 13:29:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrTextureAccess_DEFINED |
| 9 | #define GrTextureAccess_DEFINED |
| 10 | |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame^] | 11 | #include "GrNoncopyable.h" |
| 12 | #include "SkRefCnt.h" |
bsalomon@google.com | 047696c | 2012-09-11 13:29:29 +0000 | [diff] [blame] | 13 | |
| 14 | class GrTexture; |
bsalomon@google.com | 047696c | 2012-09-11 13:29:29 +0000 | [diff] [blame] | 15 | |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame^] | 16 | /** A class representing the swizzle access pattern for a texture. Note that if the texture is |
| 17 | * an alpha-only texture then the alpha channel is substituted for other components. Any mangling |
| 18 | * to handle the r,g,b->a conversions for alpha textures is automatically included in the stage |
| 19 | * key. However, if a GrCustomStage uses different swizzles based on its input then it must |
| 20 | * consider that variation in its key-generation. |
bsalomon@google.com | 047696c | 2012-09-11 13:29:29 +0000 | [diff] [blame] | 21 | */ |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame^] | 22 | class GrTextureAccess : GrNoncopyable { |
bsalomon@google.com | 047696c | 2012-09-11 13:29:29 +0000 | [diff] [blame] | 23 | public: |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame^] | 24 | /** |
| 25 | * A default GrTextureAccess must have reset() called on it in a GrCustomStage subclass's |
| 26 | * constructor if it will be accessible via GrCustomStage::textureAccess(). |
| 27 | */ |
| 28 | GrTextureAccess(); |
bsalomon@google.com | 047696c | 2012-09-11 13:29:29 +0000 | [diff] [blame] | 29 | |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame^] | 30 | /** |
| 31 | * swizzle must be a string between one and four (inclusive) characters containing only 'r', |
| 32 | * 'g', 'b', and/or 'a'. |
| 33 | */ |
| 34 | GrTextureAccess(GrTexture*, const char* swizzle); |
bsalomon@google.com | 047696c | 2012-09-11 13:29:29 +0000 | [diff] [blame] | 35 | |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame^] | 36 | /** |
| 37 | * Uses the default swizzle, "rgba". |
| 38 | */ |
| 39 | GrTextureAccess(GrTexture*); |
bsalomon@google.com | 047696c | 2012-09-11 13:29:29 +0000 | [diff] [blame] | 40 | |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame^] | 41 | void reset(GrTexture*, const char* swizzle); |
| 42 | void reset(GrTexture*); |
| 43 | |
| 44 | GrTexture* getTexture() const { return fTexture.get(); } |
| 45 | |
| 46 | /** |
| 47 | * Returns a string representing the swizzle. The string is is null-terminated. |
| 48 | */ |
| 49 | const char* getSwizzle() const { return fSwizzle; } |
| 50 | |
| 51 | enum { |
| 52 | kR_SwizzleFlag = 0x1, |
| 53 | kG_SwizzleFlag = 0x2, |
| 54 | kB_SwizzleFlag = 0x4, |
| 55 | kA_SwizzleFlag = 0x8, |
| 56 | |
| 57 | kRGB_SwizzleMask = (kR_SwizzleFlag | kG_SwizzleFlag | kB_SwizzleFlag), |
| 58 | }; |
| 59 | |
| 60 | /** Returns a mask indicating which components are referenced in the swizzle. */ |
| 61 | uint32_t swizzleMask() const { return fSwizzleMask; } |
bsalomon@google.com | 047696c | 2012-09-11 13:29:29 +0000 | [diff] [blame] | 62 | |
| 63 | private: |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame^] | 64 | SkAutoTUnref<GrTexture> fTexture; |
| 65 | uint32_t fSwizzleMask; |
| 66 | char fSwizzle[5]; |
bsalomon@google.com | 047696c | 2012-09-11 13:29:29 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | #endif |