Robert Phillips | 09b2bcb | 2021-05-12 11:56:47 -0400 | [diff] [blame] | 1 | /* |
| 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 Phillips | cc44feb | 2021-07-06 12:21:37 -0400 | [diff] [blame] | 8 | #ifndef BaseDevice_DEFINED |
| 9 | #define BaseDevice_DEFINED |
Robert Phillips | c2132ea | 2021-05-17 14:32:29 -0400 | [diff] [blame] | 10 | |
Robert Phillips | dca342a | 2021-06-02 15:48:59 -0400 | [diff] [blame] | 11 | #include "include/core/SkImage.h" |
Robert Phillips | cc44feb | 2021-07-06 12:21:37 -0400 | [diff] [blame] | 12 | #include "include/private/GrTypesPriv.h" |
Michael Ludwig | e1d0040 | 2021-08-09 12:21:52 -0400 | [diff] [blame] | 13 | #include "src/core/SkDevice.h" |
Robert Phillips | cc44feb | 2021-07-06 12:21:37 -0400 | [diff] [blame] | 14 | |
Robert Phillips | 04f22ea | 2021-07-22 15:11:03 -0400 | [diff] [blame] | 15 | class GrRenderTargetProxy; |
Robert Phillips | cc44feb | 2021-07-06 12:21:37 -0400 | [diff] [blame] | 16 | class GrSurfaceProxyView; |
Robert Phillips | dca342a | 2021-06-02 15:48:59 -0400 | [diff] [blame] | 17 | |
Robert Phillips | cc44feb | 2021-07-06 12:21:37 -0400 | [diff] [blame] | 18 | namespace skgpu { |
| 19 | |
Robert Phillips | 778d6e0 | 2021-09-13 14:51:42 -0400 | [diff] [blame] | 20 | class SurfaceContext; |
Robert Phillips | 643f481 | 2021-08-11 09:31:00 -0400 | [diff] [blame] | 21 | class SurfaceFillContext; |
| 22 | #if SK_GPU_V1 |
| 23 | namespace v1 { class SurfaceDrawContext; } |
| 24 | #endif // SK_GPU_V1 |
| 25 | |
Robert Phillips | b42cea9 | 2021-09-16 16:31:59 -0400 | [diff] [blame] | 26 | /* |
| 27 | * The most important thing to remember about this class hierarchy is there is no skgpu::SDC |
| 28 | * base class so the v1 and v2 Devices privately hold their own version of the SDC. The best |
| 29 | * the BaseDevice can do is to return the SDC-variant as a generic SFC. |
| 30 | * |
| 31 | * skgpu::BaseDevice |
| 32 | * / \ |
| 33 | * v1::Device v2::Device |
| 34 | * - v1::SDC - v2::SDC |
| 35 | */ |
Michael Ludwig | e1d0040 | 2021-08-09 12:21:52 -0400 | [diff] [blame] | 36 | class BaseDevice : public SkBaseDevice { |
Robert Phillips | 09b2bcb | 2021-05-12 11:56:47 -0400 | [diff] [blame] | 37 | public: |
Robert Phillips | f6c564e | 2021-09-07 16:10:34 -0400 | [diff] [blame] | 38 | enum class InitContents { |
| 39 | kClear, |
| 40 | kUninit |
Robert Phillips | 54c878e | 2021-05-20 13:22:52 -0400 | [diff] [blame] | 41 | }; |
| 42 | |
Robert Phillips | 04f22ea | 2021-07-22 15:11:03 -0400 | [diff] [blame] | 43 | BaseDevice(sk_sp<GrRecordingContext>, const SkImageInfo&, const SkSurfaceProps&); |
Robert Phillips | 09b2bcb | 2021-05-12 11:56:47 -0400 | [diff] [blame] | 44 | |
Robert Phillips | b42cea9 | 2021-09-16 16:31:59 -0400 | [diff] [blame] | 45 | GrSurfaceProxyView readSurfaceView(); |
Robert Phillips | 09b2bcb | 2021-05-12 11:56:47 -0400 | [diff] [blame] | 46 | |
Robert Phillips | 04f22ea | 2021-07-22 15:11:03 -0400 | [diff] [blame] | 47 | BaseDevice* asGpuDevice() override { return this; } |
| 48 | |
| 49 | #if SK_GPU_V1 |
Robert Phillips | 643f481 | 2021-08-11 09:31:00 -0400 | [diff] [blame] | 50 | virtual v1::SurfaceDrawContext* surfaceDrawContext() { return nullptr; } |
Robert Phillips | 04f22ea | 2021-07-22 15:11:03 -0400 | [diff] [blame] | 51 | #endif |
| 52 | |
Robert Phillips | 643f481 | 2021-08-11 09:31:00 -0400 | [diff] [blame] | 53 | virtual SurfaceFillContext* surfaceFillContext() = 0; |
Robert Phillips | 04f22ea | 2021-07-22 15:11:03 -0400 | [diff] [blame] | 54 | GrRenderTargetProxy* targetProxy(); |
| 55 | GrRecordingContext* recordingContext() const { return fContext.get(); } |
Robert Phillips | 4275492 | 2021-06-01 13:12:51 -0400 | [diff] [blame] | 56 | |
Robert Phillips | 0095fcb | 2021-05-24 14:34:01 -0400 | [diff] [blame] | 57 | virtual bool wait(int numSemaphores, |
| 58 | const GrBackendSemaphore* waitSemaphores, |
| 59 | bool deleteSemaphoresAfterWait) = 0; |
Robert Phillips | dca342a | 2021-06-02 15:48:59 -0400 | [diff] [blame] | 60 | virtual void discard() = 0; |
Robert Phillips | 0095fcb | 2021-05-24 14:34:01 -0400 | [diff] [blame] | 61 | |
Robert Phillips | 1e3121a | 2021-06-02 09:34:57 -0400 | [diff] [blame] | 62 | virtual bool replaceBackingProxy(SkSurface::ContentChangeMode, |
| 63 | sk_sp<GrRenderTargetProxy>, |
| 64 | GrColorType, |
| 65 | sk_sp<SkColorSpace>, |
| 66 | GrSurfaceOrigin, |
| 67 | const SkSurfaceProps&) = 0; |
| 68 | bool replaceBackingProxy(SkSurface::ContentChangeMode); |
| 69 | |
Robert Phillips | dca342a | 2021-06-02 15:48:59 -0400 | [diff] [blame] | 70 | using RescaleGamma = SkImage::RescaleGamma; |
| 71 | using RescaleMode = SkImage::RescaleMode; |
| 72 | using ReadPixelsCallback = SkImage::ReadPixelsCallback; |
| 73 | using ReadPixelsContext = SkImage::ReadPixelsContext; |
| 74 | |
| 75 | virtual void asyncRescaleAndReadPixels(const SkImageInfo& info, |
| 76 | const SkIRect& srcRect, |
| 77 | RescaleGamma rescaleGamma, |
| 78 | RescaleMode rescaleMode, |
| 79 | ReadPixelsCallback callback, |
| 80 | ReadPixelsContext context) = 0; |
| 81 | |
| 82 | virtual void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace, |
| 83 | sk_sp<SkColorSpace> dstColorSpace, |
| 84 | const SkIRect& srcRect, |
| 85 | SkISize dstSize, |
| 86 | RescaleGamma rescaleGamma, |
| 87 | RescaleMode, |
| 88 | ReadPixelsCallback callback, |
| 89 | ReadPixelsContext context) = 0; |
| 90 | |
Robert Phillips | 09b2bcb | 2021-05-12 11:56:47 -0400 | [diff] [blame] | 91 | protected: |
Robert Phillips | f6c564e | 2021-09-07 16:10:34 -0400 | [diff] [blame] | 92 | enum class DeviceFlags { |
| 93 | kNone = 0, |
| 94 | kNeedClear = 1 << 0, //!< Surface requires an initial clear |
| 95 | kIsOpaque = 1 << 1, //!< Hint from client that rendering to this device will be |
| 96 | // opaque even if the config supports alpha. |
| 97 | }; |
| 98 | GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(DeviceFlags); |
| 99 | |
| 100 | static bool CheckAlphaTypeAndGetFlags(SkAlphaType, InitContents, DeviceFlags*); |
Robert Phillips | 778d6e0 | 2021-09-13 14:51:42 -0400 | [diff] [blame] | 101 | static SkImageInfo MakeInfo(SurfaceContext*, DeviceFlags); |
Robert Phillips | f6c564e | 2021-09-07 16:10:34 -0400 | [diff] [blame] | 102 | |
Robert Phillips | 4275492 | 2021-06-01 13:12:51 -0400 | [diff] [blame] | 103 | sk_sp<GrRecordingContext> fContext; |
Robert Phillips | 09b2bcb | 2021-05-12 11:56:47 -0400 | [diff] [blame] | 104 | |
| 105 | private: |
Michael Ludwig | e1d0040 | 2021-08-09 12:21:52 -0400 | [diff] [blame] | 106 | using INHERITED = SkBaseDevice; |
Robert Phillips | 09b2bcb | 2021-05-12 11:56:47 -0400 | [diff] [blame] | 107 | }; |
| 108 | |
Robert Phillips | f6c564e | 2021-09-07 16:10:34 -0400 | [diff] [blame] | 109 | GR_MAKE_BITFIELD_CLASS_OPS(BaseDevice::DeviceFlags) |
| 110 | |
Robert Phillips | cc44feb | 2021-07-06 12:21:37 -0400 | [diff] [blame] | 111 | } // namespace skgpu |
| 112 | |
Robert Phillips | cc44feb | 2021-07-06 12:21:37 -0400 | [diff] [blame] | 113 | #endif // BaseDevice_DEFINED |