From 148a3961b1c82a891012f2feb2a875cea2593170 Mon Sep 17 00:00:00 2001 From: "bungeman@google.com" Date: Thu, 17 Jan 2013 20:19:13 +0000 Subject: [PATCH] Don't die when there are no fonts available. https://codereview.appspot.com/7147044/ git-svn-id: http://skia.googlecode.com/svn/trunk@7265 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/core/SkPictureFlat.cpp | 2 +- src/core/SkPictureFlat.h | 13 +++++++++---- src/core/SkPictureRecord.cpp | 4 ++-- tests/FontHostStreamTest.cpp | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/core/SkPictureFlat.cpp b/src/core/SkPictureFlat.cpp index e104a40..9221c1e 100644 --- a/src/core/SkPictureFlat.cpp +++ b/src/core/SkPictureFlat.cpp @@ -120,7 +120,7 @@ SkFlatData* SkFlatData::Create(SkFlatController* controller, const void* obj, SkFlatData* result = (SkFlatData*) controller->allocThrow(allocSize); result->fIndex = index; - result->fTopBot[0] = result->fTopBot[1] = 0; // initial to sentinel values + result->setTopBotUnwritten(); result->fFlatSize = size; // put the serialized contents into the data section of the new allocation diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h index 9594a59..c01e9a3 100644 --- a/src/core/SkPictureFlat.h +++ b/src/core/SkPictureFlat.h @@ -333,20 +333,20 @@ public: } // returns true if fTopBot[] has been recorded - bool isTopBotValid() const { - return fTopBot[0] < fTopBot[1]; + bool isTopBotWritten() const { + return !SkScalarIsNaN(fTopBot[0]); } // Returns fTopBot array, so it can be passed to a routine to compute them. // For efficiency, we assert that fTopBot have not been recorded yet. SkScalar* writableTopBot() { - SkASSERT(!this->isTopBotValid()); + SkASSERT(!this->isTopBotWritten()); return fTopBot; } // return the topbot[] after it has been recorded const SkScalar* topBot() const { - SkASSERT(this->isTopBotValid()); + SkASSERT(this->isTopBotWritten()); return fTopBot; } @@ -360,6 +360,11 @@ private: // This is *not* part of the key for search/sort SkScalar fTopBot[2]; + // marks fTopBot[] as unrecorded + void setTopBotUnwritten() { + this->fTopBot[0] = this->fTopBot[1] = SK_ScalarNaN; // initial to sentinel values + } + // From here down is the data we look at in the search/sort. We always begin // with the checksum and then length. uint32_t fChecksum; diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp index 4010387..3e481ac 100644 --- a/src/core/SkPictureRecord.cpp +++ b/src/core/SkPictureRecord.cpp @@ -538,9 +538,9 @@ static void computeFontMetricsTopBottom(const SkPaint& paint, SkScalar topbot[2] void SkPictureRecord::addFontMetricsTopBottom(const SkPaint& paint, int index, SkScalar minY, SkScalar maxY) { SkFlatData* flat = fPaints.writableFlatData(index); - if (!flat->isTopBotValid()) { + if (!flat->isTopBotWritten()) { computeFontMetricsTopBottom(paint, flat->writableTopBot()); - SkASSERT(flat->isTopBotValid()); + SkASSERT(flat->isTopBotWritten()); } addScalar(flat->topBot()[0] + minY); addScalar(flat->topBot()[1] + maxY); diff --git a/tests/FontHostStreamTest.cpp b/tests/FontHostStreamTest.cpp index eb301e3..bbf1a03 100644 --- a/tests/FontHostStreamTest.cpp +++ b/tests/FontHostStreamTest.cpp @@ -94,7 +94,7 @@ static void test_fontHostStream(skiatest::Reporter* reporter) { const SkFontID typefaceID = SkTypeface::UniqueID(origTypeface); SkStream* fontData = SkFontHost::OpenStream(typefaceID); SkTypeface* streamTypeface = SkTypeface::CreateFromStream(fontData); - paint.setTypeface(streamTypeface)->unref(); + SkSafeUnref(paint.setTypeface(streamTypeface)); drawBG(&streamCanvas); streamCanvas.drawPosText("A", 1, &point, paint); -- 2.7.4