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 "gl/GrGLPathRendering.h" | 8 #include "gl/GrGLPathRendering.h" |
9 #include "gl/GrGLNameAllocator.h" | 9 #include "gl/GrGLNameAllocator.h" |
10 #include "gl/GrGLUtil.h" | 10 #include "gl/GrGLUtil.h" |
11 #include "gl/GrGpuGL.h" | 11 #include "gl/GrGpuGL.h" |
12 | 12 |
13 #include "GrGLPath.h" | 13 #include "GrGLPath.h" |
14 #include "GrGLPathRange.h" | 14 #include "GrGLPathRange.h" |
15 #include "GrGLPathRendering.h" | 15 #include "GrGLPathRendering.h" |
16 | 16 |
| 17 #include "SkStream.h" |
| 18 #include "SkTypeface.h" |
| 19 |
17 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) | 20 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) |
18 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(fGpu->glInterface(), RET, X) | 21 #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(fGpu->glInterface(), RET, X) |
19 | 22 |
20 | 23 |
21 static const GrGLenum gXformType2GLType[] = { | 24 static const GrGLenum gXformType2GLType[] = { |
22 GR_GL_NONE, | 25 GR_GL_NONE, |
23 GR_GL_TRANSLATE_X, | 26 GR_GL_TRANSLATE_X, |
24 GR_GL_TRANSLATE_Y, | 27 GR_GL_TRANSLATE_Y, |
25 GR_GL_TRANSLATE_2D, | 28 GR_GL_TRANSLATE_2D, |
26 GR_GL_TRANSPOSE_AFFINE_2D | 29 GR_GL_TRANSPOSE_AFFINE_2D |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 89 } |
87 fHWActivePathTexGenSets = 0; | 90 fHWActivePathTexGenSets = 0; |
88 } | 91 } |
89 fHWPathStencilSettings.invalidate(); | 92 fHWPathStencilSettings.invalidate(); |
90 } | 93 } |
91 | 94 |
92 GrPath* GrGLPathRendering::createPath(const SkPath& inPath, const SkStrokeRec& s
troke) { | 95 GrPath* GrGLPathRendering::createPath(const SkPath& inPath, const SkStrokeRec& s
troke) { |
93 return SkNEW_ARGS(GrGLPath, (fGpu, inPath, stroke)); | 96 return SkNEW_ARGS(GrGLPath, (fGpu, inPath, stroke)); |
94 } | 97 } |
95 | 98 |
96 GrPathRange* GrGLPathRendering::createPathRange(size_t size, const SkStrokeRec&
stroke) { | 99 GrPathRange* GrGLPathRendering::createPathRange(GrPathRange::PathGenerator* path
Generator, |
97 return SkNEW_ARGS(GrGLPathRange, (fGpu, size, stroke)); | 100 const SkStrokeRec& stroke) { |
| 101 return SkNEW_ARGS(GrGLPathRange, (fGpu, pathGenerator, stroke)); |
| 102 } |
| 103 |
| 104 GrPathRange* GrGLPathRendering::createGlyphs(const SkTypeface* typeface, |
| 105 const SkDescriptor* desc, |
| 106 const SkStrokeRec& stroke) { |
| 107 if (NULL != desc || !caps().glyphLoadingSupport) { |
| 108 return GrPathRendering::createGlyphs(typeface, desc, stroke); |
| 109 } |
| 110 |
| 111 if (NULL == typeface) { |
| 112 typeface = SkTypeface::GetDefaultTypeface(); |
| 113 SkASSERT(NULL != typeface); |
| 114 } |
| 115 |
| 116 int faceIndex; |
| 117 SkAutoTUnref<SkStream> fontStream(typeface->openStream(&faceIndex)); |
| 118 |
| 119 const size_t fontDataLength = fontStream->getLength(); |
| 120 if (0 == fontDataLength) { |
| 121 return GrPathRendering::createGlyphs(typeface, NULL, stroke); |
| 122 } |
| 123 |
| 124 SkTArray<uint8_t> fontTempBuffer; |
| 125 const void* fontData = fontStream->getMemoryBase(); |
| 126 if (NULL == fontData) { |
| 127 // TODO: Find a more efficient way to pass the font data (e.g. open file
descriptor). |
| 128 fontTempBuffer.reset(fontDataLength); |
| 129 fontStream->read(&fontTempBuffer.front(), fontDataLength); |
| 130 fontData = &fontTempBuffer.front(); |
| 131 } |
| 132 |
| 133 const size_t numPaths = typeface->countGlyphs(); |
| 134 const GrGLuint basePathID = this->genPaths(numPaths); |
| 135 |
| 136 GrGLenum status; |
| 137 GL_CALL_RET(status, PathMemoryGlyphIndexArray(basePathID, GR_GL_STANDARD_FON
T_FORMAT, |
| 138 fontDataLength, fontData, face
Index, 0, numPaths, |
| 139 GrGLPath(fGpu, SkPath(), strok
e).pathID(), |
| 140 SkPaint::kCanonicalTextSizeFor
Paths)); |
| 141 |
| 142 if (GR_GL_FONT_GLYPHS_AVAILABLE != status) { |
| 143 this->deletePaths(basePathID, numPaths); |
| 144 return GrPathRendering::createGlyphs(typeface, NULL, stroke); |
| 145 } |
| 146 |
| 147 // This is a crude approximation. We may want to consider giving this class |
| 148 // a pseudo PathGenerator whose sole purpose is to track the approximate gpu |
| 149 // memory size. |
| 150 const size_t gpuMemorySize = fontDataLength / 4; |
| 151 return SkNEW_ARGS(GrGLPathRange, (fGpu, basePathID, numPaths, gpuMemorySize,
stroke)); |
98 } | 152 } |
99 | 153 |
100 void GrGLPathRendering::stencilPath(const GrPath* path, SkPath::FillType fill) { | 154 void GrGLPathRendering::stencilPath(const GrPath* path, SkPath::FillType fill) { |
101 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID(); | 155 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID(); |
102 SkASSERT(fGpu->drawState()->getRenderTarget()); | 156 SkASSERT(fGpu->drawState()->getRenderTarget()); |
103 SkASSERT(fGpu->drawState()->getRenderTarget()->getStencilBuffer()); | 157 SkASSERT(fGpu->drawState()->getRenderTarget()->getStencilBuffer()); |
104 | 158 |
105 this->flushPathStencilSettings(fill); | 159 this->flushPathStencilSettings(fill); |
106 SkASSERT(!fHWPathStencilSettings.isTwoSided()); | 160 SkASSERT(!fHWPathStencilSettings.isTwoSided()); |
107 | 161 |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 reference, mask, coverMode,
transformType, | 524 reference, mask, coverMode,
transformType, |
471 transformValues)); | 525 transformValues)); |
472 return; | 526 return; |
473 } | 527 } |
474 | 528 |
475 GL_CALL(StencilStrokePathInstanced(numPaths, pathNameType, paths, pathBase, | 529 GL_CALL(StencilStrokePathInstanced(numPaths, pathNameType, paths, pathBase, |
476 reference, mask, transformType, transform
Values)); | 530 reference, mask, transformType, transform
Values)); |
477 GL_CALL(CoverStrokePathInstanced(numPaths, pathNameType, paths, pathBase, | 531 GL_CALL(CoverStrokePathInstanced(numPaths, pathNameType, paths, pathBase, |
478 coverMode, transformType, transformValues))
; | 532 coverMode, transformType, transformValues))
; |
479 } | 533 } |
OLD | NEW |