SkDraw_text.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright 2018 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "src/core/SkDraw.h"
  8. #include "src/core/SkFontPriv.h"
  9. #include "src/core/SkPaintPriv.h"
  10. #include "src/core/SkRasterClip.h"
  11. #include "src/core/SkScalerContext.h"
  12. #include "src/core/SkStrike.h"
  13. #include "src/core/SkUtils.h"
  14. // disable warning : local variable used without having been initialized
  15. #if defined _WIN32
  16. #pragma warning ( push )
  17. #pragma warning ( disable : 4701 )
  18. #endif
  19. ////////////////////////////////////////////////////////////////////////////////////////////////////
  20. void SkDraw::paintMasks(SkSpan<const SkMask> masks, const SkPaint& paint) const {
  21. // The size used for a typical blitter.
  22. SkSTArenaAlloc<3308> alloc;
  23. SkBlitter* blitter = SkBlitter::Choose(fDst, *fMatrix, paint, &alloc, false);
  24. if (fCoverage) {
  25. blitter = alloc.make<SkPairBlitter>(
  26. blitter,
  27. SkBlitter::Choose(*fCoverage, *fMatrix, SkPaint(), &alloc, true));
  28. }
  29. SkAAClipBlitterWrapper wrapper{*fRC, blitter};
  30. blitter = wrapper.getBlitter();
  31. bool useRegion = fRC->isBW() && !fRC->isRect();
  32. if (useRegion) {
  33. for (const SkMask& mask : masks) {
  34. SkRegion::Cliperator clipper(fRC->bwRgn(), mask.fBounds);
  35. if (!clipper.done()) {
  36. if (SkMask::kARGB32_Format == mask.fFormat) {
  37. SkBitmap bm;
  38. bm.installPixels(SkImageInfo::MakeN32Premul(mask.fBounds.size()),
  39. mask.fImage,
  40. mask.fRowBytes);
  41. this->drawSprite(bm, mask.fBounds.x(), mask.fBounds.y(), paint);
  42. } else {
  43. const SkIRect& cr = clipper.rect();
  44. do {
  45. blitter->blitMask(mask, cr);
  46. clipper.next();
  47. } while (!clipper.done());
  48. }
  49. }
  50. }
  51. } else {
  52. SkIRect clipBounds = fRC->isBW() ? fRC->bwRgn().getBounds()
  53. : fRC->aaRgn().getBounds();
  54. for (const SkMask& mask : masks) {
  55. SkIRect storage;
  56. const SkIRect* bounds = &mask.fBounds;
  57. // this extra test is worth it, assuming that most of the time it succeeds
  58. // since we can avoid writing to storage
  59. if (!clipBounds.containsNoEmptyCheck(mask.fBounds)) {
  60. if (!storage.intersectNoEmptyCheck(mask.fBounds, clipBounds)) {
  61. continue;
  62. }
  63. bounds = &storage;
  64. }
  65. if (SkMask::kARGB32_Format == mask.fFormat) {
  66. SkBitmap bm;
  67. bm.installPixels(SkImageInfo::MakeN32Premul(mask.fBounds.size()),
  68. mask.fImage,
  69. mask.fRowBytes);
  70. this->drawSprite(bm, mask.fBounds.x(), mask.fBounds.y(), paint);
  71. } else {
  72. blitter->blitMask(mask, *bounds);
  73. }
  74. }
  75. }
  76. }
  77. void SkDraw::paintPaths(SkSpan<const SkPathPos> pathsAndPositions,
  78. SkScalar scale,
  79. const SkPaint& paint) const {
  80. for (const auto& pathAndPos : pathsAndPositions) {
  81. SkMatrix m;
  82. SkPoint position = pathAndPos.position;
  83. m.setScaleTranslate(scale, scale, position.x(), position.y());
  84. this->drawPath(*pathAndPos.path, paint, &m, false);
  85. }
  86. }
  87. void SkDraw::drawGlyphRunList(const SkGlyphRunList& glyphRunList,
  88. SkGlyphRunListPainter* glyphPainter) const {
  89. SkDEBUGCODE(this->validate();)
  90. if (fRC->isEmpty()) {
  91. return;
  92. }
  93. glyphPainter->drawForBitmapDevice(glyphRunList, *fMatrix, this);
  94. }
  95. #if defined _WIN32
  96. #pragma warning ( pop )
  97. #endif