OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GrAtlasTextBlob.h" | 8 #include "GrAtlasTextBlob.h" |
9 | 9 |
10 #include "GrBlurUtils.h" | 10 #include "GrBlurUtils.h" |
11 #include "GrContext.h" | 11 #include "GrContext.h" |
12 #include "GrDrawContext.h" | 12 #include "GrDrawContext.h" |
13 #include "GrTextUtils.h" | 13 #include "GrTextUtils.h" |
14 #include "SkColorFilter.h" | 14 #include "SkColorFilter.h" |
15 #include "SkDrawFilter.h" | 15 #include "SkDrawFilter.h" |
16 #include "SkGlyphCache.h" | 16 #include "SkGlyphCache.h" |
17 #include "SkTextBlobRunIterator.h" | 17 #include "SkTextBlobRunIterator.h" |
18 #include "batches/GrAtlasTextBatch.h" | 18 #include "batches/GrAtlasTextBatch.h" |
19 | 19 |
| 20 GrAtlasTextBlob* GrAtlasTextBlob::Create(GrMemoryPool* pool, int glyphCount, int
runCount) { |
| 21 // We allocate size for the GrAtlasTextBlob itself, plus size for the vertic
es array, |
| 22 // and size for the glyphIds array. |
| 23 size_t verticesCount = glyphCount * kVerticesPerGlyph * kMaxVASize; |
| 24 size_t size = sizeof(GrAtlasTextBlob) + |
| 25 verticesCount + |
| 26 glyphCount * sizeof(GrGlyph**) + |
| 27 sizeof(GrAtlasTextBlob::Run) * runCount; |
| 28 |
| 29 void* allocation = pool->allocate(size); |
| 30 if (CACHE_SANITY_CHECK) { |
| 31 sk_bzero(allocation, size); |
| 32 } |
| 33 |
| 34 GrAtlasTextBlob* cacheBlob = new (allocation) GrAtlasTextBlob; |
| 35 cacheBlob->fSize = size; |
| 36 |
| 37 // setup offsets for vertices / glyphs |
| 38 cacheBlob->fVertices = sizeof(GrAtlasTextBlob) + reinterpret_cast<unsigned c
har*>(cacheBlob); |
| 39 cacheBlob->fGlyphs = reinterpret_cast<GrGlyph**>(cacheBlob->fVertices + vert
icesCount); |
| 40 cacheBlob->fRuns = reinterpret_cast<GrAtlasTextBlob::Run*>(cacheBlob->fGlyph
s + glyphCount); |
| 41 |
| 42 // Initialize runs |
| 43 for (int i = 0; i < runCount; i++) { |
| 44 new (&cacheBlob->fRuns[i]) GrAtlasTextBlob::Run; |
| 45 } |
| 46 cacheBlob->fRunCount = runCount; |
| 47 cacheBlob->fPool = pool; |
| 48 return cacheBlob; |
| 49 } |
| 50 |
| 51 |
20 SkGlyphCache* GrAtlasTextBlob::setupCache(int runIndex, | 52 SkGlyphCache* GrAtlasTextBlob::setupCache(int runIndex, |
21 const SkSurfaceProps& props, | 53 const SkSurfaceProps& props, |
22 const SkPaint& skPaint, | 54 const SkPaint& skPaint, |
23 const SkMatrix* viewMatrix, | 55 const SkMatrix* viewMatrix, |
24 bool noGamma) { | 56 bool noGamma) { |
25 GrAtlasTextBlob::Run* run = &fRuns[runIndex]; | 57 GrAtlasTextBlob::Run* run = &fRuns[runIndex]; |
26 | 58 |
27 // if we have an override descriptor for the run, then we should use that | 59 // if we have an override descriptor for the run, then we should use that |
28 SkAutoDescriptor* desc = run->fOverrideDescriptor.get() ? run->fOverrideDesc
riptor.get() : | 60 SkAutoDescriptor* desc = run->fOverrideDescriptor.get() ? run->fOverrideDesc
riptor.get() : |
29 &run->fDescriptor; | 61 &run->fDescriptor; |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 SkASSERT_RELEASE(lSubRun.vertexStartIndex() == rSubRun.vertexStartIn
dex()); | 533 SkASSERT_RELEASE(lSubRun.vertexStartIndex() == rSubRun.vertexStartIn
dex()); |
502 SkASSERT_RELEASE(lSubRun.vertexEndIndex() == rSubRun.vertexEndIndex(
)); | 534 SkASSERT_RELEASE(lSubRun.vertexEndIndex() == rSubRun.vertexEndIndex(
)); |
503 SkASSERT_RELEASE(lSubRun.glyphStartIndex() == rSubRun.glyphStartInde
x()); | 535 SkASSERT_RELEASE(lSubRun.glyphStartIndex() == rSubRun.glyphStartInde
x()); |
504 SkASSERT_RELEASE(lSubRun.glyphEndIndex() == rSubRun.glyphEndIndex())
; | 536 SkASSERT_RELEASE(lSubRun.glyphEndIndex() == rSubRun.glyphEndIndex())
; |
505 SkASSERT_RELEASE(lSubRun.maskFormat() == rSubRun.maskFormat()); | 537 SkASSERT_RELEASE(lSubRun.maskFormat() == rSubRun.maskFormat()); |
506 SkASSERT_RELEASE(lSubRun.drawAsDistanceFields() == rSubRun.drawAsDis
tanceFields()); | 538 SkASSERT_RELEASE(lSubRun.drawAsDistanceFields() == rSubRun.drawAsDis
tanceFields()); |
507 SkASSERT_RELEASE(lSubRun.hasUseLCDText() == rSubRun.hasUseLCDText())
; | 539 SkASSERT_RELEASE(lSubRun.hasUseLCDText() == rSubRun.hasUseLCDText())
; |
508 } | 540 } |
509 } | 541 } |
510 } | 542 } |
OLD | NEW |