GrDefaultGeoProcFactory.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 GrDefaultGeoProcFactory_DEFINED
  8. #define GrDefaultGeoProcFactory_DEFINED
  9. #include "src/gpu/GrColorSpaceXform.h"
  10. #include "src/gpu/GrGeometryProcessor.h"
  11. #include "src/gpu/GrShaderCaps.h"
  12. /*
  13. * A factory for creating default Geometry Processors which simply multiply position by the uniform
  14. * view matrix and wire through color, coverage, UV coords if requested.
  15. */
  16. namespace GrDefaultGeoProcFactory {
  17. struct Color {
  18. enum Type {
  19. kPremulGrColorUniform_Type,
  20. kPremulGrColorAttribute_Type,
  21. kPremulWideColorAttribute_Type,
  22. kUnpremulSkColorAttribute_Type,
  23. };
  24. explicit Color(const SkPMColor4f& color)
  25. : fType(kPremulGrColorUniform_Type)
  26. , fColor(color)
  27. , fColorSpaceXform(nullptr) {}
  28. Color(Type type)
  29. : fType(type)
  30. , fColor(SK_PMColor4fILLEGAL)
  31. , fColorSpaceXform(nullptr) {
  32. SkASSERT(type != kPremulGrColorUniform_Type);
  33. }
  34. Type fType;
  35. SkPMColor4f fColor;
  36. // This only applies to SkColor. Any GrColors are assumed to have been color converted
  37. // during paint conversion.
  38. sk_sp<GrColorSpaceXform> fColorSpaceXform;
  39. };
  40. struct Coverage {
  41. enum Type {
  42. kSolid_Type,
  43. kUniform_Type,
  44. kAttribute_Type,
  45. kAttributeTweakAlpha_Type,
  46. };
  47. explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {}
  48. Coverage(Type type) : fType(type), fCoverage(0xff) {
  49. SkASSERT(type != kUniform_Type);
  50. }
  51. Type fType;
  52. uint8_t fCoverage;
  53. };
  54. struct LocalCoords {
  55. enum Type {
  56. kUnused_Type,
  57. kUsePosition_Type,
  58. kHasExplicit_Type,
  59. kHasTransformed_Type,
  60. };
  61. LocalCoords(Type type) : fType(type), fMatrix(nullptr) {}
  62. LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) {
  63. SkASSERT(kUnused_Type != type);
  64. }
  65. bool hasLocalMatrix() const { return nullptr != fMatrix; }
  66. Type fType;
  67. const SkMatrix* fMatrix;
  68. };
  69. sk_sp<GrGeometryProcessor> Make(const GrShaderCaps*,
  70. const Color&,
  71. const Coverage&,
  72. const LocalCoords&,
  73. const SkMatrix& viewMatrix);
  74. /*
  75. * Use this factory to create a GrGeometryProcessor that expects a device space vertex position
  76. * attribute. The view matrix must still be provided to compute correctly transformed
  77. * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible.
  78. */
  79. sk_sp<GrGeometryProcessor> MakeForDeviceSpace(const GrShaderCaps*,
  80. const Color&,
  81. const Coverage&,
  82. const LocalCoords&,
  83. const SkMatrix& viewMatrix);
  84. };
  85. #endif