SkPictureCommon.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright 2015 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. #ifndef SkPictureCommon_DEFINED
  8. #define SkPictureCommon_DEFINED
  9. // Some shared code used by both SkBigPicture and SkMiniPicture.
  10. // SkTextHunter -- SkRecord visitor that returns true when the op draws text.
  11. // SkPathCounter -- SkRecord visitor that counts paths that draw slowly on the GPU.
  12. #include "include/core/SkPathEffect.h"
  13. #include "include/core/SkShader.h"
  14. #include "include/private/SkTLogic.h"
  15. #include "src/core/SkRecords.h"
  16. // TODO: might be nicer to have operator() return an int (the number of slow paths) ?
  17. struct SkPathCounter {
  18. // Some ops have a paint, some have an optional paint. Either way, get back a pointer.
  19. static const SkPaint* AsPtr(const SkPaint& p) { return &p; }
  20. static const SkPaint* AsPtr(const SkRecords::Optional<SkPaint>& p) { return p; }
  21. SkPathCounter() : fNumSlowPathsAndDashEffects(0) {}
  22. void checkPaint(const SkPaint* paint) {
  23. if (paint && paint->getPathEffect()) {
  24. // Initially assume it's slow.
  25. fNumSlowPathsAndDashEffects++;
  26. }
  27. }
  28. void operator()(const SkRecords::DrawPoints& op) {
  29. this->checkPaint(&op.paint);
  30. const SkPathEffect* effect = op.paint.getPathEffect();
  31. if (effect) {
  32. SkPathEffect::DashInfo info;
  33. SkPathEffect::DashType dashType = effect->asADash(&info);
  34. if (2 == op.count && SkPaint::kRound_Cap != op.paint.getStrokeCap() &&
  35. SkPathEffect::kDash_DashType == dashType && 2 == info.fCount) {
  36. fNumSlowPathsAndDashEffects--;
  37. }
  38. }
  39. }
  40. void operator()(const SkRecords::DrawPath& op) {
  41. this->checkPaint(&op.paint);
  42. if (op.paint.isAntiAlias() && !op.path.isConvex()) {
  43. SkPaint::Style paintStyle = op.paint.getStyle();
  44. const SkRect& pathBounds = op.path.getBounds();
  45. if (SkPaint::kStroke_Style == paintStyle &&
  46. 0 == op.paint.getStrokeWidth()) {
  47. // AA hairline concave path is not slow.
  48. } else if (SkPaint::kFill_Style == paintStyle && pathBounds.width() < 64.f &&
  49. pathBounds.height() < 64.f && !op.path.isVolatile()) {
  50. // AADF eligible concave path is not slow.
  51. } else {
  52. fNumSlowPathsAndDashEffects++;
  53. }
  54. }
  55. }
  56. void operator()(const SkRecords::ClipPath& op) {
  57. // TODO: does the SkRegion op matter?
  58. if (op.opAA.aa() && !op.path.isConvex()) {
  59. fNumSlowPathsAndDashEffects++;
  60. }
  61. }
  62. void operator()(const SkRecords::SaveLayer& op) {
  63. this->checkPaint(AsPtr(op.paint));
  64. }
  65. template <typename T>
  66. SK_WHEN(T::kTags & SkRecords::kHasPaint_Tag, void) operator()(const T& op) {
  67. this->checkPaint(AsPtr(op.paint));
  68. }
  69. template <typename T>
  70. SK_WHEN(!(T::kTags & SkRecords::kHasPaint_Tag), void)
  71. operator()(const T& op) { /* do nothing */ }
  72. int fNumSlowPathsAndDashEffects;
  73. };
  74. sk_sp<SkImage> ImageDeserializer_SkDeserialImageProc(const void*, size_t, void* imagedeserializer);
  75. bool SkPicture_StreamIsSKP(SkStream*, SkPictInfo*);
  76. #endif // SkPictureCommon_DEFINED