SkNormalMapSource.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2016 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 SkNormalMapSource_DEFINED
  8. #define SkNormalMapSource_DEFINED
  9. #include "src/core/SkNormalSource.h"
  10. class SkNormalMapSourceImpl : public SkNormalSource {
  11. public:
  12. SkNormalMapSourceImpl(sk_sp<SkShader> mapShader, const SkMatrix& invCTM)
  13. : fMapShader(std::move(mapShader))
  14. , fInvCTM(invCTM) {}
  15. #if SK_SUPPORT_GPU
  16. std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs& args) const override;
  17. #endif
  18. SkNormalSource::Provider* asProvider(const SkShaderBase::ContextRec& rec,
  19. SkArenaAlloc* alloc) const override;
  20. protected:
  21. void flatten(SkWriteBuffer& buf) const override;
  22. bool computeNormTotalInverse(const SkShaderBase::ContextRec& rec,
  23. SkMatrix* normTotalInverse) const;
  24. private:
  25. SK_FLATTENABLE_HOOKS(SkNormalMapSourceImpl)
  26. class Provider : public SkNormalSource::Provider {
  27. public:
  28. Provider(const SkNormalMapSourceImpl& source, SkShaderBase::Context* mapContext);
  29. void fillScanLine(int x, int y, SkPoint3 output[], int count) const override;
  30. private:
  31. const SkNormalMapSourceImpl& fSource;
  32. SkShaderBase::Context* fMapContext;
  33. typedef SkNormalSource::Provider INHERITED;
  34. };
  35. sk_sp<SkShader> fMapShader;
  36. SkMatrix fInvCTM; // Inverse of the canvas total matrix, used for rotating normals.
  37. friend class SkNormalSource;
  38. typedef SkNormalSource INHERITED;
  39. };
  40. #endif