| 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 "GrStencilAndCoverTextContext.h" | 8 #include "GrStencilAndCoverTextContext.h" |
| 9 #include "GrDrawTarget.h" | 9 #include "GrDrawTarget.h" |
| 10 #include "GrGpu.h" | 10 #include "GrGpu.h" |
| 11 #include "GrPath.h" | 11 #include "GrPath.h" |
| 12 #include "GrPathRange.h" | 12 #include "GrPathRange.h" |
| 13 #include "SkAutoKern.h" | 13 #include "SkAutoKern.h" |
| 14 #include "SkDraw.h" | 14 #include "SkDraw.h" |
| 15 #include "SkDrawProcs.h" | 15 #include "SkDrawProcs.h" |
| 16 #include "SkGlyphCache.h" | 16 #include "SkGlyphCache.h" |
| 17 #include "SkGpuDevice.h" | 17 #include "SkGpuDevice.h" |
| 18 #include "SkPath.h" | 18 #include "SkPath.h" |
| 19 #include "SkTextMapStateProc.h" | 19 #include "SkTextMapStateProc.h" |
| 20 | 20 |
| 21 class GrStencilAndCoverTextContext::GlyphPathRange : public GrCacheable { | 21 class GrStencilAndCoverTextContext::GlyphPathRange : public GrGpuObject { |
| 22 static const int kMaxGlyphCount = 1 << 16; // Glyph IDs are uint16_t's | 22 static const int kMaxGlyphCount = 1 << 16; // Glyph IDs are uint16_t's |
| 23 static const int kGlyphGroupSize = 16; // Glyphs get tracked in groups of 16 | 23 static const int kGlyphGroupSize = 16; // Glyphs get tracked in groups of 16 |
| 24 | 24 |
| 25 public: | 25 public: |
| 26 static GlyphPathRange* Create(GrContext* context, | 26 static GlyphPathRange* Create(GrContext* context, |
| 27 SkGlyphCache* cache, | 27 SkGlyphCache* cache, |
| 28 const SkStrokeRec& stroke) { | 28 const SkStrokeRec& stroke) { |
| 29 static const GrCacheID::Domain gGlyphPathRangeDomain = GrCacheID::Genera
teDomain(); | 29 static const GrCacheID::Domain gGlyphPathRangeDomain = GrCacheID::Genera
teDomain(); |
| 30 | 30 |
| 31 GrCacheID::Key key; | 31 GrCacheID::Key key; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 const SkGlyph& skGlyph = cache->getGlyphIDMetrics(id); | 68 const SkGlyph& skGlyph = cache->getGlyphIDMetrics(id); |
| 69 if (const SkPath* skPath = cache->findPath(skGlyph)) { | 69 if (const SkPath* skPath = cache->findPath(skGlyph)) { |
| 70 fPathRange->initAt(id, *skPath); | 70 fPathRange->initAt(id, *skPath); |
| 71 } // GrGpu::drawPaths will silently ignore undefined paths. | 71 } // GrGpu::drawPaths will silently ignore undefined paths. |
| 72 } | 72 } |
| 73 | 73 |
| 74 fLoadedGlyphs[groupByte] |= groupBit; | 74 fLoadedGlyphs[groupByte] |= groupBit; |
| 75 this->didChangeGpuMemorySize(); | 75 this->didChangeGpuMemorySize(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // GrCacheable overrides | 78 // GrGpuObject overrides |
| 79 virtual size_t gpuMemorySize() const SK_OVERRIDE { return fPathRange->gpuMem
orySize(); } | 79 virtual size_t gpuMemorySize() const SK_OVERRIDE { return fPathRange->gpuMem
orySize(); } |
| 80 virtual bool isValidOnGpu() const SK_OVERRIDE { return fPathRange->isValidOn
Gpu(); } | |
| 81 | 80 |
| 82 private: | 81 private: |
| 83 GlyphPathRange(GrContext* context, const SkDescriptor& desc, const SkStrokeR
ec& stroke) | 82 GlyphPathRange(GrContext* context, const SkDescriptor& desc, const SkStrokeR
ec& stroke) |
| 84 : fDesc(desc.copy()) | 83 : INHERITED(context->getGpu(), false) |
| 84 , fDesc(desc.copy()) |
| 85 // We reserve a range of kMaxGlyphCount paths because of fallbacks fonts
. We | 85 // We reserve a range of kMaxGlyphCount paths because of fallbacks fonts
. We |
| 86 // can't know exactly how many glyphs we might need without preloading e
very | 86 // can't know exactly how many glyphs we might need without preloading e
very |
| 87 // fallback, which we don't want to do at this point. | 87 // fallback, which we don't want to do at this point. |
| 88 , fPathRange(context->getGpu()->createPathRange(kMaxGlyphCount, stroke))
{ | 88 , fPathRange(context->getGpu()->createPathRange(kMaxGlyphCount, stroke))
{ |
| 89 memset(fLoadedGlyphs, 0, sizeof(fLoadedGlyphs)); | 89 memset(fLoadedGlyphs, 0, sizeof(fLoadedGlyphs)); |
| 90 } | 90 } |
| 91 | 91 |
| 92 ~GlyphPathRange() { | 92 ~GlyphPathRange() { |
| 93 this->release(); |
| 93 SkDescriptor::Free(fDesc); | 94 SkDescriptor::Free(fDesc); |
| 94 } | 95 } |
| 95 | 96 |
| 97 virtual void onRelease() SK_OVERRIDE { |
| 98 INHERITED::onRelease(); |
| 99 fPathRange.reset(NULL); |
| 100 } |
| 101 |
| 102 virtual void onAbandon() SK_OVERRIDE { |
| 103 INHERITED::onAbandon(); |
| 104 fPathRange->abandon(); |
| 105 fPathRange.reset(NULL); |
| 106 } |
| 107 |
| 108 |
| 96 static const int kMaxGroupCount = (kMaxGlyphCount + (kGlyphGroupSize - 1)) /
kGlyphGroupSize; | 109 static const int kMaxGroupCount = (kMaxGlyphCount + (kGlyphGroupSize - 1)) /
kGlyphGroupSize; |
| 97 SkDescriptor* const fDesc; | 110 SkDescriptor* const fDesc; |
| 98 uint8_t fLoadedGlyphs[(kMaxGroupCount + 7) >> 3]; // One bit per glyph group | 111 uint8_t fLoadedGlyphs[(kMaxGroupCount + 7) >> 3]; // One bit per glyph group |
| 99 SkAutoTUnref<GrPathRange> fPathRange; | 112 SkAutoTUnref<GrPathRange> fPathRange; |
| 100 | 113 |
| 101 typedef GrCacheable INHERITED; | 114 typedef GrGpuObject INHERITED; |
| 102 }; | 115 }; |
| 103 | 116 |
| 104 | 117 |
| 105 GrStencilAndCoverTextContext::GrStencilAndCoverTextContext( | 118 GrStencilAndCoverTextContext::GrStencilAndCoverTextContext( |
| 106 GrContext* context, const SkDeviceProperties& properties) | 119 GrContext* context, const SkDeviceProperties& properties) |
| 107 : GrTextContext(context, properties) | 120 : GrTextContext(context, properties) |
| 108 , fStroke(SkStrokeRec::kFill_InitStyle) | 121 , fStroke(SkStrokeRec::kFill_InitStyle) |
| 109 , fPendingGlyphCount(0) { | 122 , fPendingGlyphCount(0) { |
| 110 } | 123 } |
| 111 | 124 |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 fGlyphCache = NULL; | 418 fGlyphCache = NULL; |
| 406 | 419 |
| 407 fDrawTarget->drawState()->stencil()->setDisabled(); | 420 fDrawTarget->drawState()->stencil()->setDisabled(); |
| 408 fStateRestore.set(NULL); | 421 fStateRestore.set(NULL); |
| 409 if (fNeedsDeviceSpaceGlyphs) { | 422 if (fNeedsDeviceSpaceGlyphs) { |
| 410 fContext->setMatrix(fGlyphTransform); | 423 fContext->setMatrix(fGlyphTransform); |
| 411 } | 424 } |
| 412 GrTextContext::finish(); | 425 GrTextContext::finish(); |
| 413 } | 426 } |
| 414 | 427 |
| OLD | NEW |