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

Side by Side Diff: src/gpu/GrProgramDesc.h

Issue 1154773007: Remove memcmp from GrProgramDesc op== and Less (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix assert Created 5 years, 6 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 | no next file » | 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 2014 Google Inc. 2 * Copyright 2014 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 GrProgramDesc_DEFINED 8 #ifndef GrProgramDesc_DEFINED
9 #define GrProgramDesc_DEFINED 9 #define GrProgramDesc_DEFINED
10 10
(...skipping 21 matching lines...) Expand all
32 // Gets the a checksum of the key. Can be used as a hash value for a fast lo okup in a cache. 32 // Gets the a checksum of the key. Can be used as a hash value for a fast lo okup in a cache.
33 uint32_t getChecksum() const { return *this->atOffset<uint32_t, kChecksumOff set>(); } 33 uint32_t getChecksum() const { return *this->atOffset<uint32_t, kChecksumOff set>(); }
34 34
35 GrProgramDesc& operator= (const GrProgramDesc& other) { 35 GrProgramDesc& operator= (const GrProgramDesc& other) {
36 uint32_t keyLength = other.keyLength(); 36 uint32_t keyLength = other.keyLength();
37 fKey.reset(SkToInt(keyLength)); 37 fKey.reset(SkToInt(keyLength));
38 memcpy(fKey.begin(), other.fKey.begin(), keyLength); 38 memcpy(fKey.begin(), other.fKey.begin(), keyLength);
39 return *this; 39 return *this;
40 } 40 }
41 41
42 bool operator== (const GrProgramDesc& other) const { 42 bool operator== (const GrProgramDesc& that) const {
43 // The length is masked as a hint to the compiler that the address will be 4 byte aligned. 43 SkASSERT(SkIsAlign4(this->keyLength()));
44 return 0 == memcmp(this->asKey(), other.asKey(), this->keyLength() & ~0x 3); 44 int l = this->keyLength() >> 2;
45 const uint32_t* aKey = this->asKey();
46 const uint32_t* bKey = that.asKey();
47 for (int i = 0; i < l; ++i) {
48 if (aKey[i] != bKey[i]) {
49 return false;
50 }
51 }
52 return true;
45 } 53 }
46 54
47 bool operator!= (const GrProgramDesc& other) const { 55 bool operator!= (const GrProgramDesc& other) const {
48 return !(*this == other); 56 return !(*this == other);
49 } 57 }
50 58
51 static bool Less(const GrProgramDesc& a, const GrProgramDesc& b) { 59 static bool Less(const GrProgramDesc& a, const GrProgramDesc& b) {
52 return memcmp(a.asKey(), b.asKey(), a.keyLength() & ~0x3) < 0; 60 SkASSERT(SkIsAlign4(a.keyLength()));
61 int l = a.keyLength() >> 2;
62 const uint32_t* aKey = a.asKey();
63 const uint32_t* bKey = b.asKey();
64 for (int i = 0; i < l; ++i) {
65 if (aKey[i] != bKey[i]) {
66 return aKey[i] < bKey[i] ? true : false;
67 }
68 }
69 return false;
53 } 70 }
54 71
55 struct KeyHeader { 72 struct KeyHeader {
56 uint8_t fFragPosKey; // set by GrGLShaderBuilder i f there are 73 uint8_t fFragPosKey; // set by GrGLShaderBuilder i f there are
57 // effects that read the frag ment position. 74 // effects that read the frag ment position.
58 // Otherwise, 0. 75 // Otherwise, 0.
59 uint8_t fSnapVerticesToPixelCenters; 76 uint8_t fSnapVerticesToPixelCenters;
60 int8_t fColorEffectCnt; 77 int8_t fColorEffectCnt;
61 int8_t fCoverageEffectCnt; 78 int8_t fCoverageEffectCnt;
62 }; 79 };
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 }; 134 };
118 135
119 SkSTArray<kPreAllocSize, uint8_t, true>& key() { return fKey; } 136 SkSTArray<kPreAllocSize, uint8_t, true>& key() { return fKey; }
120 const SkSTArray<kPreAllocSize, uint8_t, true>& key() const { return fKey; } 137 const SkSTArray<kPreAllocSize, uint8_t, true>& key() const { return fKey; }
121 138
122 private: 139 private:
123 SkSTArray<kPreAllocSize, uint8_t, true> fKey; 140 SkSTArray<kPreAllocSize, uint8_t, true> fKey;
124 }; 141 };
125 142
126 #endif 143 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698