OLD | NEW |
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 "GrAtlasTextContext.h" | 9 #include "GrAtlasTextContext.h" |
10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
11 #include "GrDrawTarget.h" | 11 #include "GrDrawTarget.h" |
12 #include "GrPath.h" | 12 #include "GrPath.h" |
13 #include "GrPathRange.h" | 13 #include "GrPathRange.h" |
14 #include "GrResourceProvider.h" | 14 #include "GrResourceProvider.h" |
15 #include "SkAutoKern.h" | 15 #include "SkAutoKern.h" |
16 #include "SkDraw.h" | 16 #include "SkDraw.h" |
17 #include "SkDrawProcs.h" | 17 #include "SkDrawProcs.h" |
18 #include "SkGlyphCache.h" | 18 #include "SkGlyphCache.h" |
19 #include "SkGpuDevice.h" | 19 #include "SkGpuDevice.h" |
20 #include "SkPath.h" | 20 #include "SkPath.h" |
21 #include "SkTextMapStateProc.h" | 21 #include "SkTextMapStateProc.h" |
22 #include "SkTextFormatParams.h" | 22 #include "SkTextFormatParams.h" |
23 | 23 |
24 GrStencilAndCoverTextContext::GrStencilAndCoverTextContext(GrContext* context, | 24 GrStencilAndCoverTextContext::GrStencilAndCoverTextContext(GrContext* context, |
25 GrDrawContext* drawCo
ntext, | 25 GrDrawContext* drawCo
ntext, |
26 const SkDevicePropert
ies& properties) | 26 const SkSurfaceProps&
surfaceProps) |
27 : GrTextContext(context, drawContext, properties) | 27 : GrTextContext(context, drawContext, surfaceProps) |
28 , fStroke(SkStrokeRec::kFill_InitStyle) | 28 , fStroke(SkStrokeRec::kFill_InitStyle) |
29 , fQueuedGlyphCount(0) | 29 , fQueuedGlyphCount(0) |
30 , fFallbackGlyphsIdx(kGlyphBufferSize) { | 30 , fFallbackGlyphsIdx(kGlyphBufferSize) { |
31 } | 31 } |
32 | 32 |
33 GrStencilAndCoverTextContext* | 33 GrStencilAndCoverTextContext* |
34 GrStencilAndCoverTextContext::Create(GrContext* context, GrDrawContext* drawCont
ext, | 34 GrStencilAndCoverTextContext::Create(GrContext* context, GrDrawContext* drawCont
ext, |
35 const SkDeviceProperties& props) { | 35 const SkSurfaceProps& surfaceProps) { |
36 GrStencilAndCoverTextContext* textContext = SkNEW_ARGS(GrStencilAndCoverText
Context, | 36 GrStencilAndCoverTextContext* textContext = SkNEW_ARGS(GrStencilAndCoverText
Context, |
37 (context, drawContext
, props)); | 37 (context, drawContext
, surfaceProps)); |
38 textContext->fFallbackTextContext = GrAtlasTextContext::Create(context, draw
Context, props); | 38 textContext->fFallbackTextContext = GrAtlasTextContext::Create(context, draw
Context, surfaceProps); |
39 | 39 |
40 return textContext; | 40 return textContext; |
41 } | 41 } |
42 | 42 |
43 GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() { | 43 GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() { |
44 } | 44 } |
45 | 45 |
46 bool GrStencilAndCoverTextContext::canDraw(const GrRenderTarget* rt, | 46 bool GrStencilAndCoverTextContext::canDraw(const GrRenderTarget* rt, |
47 const GrClip& clip, | 47 const GrClip& clip, |
48 const GrPaint& paint, | 48 const GrPaint& paint, |
(...skipping 13 matching lines...) Expand all Loading... |
62 | 62 |
63 // No hairlines unless we can map the 1 px width to the object space. | 63 // No hairlines unless we can map the 1 px width to the object space. |
64 if (skPaint.getStyle() == SkPaint::kStroke_Style | 64 if (skPaint.getStyle() == SkPaint::kStroke_Style |
65 && skPaint.getStrokeWidth() == 0 | 65 && skPaint.getStrokeWidth() == 0 |
66 && viewMatrix.hasPerspective()) { | 66 && viewMatrix.hasPerspective()) { |
67 return false; | 67 return false; |
68 } | 68 } |
69 | 69 |
70 // No color bitmap fonts. | 70 // No color bitmap fonts. |
71 SkScalerContext::Rec rec; | 71 SkScalerContext::Rec rec; |
72 SkScalerContext::MakeRec(skPaint, &fDeviceProperties, NULL, &rec); | 72 SkScalerContext::MakeRec(skPaint, &fSurfaceProps, NULL, &rec); |
73 return rec.getFormat() != SkMask::kARGB32_Format; | 73 return rec.getFormat() != SkMask::kARGB32_Format; |
74 } | 74 } |
75 | 75 |
76 void GrStencilAndCoverTextContext::onDrawText(GrRenderTarget* rt, | 76 void GrStencilAndCoverTextContext::onDrawText(GrRenderTarget* rt, |
77 const GrClip& clip, | 77 const GrClip& clip, |
78 const GrPaint& paint, | 78 const GrPaint& paint, |
79 const SkPaint& skPaint, | 79 const SkPaint& skPaint, |
80 const SkMatrix& viewMatrix, | 80 const SkMatrix& viewMatrix, |
81 const char text[], | 81 const char text[], |
82 size_t byteLength, | 82 size_t byteLength, |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 | 286 |
287 // Post-flip the initial matrix so we're left with just the flip after | 287 // Post-flip the initial matrix so we're left with just the flip after |
288 // the paint preConcats the inverse. | 288 // the paint preConcats the inverse. |
289 m = fContextInitialMatrix; | 289 m = fContextInitialMatrix; |
290 m.postScale(1, -1); | 290 m.postScale(1, -1); |
291 if (!m.invert(&fLocalMatrix)) { | 291 if (!m.invert(&fLocalMatrix)) { |
292 SkDebugf("Not invertible!\n"); | 292 SkDebugf("Not invertible!\n"); |
293 return; | 293 return; |
294 } | 294 } |
295 | 295 |
296 fGlyphCache = fSkPaint.detachCache(&fDeviceProperties, &fContextInitialM
atrix, | 296 fGlyphCache = fSkPaint.detachCache(&fSurfaceProps, &fContextInitialMatri
x, |
297 true /*ignoreGamma*/); | 297 true /*ignoreGamma*/); |
298 fGlyphs = get_gr_glyphs(fContext, fGlyphCache->getScalerContext()->getTy
peface(), | 298 fGlyphs = get_gr_glyphs(fContext, fGlyphCache->getScalerContext()->getTy
peface(), |
299 &fGlyphCache->getDescriptor(), fStroke); | 299 &fGlyphCache->getDescriptor(), fStroke); |
300 } else { | 300 } else { |
301 // Don't bake strokes into the glyph outlines. We will stroke the glyphs | 301 // Don't bake strokes into the glyph outlines. We will stroke the glyphs |
302 // using the GPU instead. This is the fast path. | 302 // using the GPU instead. This is the fast path. |
303 fStroke = GrStrokeInfo(fSkPaint); | 303 fStroke = GrStrokeInfo(fSkPaint); |
304 fSkPaint.setStyle(SkPaint::kFill_Style); | 304 fSkPaint.setStyle(SkPaint::kFill_Style); |
305 | 305 |
306 if (fStroke.isHairlineStyle()) { | 306 if (fStroke.isHairlineStyle()) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 fTextRatio = fTextInverseRatio = 1.0f; | 356 fTextRatio = fTextInverseRatio = 1.0f; |
357 canUseRawPaths = false; | 357 canUseRawPaths = false; |
358 } | 358 } |
359 | 359 |
360 SkMatrix textMatrix; | 360 SkMatrix textMatrix; |
361 // Glyphs loaded by GPU path rendering have an inverted y-direction. | 361 // Glyphs loaded by GPU path rendering have an inverted y-direction. |
362 textMatrix.setScale(fTextRatio, -fTextRatio); | 362 textMatrix.setScale(fTextRatio, -fTextRatio); |
363 fViewMatrix.preConcat(textMatrix); | 363 fViewMatrix.preConcat(textMatrix); |
364 fLocalMatrix = textMatrix; | 364 fLocalMatrix = textMatrix; |
365 | 365 |
366 fGlyphCache = fSkPaint.detachCache(&fDeviceProperties, NULL, true /*igno
reGamma*/); | 366 fGlyphCache = fSkPaint.detachCache(&fSurfaceProps, NULL, true /*ignoreGa
mma*/); |
367 fGlyphs = canUseRawPaths ? | 367 fGlyphs = canUseRawPaths ? |
368 get_gr_glyphs(fContext, fSkPaint.getTypeface(), NULL, fStr
oke) : | 368 get_gr_glyphs(fContext, fSkPaint.getTypeface(), NULL, fStr
oke) : |
369 get_gr_glyphs(fContext, fGlyphCache->getScalerContext()->g
etTypeface(), | 369 get_gr_glyphs(fContext, fGlyphCache->getScalerContext()->g
etTypeface(), |
370 &fGlyphCache->getDescriptor(), fStroke); | 370 &fGlyphCache->getDescriptor(), fStroke); |
371 } | 371 } |
372 | 372 |
373 fStateRestore.set(&fPipelineBuilder); | 373 fStateRestore.set(&fPipelineBuilder); |
374 | 374 |
375 fPipelineBuilder.setFromPaint(fPaint, fRenderTarget, fClip); | 375 fPipelineBuilder.setFromPaint(fPaint, fRenderTarget, fClip); |
376 SkASSERT(fRenderTarget->isStencilBufferMultisampled() || !fPaint.isAntiAlias
()); | 376 SkASSERT(fRenderTarget->isStencilBufferMultisampled() || !fPaint.isAntiAlias
()); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 fGlyphs = NULL; | 480 fGlyphs = NULL; |
481 | 481 |
482 SkGlyphCache::AttachCache(fGlyphCache); | 482 SkGlyphCache::AttachCache(fGlyphCache); |
483 fGlyphCache = NULL; | 483 fGlyphCache = NULL; |
484 | 484 |
485 fPipelineBuilder.stencil()->setDisabled(); | 485 fPipelineBuilder.stencil()->setDisabled(); |
486 fStateRestore.set(NULL); | 486 fStateRestore.set(NULL); |
487 fViewMatrix = fContextInitialMatrix; | 487 fViewMatrix = fContextInitialMatrix; |
488 } | 488 } |
489 | 489 |
OLD | NEW |