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 | |
| 8 | #ifndef SkBaseGpuDevice_DEFINED |
| 9 | #define SkBaseGpuDevice_DEFINED |
| 10 | |
Robert Phillips | c2132ea | 2021-05-17 14:32:29 -0400 | [diff] [blame] | 11 | #include "src/gpu/GrSurfaceProxyView.h" |
| 12 | |
Robert Phillips | dca342a | 2021-06-02 15:48:59 -0400 | [diff] [blame^] | 13 | #include "include/core/SkImage.h" |
| 14 | |
Robert Phillips | 09b2bcb | 2021-05-12 11:56:47 -0400 | [diff] [blame] | 15 | // 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 | |
| 33 | class SkBaseGpuDevice : public BASE_DEVICE { |
| 34 | public: |
Robert Phillips | 54c878e | 2021-05-20 13:22:52 -0400 | [diff] [blame] | 35 | enum InitContents { |
| 36 | kClear_InitContents, |
| 37 | kUninit_InitContents |
| 38 | }; |
| 39 | |
Robert Phillips | 4275492 | 2021-06-01 13:12:51 -0400 | [diff] [blame] | 40 | SkBaseGpuDevice(sk_sp<GrRecordingContext> rContext, |
| 41 | const SkImageInfo& ii, |
| 42 | const SkSurfaceProps& props) |
| 43 | : INHERITED(ii, props) |
| 44 | , fContext(std::move(rContext)) { |
Robert Phillips | 09b2bcb | 2021-05-12 11:56:47 -0400 | [diff] [blame] | 45 | } |
| 46 | |
Robert Phillips | c2132ea | 2021-05-17 14:32:29 -0400 | [diff] [blame] | 47 | virtual GrSurfaceProxyView readSurfaceView() = 0; |
Robert Phillips | fa8af0a | 2021-06-03 11:58:43 -0400 | [diff] [blame] | 48 | GrRenderTargetProxy* targetProxy() override { |
Robert Phillips | c2132ea | 2021-05-17 14:32:29 -0400 | [diff] [blame] | 49 | return this->readSurfaceView().asRenderTargetProxy(); |
| 50 | } |
Robert Phillips | 09b2bcb | 2021-05-12 11:56:47 -0400 | [diff] [blame] | 51 | |
Robert Phillips | 4275492 | 2021-06-01 13:12:51 -0400 | [diff] [blame] | 52 | GrRecordingContext* recordingContext() const override { return fContext.get(); } |
| 53 | |
Robert Phillips | 0095fcb | 2021-05-24 14:34:01 -0400 | [diff] [blame] | 54 | virtual bool wait(int numSemaphores, |
| 55 | const GrBackendSemaphore* waitSemaphores, |
| 56 | bool deleteSemaphoresAfterWait) = 0; |
Robert Phillips | dca342a | 2021-06-02 15:48:59 -0400 | [diff] [blame^] | 57 | virtual void discard() = 0; |
Robert Phillips | 0095fcb | 2021-05-24 14:34:01 -0400 | [diff] [blame] | 58 | |
Robert Phillips | 1e3121a | 2021-06-02 09:34:57 -0400 | [diff] [blame] | 59 | 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 Phillips | dca342a | 2021-06-02 15:48:59 -0400 | [diff] [blame^] | 67 | 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 Phillips | 09b2bcb | 2021-05-12 11:56:47 -0400 | [diff] [blame] | 88 | protected: |
Robert Phillips | 4275492 | 2021-06-01 13:12:51 -0400 | [diff] [blame] | 89 | sk_sp<GrRecordingContext> fContext; |
Robert Phillips | 09b2bcb | 2021-05-12 11:56:47 -0400 | [diff] [blame] | 90 | |
| 91 | private: |
| 92 | using INHERITED = BASE_DEVICE; |
| 93 | }; |
| 94 | |
| 95 | #undef BASE_DEVICE |
| 96 | |
| 97 | #endif |