| 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 | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame^] | 19 | GrTextureAccess::GrTextureAccess(GrTexture* texture, const char* swizzle) { |
| 20 | this->reset(texture, swizzle); |
| 21 | } |
| 22 | |
| 23 | GrTextureAccess::GrTextureAccess(GrTexture* texture) { |
| 24 | this->reset(texture); |
| 25 | } |
| 26 | |
| 27 | void GrTextureAccess::reset(GrTexture* texture, const char* swizzle) { |
| 28 | GrAssert(NULL != texture); |
| 29 | GrAssert(strlen(swizzle) >= 1 && strlen(swizzle) <= 4); |
| 30 | |
| 31 | texture->ref(); |
| 32 | fTexture.reset(texture); |
| 33 | |
| 34 | fSwizzleMask = 0; |
| 35 | fSwizzle[4] = '\0'; |
| 36 | int i = 0; |
| 37 | do { |
| 38 | fSwizzle[i] = swizzle[i]; |
| 39 | switch (swizzle[i]) { |
| 40 | case 'r': |
| 41 | fSwizzleMask |= kR_SwizzleFlag; |
| 42 | break; |
| 43 | case 'g': |
| 44 | fSwizzleMask |= kG_SwizzleFlag; |
| 45 | break; |
| 46 | case 'b': |
| 47 | fSwizzleMask |= kB_SwizzleFlag; |
| 48 | break; |
| 49 | case 'a': |
| 50 | fSwizzleMask |= kA_SwizzleFlag; |
| 51 | break; |
| 52 | case '\0': |
| 53 | break; |
| 54 | default: |
| 55 | GrCrash("Unexpected swizzle string character."); |
| 56 | break; |
| 57 | } |
| 58 | } while ('\0' != swizzle[i] && ++i < 4); |
| 59 | } |
| 60 | |
| 61 | void GrTextureAccess::reset(GrTexture* texture) { |
| 62 | GrAssert(NULL != texture); |
| 63 | texture->ref(); |
| 64 | fTexture.reset(texture); |
| 65 | memcpy(fSwizzle, "rgba", 5); |
| 66 | fSwizzleMask = (kRGB_SwizzleMask | kA_SwizzleFlag); |
| 67 | } |