| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "SkPaint.h" | 9 #include "SkPaint.h" |
| 10 #include "SkAnnotation.h" | 10 #include "SkAnnotation.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 *this = init; | 169 *this = init; |
| 170 #ifdef SK_BUILD_FOR_ANDROID | 170 #ifdef SK_BUILD_FOR_ANDROID |
| 171 fGenerationID = oldGenerationID + 1; | 171 fGenerationID = oldGenerationID + 1; |
| 172 #endif | 172 #endif |
| 173 } | 173 } |
| 174 | 174 |
| 175 #ifdef SK_BUILD_FOR_ANDROID | 175 #ifdef SK_BUILD_FOR_ANDROID |
| 176 uint32_t SkPaint::getGenerationID() const { | 176 uint32_t SkPaint::getGenerationID() const { |
| 177 return fGenerationID; | 177 return fGenerationID; |
| 178 } | 178 } |
| 179 |
| 180 void SkPaint::setGenerationID(uint32_t generationID) { |
| 181 fGenerationID = generationID; |
| 182 } |
| 179 #endif | 183 #endif |
| 180 | 184 |
| 181 #ifdef SK_BUILD_FOR_ANDROID | 185 #ifdef SK_BUILD_FOR_ANDROID |
| 182 unsigned SkPaint::getBaseGlyphCount(SkUnichar text) const { | 186 unsigned SkPaint::getBaseGlyphCount(SkUnichar text) const { |
| 183 SkAutoGlyphCache autoCache(*this, NULL, NULL); | 187 SkAutoGlyphCache autoCache(*this, NULL, NULL); |
| 184 SkGlyphCache* cache = autoCache.getCache(); | 188 SkGlyphCache* cache = autoCache.getCache(); |
| 185 return cache->getBaseGlyphCount(text); | 189 return cache->getBaseGlyphCount(text); |
| 186 } | 190 } |
| 187 #endif | 191 #endif |
| 188 | 192 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 /////////////////////////////////////////////////////////////////////////////// | 412 /////////////////////////////////////////////////////////////////////////////// |
| 409 | 413 |
| 410 #include "SkGlyphCache.h" | 414 #include "SkGlyphCache.h" |
| 411 #include "SkUtils.h" | 415 #include "SkUtils.h" |
| 412 | 416 |
| 413 static void DetachDescProc(const SkDescriptor* desc, void* context) { | 417 static void DetachDescProc(const SkDescriptor* desc, void* context) { |
| 414 *((SkGlyphCache**)context) = SkGlyphCache::DetachCache(desc); | 418 *((SkGlyphCache**)context) = SkGlyphCache::DetachCache(desc); |
| 415 } | 419 } |
| 416 | 420 |
| 417 #ifdef SK_BUILD_FOR_ANDROID | 421 #ifdef SK_BUILD_FOR_ANDROID |
| 418 const SkGlyph& SkPaint::getUnicharMetrics(SkUnichar text) { | 422 const SkGlyph& SkPaint::getUnicharMetrics(SkUnichar text, |
| 423 const SkMatrix* deviceMatrix) { |
| 419 SkGlyphCache* cache; | 424 SkGlyphCache* cache; |
| 420 descriptorProc(NULL, NULL, DetachDescProc, &cache, true); | 425 descriptorProc(NULL, deviceMatrix, DetachDescProc, &cache, true); |
| 421 | 426 |
| 422 const SkGlyph& glyph = cache->getUnicharMetrics(text); | 427 const SkGlyph& glyph = cache->getUnicharMetrics(text); |
| 423 | 428 |
| 424 SkGlyphCache::AttachCache(cache); | 429 SkGlyphCache::AttachCache(cache); |
| 425 return glyph; | 430 return glyph; |
| 426 } | 431 } |
| 427 | 432 |
| 428 const SkGlyph& SkPaint::getGlyphMetrics(uint16_t glyphId) { | 433 const SkGlyph& SkPaint::getGlyphMetrics(uint16_t glyphId, |
| 434 const SkMatrix* deviceMatrix) { |
| 429 SkGlyphCache* cache; | 435 SkGlyphCache* cache; |
| 430 descriptorProc(NULL, NULL, DetachDescProc, &cache, true); | 436 descriptorProc(NULL, deviceMatrix, DetachDescProc, &cache, true); |
| 431 | 437 |
| 432 const SkGlyph& glyph = cache->getGlyphIDMetrics(glyphId); | 438 const SkGlyph& glyph = cache->getGlyphIDMetrics(glyphId); |
| 433 | 439 |
| 434 SkGlyphCache::AttachCache(cache); | 440 SkGlyphCache::AttachCache(cache); |
| 435 return glyph; | 441 return glyph; |
| 436 } | 442 } |
| 437 | 443 |
| 438 const void* SkPaint::findImage(const SkGlyph& glyph) { | 444 const void* SkPaint::findImage(const SkGlyph& glyph, |
| 445 const SkMatrix* deviceMatrix) { |
| 439 // See ::detachCache() | 446 // See ::detachCache() |
| 440 SkGlyphCache* cache; | 447 SkGlyphCache* cache; |
| 441 descriptorProc(NULL, NULL, DetachDescProc, &cache, true); | 448 descriptorProc(NULL, deviceMatrix, DetachDescProc, &cache, true); |
| 442 | 449 |
| 443 const void* image = cache->findImage(glyph); | 450 const void* image = cache->findImage(glyph); |
| 444 | 451 |
| 445 SkGlyphCache::AttachCache(cache); | 452 SkGlyphCache::AttachCache(cache); |
| 446 return image; | 453 return image; |
| 447 } | 454 } |
| 448 #endif | 455 #endif |
| 449 | 456 |
| 450 int SkPaint::textToGlyphs(const void* textData, size_t byteLength, | 457 int SkPaint::textToGlyphs(const void* textData, size_t byteLength, |
| 451 uint16_t glyphs[]) const { | 458 uint16_t glyphs[]) const { |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 | 900 |
| 894 /////////////////////////////////////////////////////////////////////////////// | 901 /////////////////////////////////////////////////////////////////////////////// |
| 895 | 902 |
| 896 class SkAutoRestorePaintTextSizeAndFrame { | 903 class SkAutoRestorePaintTextSizeAndFrame { |
| 897 public: | 904 public: |
| 898 SkAutoRestorePaintTextSizeAndFrame(const SkPaint* paint) | 905 SkAutoRestorePaintTextSizeAndFrame(const SkPaint* paint) |
| 899 : fPaint((SkPaint*)paint) { | 906 : fPaint((SkPaint*)paint) { |
| 900 fTextSize = paint->getTextSize(); | 907 fTextSize = paint->getTextSize(); |
| 901 fStyle = paint->getStyle(); | 908 fStyle = paint->getStyle(); |
| 902 fPaint->setStyle(SkPaint::kFill_Style); | 909 fPaint->setStyle(SkPaint::kFill_Style); |
| 910 #ifdef SK_BUILD_FOR_ANDROID |
| 911 fGenerationID = fPaint->getGenerationID(); |
| 912 #endif |
| 903 } | 913 } |
| 904 | 914 |
| 905 ~SkAutoRestorePaintTextSizeAndFrame() { | 915 ~SkAutoRestorePaintTextSizeAndFrame() { |
| 906 fPaint->setStyle(fStyle); | 916 fPaint->setStyle(fStyle); |
| 907 fPaint->setTextSize(fTextSize); | 917 fPaint->setTextSize(fTextSize); |
| 918 #ifdef SK_BUILD_FOR_ANDROID |
| 919 fPaint->setGenerationID(fGenerationID); |
| 920 #endif |
| 908 } | 921 } |
| 909 | 922 |
| 910 private: | 923 private: |
| 911 SkPaint* fPaint; | 924 SkPaint* fPaint; |
| 912 SkScalar fTextSize; | 925 SkScalar fTextSize; |
| 913 SkPaint::Style fStyle; | 926 SkPaint::Style fStyle; |
| 927 #ifdef SK_BUILD_FOR_ANDROID |
| 928 uint32_t fGenerationID; |
| 929 #endif |
| 914 }; | 930 }; |
| 915 | 931 |
| 916 static void set_bounds(const SkGlyph& g, SkRect* bounds) { | 932 static void set_bounds(const SkGlyph& g, SkRect* bounds) { |
| 917 bounds->set(SkIntToScalar(g.fLeft), | 933 bounds->set(SkIntToScalar(g.fLeft), |
| 918 SkIntToScalar(g.fTop), | 934 SkIntToScalar(g.fTop), |
| 919 SkIntToScalar(g.fLeft + g.fWidth), | 935 SkIntToScalar(g.fLeft + g.fWidth), |
| 920 SkIntToScalar(g.fTop + g.fHeight)); | 936 SkIntToScalar(g.fTop + g.fHeight)); |
| 921 } | 937 } |
| 922 | 938 |
| 923 // 64bits wide, with a 16bit bias. Useful when accumulating lots of 16.16 so | 939 // 64bits wide, with a 16bit bias. Useful when accumulating lots of 16.16 so |
| (...skipping 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2548 if (firstTime) { | 2564 if (firstTime) { |
| 2549 *dst = r; | 2565 *dst = r; |
| 2550 } else { | 2566 } else { |
| 2551 dst->join(r); | 2567 dst->join(r); |
| 2552 } | 2568 } |
| 2553 } else { | 2569 } else { |
| 2554 break; | 2570 break; |
| 2555 } | 2571 } |
| 2556 } | 2572 } |
| 2557 } | 2573 } |
| OLD | NEW |