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 | b8eb2e8 | 2013-03-28 13:46:42 +0000 | [diff] [blame] | 9 | #include "GrColor.h" |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 10 | #include "GrTexture.h" |
| 11 | |
| 12 | GrTextureAccess::GrTextureAccess() { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 13 | #ifdef SK_DEBUG |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 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, |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 24 | GrTextureParams::FilterMode filterMode, |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 25 | SkShader::TileMode tileXAndY) { |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 26 | this->reset(texture, filterMode, 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, |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 37 | GrTextureParams::FilterMode filterMode, |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 38 | SkShader::TileMode tileXAndY) { |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 39 | this->reset(texture, swizzle, filterMode, tileXAndY); |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void GrTextureAccess::reset(GrTexture* texture, |
| 43 | const char* swizzle, |
| 44 | const GrTextureParams& params) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 45 | SkASSERT(NULL != texture); |
| 46 | SkASSERT(strlen(swizzle) >= 1 && strlen(swizzle) <= 4); |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 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, |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 55 | GrTextureParams::FilterMode filterMode, |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 56 | SkShader::TileMode tileXAndY) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 57 | SkASSERT(NULL != texture); |
| 58 | SkASSERT(strlen(swizzle) >= 1 && strlen(swizzle) <= 4); |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 59 | |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 60 | fParams.reset(tileXAndY, filterMode); |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 61 | fTexture.reset(SkRef(texture)); |
| 62 | this->setSwizzle(swizzle); |
| 63 | } |
| 64 | |
| 65 | void GrTextureAccess::reset(GrTexture* texture, |
| 66 | const GrTextureParams& params) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 67 | SkASSERT(NULL != texture); |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 68 | fTexture.reset(SkRef(texture)); |
| 69 | fParams = params; |
| 70 | memcpy(fSwizzle, "rgba", 5); |
bsalomon@google.com | b8eb2e8 | 2013-03-28 13:46:42 +0000 | [diff] [blame] | 71 | fSwizzleMask = kRGBA_GrColorComponentFlags; |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | void GrTextureAccess::reset(GrTexture* texture, |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 75 | GrTextureParams::FilterMode filterMode, |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 76 | SkShader::TileMode tileXAndY) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 77 | SkASSERT(NULL != texture); |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 78 | fTexture.reset(SkRef(texture)); |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 79 | fParams.reset(tileXAndY, filterMode); |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 80 | memcpy(fSwizzle, "rgba", 5); |
bsalomon@google.com | b8eb2e8 | 2013-03-28 13:46:42 +0000 | [diff] [blame] | 81 | fSwizzleMask = kRGBA_GrColorComponentFlags; |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 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': |
bsalomon@google.com | b8eb2e8 | 2013-03-28 13:46:42 +0000 | [diff] [blame] | 91 | fSwizzleMask |= kR_GrColorComponentFlag; |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 92 | break; |
| 93 | case 'g': |
bsalomon@google.com | b8eb2e8 | 2013-03-28 13:46:42 +0000 | [diff] [blame] | 94 | fSwizzleMask |= kG_GrColorComponentFlag; |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 95 | break; |
| 96 | case 'b': |
bsalomon@google.com | b8eb2e8 | 2013-03-28 13:46:42 +0000 | [diff] [blame] | 97 | fSwizzleMask |= kB_GrColorComponentFlag; |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 98 | break; |
| 99 | case 'a': |
bsalomon@google.com | b8eb2e8 | 2013-03-28 13:46:42 +0000 | [diff] [blame] | 100 | fSwizzleMask |= kA_GrColorComponentFlag; |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 101 | break; |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 102 | default: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 103 | SkFAIL("Unexpected swizzle string character."); |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 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 | } |