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