aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrTextureAccess.cpp
blob: 7e1eda6211f5783c0bf8ab7e0b59e781b8e74df0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "GrTextureAccess.h"
#include "GrColor.h"
#include "GrTexture.h"

GrTextureAccess::GrTextureAccess() {
#ifdef SK_DEBUG
    memcpy(fSwizzle, "void", 5);
    fSwizzleMask = 0xbeeffeed;
#endif
}

GrTextureAccess::GrTextureAccess(GrTexture* texture, const GrTextureParams& params) {
    this->reset(texture, params);
}

GrTextureAccess::GrTextureAccess(GrTexture* texture,
                                 GrTextureParams::FilterMode filterMode,
                                 SkShader::TileMode tileXAndY) {
    this->reset(texture, filterMode, tileXAndY);
}

GrTextureAccess::GrTextureAccess(GrTexture* texture,
                                 const char* swizzle,
                                 const GrTextureParams& params) {
    this->reset(texture, swizzle, params);
}

GrTextureAccess::GrTextureAccess(GrTexture* texture,
                                 const char* swizzle,
                                 GrTextureParams::FilterMode filterMode,
                                 SkShader::TileMode tileXAndY) {
    this->reset(texture, swizzle, filterMode, tileXAndY);
}

void GrTextureAccess::reset(GrTexture* texture,
                            const char* swizzle,
                            const GrTextureParams& params) {
    SkASSERT(texture);
    SkASSERT(strlen(swizzle) >= 1 && strlen(swizzle) <= 4);

    fParams = params;
    fTexture.set(SkRef(texture), kRead_GrIOType);
    this->setSwizzle(swizzle);
}

void GrTextureAccess::reset(GrTexture* texture,
                            const char* swizzle,
                            GrTextureParams::FilterMode filterMode,
                            SkShader::TileMode tileXAndY) {
    SkASSERT(texture);
    SkASSERT(strlen(swizzle) >= 1 && strlen(swizzle) <= 4);

    fParams.reset(tileXAndY, filterMode);
    fTexture.set(SkRef(texture), kRead_GrIOType);
    this->setSwizzle(swizzle);
}

void GrTextureAccess::reset(GrTexture* texture,
                            const GrTextureParams& params) {
    SkASSERT(texture);
    fTexture.set(SkRef(texture), kRead_GrIOType);
    fParams = params;
    memcpy(fSwizzle, "rgba", 5);
    fSwizzleMask = kRGBA_GrColorComponentFlags;
}

void GrTextureAccess::reset(GrTexture* texture,
                            GrTextureParams::FilterMode filterMode,
                            SkShader::TileMode tileXAndY) {
    SkASSERT(texture);
    fTexture.set(SkRef(texture), kRead_GrIOType);
    fParams.reset(tileXAndY, filterMode);
    memcpy(fSwizzle, "rgba", 5);
    fSwizzleMask = kRGBA_GrColorComponentFlags;
}

void GrTextureAccess::setSwizzle(const char* swizzle) {
    fSwizzleMask = 0;
    memset(fSwizzle, '\0', 5);
    for (int i = 0; i < 4 && '\0' != swizzle[i]; ++i) {
        fSwizzle[i] = swizzle[i];
        switch (swizzle[i]) {
            case 'r':
                fSwizzleMask |= kR_GrColorComponentFlag;
                break;
            case 'g':
                fSwizzleMask |= kG_GrColorComponentFlag;
                break;
            case 'b':
                fSwizzleMask |= kB_GrColorComponentFlag;
                break;
            case 'a':
                fSwizzleMask |= kA_GrColorComponentFlag;
                break;
            default:
                SkFAIL("Unexpected swizzle string character.");
                break;
        }
    }
}