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 BaseDevice_DEFINED 9 #define BaseDevice_DEFINED 10 11 #include "include/core/SkImage.h" 12 #include "include/private/GrTypesPriv.h" 13 #include "src/core/SkDevice.h" 14 15 class GrRenderTargetProxy; 16 class GrSurfaceProxyView; 17 18 namespace skgpu { 19 20 class SurfaceContext; 21 class SurfaceFillContext; 22 #if SK_GPU_V1 23 namespace v1 { class SurfaceDrawContext; } 24 #endif // SK_GPU_V1 25 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 */ 36 class BaseDevice : public SkBaseDevice { 37 public: 38 enum class InitContents { 39 kClear, 40 kUninit 41 }; 42 43 BaseDevice(sk_sp<GrRecordingContext>, const SkImageInfo&, const SkSurfaceProps&); 44 45 GrSurfaceProxyView readSurfaceView(); 46 asGpuDevice()47 BaseDevice* asGpuDevice() override { return this; } 48 49 #if SK_GPU_V1 surfaceDrawContext()50 virtual v1::SurfaceDrawContext* surfaceDrawContext() { return nullptr; } 51 #endif 52 53 virtual SurfaceFillContext* surfaceFillContext() = 0; 54 GrRenderTargetProxy* targetProxy(); recordingContext()55 GrRecordingContext* recordingContext() const { return fContext.get(); } 56 57 virtual bool wait(int numSemaphores, 58 const GrBackendSemaphore* waitSemaphores, 59 bool deleteSemaphoresAfterWait) = 0; 60 virtual void discard() = 0; 61 virtual void resolveMSAA() = 0; 62 63 virtual bool replaceBackingProxy(SkSurface::ContentChangeMode, 64 sk_sp<GrRenderTargetProxy>, 65 GrColorType, 66 sk_sp<SkColorSpace>, 67 GrSurfaceOrigin, 68 const SkSurfaceProps&) = 0; 69 bool replaceBackingProxy(SkSurface::ContentChangeMode); 70 71 using RescaleGamma = SkImage::RescaleGamma; 72 using RescaleMode = SkImage::RescaleMode; 73 using ReadPixelsCallback = SkImage::ReadPixelsCallback; 74 using ReadPixelsContext = SkImage::ReadPixelsContext; 75 76 virtual void asyncRescaleAndReadPixels(const SkImageInfo& info, 77 const SkIRect& srcRect, 78 RescaleGamma rescaleGamma, 79 RescaleMode rescaleMode, 80 ReadPixelsCallback callback, 81 ReadPixelsContext context) = 0; 82 83 virtual void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace, 84 sk_sp<SkColorSpace> dstColorSpace, 85 const SkIRect& srcRect, 86 SkISize dstSize, 87 RescaleGamma rescaleGamma, 88 RescaleMode, 89 ReadPixelsCallback callback, 90 ReadPixelsContext context) = 0; 91 92 protected: 93 enum class DeviceFlags { 94 kNone = 0, 95 kNeedClear = 1 << 0, //!< Surface requires an initial clear 96 kIsOpaque = 1 << 1, //!< Hint from client that rendering to this device will be 97 // opaque even if the config supports alpha. 98 }; 99 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(DeviceFlags); 100 101 static bool CheckAlphaTypeAndGetFlags(SkAlphaType, InitContents, DeviceFlags*); 102 static SkImageInfo MakeInfo(SurfaceContext*, DeviceFlags); 103 104 sk_sp<GrRecordingContext> fContext; 105 106 private: 107 using INHERITED = SkBaseDevice; 108 }; 109 110 GR_MAKE_BITFIELD_CLASS_OPS(BaseDevice::DeviceFlags) 111 112 } // namespace skgpu 113 114 #endif // BaseDevice_DEFINED 115