xref: /aosp_15_r20/external/skia/src/image/SkImage_Picture.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2023 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 SkImage_Picture_DEFINED
8 #define SkImage_Picture_DEFINED
9 
10 #include "include/core/SkRefCnt.h"
11 #include "include/core/SkTiledImageUtils.h"
12 #include "src/image/SkImage_Base.h"
13 #include "src/image/SkImage_Lazy.h"
14 
15 #include <cstdint>
16 
17 class GrDirectContext;
18 class SkCanvas;
19 class SkColorSpace;
20 class SkImage;
21 class SkMatrix;
22 class SkPaint;
23 class SkPicture;
24 class SkSurfaceProps;
25 struct SkIRect;
26 struct SkISize;
27 
28 namespace SkImages { enum class BitDepth; }
29 namespace skgpu::graphite { class Recorder; }
30 
31 class SkImage_Picture : public SkImage_Lazy {
32 public:
33     static sk_sp<SkImage> Make(sk_sp<SkPicture> picture, const SkISize& dimensions,
34                                const SkMatrix* matrix, const SkPaint* paint,
35                                SkImages::BitDepth bitDepth, sk_sp<SkColorSpace> colorSpace,
36                                SkSurfaceProps props);
37 
SkImage_Picture(Validator * validator)38     SkImage_Picture(Validator* validator) : SkImage_Lazy(validator) {}
39 
type()40     SkImage_Base::Type type() const override { return SkImage_Base::Type::kLazyPicture; }
41 
42     // This is thread safe. It is a const field set in the constructor.
43     const SkSurfaceProps* props() const;
44 
45     // Call drawPicture on the provided canvas taking care of any required mutex locking.
46     void replay(SkCanvas*) const;
47 
48     sk_sp<SkImage> onMakeSubset(GrDirectContext*, const SkIRect&) const override;
49     sk_sp<SkImage> onMakeSubset(skgpu::graphite::Recorder*,
50                                 const SkIRect&,
51                                 RequiredProperties) const override;
52 
53     // If possible, extract key data based on the underlying drawPicture-call's parameters.
54     // Takes care of any required mutex locking.
55     bool getImageKeyValues(uint32_t keyValues[SkTiledImageUtils::kNumImageKeyValues]) const;
56 };
57 
58 #endif
59