blob: 744079106c6e9d64a4fd28471cd456fc096d8e6f [file] [log] [blame]
Ethan Nicholas00543112018-07-31 09:44:36 -04001/*
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
15class 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.
Mike Klein0fb1ee92018-10-30 07:53:43 -040022class GrSkSLFPFactoryCache : public SkRefCnt {
Ethan Nicholas00543112018-07-31 09:44:36 -040023public:
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
33private:
34 std::vector<GrSkSLFPFactory*> fFactories;
35};
36
37#endif