2 * Copyright 2021 Google LLC
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef BaseDevice_DEFINED
9 #define BaseDevice_DEFINED
11 #include "include/core/SkImage.h"
12 #include "include/private/gpu/ganesh/GrTypesPriv.h"
13 #include "src/core/SkDevice.h"
15 class GrRenderTargetProxy;
16 class GrSurfaceProxyView;
21 class SurfaceFillContext;
23 namespace v1 { class SurfaceDrawContext; }
27 * This class is left over from the initial v1/v2 split. It should be merged into the v1::Device.
29 class BaseDevice : public SkBaseDevice {
31 enum class InitContents {
36 BaseDevice(sk_sp<GrRecordingContext>, const SkImageInfo&, const SkSurfaceProps&);
38 GrSurfaceProxyView readSurfaceView();
40 BaseDevice* asGaneshDevice() override { return this; }
43 virtual v1::SurfaceDrawContext* surfaceDrawContext() { return nullptr; }
46 virtual SurfaceFillContext* surfaceFillContext() = 0;
47 GrRenderTargetProxy* targetProxy();
48 GrRecordingContext* recordingContext() const { return fContext.get(); }
50 virtual bool wait(int numSemaphores,
51 const GrBackendSemaphore* waitSemaphores,
52 bool deleteSemaphoresAfterWait) = 0;
53 virtual void discard() = 0;
54 virtual void resolveMSAA() = 0;
56 virtual bool replaceBackingProxy(SkSurface::ContentChangeMode,
57 sk_sp<GrRenderTargetProxy>,
61 const SkSurfaceProps&) = 0;
62 bool replaceBackingProxy(SkSurface::ContentChangeMode);
64 using RescaleGamma = SkImage::RescaleGamma;
65 using RescaleMode = SkImage::RescaleMode;
66 using ReadPixelsCallback = SkImage::ReadPixelsCallback;
67 using ReadPixelsContext = SkImage::ReadPixelsContext;
69 virtual void asyncRescaleAndReadPixels(const SkImageInfo& info,
70 const SkIRect& srcRect,
71 RescaleGamma rescaleGamma,
72 RescaleMode rescaleMode,
73 ReadPixelsCallback callback,
74 ReadPixelsContext context) = 0;
76 virtual void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
77 sk_sp<SkColorSpace> dstColorSpace,
78 const SkIRect& srcRect,
80 RescaleGamma rescaleGamma,
82 ReadPixelsCallback callback,
83 ReadPixelsContext context) = 0;
86 enum class DeviceFlags {
88 kNeedClear = 1 << 0, //!< Surface requires an initial clear
89 kIsOpaque = 1 << 1, //!< Hint from client that rendering to this device will be
90 // opaque even if the config supports alpha.
92 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(DeviceFlags);
94 static bool CheckAlphaTypeAndGetFlags(SkAlphaType, InitContents, DeviceFlags*);
95 static SkImageInfo MakeInfo(SurfaceContext*, DeviceFlags);
97 sk_sp<GrRecordingContext> fContext;
100 using INHERITED = SkBaseDevice;
103 GR_MAKE_BITFIELD_CLASS_OPS(BaseDevice::DeviceFlags)
107 #endif // BaseDevice_DEFINED