blob: fbd28c5b9c8d3ced357b0fddd3be870e4c9d11ef [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
14class GrSurfaceProxyView;
Robert Phillipsdca342a2021-06-02 15:48:59 -040015
Robert Phillips09b2bcb2021-05-12 11:56:47 -040016// NOTE: when not defined, SkGpuDevice extends SkBaseDevice directly and manages its clip stack
17// using GrClipStack. When false, SkGpuDevice continues to extend SkClipStackDevice and uses
18// SkClipStack and GrClipStackClip to manage the clip stack.
19#if !defined(SK_DISABLE_NEW_GR_CLIP_STACK)
20 // For staging purposes, disable this for Android Framework
21 #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
22 #define SK_DISABLE_NEW_GR_CLIP_STACK
23 #endif
24#endif
25
26#if !defined(SK_DISABLE_NEW_GR_CLIP_STACK)
27 #include "src/core/SkDevice.h"
28 #define BASE_DEVICE SkBaseDevice
29#else
30 #include "src/core/SkClipStackDevice.h"
31 #define BASE_DEVICE SkClipStackDevice
32#endif
33
Robert Phillipscc44feb2021-07-06 12:21:37 -040034namespace skgpu {
35
36class BaseDevice : public BASE_DEVICE {
Robert Phillips09b2bcb2021-05-12 11:56:47 -040037public:
Robert Phillips54c878e2021-05-20 13:22:52 -040038 enum InitContents {
39 kClear_InitContents,
40 kUninit_InitContents
41 };
42
Robert Phillipscc44feb2021-07-06 12:21:37 -040043 BaseDevice(sk_sp<GrRecordingContext> rContext,
44 const SkImageInfo& ii,
45 const SkSurfaceProps& props)
Robert Phillips42754922021-06-01 13:12:51 -040046 : INHERITED(ii, props)
47 , fContext(std::move(rContext)) {
Robert Phillips09b2bcb2021-05-12 11:56:47 -040048 }
49
Robert Phillipsc2132ea2021-05-17 14:32:29 -040050 virtual GrSurfaceProxyView readSurfaceView() = 0;
Robert Phillipscc44feb2021-07-06 12:21:37 -040051 GrRenderTargetProxy* targetProxy() override;
Robert Phillips09b2bcb2021-05-12 11:56:47 -040052
Robert Phillips42754922021-06-01 13:12:51 -040053 GrRecordingContext* recordingContext() const override { return fContext.get(); }
54
Robert Phillips0095fcb2021-05-24 14:34:01 -040055 virtual bool wait(int numSemaphores,
56 const GrBackendSemaphore* waitSemaphores,
57 bool deleteSemaphoresAfterWait) = 0;
Robert Phillipsdca342a2021-06-02 15:48:59 -040058 virtual void discard() = 0;
Robert Phillips0095fcb2021-05-24 14:34:01 -040059
Robert Phillips1e3121a2021-06-02 09:34:57 -040060 virtual bool replaceBackingProxy(SkSurface::ContentChangeMode,
61 sk_sp<GrRenderTargetProxy>,
62 GrColorType,
63 sk_sp<SkColorSpace>,
64 GrSurfaceOrigin,
65 const SkSurfaceProps&) = 0;
66 bool replaceBackingProxy(SkSurface::ContentChangeMode);
67
Robert Phillipsdca342a2021-06-02 15:48:59 -040068 using RescaleGamma = SkImage::RescaleGamma;
69 using RescaleMode = SkImage::RescaleMode;
70 using ReadPixelsCallback = SkImage::ReadPixelsCallback;
71 using ReadPixelsContext = SkImage::ReadPixelsContext;
72
73 virtual void asyncRescaleAndReadPixels(const SkImageInfo& info,
74 const SkIRect& srcRect,
75 RescaleGamma rescaleGamma,
76 RescaleMode rescaleMode,
77 ReadPixelsCallback callback,
78 ReadPixelsContext context) = 0;
79
80 virtual void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
81 sk_sp<SkColorSpace> dstColorSpace,
82 const SkIRect& srcRect,
83 SkISize dstSize,
84 RescaleGamma rescaleGamma,
85 RescaleMode,
86 ReadPixelsCallback callback,
87 ReadPixelsContext context) = 0;
88
Robert Phillips09b2bcb2021-05-12 11:56:47 -040089protected:
Robert Phillips42754922021-06-01 13:12:51 -040090 sk_sp<GrRecordingContext> fContext;
Robert Phillips09b2bcb2021-05-12 11:56:47 -040091
92private:
93 using INHERITED = BASE_DEVICE;
94};
95
Robert Phillipscc44feb2021-07-06 12:21:37 -040096} // namespace skgpu
97
Robert Phillips09b2bcb2021-05-12 11:56:47 -040098#undef BASE_DEVICE
99
Robert Phillipscc44feb2021-07-06 12:21:37 -0400100#endif // BaseDevice_DEFINED