blob: 4ed6406ae6e7a276d12453d924d5d7662b3d0132 [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"
13
Robert Phillips04f22ea2021-07-22 15:11:03 -040014class GrRenderTargetProxy;
Robert Phillips4dca8312021-07-28 15:13:20 -040015namespace skgpu { namespace v1 { class SurfaceDrawContext; }}
Robert Phillips04f22ea2021-07-22 15:11:03 -040016class GrSurfaceFillContext;
Robert Phillipscc44feb2021-07-06 12:21:37 -040017class GrSurfaceProxyView;
Robert Phillipsdca342a2021-06-02 15:48:59 -040018
Robert Phillips09b2bcb2021-05-12 11:56:47 -040019// NOTE: when not defined, SkGpuDevice extends SkBaseDevice directly and manages its clip stack
20// using GrClipStack. When false, SkGpuDevice continues to extend SkClipStackDevice and uses
21// SkClipStack and GrClipStackClip to manage the clip stack.
22#if !defined(SK_DISABLE_NEW_GR_CLIP_STACK)
23 // For staging purposes, disable this for Android Framework
24 #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
25 #define SK_DISABLE_NEW_GR_CLIP_STACK
26 #endif
27#endif
28
29#if !defined(SK_DISABLE_NEW_GR_CLIP_STACK)
30 #include "src/core/SkDevice.h"
31 #define BASE_DEVICE SkBaseDevice
32#else
33 #include "src/core/SkClipStackDevice.h"
34 #define BASE_DEVICE SkClipStackDevice
35#endif
36
Robert Phillipscc44feb2021-07-06 12:21:37 -040037namespace skgpu {
38
39class BaseDevice : public BASE_DEVICE {
Robert Phillips09b2bcb2021-05-12 11:56:47 -040040public:
Robert Phillips54c878e2021-05-20 13:22:52 -040041 enum InitContents {
42 kClear_InitContents,
43 kUninit_InitContents
44 };
45
Robert Phillips04f22ea2021-07-22 15:11:03 -040046 BaseDevice(sk_sp<GrRecordingContext>, const SkImageInfo&, const SkSurfaceProps&);
Robert Phillips09b2bcb2021-05-12 11:56:47 -040047
Robert Phillipsc2132ea2021-05-17 14:32:29 -040048 virtual GrSurfaceProxyView readSurfaceView() = 0;
Robert Phillips09b2bcb2021-05-12 11:56:47 -040049
Robert Phillips04f22ea2021-07-22 15:11:03 -040050 BaseDevice* asGpuDevice() override { return this; }
51
52#if SK_GPU_V1
Robert Phillips4dca8312021-07-28 15:13:20 -040053 virtual skgpu::v1::SurfaceDrawContext* surfaceDrawContext() { return nullptr; }
Robert Phillips04f22ea2021-07-22 15:11:03 -040054#endif
55
56 virtual GrSurfaceFillContext* surfaceFillContext() = 0;
57 GrRenderTargetProxy* targetProxy();
58 GrRecordingContext* recordingContext() const { return fContext.get(); }
Robert Phillips42754922021-06-01 13:12:51 -040059
Robert Phillips0095fcb2021-05-24 14:34:01 -040060 virtual bool wait(int numSemaphores,
61 const GrBackendSemaphore* waitSemaphores,
62 bool deleteSemaphoresAfterWait) = 0;
Robert Phillipsdca342a2021-06-02 15:48:59 -040063 virtual void discard() = 0;
Robert Phillips0095fcb2021-05-24 14:34:01 -040064
Robert Phillips1e3121a2021-06-02 09:34:57 -040065 virtual bool replaceBackingProxy(SkSurface::ContentChangeMode,
66 sk_sp<GrRenderTargetProxy>,
67 GrColorType,
68 sk_sp<SkColorSpace>,
69 GrSurfaceOrigin,
70 const SkSurfaceProps&) = 0;
71 bool replaceBackingProxy(SkSurface::ContentChangeMode);
72
Robert Phillipsdca342a2021-06-02 15:48:59 -040073 using RescaleGamma = SkImage::RescaleGamma;
74 using RescaleMode = SkImage::RescaleMode;
75 using ReadPixelsCallback = SkImage::ReadPixelsCallback;
76 using ReadPixelsContext = SkImage::ReadPixelsContext;
77
78 virtual void asyncRescaleAndReadPixels(const SkImageInfo& info,
79 const SkIRect& srcRect,
80 RescaleGamma rescaleGamma,
81 RescaleMode rescaleMode,
82 ReadPixelsCallback callback,
83 ReadPixelsContext context) = 0;
84
85 virtual void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
86 sk_sp<SkColorSpace> dstColorSpace,
87 const SkIRect& srcRect,
88 SkISize dstSize,
89 RescaleGamma rescaleGamma,
90 RescaleMode,
91 ReadPixelsCallback callback,
92 ReadPixelsContext context) = 0;
93
Robert Phillips09b2bcb2021-05-12 11:56:47 -040094protected:
Robert Phillips42754922021-06-01 13:12:51 -040095 sk_sp<GrRecordingContext> fContext;
Robert Phillips09b2bcb2021-05-12 11:56:47 -040096
97private:
98 using INHERITED = BASE_DEVICE;
99};
100
Robert Phillipscc44feb2021-07-06 12:21:37 -0400101} // namespace skgpu
102
Robert Phillips09b2bcb2021-05-12 11:56:47 -0400103#undef BASE_DEVICE
104
Robert Phillipscc44feb2021-07-06 12:21:37 -0400105#endif // BaseDevice_DEFINED