• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 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 skgpu_graphite_ImageProvider_DEFINED
9 #define skgpu_graphite_ImageProvider_DEFINED
10 
11 #include "include/core/SkImage.h"
12 #include "include/core/SkRefCnt.h"
13 
14 namespace skgpu::graphite {
15 
16 class Recorder;
17 
18 /*
19  * This class provides a centralized location for clients to perform any caching of images
20  * they desire. Whenever Graphite encounters an SkImage which is not Graphite-backed
21  * it will call ImageProvider::findOrCreate. The client's derived version of this class should
22  * return a Graphite-backed version of the provided SkImage that meets the specified
23  * requirements.
24  *
25  * Skia requires that 'findOrCreate' return a Graphite-backed image that preserves the dimensions,
26  * number of channels and alpha type of the original image. The bit depth of the
27  * individual channels can change (e.g., 4444 -> 8888 is allowed).
28  * Wrt mipmapping, the returned image can have different mipmap settings than requested. If
29  * mipmapping was requested but not returned, the sampling level will be reduced to linear.
30  * If the requirements are not met by the returned image (modulo the flexibility wrt mipmapping)
31  * Graphite will drop the draw.
32  *
33  * Note: by default, Graphite will not perform any caching of images
34  *
35  * Threading concerns:
36  *   If the same ImageProvider is given to multiple Recorders it is up to the
37  *   client to handle any required thread synchronization. This is not limited to just
38  *   restricting access to whatever map a derived class may have but extends to ensuring
39  *   that an image created on one Recorder has had its creation work submitted before it
40  *   is used by any work submitted by another Recording. Please note, this requirement
41  *   (re the submission of creation work and image usage on different threads) is common to all
42  *   graphite SkImages and isn't unique to SkImages returned by the ImageProvider.
43  *
44  * TODO(b/240996632): add documentation re shutdown order.
45  * TODO(b/240997067): add unit tests
46  */
47 class SK_API ImageProvider : public SkRefCnt {
48 public:
49     // If the client's derived class already has a Graphite-backed image that has the same
50     // contents as 'image' and meets the requirements, then it can be returned.
51     // makeTextureImage can always be called to create an acceptable Graphite-backed image
52     // which could then be cached.
53     virtual sk_sp<SkImage> findOrCreate(Recorder* recorder,
54                                         const SkImage* image,
55                                         SkImage::RequiredImageProperties) = 0;
56 };
57 
58 } // namespace skgpu::graphite
59 
60 #endif // skgpu_graphite_ImageProvider_DEFINED
61