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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 static const RunRecord* First(const SkTextBlob* blob) { | 150 static const RunRecord* First(const SkTextBlob* blob) { |
151 // The first record (if present) is stored following the blob object. | 151 // The first record (if present) is stored following the blob object. |
152 return reinterpret_cast<const RunRecord*>(blob + 1); | 152 return reinterpret_cast<const RunRecord*>(blob + 1); |
153 } | 153 } |
154 | 154 |
155 static const RunRecord* Next(const RunRecord* run) { | 155 static const RunRecord* Next(const RunRecord* run) { |
156 return reinterpret_cast<const RunRecord*>(reinterpret_cast<const uint8_t
*>(run) | 156 return reinterpret_cast<const RunRecord*>(reinterpret_cast<const uint8_t
*>(run) |
157 + StorageSize(run->glyphCount(), run->positioning())); | 157 + StorageSize(run->glyphCount(), run->positioning())); |
158 } | 158 } |
159 | 159 |
160 void validate(uint8_t* storageTop) const { | 160 void validate(const uint8_t* storageTop) const { |
161 SkASSERT(kRunRecordMagic == fMagic); | 161 SkASSERT(kRunRecordMagic == fMagic); |
162 SkASSERT((uint8_t*)Next(this) <= storageTop); | 162 SkASSERT((uint8_t*)Next(this) <= storageTop); |
163 SkASSERT(glyphBuffer() + fCount <= (uint16_t*)posBuffer()); | 163 SkASSERT(glyphBuffer() + fCount <= (uint16_t*)posBuffer()); |
164 SkASSERT(posBuffer() + fCount * ScalarsPerGlyph(fPositioning) <= (SkScal
ar*)Next(this)); | 164 SkASSERT(posBuffer() + fCount * ScalarsPerGlyph(fPositioning) <= (SkScal
ar*)Next(this)); |
165 } | 165 } |
166 | 166 |
167 private: | 167 private: |
168 friend class SkTextBlobBuilder; | 168 friend class SkTextBlobBuilder; |
169 | 169 |
170 void grow(uint32_t count) { | 170 void grow(uint32_t count) { |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 SkASSERT((fRunCount > 0) == (nullptr != fStorage.get())); | 576 SkASSERT((fRunCount > 0) == (nullptr != fStorage.get())); |
577 | 577 |
578 this->updateDeferredBounds(); | 578 this->updateDeferredBounds(); |
579 | 579 |
580 if (0 == fRunCount) { | 580 if (0 == fRunCount) { |
581 SkASSERT(nullptr == fStorage.get()); | 581 SkASSERT(nullptr == fStorage.get()); |
582 fStorageUsed = sizeof(SkTextBlob); | 582 fStorageUsed = sizeof(SkTextBlob); |
583 fStorage.realloc(fStorageUsed); | 583 fStorage.realloc(fStorageUsed); |
584 } | 584 } |
585 | 585 |
| 586 const SkTextBlob* blob = new (fStorage.detach()) SkTextBlob(fRunCount, fBoun
ds); |
| 587 SkDEBUGCODE(const_cast<SkTextBlob*>(blob)->fStorageSize = fStorageSize;) |
| 588 |
586 SkDEBUGCODE( | 589 SkDEBUGCODE( |
587 size_t validateSize = sizeof(SkTextBlob); | 590 size_t validateSize = sizeof(SkTextBlob); |
588 const SkTextBlob::RunRecord* run = | 591 const SkTextBlob::RunRecord* run = SkTextBlob::RunRecord::First(blob); |
589 SkTextBlob::RunRecord::First(reinterpret_cast<const SkTextBlob*>(fSt
orage.get())); | |
590 for (int i = 0; i < fRunCount; ++i) { | 592 for (int i = 0; i < fRunCount; ++i) { |
591 validateSize += SkTextBlob::RunRecord::StorageSize(run->fCount, run-
>fPositioning); | 593 validateSize += SkTextBlob::RunRecord::StorageSize(run->fCount, run-
>fPositioning); |
592 run->validate(fStorage.get() + fStorageUsed); | 594 run->validate(reinterpret_cast<const uint8_t*>(blob) + fStorageUsed)
; |
593 run = SkTextBlob::RunRecord::Next(run); | 595 run = SkTextBlob::RunRecord::Next(run); |
594 } | 596 } |
595 SkASSERT(validateSize == fStorageUsed); | 597 SkASSERT(validateSize == fStorageUsed); |
596 ) | 598 ) |
597 | 599 |
598 const SkTextBlob* blob = new (fStorage.detach()) SkTextBlob(fRunCount, fBoun
ds); | |
599 SkDEBUGCODE(const_cast<SkTextBlob*>(blob)->fStorageSize = fStorageSize;) | |
600 | |
601 fStorageUsed = 0; | 600 fStorageUsed = 0; |
602 fStorageSize = 0; | 601 fStorageSize = 0; |
603 fRunCount = 0; | 602 fRunCount = 0; |
604 fLastRun = 0; | 603 fLastRun = 0; |
605 fBounds.setEmpty(); | 604 fBounds.setEmpty(); |
606 | 605 |
607 return blob; | 606 return blob; |
608 } | 607 } |
609 | 608 |
OLD | NEW |