OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "skia/ext/pixel_ref_utils.h" | 5 #include "skia/ext/pixel_ref_utils.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "third_party/skia/include/core/SkBitmapDevice.h" | 9 #include "third_party/skia/include/core/SkBitmapDevice.h" |
10 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 bounds.fRight += x; | 215 bounds.fRight += x; |
216 bounds.fTop += y; | 216 bounds.fTop += y; |
217 bounds.fBottom += y; | 217 bounds.fBottom += y; |
218 | 218 |
219 GatherPixelRefDevice::drawRect(draw, bounds, paint); | 219 GatherPixelRefDevice::drawRect(draw, bounds, paint); |
220 } | 220 } |
221 virtual void drawPosText(const SkDraw& draw, | 221 virtual void drawPosText(const SkDraw& draw, |
222 const void* text, | 222 const void* text, |
223 size_t len, | 223 size_t len, |
224 const SkScalar pos[], | 224 const SkScalar pos[], |
225 SkScalar const_y, | |
226 int scalars_per_pos, | 225 int scalars_per_pos, |
| 226 const SkPoint& offset, |
227 const SkPaint& paint) SK_OVERRIDE { | 227 const SkPaint& paint) SK_OVERRIDE { |
228 SkBitmap bitmap; | 228 SkBitmap bitmap; |
229 if (!GetBitmapFromPaint(paint, &bitmap)) | 229 if (!GetBitmapFromPaint(paint, &bitmap)) |
230 return; | 230 return; |
231 | 231 |
232 if (len == 0) | 232 if (len == 0) |
233 return; | 233 return; |
234 | 234 |
235 // Similar to SkDraw asserts. | 235 // Similar to SkDraw asserts. |
236 SkASSERT(scalars_per_pos == 1 || scalars_per_pos == 2); | 236 SkASSERT(scalars_per_pos == 1 || scalars_per_pos == 2); |
237 | 237 |
238 SkPoint min_point; | 238 SkPoint min_point = SkPoint::Make(offset.x() + pos[0], |
239 SkPoint max_point; | 239 offset.y() + (2 == scalars_per_pos ? pos[1
] : 0)); |
240 if (scalars_per_pos == 1) { | 240 SkPoint max_point = min_point; |
241 min_point.set(pos[0], const_y); | |
242 max_point.set(pos[0], const_y); | |
243 } else if (scalars_per_pos == 2) { | |
244 min_point.set(pos[0], const_y + pos[1]); | |
245 max_point.set(pos[0], const_y + pos[1]); | |
246 } | |
247 | 241 |
248 for (size_t i = 0; i < len; ++i) { | 242 for (size_t i = 0; i < len; ++i) { |
249 SkScalar x = pos[i * scalars_per_pos]; | 243 SkScalar x = offset.x() + pos[i * scalars_per_pos]; |
250 SkScalar y = const_y; | 244 SkScalar y = offset.y() + (2 == scalars_per_pos ? pos[i * scalars_per_pos
+ 1] : 0); |
251 if (scalars_per_pos == 2) | |
252 y += pos[i * scalars_per_pos + 1]; | |
253 | 245 |
254 min_point.set(std::min(x, min_point.x()), std::min(y, min_point.y())); | 246 min_point.set(std::min(x, min_point.x()), std::min(y, min_point.y())); |
255 max_point.set(std::max(x, max_point.x()), std::max(y, max_point.y())); | 247 max_point.set(std::max(x, max_point.x()), std::max(y, max_point.y())); |
256 } | 248 } |
257 | 249 |
258 SkRect bounds = SkRect::MakeLTRB( | 250 SkRect bounds = SkRect::MakeLTRB( |
259 min_point.x(), min_point.y(), max_point.x(), max_point.y()); | 251 min_point.x(), min_point.y(), max_point.x(), max_point.y()); |
260 | 252 |
261 // Math is borrowed from SkBBoxRecord | 253 // Math is borrowed from SkBBoxRecord |
262 SkPaint::FontMetrics metrics; | 254 SkPaint::FontMetrics metrics; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 GatherPixelRefDevice device(empty_bitmap, &pixel_ref_set); | 358 GatherPixelRefDevice device(empty_bitmap, &pixel_ref_set); |
367 SkNoSaveLayerCanvas canvas(&device); | 359 SkNoSaveLayerCanvas canvas(&device); |
368 | 360 |
369 canvas.clipRect(SkRect::MakeWH(picture->width(), picture->height()), | 361 canvas.clipRect(SkRect::MakeWH(picture->width(), picture->height()), |
370 SkRegion::kIntersect_Op, | 362 SkRegion::kIntersect_Op, |
371 false); | 363 false); |
372 canvas.drawPicture(picture); | 364 canvas.drawPicture(picture); |
373 } | 365 } |
374 | 366 |
375 } // namespace skia | 367 } // namespace skia |
OLD | NEW |