blob: 6bcdf5ee6aba9f42690a21aa08d3895c2d7efa88 [file] [log] [blame]
Robert Phillips09b2bcb2021-05-12 11:56:47 -04001/*
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
Robert Phillipscc44feb2021-07-06 12:21:37 -04008#ifndef BaseDevice_DEFINED
9#define BaseDevice_DEFINED
Robert Phillipsc2132ea2021-05-17 14:32:29 -040010
Robert Phillipsdca342a2021-06-02 15:48:59 -040011#include "include/core/SkImage.h"
Robert Phillipscc44feb2021-07-06 12:21:37 -040012#include "include/private/GrTypesPriv.h"
Michael Ludwige1d00402021-08-09 12:21:52 -040013#include "src/core/SkDevice.h"
Robert Phillipscc44feb2021-07-06 12:21:37 -040014
Robert Phillips04f22ea2021-07-22 15:11:03 -040015class GrRenderTargetProxy;
Robert Phillipscc44feb2021-07-06 12:21:37 -040016class GrSurfaceProxyView;
Robert Phillipsdca342a2021-06-02 15:48:59 -040017
Robert Phillipscc44feb2021-07-06 12:21:37 -040018namespace skgpu {
19
Robert Phillips778d6e02021-09-13 14:51:42 -040020class SurfaceContext;
Robert Phillips643f4812021-08-11 09:31:00 -040021class SurfaceFillContext;
22#if SK_GPU_V1
23namespace v1 { class SurfaceDrawContext; }
24#endif // SK_GPU_V1
25
Robert Phillipsb42cea92021-09-16 16:31:59 -040026/*
27 * The most important thing to remember about this class hierarchy is there is no skgpu::SDC
28 * base class so the v1 and v2 Devices privately hold their own version of the SDC. The best
29 * the BaseDevice can do is to return the SDC-variant as a generic SFC.
30 *
31 * skgpu::BaseDevice
32 * / \
33 * v1::Device v2::Device
34 * - v1::SDC - v2::SDC
35 */
Michael Ludwige1d00402021-08-09 12:21:52 -040036class BaseDevice : public SkBaseDevice {
Robert Phillips09b2bcb2021-05-12 11:56:47 -040037public:
Robert Phillipsf6c564e2021-09-07 16:10:34 -040038 enum class InitContents {
39 kClear,
40 kUninit
Robert Phillips54c878e2021-05-20 13:22:52 -040041 };
42
Robert Phillips04f22ea2021-07-22 15:11:03 -040043 BaseDevice(sk_sp<GrRecordingContext>, const SkImageInfo&, const SkSurfaceProps&);
Robert Phillips09b2bcb2021-05-12 11:56:47 -040044
Robert Phillipsb42cea92021-09-16 16:31:59 -040045 GrSurfaceProxyView readSurfaceView();
Robert Phillips09b2bcb2021-05-12 11:56:47 -040046
Robert Phillips04f22ea2021-07-22 15:11:03 -040047 BaseDevice* asGpuDevice() override { return this; }
48
49#if SK_GPU_V1
Robert Phillips643f4812021-08-11 09:31:00 -040050 virtual v1::SurfaceDrawContext* surfaceDrawContext() { return nullptr; }
Robert Phillips04f22ea2021-07-22 15:11:03 -040051#endif
52
Robert Phillips643f4812021-08-11 09:31:00 -040053 virtual SurfaceFillContext* surfaceFillContext() = 0;
Robert Phillips04f22ea2021-07-22 15:11:03 -040054 GrRenderTargetProxy* targetProxy();
55 GrRecordingContext* recordingContext() const { return fContext.get(); }
Robert Phillips42754922021-06-01 13:12:51 -040056
Robert Phillips0095fcb2021-05-24 14:34:01 -040057 virtual bool wait(int numSemaphores,
58 const GrBackendSemaphore* waitSemaphores,
59 bool deleteSemaphoresAfterWait) = 0;
Robert Phillipsdca342a2021-06-02 15:48:59 -040060 virtual void discard() = 0;
Robert Phillips0095fcb2021-05-24 14:34:01 -040061
Robert Phillips1e3121a2021-06-02 09:34:57 -040062 virtual bool replaceBackingProxy(SkSurface::ContentChangeMode,
63 sk_sp<GrRenderTargetProxy>,
64 GrColorType,
65 sk_sp<SkColorSpace>,
66 GrSurfaceOrigin,
67 const SkSurfaceProps&) = 0;
68 bool replaceBackingProxy(SkSurface::ContentChangeMode);
69
Robert Phillipsdca342a2021-06-02 15:48:59 -040070 using RescaleGamma = SkImage::RescaleGamma;
71 using RescaleMode = SkImage::RescaleMode;
72 using ReadPixelsCallback = SkImage::ReadPixelsCallback;
73 using ReadPixelsContext = SkImage::ReadPixelsContext;
74
75 virtual void asyncRescaleAndReadPixels(const SkImageInfo& info,
76 const SkIRect& srcRect,
77 RescaleGamma rescaleGamma,
78 RescaleMode rescaleMode,
79 ReadPixelsCallback callback,
80 ReadPixelsContext context) = 0;
81
82 virtual void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
83 sk_sp<SkColorSpace> dstColorSpace,
84 const SkIRect& srcRect,
85 SkISize dstSize,
86 RescaleGamma rescaleGamma,
87 RescaleMode,
88 ReadPixelsCallback callback,
89 ReadPixelsContext context) = 0;
90
Robert Phillips09b2bcb2021-05-12 11:56:47 -040091protected:
Robert Phillipsf6c564e2021-09-07 16:10:34 -040092 enum class DeviceFlags {
93 kNone = 0,
94 kNeedClear = 1 << 0, //!< Surface requires an initial clear
95 kIsOpaque = 1 << 1, //!< Hint from client that rendering to this device will be
96 // opaque even if the config supports alpha.
97 };
98 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(DeviceFlags);
99
100 static bool CheckAlphaTypeAndGetFlags(SkAlphaType, InitContents, DeviceFlags*);
Robert Phillips778d6e02021-09-13 14:51:42 -0400101 static SkImageInfo MakeInfo(SurfaceContext*, DeviceFlags);
Robert Phillipsf6c564e2021-09-07 16:10:34 -0400102
Robert Phillips42754922021-06-01 13:12:51 -0400103 sk_sp<GrRecordingContext> fContext;
Robert Phillips09b2bcb2021-05-12 11:56:47 -0400104
105private:
Michael Ludwige1d00402021-08-09 12:21:52 -0400106 using INHERITED = SkBaseDevice;
Robert Phillips09b2bcb2021-05-12 11:56:47 -0400107};
108
Robert Phillipsf6c564e2021-09-07 16:10:34 -0400109GR_MAKE_BITFIELD_CLASS_OPS(BaseDevice::DeviceFlags)
110
Robert Phillipscc44feb2021-07-06 12:21:37 -0400111} // namespace skgpu
112
Robert Phillipscc44feb2021-07-06 12:21:37 -0400113#endif // BaseDevice_DEFINED