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 #include "GrAtlasTextContext.h" | 7 #include "GrAtlasTextContext.h" |
8 | 8 |
9 #include "GrBatchFontCache.h" | 9 #include "GrBatchFontCache.h" |
10 #include "GrBatchTarget.h" | 10 #include "GrBatchTarget.h" |
(...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1425 | 1425 |
1426 // V3 | 1426 // V3 |
1427 position = reinterpret_cast<SkPoint*>(vertex); | 1427 position = reinterpret_cast<SkPoint*>(vertex); |
1428 position->set(positions.fRight, positions.fTop); | 1428 position->set(positions.fRight, positions.fTop); |
1429 } | 1429 } |
1430 | 1430 |
1431 subRun->fGlyphEndIndex++; | 1431 subRun->fGlyphEndIndex++; |
1432 subRun->fVertexEndIndex += vertexStride * kVerticesPerGlyph; | 1432 subRun->fVertexEndIndex += vertexStride * kVerticesPerGlyph; |
1433 } | 1433 } |
1434 | 1434 |
1435 class TextBatch : public GrBatch { | 1435 class TextBatch : public GrVertexBatch { |
1436 public: | 1436 public: |
1437 typedef GrAtlasTextContext::DistanceAdjustTable DistanceAdjustTable; | 1437 typedef GrAtlasTextContext::DistanceAdjustTable DistanceAdjustTable; |
1438 typedef GrAtlasTextBlob Blob; | 1438 typedef GrAtlasTextBlob Blob; |
1439 typedef Blob::Run Run; | 1439 typedef Blob::Run Run; |
1440 typedef Run::SubRunInfo TextInfo; | 1440 typedef Run::SubRunInfo TextInfo; |
1441 struct Geometry { | 1441 struct Geometry { |
1442 Blob* fBlob; | 1442 Blob* fBlob; |
1443 int fRun; | 1443 int fRun; |
1444 int fSubRun; | 1444 int fSubRun; |
1445 GrColor fColor; | 1445 GrColor fColor; |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1886 flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlus
h; | 1886 flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlus
h; |
1887 flushInfo->fGlyphsToFlush = 0; | 1887 flushInfo->fGlyphsToFlush = 0; |
1888 } | 1888 } |
1889 | 1889 |
1890 GrColor color() const { return fBatch.fColor; } | 1890 GrColor color() const { return fBatch.fColor; } |
1891 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } | 1891 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } |
1892 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 1892 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
1893 int numGlyphs() const { return fBatch.fNumGlyphs; } | 1893 int numGlyphs() const { return fBatch.fNumGlyphs; } |
1894 | 1894 |
1895 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 1895 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
1896 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipel
ine(), t->bounds(), | 1896 TextBatch* that = t->cast<TextBatch>(); |
1897 caps)) { | 1897 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), |
| 1898 that->bounds(), caps)) { |
1898 return false; | 1899 return false; |
1899 } | 1900 } |
1900 | 1901 |
1901 TextBatch* that = t->cast<TextBatch>(); | |
1902 | |
1903 if (fMaskType != that->fMaskType) { | 1902 if (fMaskType != that->fMaskType) { |
1904 return false; | 1903 return false; |
1905 } | 1904 } |
1906 | 1905 |
1907 if (!this->usesDistanceFields()) { | 1906 if (!this->usesDistanceFields()) { |
1908 // TODO we can often batch across LCD text if we have dual source bl
ending and don't | 1907 // TODO we can often batch across LCD text if we have dual source bl
ending and don't |
1909 // have to use the blend constant | 1908 // have to use the blend constant |
1910 if (kGrayscaleCoverageMask_MaskType != fMaskType && this->color() !=
that->color()) { | 1909 if (kGrayscaleCoverageMask_MaskType != fMaskType && this->color() !=
that->color()) { |
1911 return false; | 1910 return false; |
1912 } | 1911 } |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2080 clipBounds); | 2079 clipBounds); |
2081 break; | 2080 break; |
2082 case SkTextBlob::kFull_Positioning: | 2081 case SkTextBlob::kFull_Positioning: |
2083 this->drawPosTextAsPath(rt, clip, runPaint, viewMatrix, | 2082 this->drawPosTextAsPath(rt, clip, runPaint, viewMatrix, |
2084 (const char*)it.glyphs(), | 2083 (const char*)it.glyphs(), |
2085 textLen, it.pos(), 2, SkPoint::Make(x, y), c
lipBounds); | 2084 textLen, it.pos(), 2, SkPoint::Make(x, y), c
lipBounds); |
2086 break; | 2085 break; |
2087 } | 2086 } |
2088 } | 2087 } |
2089 | 2088 |
2090 inline GrBatch* | 2089 inline GrDrawBatch* |
2091 GrAtlasTextContext::createBatch(GrAtlasTextBlob* cacheBlob, const PerSubRunInfo&
info, | 2090 GrAtlasTextContext::createBatch(GrAtlasTextBlob* cacheBlob, const PerSubRunInfo&
info, |
2092 int glyphCount, int run, int subRun, | 2091 int glyphCount, int run, int subRun, |
2093 GrColor color, SkScalar transX, SkScalar transY, | 2092 GrColor color, SkScalar transX, SkScalar transY, |
2094 const SkPaint& skPaint) { | 2093 const SkPaint& skPaint) { |
2095 GrMaskFormat format = info.fMaskFormat; | 2094 GrMaskFormat format = info.fMaskFormat; |
2096 GrColor subRunColor; | 2095 GrColor subRunColor; |
2097 if (kARGB_GrMaskFormat == format) { | 2096 if (kARGB_GrMaskFormat == format) { |
2098 uint8_t paintAlpha = skPaint.getAlpha(); | 2097 uint8_t paintAlpha = skPaint.getAlpha(); |
2099 subRunColor = SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha, paintAl
pha); | 2098 subRunColor = SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha, paintAl
pha); |
2100 } else { | 2099 } else { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2133 GrAtlasTextBlob* cacheBlob, int run, Gr
Color color, | 2132 GrAtlasTextBlob* cacheBlob, int run, Gr
Color color, |
2134 SkScalar transX, SkScalar transY, | 2133 SkScalar transX, SkScalar transY, |
2135 const SkPaint& skPaint) { | 2134 const SkPaint& skPaint) { |
2136 for (int subRun = 0; subRun < cacheBlob->fRuns[run].fSubRunInfo.count(); sub
Run++) { | 2135 for (int subRun = 0; subRun < cacheBlob->fRuns[run].fSubRunInfo.count(); sub
Run++) { |
2137 const PerSubRunInfo& info = cacheBlob->fRuns[run].fSubRunInfo[subRun]; | 2136 const PerSubRunInfo& info = cacheBlob->fRuns[run].fSubRunInfo[subRun]; |
2138 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; | 2137 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; |
2139 if (0 == glyphCount) { | 2138 if (0 == glyphCount) { |
2140 continue; | 2139 continue; |
2141 } | 2140 } |
2142 | 2141 |
2143 SkAutoTUnref<GrBatch> batch(this->createBatch(cacheBlob, info, glyphCoun
t, run, | 2142 SkAutoTUnref<GrDrawBatch> batch(this->createBatch(cacheBlob, info, glyph
Count, run, |
2144 subRun, color, transX, tra
nsY, | 2143 subRun, color, transX,
transY, |
2145 skPaint)); | 2144 skPaint)); |
2146 fDrawContext->drawBatch(pipelineBuilder, batch); | 2145 fDrawContext->drawBatch(pipelineBuilder, batch); |
2147 } | 2146 } |
2148 } | 2147 } |
2149 | 2148 |
2150 inline void GrAtlasTextContext::flushBigGlyphs(GrAtlasTextBlob* cacheBlob, GrRen
derTarget* rt, | 2149 inline void GrAtlasTextContext::flushBigGlyphs(GrAtlasTextBlob* cacheBlob, GrRen
derTarget* rt, |
2151 const GrClip& clip, const SkPaint
& skPaint, | 2150 const GrClip& clip, const SkPaint
& skPaint, |
2152 SkScalar transX, SkScalar transY, | 2151 SkScalar transX, SkScalar transY, |
2153 const SkIRect& clipBounds) { | 2152 const SkIRect& clipBounds) { |
2154 if (!cacheBlob->fBigGlyphs.count()) { | 2153 if (!cacheBlob->fBigGlyphs.count()) { |
2155 return; | 2154 return; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2220 } | 2219 } |
2221 | 2220 |
2222 // Now flush big glyphs | 2221 // Now flush big glyphs |
2223 this->flushBigGlyphs(cacheBlob, rt, clip, skPaint, 0, 0, clipBounds); | 2222 this->flushBigGlyphs(cacheBlob, rt, clip, skPaint, 0, 0, clipBounds); |
2224 } | 2223 } |
2225 | 2224 |
2226 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 2225 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
2227 | 2226 |
2228 #ifdef GR_TEST_UTILS | 2227 #ifdef GR_TEST_UTILS |
2229 | 2228 |
2230 BATCH_TEST_DEFINE(TextBlobBatch) { | 2229 DRAW_BATCH_TEST_DEFINE(TextBlobBatch) { |
2231 static uint32_t gContextID = SK_InvalidGenID; | 2230 static uint32_t gContextID = SK_InvalidGenID; |
2232 static GrAtlasTextContext* gTextContext = NULL; | 2231 static GrAtlasTextContext* gTextContext = NULL; |
2233 static SkSurfaceProps gSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType
); | 2232 static SkSurfaceProps gSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType
); |
2234 | 2233 |
2235 if (context->uniqueID() != gContextID) { | 2234 if (context->uniqueID() != gContextID) { |
2236 gContextID = context->uniqueID(); | 2235 gContextID = context->uniqueID(); |
2237 SkDELETE(gTextContext); | 2236 SkDELETE(gTextContext); |
2238 | 2237 |
2239 // We don't yet test the fall back to paths in the GrTextContext base cl
ass. This is mostly | 2238 // We don't yet test the fall back to paths in the GrTextContext base cl
ass. This is mostly |
2240 // because we don't really want to have a gpu device here. | 2239 // because we don't really want to have a gpu device here. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2283 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, | 2282 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, |
2284 static_cast<size_t>(textLen), 0, 0,
noClip)); | 2283 static_cast<size_t>(textLen), 0, 0,
noClip)); |
2285 | 2284 |
2286 SkScalar transX = static_cast<SkScalar>(random->nextU()); | 2285 SkScalar transX = static_cast<SkScalar>(random->nextU()); |
2287 SkScalar transY = static_cast<SkScalar>(random->nextU()); | 2286 SkScalar transY = static_cast<SkScalar>(random->nextU()); |
2288 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; | 2287 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; |
2289 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); | 2288 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); |
2290 } | 2289 } |
2291 | 2290 |
2292 #endif | 2291 #endif |
OLD | NEW |