diff options
author | joshualitt <joshualitt@chromium.org> | 2015-04-22 13:47:02 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-22 13:47:02 -0700 |
commit | 97202d2821c2b9e997d36146ecb9711e02fd7734 (patch) | |
tree | 56f31d5a0829c20a33a226e585f181ca0718b864 /src/gpu/GrAtlasTextContext.h | |
parent | 2b4bb07492790d7d18dc046f05999915d4384c5d (diff) |
Fix for segfault on destruction of BitmapTextBlob
BUG=skia:
Review URL: https://codereview.chromium.org/1065773005
Diffstat (limited to 'src/gpu/GrAtlasTextContext.h')
-rw-r--r-- | src/gpu/GrAtlasTextContext.h | 70 |
1 files changed, 16 insertions, 54 deletions
diff --git a/src/gpu/GrAtlasTextContext.h b/src/gpu/GrAtlasTextContext.h index ebd94f9b3d..1a24e809a3 100644 --- a/src/gpu/GrAtlasTextContext.h +++ b/src/gpu/GrAtlasTextContext.h @@ -94,6 +94,8 @@ private: , fInitialized(false) , fDrawAsPaths(false) { fVertexBounds.setLargestInverted(); + // To ensure we always have one subrun, we push back a fresh run here + fSubRunInfo.push_back(); } struct SubRunInfo { SubRunInfo() @@ -110,7 +112,6 @@ private: // TODO we could have a descriptor cache, it would reduce the size of these blobs // significantly, and then the subrun could just have a refed pointer to the // correct descriptor. - SkAutoTDelete<SkAutoDescriptor> fOverrideDescriptor; // df properties GrBatchAtlas::BulkUseTokenUpdater fBulkUseToken; uint64_t fAtlasGeneration; size_t fVertexStartIndex; @@ -123,63 +124,24 @@ private: bool fUseLCDText; // df property }; - class SubRunInfoArray { - public: - SubRunInfoArray() - : fSubRunCount(0) - , fSubRunAllocation(kMinSubRuns) { - SK_COMPILE_ASSERT(kMinSubRuns > 0, insufficient_subrun_allocation); - // We always seed with one here, so we can assume a valid subrun during - // push_back - fPtr = reinterpret_cast<SubRunInfo*>(fSubRunStorage.get()); - SkNEW_PLACEMENT(&fPtr[fSubRunCount++], SubRunInfo); - } - ~SubRunInfoArray() { - for (int i = 0; i < fSubRunCount; i++) { - fPtr[i].~SubRunInfo(); - } - } - - int count() const { return fSubRunCount; } - SubRunInfo& back() { return fPtr[fSubRunCount - 1]; } - SubRunInfo& push_back() { - if (fSubRunCount >= fSubRunAllocation) { - fSubRunAllocation = fSubRunAllocation << 1; - fSubRunStorage.realloc(fSubRunAllocation * sizeof(SubRunInfo)); - fPtr = reinterpret_cast<SubRunInfo*>(fSubRunStorage.get()); - } - SkNEW_PLACEMENT(&fPtr[fSubRunCount], SubRunInfo); - - // Forward glyph / vertex information to seed the new sub run - SubRunInfo& newSubRun = fPtr[fSubRunCount]; - SubRunInfo& prevSubRun = fPtr[fSubRunCount - 1]; - newSubRun.fGlyphStartIndex = prevSubRun.fGlyphEndIndex; - newSubRun.fGlyphEndIndex = prevSubRun.fGlyphEndIndex; - - newSubRun.fVertexStartIndex = prevSubRun.fVertexEndIndex; - newSubRun.fVertexEndIndex = prevSubRun.fVertexEndIndex; - return fPtr[fSubRunCount++]; - } - SubRunInfo& operator[](int index) { - return fPtr[index]; - } - const SubRunInfo& operator[](int index) const { - return fPtr[index]; - } - - private: - static const int kMinSubRuns = 1; - static const int kMinSubRunStorage = kMinSubRuns * sizeof(SubRunInfo); - SubRunInfo* fPtr; - SkAutoSTMalloc<kMinSubRunStorage, unsigned char> fSubRunStorage; - int fSubRunCount; - int fSubRunAllocation; - }; + SubRunInfo& push_back() { + // Forward glyph / vertex information to seed the new sub run + SubRunInfo& prevSubRun = fSubRunInfo.back(); + SubRunInfo& newSubRun = fSubRunInfo.push_back(); + newSubRun.fGlyphStartIndex = prevSubRun.fGlyphEndIndex; + newSubRun.fGlyphEndIndex = prevSubRun.fGlyphEndIndex; + + newSubRun.fVertexStartIndex = prevSubRun.fVertexEndIndex; + newSubRun.fVertexEndIndex = prevSubRun.fVertexEndIndex; + return newSubRun; + } + static const int kMinSubRuns = 1; SkAutoTUnref<GrBatchTextStrike> fStrike; SkAutoTUnref<SkTypeface> fTypeface; SkRect fVertexBounds; - SubRunInfoArray fSubRunInfo; + SkSTArray<kMinSubRuns, SubRunInfo> fSubRunInfo; SkAutoDescriptor fDescriptor; + SkAutoTDelete<SkAutoDescriptor> fOverrideDescriptor; // df properties GrColor fColor; bool fInitialized; bool fDrawAsPaths; |