blob: 8c6a60c26364f0d64eb7b313566f49f1243e9a37 [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 Phillipsf3868622021-08-04 13:27:43 -040015namespace skgpu {
16 class SurfaceFillContext;
17#if SK_GPU_V1
18 namespace v1 { class SurfaceDrawContext; }
19#endif // SK_GPU_V1
20}
Robert Phillipscc44feb2021-07-06 12:21:37 -040021class GrSurfaceProxyView;
Robert Phillipsdca342a2021-06-02 15:48:59 -040022
Robert Phillips09b2bcb2021-05-12 11:56:47 -040023// NOTE: when not defined, SkGpuDevice extends SkBaseDevice directly and manages its clip stack
24// using GrClipStack. When false, SkGpuDevice continues to extend SkClipStackDevice and uses
25// SkClipStack and GrClipStackClip to manage the clip stack.
26#if !defined(SK_DISABLE_NEW_GR_CLIP_STACK)
27 // For staging purposes, disable this for Android Framework
28 #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
29 #define SK_DISABLE_NEW_GR_CLIP_STACK
30 #endif
31#endif
32
33#if !defined(SK_DISABLE_NEW_GR_CLIP_STACK)
34 #include "src/core/SkDevice.h"
35 #define BASE_DEVICE SkBaseDevice
36#else
37 #include "src/core/SkClipStackDevice.h"
38 #define BASE_DEVICE SkClipStackDevice
39#endif
40
Robert Phillipscc44feb2021-07-06 12:21:37 -040041namespace skgpu {
42
43class BaseDevice : public BASE_DEVICE {
Robert Phillips09b2bcb2021-05-12 11:56:47 -040044public:
Robert Phillips54c878e2021-05-20 13:22:52 -040045 enum InitContents {
46 kClear_InitContents,
47 kUninit_InitContents
48 };
49
Robert Phillips04f22ea2021-07-22 15:11:03 -040050 BaseDevice(sk_sp<GrRecordingContext>, const SkImageInfo&, const SkSurfaceProps&);
Robert Phillips09b2bcb2021-05-12 11:56:47 -040051
Robert Phillipsc2132ea2021-05-17 14:32:29 -040052 virtual GrSurfaceProxyView readSurfaceView() = 0;
Robert Phillips09b2bcb2021-05-12 11:56:47 -040053
Robert Phillips04f22ea2021-07-22 15:11:03 -040054 BaseDevice* asGpuDevice() override { return this; }
55
56#if SK_GPU_V1
Robert Phillips4dca8312021-07-28 15:13:20 -040057 virtual skgpu::v1::SurfaceDrawContext* surfaceDrawContext() { return nullptr; }
Robert Phillips04f22ea2021-07-22 15:11:03 -040058#endif
59
Robert Phillipsf3868622021-08-04 13:27:43 -040060 virtual skgpu::SurfaceFillContext* surfaceFillContext() = 0;
Robert Phillips04f22ea2021-07-22 15:11:03 -040061 GrRenderTargetProxy* targetProxy();
62 GrRecordingContext* recordingContext() const { return fContext.get(); }
Robert Phillips42754922021-06-01 13:12:51 -040063
Robert Phillips0095fcb2021-05-24 14:34:01 -040064 virtual bool wait(int numSemaphores,
65 const GrBackendSemaphore* waitSemaphores,
66 bool deleteSemaphoresAfterWait) = 0;
Robert Phillipsdca342a2021-06-02 15:48:59 -040067 virtual void discard() = 0;
Robert Phillips0095fcb2021-05-24 14:34:01 -040068
Robert Phillips1e3121a2021-06-02 09:34:57 -040069 virtual bool replaceBackingProxy(SkSurface::ContentChangeMode,
70 sk_sp<GrRenderTargetProxy>,
71 GrColorType,
72 sk_sp<SkColorSpace>,
73 GrSurfaceOrigin,
74 const SkSurfaceProps&) = 0;
75 bool replaceBackingProxy(SkSurface::ContentChangeMode);
76
Robert Phillipsdca342a2021-06-02 15:48:59 -040077 using RescaleGamma = SkImage::RescaleGamma;
78 using RescaleMode = SkImage::RescaleMode;
79 using ReadPixelsCallback = SkImage::ReadPixelsCallback;
80 using ReadPixelsContext = SkImage::ReadPixelsContext;
81
82 virtual void asyncRescaleAndReadPixels(const SkImageInfo& info,
83 const SkIRect& srcRect,
84 RescaleGamma rescaleGamma,
85 RescaleMode rescaleMode,
86 ReadPixelsCallback callback,
87 ReadPixelsContext context) = 0;
88
89 virtual void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
90 sk_sp<SkColorSpace> dstColorSpace,
91 const SkIRect& srcRect,
92 SkISize dstSize,
93 RescaleGamma rescaleGamma,
94 RescaleMode,
95 ReadPixelsCallback callback,
96 ReadPixelsContext context) = 0;
97
Robert Phillips09b2bcb2021-05-12 11:56:47 -040098protected:
Robert Phillips42754922021-06-01 13:12:51 -040099 sk_sp<GrRecordingContext> fContext;
Robert Phillips09b2bcb2021-05-12 11:56:47 -0400100
101private:
102 using INHERITED = BASE_DEVICE;
103};
104
Robert Phillipscc44feb2021-07-06 12:21:37 -0400105} // namespace skgpu
106
Robert Phillips09b2bcb2021-05-12 11:56:47 -0400107#undef BASE_DEVICE
108
Robert Phillipscc44feb2021-07-06 12:21:37 -0400109#endif // BaseDevice_DEFINED