blob: fe88870f65a5d7b02a96903e492305a4d4e5d6bb [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 Phillips643f4812021-08-11 09:31:00 -040020class SurfaceFillContext;
21#if SK_GPU_V1
22namespace v1 { class SurfaceDrawContext; }
23#endif // SK_GPU_V1
24
Michael Ludwige1d00402021-08-09 12:21:52 -040025class BaseDevice : public SkBaseDevice {
Robert Phillips09b2bcb2021-05-12 11:56:47 -040026public:
Robert Phillips54c878e2021-05-20 13:22:52 -040027 enum InitContents {
28 kClear_InitContents,
29 kUninit_InitContents
30 };
31
Robert Phillips04f22ea2021-07-22 15:11:03 -040032 BaseDevice(sk_sp<GrRecordingContext>, const SkImageInfo&, const SkSurfaceProps&);
Robert Phillips09b2bcb2021-05-12 11:56:47 -040033
Robert Phillipsc2132ea2021-05-17 14:32:29 -040034 virtual GrSurfaceProxyView readSurfaceView() = 0;
Robert Phillips09b2bcb2021-05-12 11:56:47 -040035
Robert Phillips04f22ea2021-07-22 15:11:03 -040036 BaseDevice* asGpuDevice() override { return this; }
37
38#if SK_GPU_V1
Robert Phillips643f4812021-08-11 09:31:00 -040039 virtual v1::SurfaceDrawContext* surfaceDrawContext() { return nullptr; }
Robert Phillips04f22ea2021-07-22 15:11:03 -040040#endif
41
Robert Phillips643f4812021-08-11 09:31:00 -040042 virtual SurfaceFillContext* surfaceFillContext() = 0;
Robert Phillips04f22ea2021-07-22 15:11:03 -040043 GrRenderTargetProxy* targetProxy();
44 GrRecordingContext* recordingContext() const { return fContext.get(); }
Robert Phillips42754922021-06-01 13:12:51 -040045
Robert Phillips0095fcb2021-05-24 14:34:01 -040046 virtual bool wait(int numSemaphores,
47 const GrBackendSemaphore* waitSemaphores,
48 bool deleteSemaphoresAfterWait) = 0;
Robert Phillipsdca342a2021-06-02 15:48:59 -040049 virtual void discard() = 0;
Robert Phillips0095fcb2021-05-24 14:34:01 -040050
Robert Phillips1e3121a2021-06-02 09:34:57 -040051 virtual bool replaceBackingProxy(SkSurface::ContentChangeMode,
52 sk_sp<GrRenderTargetProxy>,
53 GrColorType,
54 sk_sp<SkColorSpace>,
55 GrSurfaceOrigin,
56 const SkSurfaceProps&) = 0;
57 bool replaceBackingProxy(SkSurface::ContentChangeMode);
58
Robert Phillipsdca342a2021-06-02 15:48:59 -040059 using RescaleGamma = SkImage::RescaleGamma;
60 using RescaleMode = SkImage::RescaleMode;
61 using ReadPixelsCallback = SkImage::ReadPixelsCallback;
62 using ReadPixelsContext = SkImage::ReadPixelsContext;
63
64 virtual void asyncRescaleAndReadPixels(const SkImageInfo& info,
65 const SkIRect& srcRect,
66 RescaleGamma rescaleGamma,
67 RescaleMode rescaleMode,
68 ReadPixelsCallback callback,
69 ReadPixelsContext context) = 0;
70
71 virtual void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
72 sk_sp<SkColorSpace> dstColorSpace,
73 const SkIRect& srcRect,
74 SkISize dstSize,
75 RescaleGamma rescaleGamma,
76 RescaleMode,
77 ReadPixelsCallback callback,
78 ReadPixelsContext context) = 0;
79
Robert Phillips09b2bcb2021-05-12 11:56:47 -040080protected:
Robert Phillips42754922021-06-01 13:12:51 -040081 sk_sp<GrRecordingContext> fContext;
Robert Phillips09b2bcb2021-05-12 11:56:47 -040082
83private:
Michael Ludwige1d00402021-08-09 12:21:52 -040084 using INHERITED = SkBaseDevice;
Robert Phillips09b2bcb2021-05-12 11:56:47 -040085};
86
Robert Phillipscc44feb2021-07-06 12:21:37 -040087} // namespace skgpu
88
Robert Phillipscc44feb2021-07-06 12:21:37 -040089#endif // BaseDevice_DEFINED