| 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 #ifndef GrAtlasTextBlob_DEFINED | 8 #ifndef GrAtlasTextBlob_DEFINED | 
| 9 #define GrAtlasTextBlob_DEFINED | 9 #define GrAtlasTextBlob_DEFINED | 
| 10 | 10 | 
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 203 #ifdef CACHE_SANITY_CHECK | 203 #ifdef CACHE_SANITY_CHECK | 
| 204     static void AssertEqual(const GrAtlasTextBlob&, const GrAtlasTextBlob&); | 204     static void AssertEqual(const GrAtlasTextBlob&, const GrAtlasTextBlob&); | 
| 205     size_t fSize; | 205     size_t fSize; | 
| 206 #endif | 206 #endif | 
| 207 | 207 | 
| 208     // The color here is the GrPaint color, and it is used to determine whether 
     we | 208     // The color here is the GrPaint color, and it is used to determine whether 
     we | 
| 209     // have to regenerate LCD text blobs. | 209     // have to regenerate LCD text blobs. | 
| 210     // We use this color vs the SkPaint color because it has the colorfilter app
     lied. | 210     // We use this color vs the SkPaint color because it has the colorfilter app
     lied. | 
| 211     void initReusableBlob(GrColor color, const SkMatrix& viewMatrix, SkScalar x,
      SkScalar y) { | 211     void initReusableBlob(GrColor color, const SkMatrix& viewMatrix, SkScalar x,
      SkScalar y) { | 
| 212         fPaintColor = color; | 212         fPaintColor = color; | 
| 213         fViewMatrix = viewMatrix; | 213         this->setupViewMatrix(viewMatrix, x, y); | 
| 214         fX = x; |  | 
| 215         fY = y; |  | 
| 216     } | 214     } | 
| 217 | 215 | 
| 218     void initThrowawayBlob(const SkMatrix& viewMatrix) { | 216     void initThrowawayBlob(const SkMatrix& viewMatrix, SkScalar x, SkScalar y) { | 
| 219         fViewMatrix = viewMatrix; | 217         this->setupViewMatrix(viewMatrix, x, y); | 
| 220     } | 218     } | 
| 221 | 219 | 
| 222     GrDrawBatch* test_createBatch(int glyphCount, int run, int subRun, | 220     GrDrawBatch* test_createBatch(int glyphCount, int run, int subRun, | 
| 223                                   GrColor color, SkScalar transX, SkScalar trans
     Y, | 221                                   GrColor color, SkScalar transX, SkScalar trans
     Y, | 
| 224                                   const SkPaint& skPaint, const SkSurfaceProps& 
     props, | 222                                   const SkPaint& skPaint, const SkSurfaceProps& 
     props, | 
| 225                                   const GrDistanceFieldAdjustTable* distanceAdju
     stTable, | 223                                   const GrDistanceFieldAdjustTable* distanceAdju
     stTable, | 
| 226                                   GrBatchFontCache* cache); | 224                                   GrBatchFontCache* cache); | 
| 227 | 225 | 
| 228 private: | 226 private: | 
| 229     void appendLargeGlyph(GrGlyph* glyph, GrFontScaler* scaler, const SkGlyph& s
     kGlyph, | 227     void appendLargeGlyph(GrGlyph* glyph, GrFontScaler* scaler, const SkGlyph& s
     kGlyph, | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 242                         const SkIRect& clipBounds); | 240                         const SkIRect& clipBounds); | 
| 243 | 241 | 
| 244     void flushRunAsPaths(GrContext* context, | 242     void flushRunAsPaths(GrContext* context, | 
| 245                          GrDrawContext* dc, | 243                          GrDrawContext* dc, | 
| 246                          const SkSurfaceProps& props, | 244                          const SkSurfaceProps& props, | 
| 247                          const SkTextBlobRunIterator& it, | 245                          const SkTextBlobRunIterator& it, | 
| 248                          const GrClip& clip, const SkPaint& skPaint, | 246                          const GrClip& clip, const SkPaint& skPaint, | 
| 249                          SkDrawFilter* drawFilter, const SkMatrix& viewMatrix, | 247                          SkDrawFilter* drawFilter, const SkMatrix& viewMatrix, | 
| 250                          const SkIRect& clipBounds, SkScalar x, SkScalar y); | 248                          const SkIRect& clipBounds, SkScalar x, SkScalar y); | 
| 251 | 249 | 
|  | 250     // This function will only be called when we are regenerating a blob from sc
     ratch. We record the | 
|  | 251     // initial view matrix and initial offsets(x,y), because we record vertex bo
     unds relative to | 
|  | 252     // these numbers.  When blobs are reused with new matrices, we need to retur
     n to model space so | 
|  | 253     // we can update the vertex bounds appropriately. | 
|  | 254     void setupViewMatrix(const SkMatrix& viewMatrix, SkScalar x, SkScalar y) { | 
|  | 255         fViewMatrix = viewMatrix; | 
|  | 256         if (!viewMatrix.invert(&fInitialViewMatrixInverse)) { | 
|  | 257             fInitialViewMatrixInverse = SkMatrix::I(); | 
|  | 258             SkDebugf("Could not invert viewmatrix\n"); | 
|  | 259         } | 
|  | 260         fX = fInitialX = x; | 
|  | 261         fY = fInitialY = y; | 
|  | 262     } | 
|  | 263 | 
| 252     /* | 264     /* | 
| 253      * Each Run inside of the blob can have its texture coordinates regenerated 
     if required. | 265      * Each Run inside of the blob can have its texture coordinates regenerated 
     if required. | 
| 254      * To determine if regeneration is necessary, fAtlasGeneration is used.  If 
     there have been | 266      * To determine if regeneration is necessary, fAtlasGeneration is used.  If 
     there have been | 
| 255      * any evictions inside of the atlas, then we will simply regenerate Runs.  
     We could track | 267      * any evictions inside of the atlas, then we will simply regenerate Runs.  
     We could track | 
| 256      * this at a more fine grained level, but its not clear if this is worth it,
      as evictions | 268      * this at a more fine grained level, but its not clear if this is worth it,
      as evictions | 
| 257      * should be fairly rare. | 269      * should be fairly rare. | 
| 258      * | 270      * | 
| 259      * One additional point, each run can contain glyphs with any of the three m
     ask formats. | 271      * One additional point, each run can contain glyphs with any of the three m
     ask formats. | 
| 260      * We call these SubRuns.  Because a subrun must be a contiguous range, we h
     ave to create | 272      * We call these SubRuns.  Because a subrun must be a contiguous range, we h
     ave to create | 
| 261      * a new subrun each time the mask format changes in a run.  In theory, a ru
     n can have as | 273      * a new subrun each time the mask format changes in a run.  In theory, a ru
     n can have as | 
| 262      * many SubRuns as it has glyphs, ie if a run alternates between color emoji
      and A8.  In | 274      * many SubRuns as it has glyphs, ie if a run alternates between color emoji
      and A8.  In | 
| 263      * practice, the vast majority of runs have only a single subrun. | 275      * practice, the vast majority of runs have only a single subrun. | 
| 264      * | 276      * | 
| 265      * Finally, for runs where the entire thing is too large for the GrAtlasText
     Context to | 277      * Finally, for runs where the entire thing is too large for the GrAtlasText
     Context to | 
| 266      * handle, we have a bit to mark the run as flusahable via rendering as path
     s.  It is worth | 278      * handle, we have a bit to mark the run as flusahable via rendering as path
     s.  It is worth | 
| 267      * pointing. It would be a bit expensive to figure out ahead of time whether
      or not a run | 279      * pointing. It would be a bit expensive to figure out ahead of time whether
      or not a run | 
| 268      * can flush in this manner, so we always allocate vertices for the run, reg
     ardless of | 280      * can flush in this manner, so we always allocate vertices for the run, reg
     ardless of | 
| 269      * whether or not it is too large.  The benefit of this strategy is that we 
     can always reuse | 281      * whether or not it is too large.  The benefit of this strategy is that we 
     can always reuse | 
| 270      * a blob allocation regardless of viewmatrix changes.  We could store posit
     ions for these | 282      * a blob allocation regardless of viewmatrix changes.  We could store posit
     ions for these | 
| 271      * glyphs.  However, its not clear if this is a win because we'd still have 
     to either go the | 283      * glyphs.  However, its not clear if this is a win because we'd still have 
     to either go the | 
| 272      * glyph cache to get the path at flush time, or hold onto the path in the c
     ache, which | 284      * glyph cache to get the path at flush time, or hold onto the path in the c
     ache, which | 
| 273      * would greatly increase the memory of these cached items. | 285      * would greatly increase the memory of these cached items. | 
| 274      */ | 286      */ | 
| 275     struct Run { | 287     struct Run { | 
| 276         Run() | 288         Run() | 
| 277             : fInitialized(false) | 289             : fInitialized(false) | 
| 278             , fDrawAsPaths(false) { | 290             , fDrawAsPaths(false) { | 
| 279             fVertexBounds.setLargestInverted(); |  | 
| 280             // To ensure we always have one subrun, we push back a fresh run her
     e | 291             // To ensure we always have one subrun, we push back a fresh run her
     e | 
| 281             fSubRunInfo.push_back(); | 292             fSubRunInfo.push_back(); | 
| 282         } | 293         } | 
| 283         struct SubRunInfo { | 294         struct SubRunInfo { | 
| 284             SubRunInfo() | 295             SubRunInfo() | 
| 285                 : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGeneration) | 296                 : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGeneration) | 
| 286                 , fVertexStartIndex(0) | 297                 , fVertexStartIndex(0) | 
| 287                 , fVertexEndIndex(0) | 298                 , fVertexEndIndex(0) | 
| 288                 , fGlyphStartIndex(0) | 299                 , fGlyphStartIndex(0) | 
| 289                 , fGlyphEndIndex(0) | 300                 , fGlyphEndIndex(0) | 
| 290                 , fColor(GrColor_ILLEGAL) | 301                 , fColor(GrColor_ILLEGAL) | 
| 291                 , fMaskFormat(kA8_GrMaskFormat) | 302                 , fMaskFormat(kA8_GrMaskFormat) | 
| 292                 , fDrawAsDistanceFields(false) | 303                 , fDrawAsDistanceFields(false) | 
| 293                 , fUseLCDText(false) {} | 304                 , fUseLCDText(false) { | 
|  | 305                 fVertexBounds.setLargestInverted(); | 
|  | 306             } | 
| 294             SubRunInfo(const SubRunInfo& that) | 307             SubRunInfo(const SubRunInfo& that) | 
| 295                 : fBulkUseToken(that.fBulkUseToken) | 308                 : fBulkUseToken(that.fBulkUseToken) | 
| 296                 , fStrike(SkSafeRef(that.fStrike.get())) | 309                 , fStrike(SkSafeRef(that.fStrike.get())) | 
|  | 310                 , fVertexBounds(that.fVertexBounds) | 
| 297                 , fAtlasGeneration(that.fAtlasGeneration) | 311                 , fAtlasGeneration(that.fAtlasGeneration) | 
| 298                 , fVertexStartIndex(that.fVertexStartIndex) | 312                 , fVertexStartIndex(that.fVertexStartIndex) | 
| 299                 , fVertexEndIndex(that.fVertexEndIndex) | 313                 , fVertexEndIndex(that.fVertexEndIndex) | 
| 300                 , fGlyphStartIndex(that.fGlyphStartIndex) | 314                 , fGlyphStartIndex(that.fGlyphStartIndex) | 
| 301                 , fGlyphEndIndex(that.fGlyphEndIndex) | 315                 , fGlyphEndIndex(that.fGlyphEndIndex) | 
| 302                 , fColor(that.fColor) | 316                 , fColor(that.fColor) | 
| 303                 , fMaskFormat(that.fMaskFormat) | 317                 , fMaskFormat(that.fMaskFormat) | 
| 304                 , fDrawAsDistanceFields(that.fDrawAsDistanceFields) | 318                 , fDrawAsDistanceFields(that.fDrawAsDistanceFields) | 
| 305                 , fUseLCDText(that.fUseLCDText) { | 319                 , fUseLCDText(that.fUseLCDText) { | 
| 306             } | 320             } | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 331             GrMaskFormat maskFormat() const { return fMaskFormat; } | 345             GrMaskFormat maskFormat() const { return fMaskFormat; } | 
| 332 | 346 | 
| 333             void setAsSuccessor(const SubRunInfo& prev) { | 347             void setAsSuccessor(const SubRunInfo& prev) { | 
| 334                 fGlyphStartIndex = prev.glyphEndIndex(); | 348                 fGlyphStartIndex = prev.glyphEndIndex(); | 
| 335                 fGlyphEndIndex = prev.glyphEndIndex(); | 349                 fGlyphEndIndex = prev.glyphEndIndex(); | 
| 336 | 350 | 
| 337                 fVertexStartIndex = prev.vertexEndIndex(); | 351                 fVertexStartIndex = prev.vertexEndIndex(); | 
| 338                 fVertexEndIndex = prev.vertexEndIndex(); | 352                 fVertexEndIndex = prev.vertexEndIndex(); | 
| 339             } | 353             } | 
| 340 | 354 | 
|  | 355             const SkRect& vertexBounds() const { return fVertexBounds; } | 
|  | 356             void joinGlyphBounds(const SkRect& glyphBounds) { | 
|  | 357                 fVertexBounds.joinNonEmptyArg(glyphBounds); | 
|  | 358             } | 
|  | 359 | 
| 341             // df properties | 360             // df properties | 
| 342             void setUseLCDText(bool useLCDText) { fUseLCDText = useLCDText; } | 361             void setUseLCDText(bool useLCDText) { fUseLCDText = useLCDText; } | 
| 343             bool hasUseLCDText() const { return fUseLCDText; } | 362             bool hasUseLCDText() const { return fUseLCDText; } | 
| 344             void setDrawAsDistanceFields() { fDrawAsDistanceFields = true; } | 363             void setDrawAsDistanceFields() { fDrawAsDistanceFields = true; } | 
| 345             bool drawAsDistanceFields() const { return fDrawAsDistanceFields; } | 364             bool drawAsDistanceFields() const { return fDrawAsDistanceFields; } | 
| 346 | 365 | 
| 347         private: | 366         private: | 
| 348             GrBatchAtlas::BulkUseTokenUpdater fBulkUseToken; | 367             GrBatchAtlas::BulkUseTokenUpdater fBulkUseToken; | 
| 349             SkAutoTUnref<GrBatchTextStrike> fStrike; | 368             SkAutoTUnref<GrBatchTextStrike> fStrike; | 
|  | 369             SkRect fVertexBounds; | 
| 350             uint64_t fAtlasGeneration; | 370             uint64_t fAtlasGeneration; | 
| 351             size_t fVertexStartIndex; | 371             size_t fVertexStartIndex; | 
| 352             size_t fVertexEndIndex; | 372             size_t fVertexEndIndex; | 
| 353             uint32_t fGlyphStartIndex; | 373             uint32_t fGlyphStartIndex; | 
| 354             uint32_t fGlyphEndIndex; | 374             uint32_t fGlyphEndIndex; | 
| 355             GrColor fColor; | 375             GrColor fColor; | 
| 356             GrMaskFormat fMaskFormat; | 376             GrMaskFormat fMaskFormat; | 
| 357             bool fDrawAsDistanceFields; // df property | 377             bool fDrawAsDistanceFields; // df property | 
| 358             bool fUseLCDText; // df property | 378             bool fUseLCDText; // df property | 
| 359         }; | 379         }; | 
| 360 | 380 | 
| 361         SubRunInfo& push_back() { | 381         SubRunInfo& push_back() { | 
| 362             // Forward glyph / vertex information to seed the new sub run | 382             // Forward glyph / vertex information to seed the new sub run | 
| 363             SubRunInfo& newSubRun = fSubRunInfo.push_back(); | 383             SubRunInfo& newSubRun = fSubRunInfo.push_back(); | 
| 364             const SubRunInfo& prevSubRun = fSubRunInfo.fromBack(1); | 384             const SubRunInfo& prevSubRun = fSubRunInfo.fromBack(1); | 
| 365 | 385 | 
| 366             newSubRun.setAsSuccessor(prevSubRun); | 386             newSubRun.setAsSuccessor(prevSubRun); | 
| 367             return newSubRun; | 387             return newSubRun; | 
| 368         } | 388         } | 
| 369         static const int kMinSubRuns = 1; | 389         static const int kMinSubRuns = 1; | 
| 370         SkAutoTUnref<SkTypeface> fTypeface; | 390         SkAutoTUnref<SkTypeface> fTypeface; | 
| 371         SkRect fVertexBounds; |  | 
| 372         SkSTArray<kMinSubRuns, SubRunInfo> fSubRunInfo; | 391         SkSTArray<kMinSubRuns, SubRunInfo> fSubRunInfo; | 
| 373         SkAutoDescriptor fDescriptor; | 392         SkAutoDescriptor fDescriptor; | 
| 374 | 393 | 
| 375         // Distance field text cannot draw coloremoji, and so has to fall back. 
      However, | 394         // Distance field text cannot draw coloremoji, and so has to fall back. 
      However, | 
| 376         // though the distance field text and the coloremoji may share the same 
     run, they | 395         // though the distance field text and the coloremoji may share the same 
     run, they | 
| 377         // will have different descriptors.  If fOverrideDescriptor is non-nullp
     tr, then it | 396         // will have different descriptors.  If fOverrideDescriptor is non-nullp
     tr, then it | 
| 378         // will be used in place of the run's descriptor to regen texture coords | 397         // will be used in place of the run's descriptor to regen texture coords | 
| 379         SkAutoTDelete<SkAutoDescriptor> fOverrideDescriptor; // df properties | 398         SkAutoTDelete<SkAutoDescriptor> fOverrideDescriptor; // df properties | 
| 380         bool fInitialized; | 399         bool fInitialized; | 
| 381         bool fDrawAsPaths; | 400         bool fDrawAsPaths; | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 416     // all glyph / vertex offsets are into these pools. | 435     // all glyph / vertex offsets are into these pools. | 
| 417     unsigned char* fVertices; | 436     unsigned char* fVertices; | 
| 418     GrGlyph** fGlyphs; | 437     GrGlyph** fGlyphs; | 
| 419     Run* fRuns; | 438     Run* fRuns; | 
| 420     GrMemoryPool* fPool; | 439     GrMemoryPool* fPool; | 
| 421     SkMaskFilter::BlurRec fBlurRec; | 440     SkMaskFilter::BlurRec fBlurRec; | 
| 422     StrokeInfo fStrokeInfo; | 441     StrokeInfo fStrokeInfo; | 
| 423     SkTArray<BigGlyph> fBigGlyphs; | 442     SkTArray<BigGlyph> fBigGlyphs; | 
| 424     Key fKey; | 443     Key fKey; | 
| 425     SkMatrix fViewMatrix; | 444     SkMatrix fViewMatrix; | 
|  | 445     SkMatrix fInitialViewMatrixInverse; | 
| 426     GrColor fPaintColor; | 446     GrColor fPaintColor; | 
|  | 447     SkScalar fInitialX; | 
|  | 448     SkScalar fInitialY; | 
| 427     SkScalar fX; | 449     SkScalar fX; | 
| 428     SkScalar fY; | 450     SkScalar fY; | 
| 429 | 451 | 
| 430     // We can reuse distance field text, but only if the new viewmatrix would no
     t result in | 452     // We can reuse distance field text, but only if the new viewmatrix would no
     t result in | 
| 431     // a mip change.  Because there can be multiple runs in a blob, we track the
      overall | 453     // a mip change.  Because there can be multiple runs in a blob, we track the
      overall | 
| 432     // maximum minimum scale, and minimum maximum scale, we can support before w
     e need to regen | 454     // maximum minimum scale, and minimum maximum scale, we can support before w
     e need to regen | 
| 433     SkScalar fMaxMinScale; | 455     SkScalar fMaxMinScale; | 
| 434     SkScalar fMinMaxScale; | 456     SkScalar fMinMaxScale; | 
| 435     int fRunCount; | 457     int fRunCount; | 
| 436     uint8_t fTextType; | 458     uint8_t fTextType; | 
| 437 | 459 | 
| 438     friend class GrAtlasTextBatch; // We might be able to get rid of this friend
     ing | 460     friend class GrAtlasTextBatch; // We might be able to get rid of this friend
     ing | 
| 439     friend class GrTextBlobCache; // Needs to access the key | 461     friend class GrTextBlobCache; // Needs to access the key | 
| 440 }; | 462 }; | 
| 441 | 463 | 
| 442 #endif | 464 #endif | 
| OLD | NEW | 
|---|