Flutter Engine
The Flutter Engine
Surface_Graphite.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 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_Surface_Graphite_DEFINED
9#define skgpu_graphite_Surface_Graphite_DEFINED
10
12
17
18namespace skgpu::graphite {
19
20class Context;
21class Device;
22class Image;
23class Recorder;
24class TextureProxy;
25
26class Surface final : public SkSurface_Base {
27public:
28 // Convenience factory to create a Device, instantiate its target proxy and return as a Surface.
30 const SkImageInfo& info,
31 std::string_view label,
32 Budgeted budgeted,
33 Mipmapped mipmapped = Mipmapped::kNo,
35 const SkSurfaceProps* props = nullptr) {
36 return Make(recorder, info, std::move(label), budgeted, mipmapped, backingFit, props,
37 LoadOp::kClear, /*registerWithRecorder=*/true);
38 }
39 // Make a surface that is not registered with the provided recorder. This surface should be
40 // short-lived and it must be flushed manually for its draw commands to be recorded. Most
41 // scratch surfaces will be budgeted, but if the underlying texture is being returned as a
42 // client-owned image, that may not be the case.
44 const SkImageInfo& info,
45 std::string_view label,
46 Budgeted budgeted = Budgeted::kYes,
47 Mipmapped mipmapped = Mipmapped::kNo,
49 return Make(recorder, info, std::move(label), budgeted, mipmapped, backingFit,
50 /*props=*/nullptr, LoadOp::kDiscard, /*registerWithRecorder=*/false);
51 }
52
54 ~Surface() override;
55
56 // From SkSurface.h
57 SkImageInfo imageInfo() const override;
58
59 // From SkSurface_Base.h
61
62 Recorder* onGetRecorder() const override;
63 SkCanvas* onNewCanvas() override;
65 sk_sp<SkImage> onNewImageSnapshot(const SkIRect* subset) override;
66 void onWritePixels(const SkPixmap&, int x, int y) override;
68 SkIRect srcRect,
69 RescaleGamma rescaleGamma,
70 RescaleMode rescaleMode,
72 ReadPixelsContext context) override;
74 bool readAlpha,
75 sk_sp<SkColorSpace> dstColorSpace,
76 SkIRect srcRect,
77 SkISize dstSize,
78 RescaleGamma rescaleGamma,
81 ReadPixelsContext context) override;
82 bool onCopyOnWrite(ContentChangeMode) override;
84
86 sk_sp<Image> asImage() const;
87 sk_sp<Image> makeImageCopy(const SkIRect* subset, Mipmapped) const;
89
90private:
91 // Regular and scratch surfaces differ by initial clear and if they are registered or not,
92 // otherwise are constructed the same.
94 const SkImageInfo&,
95 std::string_view label,
99 const SkSurfaceProps* props,
100 LoadOp initialLoadOp,
101 bool registerWithRecorder);
102
103 sk_sp<Device> fDevice;
104 sk_sp<Image> fImageView; // the image object returned by asImage()
105
106 friend void Flush(SkSurface*);
107};
108
109// TODO: The long-term for the public API around surfaces and flushing/submitting will likely
110// be replaced with explicit control over Recorders and submitting Recordings to the Context
111// directly. For now, internal tools often rely on surface/canvas flushing to control what's
112// being timed (nanobench or viewer's stats layer), so we flush any pending draws to a DrawPass.
113// While this won't measure actual conversion of the task list to backend command buffers, that
114// should be fairly negligible since most of the work is handled in DrawPass::Make().
115// Additionally flushing pending work here ensures we don't batch across or clear prior recorded
116// work when looping in a benchmark, as the controlling code expects.
118void Flush(SkSurface* surface);
119
120} // namespace skgpu::graphite
121
122#endif // skgpu_graphite_Surface_Graphite_DEFINED
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
SkBackingFit
Definition: SkBackingFit.h:16
SkYUVColorSpace
Definition: SkImageInfo.h:68
RescaleMode
Definition: SkImage.h:587
RescaleGamma
Definition: SkImage.h:585
ContentChangeMode
Definition: SkSurface.h:203
const SkSurfaceProps & props() const
Definition: SkSurface.h:604
skgpu::graphite::Recorder * recorder() const
Definition: SkSurface.cpp:232
void onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace, bool readAlpha, sk_sp< SkColorSpace > dstColorSpace, SkIRect srcRect, SkISize dstSize, RescaleGamma rescaleGamma, RescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) override
static sk_sp< Surface > Make(Recorder *recorder, const SkImageInfo &info, std::string_view label, Budgeted budgeted, Mipmapped mipmapped=Mipmapped::kNo, SkBackingFit backingFit=SkBackingFit::kExact, const SkSurfaceProps *props=nullptr)
void onAsyncRescaleAndReadPixels(const SkImageInfo &info, SkIRect srcRect, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) override
SkCanvas * onNewCanvas() override
sk_sp< Image > makeImageCopy(const SkIRect *subset, Mipmapped) const
sk_sp< SkSurface > onNewSurface(const SkImageInfo &) override
sk_sp< Image > asImage() const
SkSurface_Base::Type type() const override
Recorder * onGetRecorder() const override
static sk_sp< Surface > MakeScratch(Recorder *recorder, const SkImageInfo &info, std::string_view label, Budgeted budgeted=Budgeted::kYes, Mipmapped mipmapped=Mipmapped::kNo, SkBackingFit backingFit=SkBackingFit::kApprox)
sk_sp< SkImage > onNewImageSnapshot(const SkIRect *subset) override
bool onCopyOnWrite(ContentChangeMode) override
void onWritePixels(const SkPixmap &, int x, int y) override
SkImageInfo imageInfo() const override
TextureProxyView readSurfaceView() const
sk_sp< const SkCapabilities > onCapabilities() override
friend void Flush(SkSurface *)
Definition: GpuTools.h:25
TextureProxy * backingTextureProxy() const
VkSurfaceKHR surface
Definition: main.cc:49
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
SkImage::ReadPixelsContext ReadPixelsContext
Definition: Device.cpp:81
SkImage::ReadPixelsCallback ReadPixelsCallback
Definition: Device.cpp:80
double y
double x
CanvasImage Image
Definition: dart_ui.cc:55
void Flush(sk_sp< SkSurface > surface)
Budgeted
Definition: GpuTypes.h:35
Mipmapped
Definition: GpuTypes.h:53
Definition: SkRect.h:32
Definition: SkSize.h:16