1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2021 Google LLC 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#ifndef BaseDevice_DEFINED 9cb93a386Sopenharmony_ci#define BaseDevice_DEFINED 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci#include "include/core/SkImage.h" 12cb93a386Sopenharmony_ci#include "include/private/GrTypesPriv.h" 13cb93a386Sopenharmony_ci#include "src/core/SkDevice.h" 14cb93a386Sopenharmony_ci 15cb93a386Sopenharmony_ciclass GrRenderTargetProxy; 16cb93a386Sopenharmony_ciclass GrSurfaceProxyView; 17cb93a386Sopenharmony_ci 18cb93a386Sopenharmony_cinamespace skgpu { 19cb93a386Sopenharmony_ci 20cb93a386Sopenharmony_ciclass SurfaceContext; 21cb93a386Sopenharmony_ciclass SurfaceFillContext; 22cb93a386Sopenharmony_ci#if SK_GPU_V1 23cb93a386Sopenharmony_cinamespace v1 { class SurfaceDrawContext; } 24cb93a386Sopenharmony_ci#endif // SK_GPU_V1 25cb93a386Sopenharmony_ci 26cb93a386Sopenharmony_ci/* 27cb93a386Sopenharmony_ci * The most important thing to remember about this class hierarchy is there is no skgpu::SDC 28cb93a386Sopenharmony_ci * base class so the v1 and v2 Devices privately hold their own version of the SDC. The best 29cb93a386Sopenharmony_ci * the BaseDevice can do is to return the SDC-variant as a generic SFC. 30cb93a386Sopenharmony_ci * 31cb93a386Sopenharmony_ci * skgpu::BaseDevice 32cb93a386Sopenharmony_ci * / \ 33cb93a386Sopenharmony_ci * v1::Device v2::Device 34cb93a386Sopenharmony_ci * - v1::SDC - v2::SDC 35cb93a386Sopenharmony_ci */ 36cb93a386Sopenharmony_ciclass BaseDevice : public SkBaseDevice { 37cb93a386Sopenharmony_cipublic: 38cb93a386Sopenharmony_ci enum class InitContents { 39cb93a386Sopenharmony_ci kClear, 40cb93a386Sopenharmony_ci kUninit 41cb93a386Sopenharmony_ci }; 42cb93a386Sopenharmony_ci 43cb93a386Sopenharmony_ci BaseDevice(sk_sp<GrRecordingContext>, const SkImageInfo&, const SkSurfaceProps&); 44cb93a386Sopenharmony_ci 45cb93a386Sopenharmony_ci GrSurfaceProxyView readSurfaceView(); 46cb93a386Sopenharmony_ci 47cb93a386Sopenharmony_ci BaseDevice* asGpuDevice() override { return this; } 48cb93a386Sopenharmony_ci 49cb93a386Sopenharmony_ci#if SK_GPU_V1 50cb93a386Sopenharmony_ci virtual v1::SurfaceDrawContext* surfaceDrawContext() { return nullptr; } 51cb93a386Sopenharmony_ci#endif 52cb93a386Sopenharmony_ci 53cb93a386Sopenharmony_ci virtual SurfaceFillContext* surfaceFillContext() = 0; 54cb93a386Sopenharmony_ci GrRenderTargetProxy* targetProxy(); 55cb93a386Sopenharmony_ci GrRecordingContext* recordingContext() const { return fContext.get(); } 56cb93a386Sopenharmony_ci 57cb93a386Sopenharmony_ci virtual bool wait(int numSemaphores, 58cb93a386Sopenharmony_ci const GrBackendSemaphore* waitSemaphores, 59cb93a386Sopenharmony_ci bool deleteSemaphoresAfterWait) = 0; 60cb93a386Sopenharmony_ci virtual void discard() = 0; 61cb93a386Sopenharmony_ci 62cb93a386Sopenharmony_ci virtual bool replaceBackingProxy(SkSurface::ContentChangeMode, 63cb93a386Sopenharmony_ci sk_sp<GrRenderTargetProxy>, 64cb93a386Sopenharmony_ci GrColorType, 65cb93a386Sopenharmony_ci sk_sp<SkColorSpace>, 66cb93a386Sopenharmony_ci GrSurfaceOrigin, 67cb93a386Sopenharmony_ci const SkSurfaceProps&) = 0; 68cb93a386Sopenharmony_ci bool replaceBackingProxy(SkSurface::ContentChangeMode); 69cb93a386Sopenharmony_ci 70cb93a386Sopenharmony_ci using RescaleGamma = SkImage::RescaleGamma; 71cb93a386Sopenharmony_ci using RescaleMode = SkImage::RescaleMode; 72cb93a386Sopenharmony_ci using ReadPixelsCallback = SkImage::ReadPixelsCallback; 73cb93a386Sopenharmony_ci using ReadPixelsContext = SkImage::ReadPixelsContext; 74cb93a386Sopenharmony_ci 75cb93a386Sopenharmony_ci virtual void asyncRescaleAndReadPixels(const SkImageInfo& info, 76cb93a386Sopenharmony_ci const SkIRect& srcRect, 77cb93a386Sopenharmony_ci RescaleGamma rescaleGamma, 78cb93a386Sopenharmony_ci RescaleMode rescaleMode, 79cb93a386Sopenharmony_ci ReadPixelsCallback callback, 80cb93a386Sopenharmony_ci ReadPixelsContext context) = 0; 81cb93a386Sopenharmony_ci 82cb93a386Sopenharmony_ci virtual void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace, 83cb93a386Sopenharmony_ci sk_sp<SkColorSpace> dstColorSpace, 84cb93a386Sopenharmony_ci const SkIRect& srcRect, 85cb93a386Sopenharmony_ci SkISize dstSize, 86cb93a386Sopenharmony_ci RescaleGamma rescaleGamma, 87cb93a386Sopenharmony_ci RescaleMode, 88cb93a386Sopenharmony_ci ReadPixelsCallback callback, 89cb93a386Sopenharmony_ci ReadPixelsContext context) = 0; 90cb93a386Sopenharmony_ci 91cb93a386Sopenharmony_ciprotected: 92cb93a386Sopenharmony_ci enum class DeviceFlags { 93cb93a386Sopenharmony_ci kNone = 0, 94cb93a386Sopenharmony_ci kNeedClear = 1 << 0, //!< Surface requires an initial clear 95cb93a386Sopenharmony_ci kIsOpaque = 1 << 1, //!< Hint from client that rendering to this device will be 96cb93a386Sopenharmony_ci // opaque even if the config supports alpha. 97cb93a386Sopenharmony_ci }; 98cb93a386Sopenharmony_ci GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(DeviceFlags); 99cb93a386Sopenharmony_ci 100cb93a386Sopenharmony_ci static bool CheckAlphaTypeAndGetFlags(SkAlphaType, InitContents, DeviceFlags*); 101cb93a386Sopenharmony_ci static SkImageInfo MakeInfo(SurfaceContext*, DeviceFlags); 102cb93a386Sopenharmony_ci 103cb93a386Sopenharmony_ci sk_sp<GrRecordingContext> fContext; 104cb93a386Sopenharmony_ci 105cb93a386Sopenharmony_ciprivate: 106cb93a386Sopenharmony_ci using INHERITED = SkBaseDevice; 107cb93a386Sopenharmony_ci}; 108cb93a386Sopenharmony_ci 109cb93a386Sopenharmony_ciGR_MAKE_BITFIELD_CLASS_OPS(BaseDevice::DeviceFlags) 110cb93a386Sopenharmony_ci 111cb93a386Sopenharmony_ci} // namespace skgpu 112cb93a386Sopenharmony_ci 113cb93a386Sopenharmony_ci#endif // BaseDevice_DEFINED 114