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 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 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 91 protected: 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*); 101 static SkImageInfo MakeInfo(SurfaceContext*, DeviceFlags); 102 103 sk_sp<GrRecordingContext> fContext; 104 105 private: 106 using INHERITED = SkBaseDevice; 107 }; 108 109 GR_MAKE_BITFIELD_CLASS_OPS(BaseDevice::DeviceFlags) 110 111 } // namespace skgpu 112 113 #endif // BaseDevice_DEFINED 114