GrSkSLFPFactoryCache.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright 2018 Google LLC
  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 GrSkSLFPFactoryCache_DEFINED
  8. #define GrSkSLFPFactoryCache_DEFINED
  9. #include "include/core/SkRefCnt.h"
  10. #include <vector>
  11. class GrSkSLFPFactory;
  12. // This is a cache used by GrSkSLFP to retain GrSkSLFPFactory instances, so we don't have to
  13. // re-process the SkSL source code every time we create a GrSkSLFP instance.
  14. // For thread safety, it is important that GrSkSLFP only interact with the cache from methods that
  15. // are only called from within the rendering thread, like onCreateGLSLInstance and
  16. // onGetGLSLProcessorKey.
  17. class GrSkSLFPFactoryCache : public SkNVRefCnt<GrSkSLFPFactoryCache> {
  18. public:
  19. // Returns a factory by its numeric index, or null if no such factory exists. Indices are
  20. // allocated by GrSkSLFP::NewIndex().
  21. sk_sp<GrSkSLFPFactory> get(int index);
  22. // Stores a new factory with the given index.
  23. void set(int index, sk_sp<GrSkSLFPFactory> factory);
  24. ~GrSkSLFPFactoryCache();
  25. private:
  26. std::vector<GrSkSLFPFactory*> fFactories;
  27. };
  28. #endif