GrPathRendering.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright 2014 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 GrPathRendering_DEFINED
  8. #define GrPathRendering_DEFINED
  9. #include "include/core/SkPath.h"
  10. #include "src/gpu/GrPipeline.h"
  11. class GrGpu;
  12. class GrPath;
  13. class GrStencilSettings;
  14. class GrStyle;
  15. struct SkScalerContextEffects;
  16. class SkDescriptor;
  17. class SkTypeface;
  18. /**
  19. * Abstract class wrapping HW path rendering API.
  20. *
  21. * The subclasses of this class use the possible HW API to render paths (as opposed to path
  22. * rendering implemented in Skia on top of a "3d" HW API).
  23. * The subclasses hold the global state needed to render paths, including shadow of the global HW
  24. * API state. Similar to GrGpu.
  25. *
  26. * It is expected that the lifetimes of GrGpuXX and GrXXPathRendering are the same. The call context
  27. * interface (eg. * the concrete instance of GrGpu subclass) should be provided to the instance
  28. * during construction.
  29. */
  30. class GrPathRendering {
  31. public:
  32. virtual ~GrPathRendering() { }
  33. enum PathTransformType {
  34. kNone_PathTransformType, //!< []
  35. kTranslateX_PathTransformType, //!< [kMTransX]
  36. kTranslateY_PathTransformType, //!< [kMTransY]
  37. kTranslate_PathTransformType, //!< [kMTransX, kMTransY]
  38. kAffine_PathTransformType, //!< [kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY]
  39. kLast_PathTransformType = kAffine_PathTransformType
  40. };
  41. static inline int PathTransformSize(PathTransformType type) {
  42. switch (type) {
  43. case kNone_PathTransformType:
  44. return 0;
  45. case kTranslateX_PathTransformType:
  46. case kTranslateY_PathTransformType:
  47. return 1;
  48. case kTranslate_PathTransformType:
  49. return 2;
  50. case kAffine_PathTransformType:
  51. return 6;
  52. default:
  53. SK_ABORT("Unknown path transform type");
  54. return 0;
  55. }
  56. }
  57. // No native support for inverse at this time
  58. enum FillType {
  59. /** Specifies that "inside" is computed by a non-zero sum of signed
  60. edge crossings
  61. */
  62. kWinding_FillType,
  63. /** Specifies that "inside" is computed by an odd number of edge
  64. crossings
  65. */
  66. kEvenOdd_FillType,
  67. };
  68. static const GrUserStencilSettings& GetStencilPassSettings(FillType);
  69. /**
  70. * Creates a new gpu path, based on the specified path and stroke and returns it.
  71. *
  72. * @param SkPath the geometry.
  73. * @param GrStyle the style applied to the path. Styles with non-dash path effects are not
  74. * allowed.
  75. * @return a new GPU path object.
  76. */
  77. virtual sk_sp<GrPath> createPath(const SkPath&, const GrStyle&) = 0;
  78. /** None of these params are optional, pointers used just to avoid making copies. */
  79. struct StencilPathArgs {
  80. StencilPathArgs(bool useHWAA,
  81. GrRenderTargetProxy* proxy,
  82. const SkMatrix* viewMatrix,
  83. const GrScissorState* scissor,
  84. const GrStencilSettings* stencil)
  85. : fUseHWAA(useHWAA)
  86. , fProxy(proxy)
  87. , fViewMatrix(viewMatrix)
  88. , fScissor(scissor)
  89. , fStencil(stencil) {
  90. }
  91. bool fUseHWAA;
  92. GrRenderTargetProxy* fProxy;
  93. const SkMatrix* fViewMatrix;
  94. const GrScissorState* fScissor;
  95. const GrStencilSettings* fStencil;
  96. };
  97. void stencilPath(const StencilPathArgs& args, const GrPath* path);
  98. void drawPath(GrRenderTarget*, GrSurfaceOrigin,
  99. const GrPrimitiveProcessor& primProc,
  100. const GrPipeline& pipeline,
  101. const GrPipeline::FixedDynamicState&,
  102. const GrStencilSettings& stencilPassSettings, // Cover pass settings in pipeline.
  103. const GrPath* path);
  104. protected:
  105. GrPathRendering(GrGpu* gpu) : fGpu(gpu) { }
  106. virtual void onStencilPath(const StencilPathArgs&, const GrPath*) = 0;
  107. virtual void onDrawPath(GrRenderTarget*, GrSurfaceOrigin,
  108. const GrPrimitiveProcessor&,
  109. const GrPipeline&,
  110. const GrPipeline::FixedDynamicState&,
  111. const GrStencilSettings&,
  112. const GrPath*) = 0;
  113. GrGpu* fGpu;
  114. private:
  115. GrPathRendering& operator=(const GrPathRendering&);
  116. };
  117. #endif