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

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

Issue 659993003: Revert of Change drawText() to generate positions and send to drawPosText() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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"
14 #include "SkDraw.h" 15 #include "SkDraw.h"
15 #include "SkDrawProcs.h" 16 #include "SkDrawProcs.h"
16 #include "SkGlyphCache.h" 17 #include "SkGlyphCache.h"
17 #include "SkGpuDevice.h" 18 #include "SkGpuDevice.h"
18 #include "SkPath.h" 19 #include "SkPath.h"
19 #include "SkTextMapStateProc.h" 20 #include "SkTextMapStateProc.h"
20 #include "SkTextFormatParams.h" 21 #include "SkTextFormatParams.h"
21 22
22 GrStencilAndCoverTextContext::GrStencilAndCoverTextContext( 23 GrStencilAndCoverTextContext::GrStencilAndCoverTextContext(
23 GrContext* context, const SkDeviceProperties& properties) 24 GrContext* context, const SkDeviceProperties& properties)
(...skipping 30 matching lines...) Expand all
54 && fContext->getMatrix().hasPerspective()) { 55 && fContext->getMatrix().hasPerspective()) {
55 return false; 56 return false;
56 } 57 }
57 58
58 // No color bitmap fonts. 59 // No color bitmap fonts.
59 SkScalerContext::Rec rec; 60 SkScalerContext::Rec rec;
60 SkScalerContext::MakeRec(paint, &fDeviceProperties, NULL, &rec); 61 SkScalerContext::MakeRec(paint, &fDeviceProperties, NULL, &rec);
61 return rec.getFormat() != SkMask::kARGB32_Format; 62 return rec.getFormat() != SkMask::kARGB32_Format;
62 } 63 }
63 64
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
64 void GrStencilAndCoverTextContext::onDrawPosText(const GrPaint& paint, 155 void GrStencilAndCoverTextContext::onDrawPosText(const GrPaint& paint,
65 const SkPaint& skPaint, 156 const SkPaint& skPaint,
66 const char text[], 157 const char text[],
67 size_t byteLength, 158 size_t byteLength,
68 const SkScalar pos[], 159 const SkScalar pos[],
69 int scalarsPerPosition, 160 int scalarsPerPosition,
70 const SkPoint& offset) { 161 const SkPoint& offset) {
71 SkASSERT(byteLength == 0 || text != NULL); 162 SkASSERT(byteLength == 0 || text != NULL);
72 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 163 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
73 164
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 426
336 SkGlyphCache::AttachCache(fGlyphCache); 427 SkGlyphCache::AttachCache(fGlyphCache);
337 fGlyphCache = NULL; 428 fGlyphCache = NULL;
338 429
339 fDrawTarget->drawState()->stencil()->setDisabled(); 430 fDrawTarget->drawState()->stencil()->setDisabled();
340 fStateRestore.set(NULL); 431 fStateRestore.set(NULL);
341 fContext->setMatrix(fContextInitialMatrix); 432 fContext->setMatrix(fContextInitialMatrix);
342 GrTextContext::finish(); 433 GrTextContext::finish();
343 } 434 }
344 435
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