blob: b448922db9e6e56e19f84176c855a6e87845f619 [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
8#ifndef SkBaseGpuDevice_DEFINED
9#define SkBaseGpuDevice_DEFINED
10
Robert Phillipsc2132ea2021-05-17 14:32:29 -040011#include "src/gpu/GrSurfaceProxyView.h"
12
Robert Phillipsdca342a2021-06-02 15:48:59 -040013#include "include/core/SkImage.h"
14
Robert Phillips09b2bcb2021-05-12 11:56:47 -040015// NOTE: when not defined, SkGpuDevice extends SkBaseDevice directly and manages its clip stack
16// using GrClipStack. When false, SkGpuDevice continues to extend SkClipStackDevice and uses
17// SkClipStack and GrClipStackClip to manage the clip stack.
18#if !defined(SK_DISABLE_NEW_GR_CLIP_STACK)
19 // For staging purposes, disable this for Android Framework
20 #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
21 #define SK_DISABLE_NEW_GR_CLIP_STACK
22 #endif
23#endif
24
25#if !defined(SK_DISABLE_NEW_GR_CLIP_STACK)
26 #include "src/core/SkDevice.h"
27 #define BASE_DEVICE SkBaseDevice
28#else
29 #include "src/core/SkClipStackDevice.h"
30 #define BASE_DEVICE SkClipStackDevice
31#endif
32
33class SkBaseGpuDevice : public BASE_DEVICE {
34public:
Robert Phillips54c878e2021-05-20 13:22:52 -040035 enum InitContents {
36 kClear_InitContents,
37 kUninit_InitContents
38 };
39
Robert Phillips42754922021-06-01 13:12:51 -040040 SkBaseGpuDevice(sk_sp<GrRecordingContext> rContext,
41 const SkImageInfo& ii,
42 const SkSurfaceProps& props)
43 : INHERITED(ii, props)
44 , fContext(std::move(rContext)) {
Robert Phillips09b2bcb2021-05-12 11:56:47 -040045 }
46
Robert Phillipsc2132ea2021-05-17 14:32:29 -040047 virtual GrSurfaceProxyView readSurfaceView() = 0;
Robert Phillipsfa8af0a2021-06-03 11:58:43 -040048 GrRenderTargetProxy* targetProxy() override {
Robert Phillipsc2132ea2021-05-17 14:32:29 -040049 return this->readSurfaceView().asRenderTargetProxy();
50 }
Robert Phillips09b2bcb2021-05-12 11:56:47 -040051
Robert Phillips42754922021-06-01 13:12:51 -040052 GrRecordingContext* recordingContext() const override { return fContext.get(); }
53
Robert Phillips0095fcb2021-05-24 14:34:01 -040054 virtual bool wait(int numSemaphores,
55 const GrBackendSemaphore* waitSemaphores,
56 bool deleteSemaphoresAfterWait) = 0;
Robert Phillipsdca342a2021-06-02 15:48:59 -040057 virtual void discard() = 0;
Robert Phillips0095fcb2021-05-24 14:34:01 -040058
Robert Phillips1e3121a2021-06-02 09:34:57 -040059 virtual bool replaceBackingProxy(SkSurface::ContentChangeMode,
60 sk_sp<GrRenderTargetProxy>,
61 GrColorType,
62 sk_sp<SkColorSpace>,
63 GrSurfaceOrigin,
64 const SkSurfaceProps&) = 0;
65 bool replaceBackingProxy(SkSurface::ContentChangeMode);
66
Robert Phillipsdca342a2021-06-02 15:48:59 -040067 using RescaleGamma = SkImage::RescaleGamma;
68 using RescaleMode = SkImage::RescaleMode;
69 using ReadPixelsCallback = SkImage::ReadPixelsCallback;
70 using ReadPixelsContext = SkImage::ReadPixelsContext;
71
72 virtual void asyncRescaleAndReadPixels(const SkImageInfo& info,
73 const SkIRect& srcRect,
74 RescaleGamma rescaleGamma,
75 RescaleMode rescaleMode,
76 ReadPixelsCallback callback,
77 ReadPixelsContext context) = 0;
78
79 virtual void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
80 sk_sp<SkColorSpace> dstColorSpace,
81 const SkIRect& srcRect,
82 SkISize dstSize,
83 RescaleGamma rescaleGamma,
84 RescaleMode,
85 ReadPixelsCallback callback,
86 ReadPixelsContext context) = 0;
87
Robert Phillips09b2bcb2021-05-12 11:56:47 -040088protected:
Robert Phillips42754922021-06-01 13:12:51 -040089 sk_sp<GrRecordingContext> fContext;
Robert Phillips09b2bcb2021-05-12 11:56:47 -040090
91private:
92 using INHERITED = BASE_DEVICE;
93};
94
95#undef BASE_DEVICE
96
97#endif