Debian Codegraph @

include/core/SkCPURecorder.h

raw
1 /*
2 * Copyright 2025 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 skcpu_Recorder_DEFINED
9 #define skcpu_Recorder_DEFINED
10
11 #include "include/core/SkRecorder.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/private/base/SkAPI.h"
14
15 class SkCanvas;
16 class SkSurface;
17 class SkSurfaceProps;
18 struct SkImageInfo;
19
20 #include <cstddef>
21
22 namespace skcpu {
23
24 class SK_API Recorder : public SkRecorder {
25 public:
26 /** Returns a non-null global context. Can be used as a means of transitioning onto
27 * new APIs when a skcpu::Context/Recorder has not been piped down into the code paths
28 */
29 static Recorder* TODO();
30
31 SkRecorder::Type type() const final { return SkRecorder::Type::kCPU; }
32 skcpu::Recorder* cpuRecorder() final { return this; }
33
34 /** Allocates a bitmap-backed SkSurface. SkCanvas returned by SkSurface draws directly into
35 * those allocated pixels, which are zeroed before use. Pixel memory size is imageInfo.height()
36 * times imageInfo.minRowBytes() or rowBytes, if provided and non-zero.
37 *
38 * Pixel memory is deleted when SkSurface is deleted.
39 *
40 * Validity constraints include:
41 * - info dimensions are greater than zero;
42 * - info contains SkColorType and SkAlphaType supported by raster surface.
43 *
44 * @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
45 * of raster surface; width and height must be greater than zero
46 * @param rowBytes interval from one SkSurface row to the next.
47 * @param props LCD striping orientation and setting for device independent fonts;
48 * may be nullptr
49 * @return SkSurface if parameters are valid and memory was allocated, else nullptr.
50 */
51 sk_sp<SkSurface> makeBitmapSurface(const SkImageInfo& imageInfo,
52 size_t rowBytes,
53 const SkSurfaceProps* surfaceProps);
54 sk_sp<SkSurface> makeBitmapSurface(const SkImageInfo& imageInfo,
55 const SkSurfaceProps* surfaceProps = nullptr);
56
57 private:
58 // TODO (b/412351769): Implement this so we can capture from a CPU Recorder.
59 SkCanvas* makeCaptureCanvas(SkCanvas*) final { return nullptr; }
60 void createCaptureBreakpoint(SkSurface*) final {}
61 };
62
63 inline Recorder* AsRecorder(SkRecorder* recorder) {
64 if (!recorder) {
65 return nullptr;
66 }
67 if (recorder->type() != SkRecorder::Type::kCPU) {
68 return nullptr;
69 }
70 return static_cast<Recorder*>(recorder);
71 }
72
73 } // namespace skcpu
74
75 #endif