blob: 14279212a3da235900c28f61e33367265d43e216 [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;
15class GrSurfaceDrawContext;
16class 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
53 // TODO: make this return a skgpu::v1:SurfaceDrawContext
54 virtual GrSurfaceDrawContext* surfaceDrawContext() { return nullptr; }
55#endif
56
57 virtual GrSurfaceFillContext* surfaceFillContext() = 0;
58 GrRenderTargetProxy* targetProxy();
59 GrRecordingContext* recordingContext() const { return fContext.get(); }
Robert Phillips42754922021-06-01 13:12:51 -040060
Robert Phillips0095fcb2021-05-24 14:34:01 -040061 virtual bool wait(int numSemaphores,
62 const GrBackendSemaphore* waitSemaphores,
63 bool deleteSemaphoresAfterWait) = 0;
Robert Phillipsdca342a2021-06-02 15:48:59 -040064 virtual void discard() = 0;
Robert Phillips0095fcb2021-05-24 14:34:01 -040065
Robert Phillips1e3121a2021-06-02 09:34:57 -040066 virtual bool replaceBackingProxy(SkSurface::ContentChangeMode,
67 sk_sp<GrRenderTargetProxy>,
68 GrColorType,
69 sk_sp<SkColorSpace>,
70 GrSurfaceOrigin,
71 const SkSurfaceProps&) = 0;
72 bool replaceBackingProxy(SkSurface::ContentChangeMode);
73
Robert Phillipsdca342a2021-06-02 15:48:59 -040074 using RescaleGamma = SkImage::RescaleGamma;
75 using RescaleMode = SkImage::RescaleMode;
76 using ReadPixelsCallback = SkImage::ReadPixelsCallback;
77 using ReadPixelsContext = SkImage::ReadPixelsContext;
78
79 virtual void asyncRescaleAndReadPixels(const SkImageInfo& info,
80 const SkIRect& srcRect,
81 RescaleGamma rescaleGamma,
82 RescaleMode rescaleMode,
83 ReadPixelsCallback callback,
84 ReadPixelsContext context) = 0;
85
86 virtual void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
87 sk_sp<SkColorSpace> dstColorSpace,
88 const SkIRect& srcRect,
89 SkISize dstSize,
90 RescaleGamma rescaleGamma,
91 RescaleMode,
92 ReadPixelsCallback callback,
93 ReadPixelsContext context) = 0;
94
Robert Phillips09b2bcb2021-05-12 11:56:47 -040095protected:
Robert Phillips42754922021-06-01 13:12:51 -040096 sk_sp<GrRecordingContext> fContext;
Robert Phillips09b2bcb2021-05-12 11:56:47 -040097
98private:
99 using INHERITED = BASE_DEVICE;
100};
101
Robert Phillipscc44feb2021-07-06 12:21:37 -0400102} // namespace skgpu
103
Robert Phillips09b2bcb2021-05-12 11:56:47 -0400104#undef BASE_DEVICE
105
Robert Phillipscc44feb2021-07-06 12:21:37 -0400106#endif // BaseDevice_DEFINED