GrFPArgs.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #ifndef GrFPArgs_DEFINED
  8. #define GrFPArgs_DEFINED
  9. #include "include/core/SkFilterQuality.h"
  10. #include "include/core/SkMatrix.h"
  11. class GrColorSpaceInfo;
  12. class GrRecordingContext;
  13. struct GrFPArgs {
  14. GrFPArgs(GrRecordingContext* context,
  15. const SkMatrix* viewMatrix,
  16. SkFilterQuality filterQuality,
  17. const GrColorSpaceInfo* dstColorSpaceInfo)
  18. : fContext(context)
  19. , fViewMatrix(viewMatrix)
  20. , fFilterQuality(filterQuality)
  21. , fDstColorSpaceInfo(dstColorSpaceInfo) {
  22. SkASSERT(fContext);
  23. SkASSERT(fViewMatrix);
  24. }
  25. class WithPreLocalMatrix;
  26. class WithPostLocalMatrix;
  27. GrRecordingContext* fContext;
  28. const SkMatrix* fViewMatrix;
  29. // We track both pre and post local matrix adjustments. For a given FP:
  30. //
  31. // total_local_matrix = postLocalMatrix x FP_localMatrix x preLocalMatrix
  32. //
  33. // Use the helpers above to create pre/post GrFPArgs wrappers.
  34. //
  35. const SkMatrix* fPreLocalMatrix = nullptr;
  36. const SkMatrix* fPostLocalMatrix = nullptr;
  37. // Make this SkAlphaType?
  38. bool fInputColorIsOpaque = false;
  39. SkFilterQuality fFilterQuality;
  40. const GrColorSpaceInfo* fDstColorSpaceInfo;
  41. };
  42. class GrFPArgs::WithPreLocalMatrix final : public GrFPArgs {
  43. public:
  44. WithPreLocalMatrix(const GrFPArgs& args, const SkMatrix& lm) : INHERITED(args) {
  45. if (!lm.isIdentity()) {
  46. if (fPreLocalMatrix) {
  47. fStorage.setConcat(lm, *fPreLocalMatrix);
  48. fPreLocalMatrix = fStorage.isIdentity() ? nullptr : &fStorage;
  49. } else {
  50. fPreLocalMatrix = &lm;
  51. }
  52. }
  53. }
  54. private:
  55. WithPreLocalMatrix(const WithPreLocalMatrix&) = delete;
  56. WithPreLocalMatrix& operator=(const WithPreLocalMatrix&) = delete;
  57. SkMatrix fStorage;
  58. using INHERITED = GrFPArgs;
  59. };
  60. class GrFPArgs::WithPostLocalMatrix final : public GrFPArgs {
  61. public:
  62. WithPostLocalMatrix(const GrFPArgs& args, const SkMatrix& lm) : INHERITED(args) {
  63. if (!lm.isIdentity()) {
  64. if (fPostLocalMatrix) {
  65. fStorage.setConcat(*fPostLocalMatrix, lm);
  66. fPostLocalMatrix = fStorage.isIdentity() ? nullptr : &fStorage;
  67. } else {
  68. fPostLocalMatrix = &lm;
  69. }
  70. }
  71. }
  72. private:
  73. WithPostLocalMatrix(const WithPostLocalMatrix&) = delete;
  74. WithPostLocalMatrix& operator=(const WithPostLocalMatrix&) = delete;
  75. SkMatrix fStorage;
  76. using INHERITED = GrFPArgs;
  77. };
  78. #endif