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 | #include "GrTextureAccess.h" |
bsalomon@google.com | 047696c | 2012-09-11 13:29:29 +0000 | [diff] [blame] | 9 | |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 10 | #include "GrTexture.h" |
| 11 | |
| 12 | GrTextureAccess::GrTextureAccess() { |
| 13 | #if GR_DEBUG |
| 14 | memcpy(fSwizzle, "void", 5); |
| 15 | fSwizzleMask = 0xbeeffeed; |
| 16 | #endif |
bsalomon@google.com | 047696c | 2012-09-11 13:29:29 +0000 | [diff] [blame] | 17 | } |
| 18 | |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 19 | GrTextureAccess::GrTextureAccess(GrTexture* texture, const GrTextureParams& params) { |
| 20 | this->reset(texture, params); |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 21 | } |
| 22 | |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 23 | GrTextureAccess::GrTextureAccess(GrTexture* texture, |
| 24 | bool bilerp, |
| 25 | SkShader::TileMode tileXAndY) { |
| 26 | this->reset(texture, bilerp, tileXAndY); |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 27 | } |
| 28 | |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 29 | GrTextureAccess::GrTextureAccess(GrTexture* texture, |
| 30 | const char* swizzle, |
| 31 | const GrTextureParams& params) { |
| 32 | this->reset(texture, swizzle, params); |
| 33 | } |
| 34 | |
| 35 | GrTextureAccess::GrTextureAccess(GrTexture* texture, |
| 36 | const char* swizzle, |
| 37 | bool bilerp, |
| 38 | SkShader::TileMode tileXAndY) { |
| 39 | this->reset(texture, swizzle, bilerp, tileXAndY); |
| 40 | } |
| 41 | |
| 42 | void GrTextureAccess::reset(GrTexture* texture, |
| 43 | const char* swizzle, |
| 44 | const GrTextureParams& params) { |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 45 | GrAssert(NULL != texture); |
| 46 | GrAssert(strlen(swizzle) >= 1 && strlen(swizzle) <= 4); |
| 47 | |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 48 | fParams = params; |
| 49 | fTexture.reset(SkRef(texture)); |
| 50 | this->setSwizzle(swizzle); |
| 51 | } |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 52 | |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 53 | void GrTextureAccess::reset(GrTexture* texture, |
| 54 | const char* swizzle, |
| 55 | bool bilerp, |
| 56 | SkShader::TileMode tileXAndY) { |
| 57 | GrAssert(NULL != texture); |
| 58 | GrAssert(strlen(swizzle) >= 1 && strlen(swizzle) <= 4); |
| 59 | |
| 60 | fParams.reset(tileXAndY, bilerp); |
| 61 | fTexture.reset(SkRef(texture)); |
| 62 | this->setSwizzle(swizzle); |
| 63 | } |
| 64 | |
| 65 | void GrTextureAccess::reset(GrTexture* texture, |
| 66 | const GrTextureParams& params) { |
| 67 | GrAssert(NULL != texture); |
| 68 | fTexture.reset(SkRef(texture)); |
| 69 | fParams = params; |
| 70 | memcpy(fSwizzle, "rgba", 5); |
| 71 | fSwizzleMask = (kRGB_SwizzleMask | kA_SwizzleFlag); |
| 72 | } |
| 73 | |
| 74 | void GrTextureAccess::reset(GrTexture* texture, |
| 75 | bool bilerp, |
| 76 | SkShader::TileMode tileXAndY) { |
| 77 | GrAssert(NULL != texture); |
| 78 | fTexture.reset(SkRef(texture)); |
| 79 | fParams.reset(tileXAndY, bilerp); |
| 80 | memcpy(fSwizzle, "rgba", 5); |
| 81 | fSwizzleMask = (kRGB_SwizzleMask | kA_SwizzleFlag); |
| 82 | } |
| 83 | |
| 84 | void GrTextureAccess::setSwizzle(const char* swizzle) { |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 85 | fSwizzleMask = 0; |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 86 | memset(fSwizzle, '\0', 5); |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 87 | for (int i = 0; i < 4 && '\0' != swizzle[i]; ++i) { |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 88 | fSwizzle[i] = swizzle[i]; |
| 89 | switch (swizzle[i]) { |
| 90 | case 'r': |
| 91 | fSwizzleMask |= kR_SwizzleFlag; |
| 92 | break; |
| 93 | case 'g': |
| 94 | fSwizzleMask |= kG_SwizzleFlag; |
| 95 | break; |
| 96 | case 'b': |
| 97 | fSwizzleMask |= kB_SwizzleFlag; |
| 98 | break; |
| 99 | case 'a': |
| 100 | fSwizzleMask |= kA_SwizzleFlag; |
| 101 | break; |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 102 | default: |
| 103 | GrCrash("Unexpected swizzle string character."); |
| 104 | break; |
| 105 | } |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 106 | } |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 107 | } |