SkLocalMatrixShader.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 SkLocalMatrixShader_DEFINED
  8. #define SkLocalMatrixShader_DEFINED
  9. #include "src/core/SkReadBuffer.h"
  10. #include "src/core/SkWriteBuffer.h"
  11. #include "src/shaders/SkShaderBase.h"
  12. class GrFragmentProcessor;
  13. class SkArenaAlloc;
  14. class SkLocalMatrixShader final : public SkShaderBase {
  15. public:
  16. SkLocalMatrixShader(sk_sp<SkShader> proxy, const SkMatrix& localMatrix)
  17. : INHERITED(&localMatrix)
  18. , fProxyShader(std::move(proxy))
  19. {}
  20. GradientType asAGradient(GradientInfo* info) const override {
  21. return fProxyShader->asAGradient(info);
  22. }
  23. #if SK_SUPPORT_GPU
  24. std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
  25. #endif
  26. sk_sp<SkShader> makeAsALocalMatrixShader(SkMatrix* localMatrix) const override {
  27. if (localMatrix) {
  28. *localMatrix = this->getLocalMatrix();
  29. }
  30. return fProxyShader;
  31. }
  32. SkPicture* isAPicture(SkMatrix*, SkTileMode[2], SkRect* tile) const override;
  33. protected:
  34. void flatten(SkWriteBuffer&) const override;
  35. #ifdef SK_ENABLE_LEGACY_SHADERCONTEXT
  36. Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override;
  37. #endif
  38. SkImage* onIsAImage(SkMatrix* matrix, SkTileMode* mode) const override;
  39. bool onAppendStages(const SkStageRec&) const override;
  40. private:
  41. SK_FLATTENABLE_HOOKS(SkLocalMatrixShader)
  42. sk_sp<SkShader> fProxyShader;
  43. typedef SkShaderBase INHERITED;
  44. };
  45. #endif