GrPathRendererChain.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2011 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 GrPathRendererChain_DEFINED
  8. #define GrPathRendererChain_DEFINED
  9. #include "src/gpu/GrPathRenderer.h"
  10. #include "include/core/SkTypes.h"
  11. #include "include/private/GrTypesPriv.h"
  12. #include "include/private/SkNoncopyable.h"
  13. #include "include/private/SkTArray.h"
  14. class GrContext;
  15. class GrCoverageCountingPathRenderer;
  16. /**
  17. * Keeps track of an ordered list of path renderers. When a path needs to be
  18. * drawn this list is scanned to find the most preferred renderer. To add your
  19. * path renderer to the list implement the GrPathRenderer::AddPathRenderers
  20. * function.
  21. */
  22. class GrPathRendererChain : public SkNoncopyable {
  23. public:
  24. struct Options {
  25. bool fAllowPathMaskCaching = false;
  26. GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kAll;
  27. };
  28. GrPathRendererChain(GrRecordingContext* context, const Options&);
  29. /** Documents how the caller plans to use a GrPathRenderer to draw a path. It affects the PR
  30. returned by getPathRenderer */
  31. enum class DrawType {
  32. kColor, // draw to the color buffer, no AA
  33. kStencil, // draw just to the stencil buffer
  34. kStencilAndColor, // draw the stencil and color buffer, no AA
  35. };
  36. /** Returns a GrPathRenderer compatible with the request if one is available. If the caller
  37. is drawing the path to the stencil buffer then stencilSupport can be used to determine
  38. whether the path can be rendered with arbitrary stencil rules or not. See comments on
  39. StencilSupport in GrPathRenderer.h. */
  40. GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
  41. DrawType drawType,
  42. GrPathRenderer::StencilSupport* stencilSupport);
  43. /** Returns a direct pointer to the coverage counting path renderer, or null if it is not in the
  44. chain. */
  45. GrCoverageCountingPathRenderer* getCoverageCountingPathRenderer() {
  46. return fCoverageCountingPathRenderer;
  47. }
  48. private:
  49. enum {
  50. kPreAllocCount = 8,
  51. };
  52. SkSTArray<kPreAllocCount, sk_sp<GrPathRenderer>> fChain;
  53. GrCoverageCountingPathRenderer* fCoverageCountingPathRenderer = nullptr;
  54. };
  55. #endif