Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: include/gpu/GrTextureAccess.h

Issue 1569393002: Revert of Add a class representing texture swizzle. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | include/gpu/GrTypesPriv.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrTextureAccess_DEFINED 8 #ifndef GrTextureAccess_DEFINED
9 #define GrTextureAccess_DEFINED 9 #define GrTextureAccess_DEFINED
10 10
11 #include "GrGpuResourceRef.h" 11 #include "GrGpuResourceRef.h"
12 #include "GrTexture.h" 12 #include "GrTexture.h"
13 #include "GrTextureParams.h" 13 #include "GrTextureParams.h"
14 #include "SkRefCnt.h" 14 #include "SkRefCnt.h"
15 #include "SkShader.h" 15 #include "SkShader.h"
16 16
17 /** 17 /** A class representing the swizzle access pattern for a texture. Note that if the texture is
18 * Used to represent a texture that is required by a GrProcessor. It holds a GrT exture along with 18 * an alpha-only texture then the alpha channel is substituted for other compon ents. Any mangling
19 * an associated GrTextureParams 19 * to handle the r,g,b->a conversions for alpha textures is automatically inclu ded in the stage
20 * key. However, if a GrProcessor uses different swizzles based on its input th en it must
21 * consider that variation in its key-generation.
20 */ 22 */
21 class GrTextureAccess : public SkNoncopyable { 23 class GrTextureAccess : public SkNoncopyable {
22 public: 24 public:
23 /** 25 /**
24 * Must be initialized before adding to a GrProcessor's texture access list. 26 * A default GrTextureAccess must have reset() called on it in a GrProcessor subclass's
27 * constructor if it will be accessible via GrProcessor::textureAccess().
25 */ 28 */
26 GrTextureAccess(); 29 GrTextureAccess();
27 30
31 /**
32 * Uses the default swizzle, "rgba".
33 */
28 GrTextureAccess(GrTexture*, const GrTextureParams&); 34 GrTextureAccess(GrTexture*, const GrTextureParams&);
29
30 explicit GrTextureAccess(GrTexture*, 35 explicit GrTextureAccess(GrTexture*,
31 GrTextureParams::FilterMode = GrTextureParams::kNon e_FilterMode, 36 GrTextureParams::FilterMode = GrTextureParams::kNon e_FilterMode,
32 SkShader::TileMode tileXAndY = SkShader::kClamp_Til eMode); 37 SkShader::TileMode tileXAndY = SkShader::kClamp_Til eMode);
33 38
39 /**
40 * swizzle must be a string between one and four (inclusive) characters cont aining only 'r',
41 * 'g', 'b', and/or 'a'.
42 */
43 GrTextureAccess(GrTexture*, const char* swizzle, const GrTextureParams&);
44 GrTextureAccess(GrTexture*,
45 const char* swizzle,
46 GrTextureParams::FilterMode = GrTextureParams::kNone_FilterM ode,
47 SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode);
48
34 void reset(GrTexture*, const GrTextureParams&); 49 void reset(GrTexture*, const GrTextureParams&);
35 void reset(GrTexture*, 50 void reset(GrTexture*,
36 GrTextureParams::FilterMode = GrTextureParams::kNone_FilterMode, 51 GrTextureParams::FilterMode = GrTextureParams::kNone_FilterMode,
37 SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode); 52 SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode);
53 void reset(GrTexture*, const char* swizzle, const GrTextureParams&);
54 void reset(GrTexture*,
55 const char* swizzle,
56 GrTextureParams::FilterMode = GrTextureParams::kNone_FilterMode,
57 SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode);
38 58
39 bool operator==(const GrTextureAccess& that) const { 59 bool operator== (const GrTextureAccess& other) const {
40 return this->getTexture() == that.getTexture() && fParams == that.fParam s; 60 #ifdef SK_DEBUG
61 // below assumes all chars in fSwizzle are initialized even if string is < 4 chars long.
62 SkASSERT(memcmp(fSwizzle, other.fSwizzle, sizeof(fSwizzle)-1) ==
63 strcmp(fSwizzle, other.fSwizzle));
64 #endif
65 return fParams == other.fParams &&
66 (this->getTexture() == other.getTexture()) &&
67 (0 == memcmp(fSwizzle, other.fSwizzle, sizeof(fSwizzle)-1));
41 } 68 }
42 69
43 bool operator!=(const GrTextureAccess& other) const { return !(*this == othe r); } 70 bool operator!= (const GrTextureAccess& other) const { return !(*this == oth er); }
44 71
45 GrTexture* getTexture() const { return fTexture.get(); } 72 GrTexture* getTexture() const { return fTexture.get(); }
46 73
47 /** 74 /**
48 * For internal use by GrProcessor. 75 * For internal use by GrProcessor.
49 */ 76 */
50 const GrGpuResourceRef* getProgramTexture() const { return &fTexture; } 77 const GrGpuResourceRef* getProgramTexture() const { return &fTexture; }
51 78
79 /**
80 * Returns a string representing the swizzle. The string is is null-terminat ed.
81 */
82 const char* getSwizzle() const { return fSwizzle; }
83
84 /** Returns a mask indicating which components are referenced in the swizzle . The return
85 is a bitfield of GrColorComponentFlags. */
86 uint32_t swizzleMask() const { return fSwizzleMask; }
87
52 const GrTextureParams& getParams() const { return fParams; } 88 const GrTextureParams& getParams() const { return fParams; }
53 89
54 private: 90 private:
91 void setSwizzle(const char*);
55 92
56 typedef GrTGpuResourceRef<GrTexture> ProgramTexture; 93 typedef GrTGpuResourceRef<GrTexture> ProgramTexture;
57 94
58 ProgramTexture fTexture; 95 ProgramTexture fTexture;
59 GrTextureParams fParams; 96 GrTextureParams fParams;
97 uint32_t fSwizzleMask;
98 char fSwizzle[5];
60 99
61 typedef SkNoncopyable INHERITED; 100 typedef SkNoncopyable INHERITED;
62 }; 101 };
63 102
64 #endif 103 #endif
OLDNEW
« no previous file with comments | « no previous file | include/gpu/GrTypesPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698