• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #include "src/image/SkSurface_Base.h"
12 
13 #include "src/gpu/graphite/TextureProxyView.h"
14 
15 namespace skgpu::graphite {
16 
17 class Context;
18 class Device;
19 class Recorder;
20 class TextureProxy;
21 
22 class Surface final : public SkSurface_Base {
23 public:
24     static sk_sp<SkSurface> MakeGraphite(Recorder* recorder,
25                                          const SkImageInfo& info,
26                                          skgpu::Budgeted budgeted,
27                                          Mipmapped = Mipmapped::kNo,
28                                          const SkSurfaceProps* props = nullptr);
29 
30     Surface(sk_sp<Device>);
31     ~Surface() override;
32 
33     SkImageInfo imageInfo() const override;
34 
35     Recorder* onGetRecorder() override;
36     SkCanvas* onNewCanvas() override;
37     sk_sp<SkSurface> onNewSurface(const SkImageInfo&) override;
38     sk_sp<SkImage> onNewImageSnapshot(const SkIRect* subset) override;
39     sk_sp<SkImage> onAsImage() override;
40     sk_sp<SkImage> onMakeImageCopy(const SkIRect* subset, Mipmapped) override;
41     void onWritePixels(const SkPixmap&, int x, int y) override;
42     void onAsyncRescaleAndReadPixels(const SkImageInfo& info,
43                                      SkIRect srcRect,
44                                      RescaleGamma rescaleGamma,
45                                      RescaleMode rescaleMode,
46                                      ReadPixelsCallback callback,
47                                      ReadPixelsContext context) override;
48     void onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
49                                            sk_sp<SkColorSpace> dstColorSpace,
50                                            SkIRect srcRect,
51                                            SkISize dstSize,
52                                            RescaleGamma rescaleGamma,
53                                            RescaleMode,
54                                            ReadPixelsCallback callback,
55                                            ReadPixelsContext context) override;
56     bool onCopyOnWrite(ContentChangeMode) override;
57     sk_sp<const SkCapabilities> onCapabilities() override;
isGraphiteBacked()58     bool isGraphiteBacked() const override { return true; }
59 
60     TextureProxyView readSurfaceView() const;
61 
62 #if GRAPHITE_TEST_UTILS && defined(SK_GANESH)
63     // TODO: The long-term for the public API around surfaces and flushing/submitting will likely
64     // be replaced with explicit control over Recorders and submitting Recordings to the Context
65     // directly. For now, internal tools often rely on surface/canvas flushing to control what's
66     // being timed (nanobench or viewer's stats layer), so we flush any pending draws to a DrawPass.
67     // While this won't measure actual conversion of the task list to backend command buffers, that
68     // should be fairly negligible since most of the work is handled in DrawPass::Make().
69     // Additionally flushing pending work here ensures we don't batch across or clear prior recorded
70     // work when looping in a benchmark, as the controlling code expects.
71     GrSemaphoresSubmitted onFlush(BackendSurfaceAccess access,
72                                   const GrFlushInfo&,
73                                   const skgpu::MutableTextureState*) override;
74 #endif
75 
76     TextureProxy* backingTextureProxy();
77 
78 private:
79     sk_sp<Device> fDevice;
80 };
81 
82 } // namespace skgpu::graphite
83 
84 #endif // skgpu_graphite_Surface_Graphite_DEFINED
85