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 "SkTextBlobRunIterator.h" | 8 #include "SkTextBlobRunIterator.h" |
9 | 9 |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 buffer.writeByteArray(it.glyphs(), it.glyphCount() * sizeof(uint16_t)); | 239 buffer.writeByteArray(it.glyphs(), it.glyphCount() * sizeof(uint16_t)); |
240 buffer.writeByteArray(it.pos(), | 240 buffer.writeByteArray(it.pos(), |
241 it.glyphCount() * sizeof(SkScalar) * ScalarsPerGlyph(it.positioning(
))); | 241 it.glyphCount() * sizeof(SkScalar) * ScalarsPerGlyph(it.positioning(
))); |
242 | 242 |
243 it.next(); | 243 it.next(); |
244 SkDEBUGCODE(runCount--); | 244 SkDEBUGCODE(runCount--); |
245 } | 245 } |
246 SkASSERT(0 == runCount); | 246 SkASSERT(0 == runCount); |
247 } | 247 } |
248 | 248 |
249 const SkTextBlob* SkTextBlob::CreateFromBuffer(SkReadBuffer& reader) { | 249 sk_sp<SkTextBlob> SkTextBlob::MakeFromBuffer(SkReadBuffer& reader) { |
250 int runCount = reader.read32(); | 250 int runCount = reader.read32(); |
251 if (runCount < 0) { | 251 if (runCount < 0) { |
252 return nullptr; | 252 return nullptr; |
253 } | 253 } |
254 | 254 |
255 SkRect bounds; | 255 SkRect bounds; |
256 reader.readRect(&bounds); | 256 reader.readRect(&bounds); |
257 | 257 |
258 SkTextBlobBuilder blobBuilder; | 258 SkTextBlobBuilder blobBuilder; |
259 for (int i = 0; i < runCount; ++i) { | 259 for (int i = 0; i < runCount; ++i) { |
(...skipping 23 matching lines...) Expand all Loading... |
283 return nullptr; | 283 return nullptr; |
284 } | 284 } |
285 | 285 |
286 if (!reader.readByteArray(buf->glyphs, glyphCount * sizeof(uint16_t)) || | 286 if (!reader.readByteArray(buf->glyphs, glyphCount * sizeof(uint16_t)) || |
287 !reader.readByteArray(buf->pos, | 287 !reader.readByteArray(buf->pos, |
288 glyphCount * sizeof(SkScalar) * ScalarsPerGlyp
h(pos))) { | 288 glyphCount * sizeof(SkScalar) * ScalarsPerGlyp
h(pos))) { |
289 return nullptr; | 289 return nullptr; |
290 } | 290 } |
291 } | 291 } |
292 | 292 |
293 return blobBuilder.build(); | 293 return blobBuilder.make(); |
294 } | 294 } |
295 | 295 |
296 unsigned SkTextBlob::ScalarsPerGlyph(GlyphPositioning pos) { | 296 unsigned SkTextBlob::ScalarsPerGlyph(GlyphPositioning pos) { |
297 // GlyphPositioning values are directly mapped to scalars-per-glyph. | 297 // GlyphPositioning values are directly mapped to scalars-per-glyph. |
298 SkASSERT(pos <= 2); | 298 SkASSERT(pos <= 2); |
299 return pos; | 299 return pos; |
300 } | 300 } |
301 | 301 |
302 SkTextBlobRunIterator::SkTextBlobRunIterator(const SkTextBlob* blob) | 302 SkTextBlobRunIterator::SkTextBlobRunIterator(const SkTextBlob* blob) |
303 : fCurrentRun(SkTextBlob::RunRecord::First(blob)) | 303 : fCurrentRun(SkTextBlob::RunRecord::First(blob)) |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 return fCurrentRunBuffer; | 606 return fCurrentRunBuffer; |
607 } | 607 } |
608 | 608 |
609 const SkTextBlobBuilder::RunBuffer& SkTextBlobBuilder::allocRunPos(const SkPaint
& font, int count, | 609 const SkTextBlobBuilder::RunBuffer& SkTextBlobBuilder::allocRunPos(const SkPaint
& font, int count, |
610 const SkRect
*bounds) { | 610 const SkRect
*bounds) { |
611 this->allocInternal(font, SkTextBlob::kFull_Positioning, count, SkPoint::Mak
e(0, 0), bounds); | 611 this->allocInternal(font, SkTextBlob::kFull_Positioning, count, SkPoint::Mak
e(0, 0), bounds); |
612 | 612 |
613 return fCurrentRunBuffer; | 613 return fCurrentRunBuffer; |
614 } | 614 } |
615 | 615 |
616 const SkTextBlob* SkTextBlobBuilder::build() { | 616 sk_sp<SkTextBlob> SkTextBlobBuilder::make() { |
617 SkASSERT((fRunCount > 0) == (nullptr != fStorage.get())); | 617 SkASSERT((fRunCount > 0) == (nullptr != fStorage.get())); |
618 | 618 |
619 this->updateDeferredBounds(); | 619 this->updateDeferredBounds(); |
620 | 620 |
621 if (0 == fRunCount) { | 621 if (0 == fRunCount) { |
622 SkASSERT(nullptr == fStorage.get()); | 622 SkASSERT(nullptr == fStorage.get()); |
623 fStorageUsed = sizeof(SkTextBlob); | 623 fStorageUsed = sizeof(SkTextBlob); |
624 fStorage.realloc(fStorageUsed); | 624 fStorage.realloc(fStorageUsed); |
625 } | 625 } |
626 | 626 |
627 const SkTextBlob* blob = new (fStorage.release()) SkTextBlob(fRunCount, fBou
nds); | 627 SkTextBlob* blob = new (fStorage.release()) SkTextBlob(fRunCount, fBounds); |
628 SkDEBUGCODE(const_cast<SkTextBlob*>(blob)->fStorageSize = fStorageSize;) | 628 SkDEBUGCODE(const_cast<SkTextBlob*>(blob)->fStorageSize = fStorageSize;) |
629 | 629 |
630 SkDEBUGCODE( | 630 SkDEBUGCODE( |
631 size_t validateSize = sizeof(SkTextBlob); | 631 size_t validateSize = sizeof(SkTextBlob); |
632 const SkTextBlob::RunRecord* run = SkTextBlob::RunRecord::First(blob); | 632 const SkTextBlob::RunRecord* run = SkTextBlob::RunRecord::First(blob); |
633 for (int i = 0; i < fRunCount; ++i) { | 633 for (int i = 0; i < fRunCount; ++i) { |
634 validateSize += SkTextBlob::RunRecord::StorageSize(run->fCount, run-
>fPositioning); | 634 validateSize += SkTextBlob::RunRecord::StorageSize(run->fCount, run-
>fPositioning); |
635 run->validate(reinterpret_cast<const uint8_t*>(blob) + fStorageUsed)
; | 635 run->validate(reinterpret_cast<const uint8_t*>(blob) + fStorageUsed)
; |
636 run = SkTextBlob::RunRecord::Next(run); | 636 run = SkTextBlob::RunRecord::Next(run); |
637 } | 637 } |
638 SkASSERT(validateSize == fStorageUsed); | 638 SkASSERT(validateSize == fStorageUsed); |
639 ) | 639 ) |
640 | 640 |
641 fStorageUsed = 0; | 641 fStorageUsed = 0; |
642 fStorageSize = 0; | 642 fStorageSize = 0; |
643 fRunCount = 0; | 643 fRunCount = 0; |
644 fLastRun = 0; | 644 fLastRun = 0; |
645 fBounds.setEmpty(); | 645 fBounds.setEmpty(); |
646 | 646 |
647 return blob; | 647 return sk_sp<SkTextBlob>(blob); |
648 } | 648 } |
OLD | NEW |