OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkDevice.h" | 8 #include "SkDevice.h" |
9 #include "SkDeviceProperties.h" | 9 #include "SkDeviceProperties.h" |
10 #include "SkDraw.h" | 10 #include "SkDraw.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 this->drawVertices(draw, SkCanvas::kTriangles_VertexMode, data.fVertexCo
unt, data.fPoints, | 89 this->drawVertices(draw, SkCanvas::kTriangles_VertexMode, data.fVertexCo
unt, data.fPoints, |
90 data.fTexCoords, data.fColors, xmode, data.fIndices,
data.fIndexCount, | 90 data.fTexCoords, data.fColors, xmode, data.fIndices,
data.fIndexCount, |
91 paint); | 91 paint); |
92 } | 92 } |
93 } | 93 } |
94 | 94 |
95 void SkBaseDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSc
alar x, SkScalar y, | 95 void SkBaseDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSc
alar x, SkScalar y, |
96 const SkPaint &paint) { | 96 const SkPaint &paint) { |
97 | 97 |
98 SkPaint runPaint = paint; | 98 SkPaint runPaint = paint; |
99 SkMatrix localMatrix; | |
100 SkDraw localDraw(draw); | |
101 | |
102 if (x || y) { | |
103 localMatrix = *draw.fMatrix; | |
104 localMatrix.preTranslate(x, y); | |
105 localDraw.fMatrix = &localMatrix; | |
106 | |
107 if (paint.getShader()) { | |
108 // FIXME: We need to compensate for the translate above. This is sub
optimal but | |
109 // temporary -- until we get proper derived class drawTextBlob imple
mentations. | |
110 | |
111 // TODO: pass x,y down to the other methods so they can handle the a
dditional | |
112 // translate without needing to allocate a new shader. | |
113 SkMatrix shaderMatrix; | |
114 shaderMatrix.setTranslate(-x, -y); | |
115 SkAutoTUnref<SkShader> wrapper( | |
116 SkShader::CreateLocalMatrixShader(paint.getShader(), shaderMatri
x)); | |
117 runPaint.setShader(wrapper); | |
118 } | |
119 } | |
120 | 99 |
121 SkTextBlob::RunIterator it(blob); | 100 SkTextBlob::RunIterator it(blob); |
122 while (!it.done()) { | 101 while (!it.done()) { |
123 size_t textLen = it.glyphCount() * sizeof(uint16_t); | 102 size_t textLen = it.glyphCount() * sizeof(uint16_t); |
124 const SkPoint& offset = it.offset(); | 103 const SkPoint& offset = it.offset(); |
125 // applyFontToPaint() always overwrites the exact same attributes, | 104 // applyFontToPaint() always overwrites the exact same attributes, |
126 // so it is safe to not re-seed the paint. | 105 // so it is safe to not re-seed the paint. |
127 it.applyFontToPaint(&runPaint); | 106 it.applyFontToPaint(&runPaint); |
128 | 107 |
129 switch (it.positioning()) { | 108 switch (it.positioning()) { |
130 case SkTextBlob::kDefault_Positioning: | 109 case SkTextBlob::kDefault_Positioning: |
131 this->drawText(localDraw, it.glyphs(), textLen, offset.x(), offset.y
(), runPaint); | 110 this->drawText(draw, it.glyphs(), textLen, x + offset.x(), y + offse
t.y(), runPaint); |
132 break; | 111 break; |
133 case SkTextBlob::kHorizontal_Positioning: | 112 case SkTextBlob::kHorizontal_Positioning: |
| 113 this->drawPosText(draw, it.glyphs(), textLen, it.pos(), 1, |
| 114 SkPoint::Make(x, y + offset.y()), runPaint); |
| 115 break; |
134 case SkTextBlob::kFull_Positioning: | 116 case SkTextBlob::kFull_Positioning: |
135 this->drawPosText(localDraw, it.glyphs(), textLen, it.pos(), offset.
y(), | 117 this->drawPosText(draw, it.glyphs(), textLen, it.pos(), 2, |
136 SkTextBlob::ScalarsPerGlyph(it.positioning()), run
Paint); | 118 SkPoint::Make(x, y), runPaint); |
137 break; | 119 break; |
138 default: | 120 default: |
139 SkFAIL("unhandled positioning mode"); | 121 SkFAIL("unhandled positioning mode"); |
140 } | 122 } |
141 | 123 |
142 it.next(); | 124 it.next(); |
143 } | 125 } |
144 } | 126 } |
145 | 127 |
146 bool SkBaseDevice::readPixels(const SkImageInfo& info, void* dstP, size_t rowByt
es, int x, int y) { | 128 bool SkBaseDevice::readPixels(const SkImageInfo& info, void* dstP, size_t rowByt
es, int x, int y) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 180 |
199 void SkBaseDevice::EXPERIMENTAL_optimize(const SkPicture* picture) { | 181 void SkBaseDevice::EXPERIMENTAL_optimize(const SkPicture* picture) { |
200 // The base class doesn't perform any analysis but derived classes may | 182 // The base class doesn't perform any analysis but derived classes may |
201 } | 183 } |
202 | 184 |
203 bool SkBaseDevice::EXPERIMENTAL_drawPicture(SkCanvas*, const SkPicture*, const S
kMatrix*, | 185 bool SkBaseDevice::EXPERIMENTAL_drawPicture(SkCanvas*, const SkPicture*, const S
kMatrix*, |
204 const SkPaint*) { | 186 const SkPaint*) { |
205 // The base class doesn't perform any accelerated picture rendering | 187 // The base class doesn't perform any accelerated picture rendering |
206 return false; | 188 return false; |
207 } | 189 } |
OLD | NEW |