OLD | NEW |
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 #include "SkTextBlob.h" | 8 #include "SkTextBlob.h" |
9 | 9 |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 } | 101 } |
102 | 102 |
103 uint32_t fCount; | 103 uint32_t fCount; |
104 SkPoint fOffset; | 104 SkPoint fOffset; |
105 SkPaint fFont; | 105 SkPaint fFont; |
106 GlyphPositioning fPositioning; | 106 GlyphPositioning fPositioning; |
107 | 107 |
108 SkDEBUGCODE(unsigned fMagic;) | 108 SkDEBUGCODE(unsigned fMagic;) |
109 }; | 109 }; |
110 | 110 |
| 111 static int32_t gNextID = 1; |
| 112 static int32_t next_id() { |
| 113 int32_t id; |
| 114 do { |
| 115 id = sk_atomic_inc(&gNextID); |
| 116 } while (id == SK_InvalidGenID); |
| 117 return id; |
| 118 } |
| 119 |
111 SkTextBlob::SkTextBlob(int runCount, const SkRect& bounds) | 120 SkTextBlob::SkTextBlob(int runCount, const SkRect& bounds) |
112 : fRunCount(runCount) | 121 : fRunCount(runCount) |
113 , fBounds(bounds) { | 122 , fBounds(bounds) |
| 123 , fUniqueID(next_id()) { |
114 } | 124 } |
115 | 125 |
116 SkTextBlob::~SkTextBlob() { | 126 SkTextBlob::~SkTextBlob() { |
117 const RunRecord* run = RunRecord::First(this); | 127 const RunRecord* run = RunRecord::First(this); |
118 for (int i = 0; i < fRunCount; ++i) { | 128 for (int i = 0; i < fRunCount; ++i) { |
119 const RunRecord* nextRun = RunRecord::Next(run); | 129 const RunRecord* nextRun = RunRecord::Next(run); |
120 SkDEBUGCODE(run->validate((uint8_t*)this + fStorageSize);) | 130 SkDEBUGCODE(run->validate((uint8_t*)this + fStorageSize);) |
121 run->~RunRecord(); | 131 run->~RunRecord(); |
122 run = nextRun; | 132 run = nextRun; |
123 } | 133 } |
124 } | 134 } |
125 | 135 |
126 uint32_t SkTextBlob::uniqueID() const { | |
127 static int32_t gTextBlobGenerationID; // = 0; | |
128 | |
129 // loop in case our global wraps around, as we never want to return SK_Inval
idGenID | |
130 while (SK_InvalidGenID == fUniqueID) { | |
131 fUniqueID = sk_atomic_inc(&gTextBlobGenerationID) + 1; | |
132 } | |
133 | |
134 return fUniqueID; | |
135 } | |
136 | |
137 void SkTextBlob::flatten(SkWriteBuffer& buffer) const { | 136 void SkTextBlob::flatten(SkWriteBuffer& buffer) const { |
138 int runCount = fRunCount; | 137 int runCount = fRunCount; |
139 | 138 |
140 buffer.write32(runCount); | 139 buffer.write32(runCount); |
141 buffer.writeRect(fBounds); | 140 buffer.writeRect(fBounds); |
142 | 141 |
143 SkPaint runPaint; | 142 SkPaint runPaint; |
144 RunIterator it(this); | 143 RunIterator it(this); |
145 while (!it.done()) { | 144 while (!it.done()) { |
146 SkASSERT(it.glyphCount() > 0); | 145 SkASSERT(it.glyphCount() > 0); |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 | 535 |
537 fStorageUsed = 0; | 536 fStorageUsed = 0; |
538 fStorageSize = 0; | 537 fStorageSize = 0; |
539 fRunCount = 0; | 538 fRunCount = 0; |
540 fLastRun = 0; | 539 fLastRun = 0; |
541 fBounds.setEmpty(); | 540 fBounds.setEmpty(); |
542 | 541 |
543 return blob; | 542 return blob; |
544 } | 543 } |
545 | 544 |
OLD | NEW |