Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 Budgeted budgeted,
32 Mipmapped mipmapped = Mipmapped::kNo,
34 const SkSurfaceProps* props = nullptr) {
35 return Make(recorder, info, budgeted, mipmapped, backingFit, props,
36 LoadOp::kClear, /*registerWithRecorder=*/true);
37 }
38 // Make a surface that is not registered with the provided recorder. This surface should be
39 // short-lived and it must be flushed manually for its draw commands to be recorded. Most
40 // scratch surfaces will be budgeted, but if the underlying texture is being returned as a
41 // client-owned image, that may not be the case.
43 const SkImageInfo& info,
44 Budgeted budgeted = Budgeted::kYes,
45 Mipmapped mipmapped = Mipmapped::kNo,
47 return Make(recorder, info, budgeted, mipmapped, backingFit,
48 /*props=*/nullptr, LoadOp::kDiscard, /*registerWithRecorder=*/false);
49 }
50
52 ~Surface() override;
53
54 // From SkSurface.h
55 SkImageInfo imageInfo() const override;
56
57 // From SkSurface_Base.h
59
60 Recorder* onGetRecorder() const override;
61 SkCanvas* onNewCanvas() override;
63 sk_sp<SkImage> onNewImageSnapshot(const SkIRect* subset) override;
64 void onWritePixels(const SkPixmap&, int x, int y) override;
66 SkIRect srcRect,
67 RescaleGamma rescaleGamma,
68 RescaleMode rescaleMode,
70 ReadPixelsContext context) override;
72 bool readAlpha,
73 sk_sp<SkColorSpace> dstColorSpace,
74 SkIRect srcRect,
75 SkISize dstSize,
76 RescaleGamma rescaleGamma,
79 ReadPixelsContext context) override;
80 bool onCopyOnWrite(ContentChangeMode) override;
82
84 sk_sp<Image> asImage() const;
85 sk_sp<Image> makeImageCopy(const SkIRect* subset, Mipmapped) const;
87
88private:
89 // Regular and scratch surfaces differ by initial clear and if they are registered or not,
90 // otherwise are constructed the same.
92 const SkImageInfo&,
96 const SkSurfaceProps* props,
97 LoadOp initialLoadOp,
98 bool registerWithRecorder);
99
100 sk_sp<Device> fDevice;
101 sk_sp<Image> fImageView; // the image object returned by asImage()
102
103 friend void Flush(SkSurface*);
104};
105
106// TODO: The long-term for the public API around surfaces and flushing/submitting will likely
107// be replaced with explicit control over Recorders and submitting Recordings to the Context
108// directly. For now, internal tools often rely on surface/canvas flushing to control what's
109// being timed (nanobench or viewer's stats layer), so we flush any pending draws to a DrawPass.
110// While this won't measure actual conversion of the task list to backend command buffers, that
111// should be fairly negligible since most of the work is handled in DrawPass::Make().
112// Additionally flushing pending work here ensures we don't batch across or clear prior recorded
113// work when looping in a benchmark, as the controlling code expects.
115void Flush(SkSurface* surface);
116
117} // namespace skgpu::graphite
118
119#endif // skgpu_graphite_Surface_Graphite_DEFINED
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
SkBackingFit
SkYUVColorSpace
Definition SkImageInfo.h:68
RescaleMode
Definition SkImage.h:587
RescaleGamma
Definition SkImage.h:585
const SkSurfaceProps & props() const
Definition SkSurface.h:604
skgpu::graphite::Recorder * recorder() const
void onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace, bool readAlpha, sk_sp< SkColorSpace > dstColorSpace, SkIRect srcRect, SkISize dstSize, RescaleGamma rescaleGamma, RescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) override
void onAsyncRescaleAndReadPixels(const SkImageInfo &info, SkIRect srcRect, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) override
SkCanvas * onNewCanvas() override
static sk_sp< Surface > Make(Recorder *recorder, const SkImageInfo &info, Budgeted budgeted, Mipmapped mipmapped=Mipmapped::kNo, SkBackingFit backingFit=SkBackingFit::kExact, const SkSurfaceProps *props=nullptr)
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
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
static sk_sp< Surface > MakeScratch(Recorder *recorder, const SkImageInfo &info, Budgeted budgeted=Budgeted::kYes, Mipmapped mipmapped=Mipmapped::kNo, SkBackingFit backingFit=SkBackingFit::kApprox)
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