blob: ce993438cb3e767b9dacdccb78428e4a5e026579 [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 Phillipsf3868622021-08-04 13:27:43 -040016namespace skgpu {
17 class SurfaceFillContext;
18#if SK_GPU_V1
19 namespace v1 { class SurfaceDrawContext; }
20#endif // SK_GPU_V1
21}
Robert Phillipscc44feb2021-07-06 12:21:37 -040022class GrSurfaceProxyView;
Robert Phillipsdca342a2021-06-02 15:48:59 -040023
Robert Phillipscc44feb2021-07-06 12:21:37 -040024namespace skgpu {
25
Michael Ludwige1d00402021-08-09 12:21:52 -040026class BaseDevice : public SkBaseDevice {
Robert Phillips09b2bcb2021-05-12 11:56:47 -040027public:
Robert Phillips54c878e2021-05-20 13:22:52 -040028 enum InitContents {
29 kClear_InitContents,
30 kUninit_InitContents
31 };
32
Robert Phillips04f22ea2021-07-22 15:11:03 -040033 BaseDevice(sk_sp<GrRecordingContext>, const SkImageInfo&, const SkSurfaceProps&);
Robert Phillips09b2bcb2021-05-12 11:56:47 -040034
Robert Phillipsc2132ea2021-05-17 14:32:29 -040035 virtual GrSurfaceProxyView readSurfaceView() = 0;
Robert Phillips09b2bcb2021-05-12 11:56:47 -040036
Robert Phillips04f22ea2021-07-22 15:11:03 -040037 BaseDevice* asGpuDevice() override { return this; }
38
39#if SK_GPU_V1
Robert Phillips4dca8312021-07-28 15:13:20 -040040 virtual skgpu::v1::SurfaceDrawContext* surfaceDrawContext() { return nullptr; }
Robert Phillips04f22ea2021-07-22 15:11:03 -040041#endif
42
Robert Phillipsf3868622021-08-04 13:27:43 -040043 virtual skgpu::SurfaceFillContext* surfaceFillContext() = 0;
Robert Phillips04f22ea2021-07-22 15:11:03 -040044 GrRenderTargetProxy* targetProxy();
45 GrRecordingContext* recordingContext() const { return fContext.get(); }
Robert Phillips42754922021-06-01 13:12:51 -040046
Robert Phillips0095fcb2021-05-24 14:34:01 -040047 virtual bool wait(int numSemaphores,
48 const GrBackendSemaphore* waitSemaphores,
49 bool deleteSemaphoresAfterWait) = 0;
Robert Phillipsdca342a2021-06-02 15:48:59 -040050 virtual void discard() = 0;
Robert Phillips0095fcb2021-05-24 14:34:01 -040051
Robert Phillips1e3121a2021-06-02 09:34:57 -040052 virtual bool replaceBackingProxy(SkSurface::ContentChangeMode,
53 sk_sp<GrRenderTargetProxy>,
54 GrColorType,
55 sk_sp<SkColorSpace>,
56 GrSurfaceOrigin,
57 const SkSurfaceProps&) = 0;
58 bool replaceBackingProxy(SkSurface::ContentChangeMode);
59
Robert Phillipsdca342a2021-06-02 15:48:59 -040060 using RescaleGamma = SkImage::RescaleGamma;
61 using RescaleMode = SkImage::RescaleMode;
62 using ReadPixelsCallback = SkImage::ReadPixelsCallback;
63 using ReadPixelsContext = SkImage::ReadPixelsContext;
64
65 virtual void asyncRescaleAndReadPixels(const SkImageInfo& info,
66 const SkIRect& srcRect,
67 RescaleGamma rescaleGamma,
68 RescaleMode rescaleMode,
69 ReadPixelsCallback callback,
70 ReadPixelsContext context) = 0;
71
72 virtual void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
73 sk_sp<SkColorSpace> dstColorSpace,
74 const SkIRect& srcRect,
75 SkISize dstSize,
76 RescaleGamma rescaleGamma,
77 RescaleMode,
78 ReadPixelsCallback callback,
79 ReadPixelsContext context) = 0;
80
Robert Phillips09b2bcb2021-05-12 11:56:47 -040081protected:
Robert Phillips42754922021-06-01 13:12:51 -040082 sk_sp<GrRecordingContext> fContext;
Robert Phillips09b2bcb2021-05-12 11:56:47 -040083
84private:
Michael Ludwige1d00402021-08-09 12:21:52 -040085 using INHERITED = SkBaseDevice;
Robert Phillips09b2bcb2021-05-12 11:56:47 -040086};
87
Robert Phillipscc44feb2021-07-06 12:21:37 -040088} // namespace skgpu
89
Robert Phillipscc44feb2021-07-06 12:21:37 -040090#endif // BaseDevice_DEFINED