Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Side by Side Diff: src/gpu/GrStencilAndCoverTextContext.cpp

Issue 653133004: Change drawText() to generate positions and send to drawPosText() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add ignored GMs Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrStencilAndCoverTextContext.h ('k') | src/gpu/GrTextContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "GrBitmapTextContext.h" 9 #include "GrBitmapTextContext.h"
10 #include "GrDrawTarget.h" 10 #include "GrDrawTarget.h"
11 #include "GrGpu.h" 11 #include "GrGpu.h"
12 #include "GrPath.h" 12 #include "GrPath.h"
13 #include "GrPathRange.h" 13 #include "GrPathRange.h"
14 #include "SkAutoKern.h"
15 #include "SkDraw.h" 14 #include "SkDraw.h"
16 #include "SkDrawProcs.h" 15 #include "SkDrawProcs.h"
17 #include "SkGlyphCache.h" 16 #include "SkGlyphCache.h"
18 #include "SkGpuDevice.h" 17 #include "SkGpuDevice.h"
19 #include "SkPath.h" 18 #include "SkPath.h"
20 #include "SkTextMapStateProc.h" 19 #include "SkTextMapStateProc.h"
21 #include "SkTextFormatParams.h" 20 #include "SkTextFormatParams.h"
22 21
23 GrStencilAndCoverTextContext::GrStencilAndCoverTextContext( 22 GrStencilAndCoverTextContext::GrStencilAndCoverTextContext(
24 GrContext* context, const SkDeviceProperties& properties) 23 GrContext* context, const SkDeviceProperties& properties)
(...skipping 30 matching lines...) Expand all
55 && fContext->getMatrix().hasPerspective()) { 54 && fContext->getMatrix().hasPerspective()) {
56 return false; 55 return false;
57 } 56 }
58 57
59 // No color bitmap fonts. 58 // No color bitmap fonts.
60 SkScalerContext::Rec rec; 59 SkScalerContext::Rec rec;
61 SkScalerContext::MakeRec(paint, &fDeviceProperties, NULL, &rec); 60 SkScalerContext::MakeRec(paint, &fDeviceProperties, NULL, &rec);
62 return rec.getFormat() != SkMask::kARGB32_Format; 61 return rec.getFormat() != SkMask::kARGB32_Format;
63 } 62 }
64 63
65 void GrStencilAndCoverTextContext::onDrawText(const GrPaint& paint,
66 const SkPaint& skPaint,
67 const char text[],
68 size_t byteLength,
69 SkScalar x, SkScalar y) {
70 SkASSERT(byteLength == 0 || text != NULL);
71
72 if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) {
73 return;
74 }
75
76 // This is the slow path, mainly used by Skia unit tests. The other
77 // backends (8888, gpu, ...) use device-space dependent glyph caches. In
78 // order to match the glyph positions that the other code paths produce, we
79 // must also use device-space dependent glyph cache. This has the
80 // side-effect that the glyph shape outline will be in device-space,
81 // too. This in turn has the side-effect that NVPR can not stroke the paths,
82 // as the stroke in NVPR is defined in object-space.
83 // NOTE: here we have following coincidence that works at the moment:
84 // - When using the device-space glyphs, the transforms we pass to NVPR
85 // instanced drawing are the global transforms, and the view transform is
86 // identity. NVPR can not use non-affine transforms in the instanced
87 // drawing. This is taken care of by SkDraw::ShouldDrawTextAsPaths since it
88 // will turn off the use of device-space glyphs when perspective transforms
89 // are in use.
90
91 this->init(paint, skPaint, byteLength, kMaxAccuracy_RenderMode, SkPoint::Mak e(0, 0));
92
93 // Transform our starting point.
94 if (fNeedsDeviceSpaceGlyphs) {
95 SkPoint loc;
96 fContextInitialMatrix.mapXY(x, y, &loc);
97 x = loc.fX;
98 y = loc.fY;
99 }
100
101 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
102
103 fTransformType = GrPathRendering::kTranslate_PathTransformType;
104
105 const char* stop = text + byteLength;
106
107 // Measure first if needed.
108 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) {
109 SkFixed stopX = 0;
110 SkFixed stopY = 0;
111
112 const char* textPtr = text;
113 while (textPtr < stop) {
114 // We don't need x, y here, since all subpixel variants will have th e
115 // same advance.
116 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &textPtr, 0, 0);
117
118 stopX += glyph.fAdvanceX;
119 stopY += glyph.fAdvanceY;
120 }
121 SkASSERT(textPtr == stop);
122
123 SkScalar alignX = SkFixedToScalar(stopX) * fTextRatio;
124 SkScalar alignY = SkFixedToScalar(stopY) * fTextRatio;
125
126 if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) {
127 alignX = SkScalarHalf(alignX);
128 alignY = SkScalarHalf(alignY);
129 }
130
131 x -= alignX;
132 y -= alignY;
133 }
134
135 SkAutoKern autokern;
136
137 SkFixed fixedSizeRatio = SkScalarToFixed(fTextRatio);
138
139 SkFixed fx = SkScalarToFixed(x);
140 SkFixed fy = SkScalarToFixed(y);
141 while (text < stop) {
142 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0);
143 fx += SkFixedMul_portable(autokern.adjust(glyph), fixedSizeRatio);
144 if (glyph.fWidth) {
145 this->appendGlyph(glyph.getGlyphID(), SkFixedToScalar(fx), SkFixedTo Scalar(fy));
146 }
147
148 fx += SkFixedMul_portable(glyph.fAdvanceX, fixedSizeRatio);
149 fy += SkFixedMul_portable(glyph.fAdvanceY, fixedSizeRatio);
150 }
151
152 this->finish();
153 }
154
155 void GrStencilAndCoverTextContext::onDrawPosText(const GrPaint& paint, 64 void GrStencilAndCoverTextContext::onDrawPosText(const GrPaint& paint,
156 const SkPaint& skPaint, 65 const SkPaint& skPaint,
157 const char text[], 66 const char text[],
158 size_t byteLength, 67 size_t byteLength,
159 const SkScalar pos[], 68 const SkScalar pos[],
160 int scalarsPerPosition, 69 int scalarsPerPosition,
161 const SkPoint& offset) { 70 const SkPoint& offset) {
162 SkASSERT(byteLength == 0 || text != NULL); 71 SkASSERT(byteLength == 0 || text != NULL);
163 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 72 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
164 73
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 335
427 SkGlyphCache::AttachCache(fGlyphCache); 336 SkGlyphCache::AttachCache(fGlyphCache);
428 fGlyphCache = NULL; 337 fGlyphCache = NULL;
429 338
430 fDrawTarget->drawState()->stencil()->setDisabled(); 339 fDrawTarget->drawState()->stencil()->setDisabled();
431 fStateRestore.set(NULL); 340 fStateRestore.set(NULL);
432 fContext->setMatrix(fContextInitialMatrix); 341 fContext->setMatrix(fContextInitialMatrix);
433 GrTextContext::finish(); 342 GrTextContext::finish();
434 } 343 }
435 344
OLDNEW
« no previous file with comments | « src/gpu/GrStencilAndCoverTextContext.h ('k') | src/gpu/GrTextContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698