Remove BaseDevice class
This was left over from the initial attempt to split Ganesh into v1 and v2 versions. It is no longer needed w/ the move to Graphite.
This CL pretty much just folds BaseDevice into v1::Device.
Change-Id: I8fe180928b257c63f7ed3d58ac19d2ca454471dc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/565996
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
diff --git a/gn/gpu.gni b/gn/gpu.gni
index 0a35b87..c331046 100644
--- a/gn/gpu.gni
+++ b/gn/gpu.gni
@@ -363,8 +363,6 @@
"$_src/gpu/ganesh/mock/GrMockTypes.cpp",
# Sk files
- "$_src/gpu/ganesh/BaseDevice.cpp",
- "$_src/gpu/ganesh/BaseDevice.h",
"$_src/gpu/ganesh/SkGr.cpp",
"$_src/gpu/ganesh/SkGr.h",
"$_src/image/SkImage_Gpu.cpp",
diff --git a/public.bzl b/public.bzl
index 361aded..71faa0a 100644
--- a/public.bzl
+++ b/public.bzl
@@ -799,8 +799,6 @@
"src/gpu/Swizzle.cpp",
"src/gpu/Swizzle.h",
# We include the ganesh files, but leave out any specific backend (e.g. GL, Vulkan)
- "src/gpu/ganesh/BaseDevice.cpp",
- "src/gpu/ganesh/BaseDevice.h",
"src/gpu/ganesh/GrAHardwareBufferImageGenerator.cpp",
"src/gpu/ganesh/GrAHardwareBufferImageGenerator.h",
"src/gpu/ganesh/GrAHardwareBufferUtils.cpp",
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index d7a62dd..8f887b0 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -54,7 +54,6 @@
#if SK_SUPPORT_GPU
#include "include/gpu/GrDirectContext.h"
-#include "src/gpu/ganesh/BaseDevice.h"
#include "src/gpu/ganesh/SkGr.h"
#include "src/utils/SkTestCanvas.h"
#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
diff --git a/src/core/SkCanvasPriv.cpp b/src/core/SkCanvasPriv.cpp
index efaf54b..ee3b979 100644
--- a/src/core/SkCanvasPriv.cpp
+++ b/src/core/SkCanvasPriv.cpp
@@ -104,7 +104,7 @@
#if GR_TEST_UTILS
#if SK_SUPPORT_GPU
-#include "src/gpu/ganesh/BaseDevice.h"
+#include "src/gpu/ganesh/v1/Device_v1.h"
#if SK_GPU_V1
skgpu::v1::SurfaceDrawContext* SkCanvasPriv::TopDeviceSurfaceDrawContext(SkCanvas* canvas) {
@@ -141,7 +141,7 @@
#endif // GR_TEST_UTILS
#if SK_SUPPORT_GPU
-#include "src/gpu/ganesh/BaseDevice.h"
+#include "src/gpu/ganesh/v1/Device_v1.h"
GrRenderTargetProxy* SkCanvasPriv::TopDeviceTargetProxy(SkCanvas* canvas) {
if (auto gpuDevice = canvas->topDevice()->asGaneshDevice()) {
diff --git a/src/core/SkDeferredDisplayListRecorder.cpp b/src/core/SkDeferredDisplayListRecorder.cpp
index dd333a1..f2de052 100644
--- a/src/core/SkDeferredDisplayListRecorder.cpp
+++ b/src/core/SkDeferredDisplayListRecorder.cpp
@@ -163,7 +163,7 @@
fCharacterization.refColorSpace(),
fCharacterization.origin(),
fCharacterization.surfaceProps(),
- skgpu::BaseDevice::InitContents::kUninit);
+ skgpu::v1::Device::InitContents::kUninit);
if (!device) {
return false;
}
diff --git a/src/core/SkDevice.h b/src/core/SkDevice.h
index 10bdcfb..acacfb3 100644
--- a/src/core/SkDevice.h
+++ b/src/core/SkDevice.h
@@ -37,8 +37,8 @@
class SkSpecialImage;
namespace skif { class Mapping; }
-namespace skgpu {
-class BaseDevice;
+namespace skgpu::v1 {
+class Device;
}
namespace skgpu::graphite {
class Device;
@@ -214,7 +214,7 @@
virtual bool android_utils_clipWithStencil() { return false; }
- virtual skgpu::BaseDevice* asGaneshDevice() { return nullptr; }
+ virtual skgpu::v1::Device* asGaneshDevice() { return nullptr; }
virtual skgpu::graphite::Device* asGraphiteDevice() { return nullptr; }
// Ensure that non-RSXForm runs are passed to onDrawGlyphRunList.
diff --git a/src/core/SkSpecialSurface.cpp b/src/core/SkSpecialSurface.cpp
index 1545197..5daac41 100644
--- a/src/core/SkSpecialSurface.cpp
+++ b/src/core/SkSpecialSurface.cpp
@@ -124,7 +124,7 @@
class SkSpecialSurface_Gpu : public SkSpecialSurface_Base {
public:
- SkSpecialSurface_Gpu(sk_sp<skgpu::BaseDevice> device, SkIRect subset)
+ SkSpecialSurface_Gpu(sk_sp<skgpu::v1::Device> device, SkIRect subset)
: INHERITED(subset, device->surfaceProps())
, fReadView(device->readSurfaceView()) {
@@ -167,7 +167,7 @@
auto device = rContext->priv().createDevice(SkBudgeted::kYes, ii, SkBackingFit::kApprox, 1,
GrMipmapped::kNo, GrProtected::kNo,
surfaceOrigin, props,
- skgpu::BaseDevice::InitContents::kUninit);
+ skgpu::v1::Device::InitContents::kUninit);
if (!device) {
return nullptr;
}
diff --git a/src/gpu/ganesh/BUILD.bazel b/src/gpu/ganesh/BUILD.bazel
index 584391d..e4f1535 100644
--- a/src/gpu/ganesh/BUILD.bazel
+++ b/src/gpu/ganesh/BUILD.bazel
@@ -5,8 +5,6 @@
exports_files_legacy()
CORE_FILES = [
- "BaseDevice.cpp",
- "BaseDevice.h",
"GrAHardwareBufferImageGenerator.cpp",
"GrAHardwareBufferImageGenerator.h",
"GrAHardwareBufferUtils.cpp",
diff --git a/src/gpu/ganesh/BaseDevice.cpp b/src/gpu/ganesh/BaseDevice.cpp
deleted file mode 100644
index 8130b50..0000000
--- a/src/gpu/ganesh/BaseDevice.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright 2021 Google LLC
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "src/gpu/ganesh/BaseDevice.h"
-
-#include "include/core/SkColorSpace.h"
-#include "include/gpu/GrRecordingContext.h"
-#include "src/gpu/ganesh/GrProxyProvider.h"
-#include "src/gpu/ganesh/GrRecordingContextPriv.h"
-#include "src/gpu/ganesh/GrSurfaceProxyView.h"
-#include "src/gpu/ganesh/SurfaceContext.h"
-#include "src/gpu/ganesh/SurfaceFillContext.h"
-
-#define ASSERT_SINGLE_OWNER SKGPU_ASSERT_SINGLE_OWNER(fContext->priv().singleOwner())
-
-namespace skgpu {
-
-BaseDevice::BaseDevice(sk_sp<GrRecordingContext> rContext,
- const SkImageInfo& ii,
- const SkSurfaceProps& props)
- : INHERITED(ii, props)
- , fContext(std::move(rContext)) {
-}
-
-GrSurfaceProxyView BaseDevice::readSurfaceView() {
- return this->surfaceFillContext()->readSurfaceView();
-}
-
-/** Checks that the alpha type is legal and gets constructor flags. Returns false if device creation
- should fail. */
-bool BaseDevice::CheckAlphaTypeAndGetFlags(SkAlphaType alphaType,
- InitContents init,
- DeviceFlags* flags) {
- *flags = DeviceFlags::kNone;
- switch (alphaType) {
- case kPremul_SkAlphaType:
- break;
- case kOpaque_SkAlphaType:
- *flags |= DeviceFlags::kIsOpaque;
- break;
- default: // If it is unpremul or unknown don't try to render
- return false;
- }
- if (InitContents::kClear == init) {
- *flags |= DeviceFlags::kNeedClear;
- }
- return true;
-}
-
-SkImageInfo BaseDevice::MakeInfo(SurfaceContext* sc, DeviceFlags flags) {
- SkColorType colorType = GrColorTypeToSkColorType(sc->colorInfo().colorType());
- return SkImageInfo::Make(sc->width(), sc->height(), colorType,
- flags & DeviceFlags::kIsOpaque ? kOpaque_SkAlphaType
- : kPremul_SkAlphaType,
- sc->colorInfo().refColorSpace());
-}
-
-GrRenderTargetProxy* BaseDevice::targetProxy() {
- return this->readSurfaceView().asRenderTargetProxy();
-}
-
-bool BaseDevice::replaceBackingProxy(SkSurface::ContentChangeMode mode) {
- ASSERT_SINGLE_OWNER
-
- const SkImageInfo& ii = this->imageInfo();
- GrRenderTargetProxy* oldRTP = this->targetProxy();
- GrSurfaceProxyView oldView = this->readSurfaceView();
-
- auto grColorType = SkColorTypeToGrColorType(ii.colorType());
- auto format = fContext->priv().caps()->getDefaultBackendFormat(grColorType, GrRenderable::kYes);
- if (!format.isValid()) {
- return false;
- }
-
- GrProxyProvider* proxyProvider = fContext->priv().proxyProvider();
- // This entry point is used by SkSurface_Gpu::onCopyOnWrite so it must create a
- // kExact-backed render target proxy
- sk_sp<GrTextureProxy> proxy =
- proxyProvider->createProxy(format,
- ii.dimensions(),
- GrRenderable::kYes,
- oldRTP->numSamples(),
- oldView.mipmapped(),
- SkBackingFit::kExact,
- oldRTP->isBudgeted(),
- GrProtected::kNo,
- /*label=*/"BaseDevice_ReplaceBackingProxy");
- if (!proxy) {
- return false;
- }
-
- return this->replaceBackingProxy(mode, sk_ref_sp(proxy->asRenderTargetProxy()),
- grColorType, ii.refColorSpace(), oldView.origin(),
- this->surfaceProps());
-}
-
-} // namespace skgpu
diff --git a/src/gpu/ganesh/BaseDevice.h b/src/gpu/ganesh/BaseDevice.h
deleted file mode 100644
index 0a8b431..0000000
--- a/src/gpu/ganesh/BaseDevice.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright 2021 Google LLC
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef BaseDevice_DEFINED
-#define BaseDevice_DEFINED
-
-#include "include/core/SkImage.h"
-#include "include/private/gpu/ganesh/GrTypesPriv.h"
-#include "src/core/SkDevice.h"
-
-class GrRenderTargetProxy;
-class GrSurfaceProxyView;
-
-namespace skgpu {
-
-class SurfaceContext;
-class SurfaceFillContext;
-#if SK_GPU_V1
-namespace v1 { class SurfaceDrawContext; }
-#endif // SK_GPU_V1
-
-/*
- * This class is left over from the initial v1/v2 split. It should be merged into the v1::Device.
- */
-class BaseDevice : public SkBaseDevice {
-public:
- enum class InitContents {
- kClear,
- kUninit
- };
-
- BaseDevice(sk_sp<GrRecordingContext>, const SkImageInfo&, const SkSurfaceProps&);
-
- GrSurfaceProxyView readSurfaceView();
-
- BaseDevice* asGaneshDevice() override { return this; }
-
-#if SK_GPU_V1
- virtual v1::SurfaceDrawContext* surfaceDrawContext() { return nullptr; }
-#endif
-
- virtual SurfaceFillContext* surfaceFillContext() = 0;
- GrRenderTargetProxy* targetProxy();
- GrRecordingContext* recordingContext() const { return fContext.get(); }
-
- virtual bool wait(int numSemaphores,
- const GrBackendSemaphore* waitSemaphores,
- bool deleteSemaphoresAfterWait) = 0;
- virtual void discard() = 0;
- virtual void resolveMSAA() = 0;
-
- virtual bool replaceBackingProxy(SkSurface::ContentChangeMode,
- sk_sp<GrRenderTargetProxy>,
- GrColorType,
- sk_sp<SkColorSpace>,
- GrSurfaceOrigin,
- const SkSurfaceProps&) = 0;
- bool replaceBackingProxy(SkSurface::ContentChangeMode);
-
- using RescaleGamma = SkImage::RescaleGamma;
- using RescaleMode = SkImage::RescaleMode;
- using ReadPixelsCallback = SkImage::ReadPixelsCallback;
- using ReadPixelsContext = SkImage::ReadPixelsContext;
-
- virtual void asyncRescaleAndReadPixels(const SkImageInfo& info,
- const SkIRect& srcRect,
- RescaleGamma rescaleGamma,
- RescaleMode rescaleMode,
- ReadPixelsCallback callback,
- ReadPixelsContext context) = 0;
-
- virtual void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
- sk_sp<SkColorSpace> dstColorSpace,
- const SkIRect& srcRect,
- SkISize dstSize,
- RescaleGamma rescaleGamma,
- RescaleMode,
- ReadPixelsCallback callback,
- ReadPixelsContext context) = 0;
-
-protected:
- enum class DeviceFlags {
- kNone = 0,
- kNeedClear = 1 << 0, //!< Surface requires an initial clear
- kIsOpaque = 1 << 1, //!< Hint from client that rendering to this device will be
- // opaque even if the config supports alpha.
- };
- GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(DeviceFlags);
-
- static bool CheckAlphaTypeAndGetFlags(SkAlphaType, InitContents, DeviceFlags*);
- static SkImageInfo MakeInfo(SurfaceContext*, DeviceFlags);
-
- sk_sp<GrRecordingContext> fContext;
-
-private:
- using INHERITED = SkBaseDevice;
-};
-
-GR_MAKE_BITFIELD_CLASS_OPS(BaseDevice::DeviceFlags)
-
-} // namespace skgpu
-
-#endif // BaseDevice_DEFINED
diff --git a/src/gpu/ganesh/GrDirectContextPriv.h b/src/gpu/ganesh/GrDirectContextPriv.h
index 570997d..8dab6c8 100644
--- a/src/gpu/ganesh/GrDirectContextPriv.h
+++ b/src/gpu/ganesh/GrDirectContextPriv.h
@@ -12,8 +12,8 @@
#include "include/core/SkSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "src/gpu/AtlasTypes.h"
-#include "src/gpu/ganesh/BaseDevice.h"
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
+#include "src/gpu/ganesh/v1/Device_v1.h"
class GrAtlasManager;
class GrBackendFormat;
diff --git a/src/gpu/ganesh/GrRecordingContextPriv.cpp b/src/gpu/ganesh/GrRecordingContextPriv.cpp
index 42733d4..bada215 100644
--- a/src/gpu/ganesh/GrRecordingContextPriv.cpp
+++ b/src/gpu/ganesh/GrRecordingContextPriv.cpp
@@ -24,12 +24,12 @@
this->context()->addOnFlushCallbackObject(onFlushCBObject);
}
-sk_sp<skgpu::BaseDevice> GrRecordingContextPriv::createDevice(GrColorType colorType,
+sk_sp<skgpu::v1::Device> GrRecordingContextPriv::createDevice(GrColorType colorType,
sk_sp<GrSurfaceProxy> proxy,
sk_sp<SkColorSpace> colorSpace,
GrSurfaceOrigin origin,
const SkSurfaceProps& props,
- skgpu::BaseDevice::InitContents init) {
+ skgpu::v1::Device::InitContents init) {
#if SK_GPU_V1
return skgpu::v1::Device::Make(this->context(), colorType, std::move(proxy),
std::move(colorSpace), origin, props, init);
@@ -38,7 +38,7 @@
#endif
}
-sk_sp<skgpu::BaseDevice> GrRecordingContextPriv::createDevice(SkBudgeted budgeted,
+sk_sp<skgpu::v1::Device> GrRecordingContextPriv::createDevice(SkBudgeted budgeted,
const SkImageInfo& ii,
SkBackingFit fit,
int sampleCount,
@@ -46,7 +46,7 @@
GrProtected isProtected,
GrSurfaceOrigin origin,
const SkSurfaceProps& props,
- skgpu::BaseDevice::InitContents init) {
+ skgpu::v1::Device::InitContents init) {
#if SK_GPU_V1
return skgpu::v1::Device::Make(this->context(), budgeted, ii, fit, sampleCount,
mipmapped, isProtected, origin, props, init);
diff --git a/src/gpu/ganesh/GrRecordingContextPriv.h b/src/gpu/ganesh/GrRecordingContextPriv.h
index cf4f264..0824921 100644
--- a/src/gpu/ganesh/GrRecordingContextPriv.h
+++ b/src/gpu/ganesh/GrRecordingContextPriv.h
@@ -11,8 +11,8 @@
#include "include/core/SkPaint.h"
#include "include/gpu/GrRecordingContext.h"
#include "src/gpu/RefCntedCallback.h"
-#include "src/gpu/ganesh/BaseDevice.h"
#include "src/gpu/ganesh/GrImageContextPriv.h"
+#include "src/gpu/ganesh/v1/Device_v1.h"
#include "src/text/gpu/SDFTControl.h"
class GrImageInfo;
@@ -115,13 +115,13 @@
*/
static sk_sp<GrRecordingContext> MakeDDL(sk_sp<GrContextThreadSafeProxy>);
- sk_sp<skgpu::BaseDevice> createDevice(GrColorType,
+ sk_sp<skgpu::v1::Device> createDevice(GrColorType,
sk_sp<GrSurfaceProxy>,
sk_sp<SkColorSpace>,
GrSurfaceOrigin,
const SkSurfaceProps&,
- skgpu::BaseDevice::InitContents);
- sk_sp<skgpu::BaseDevice> createDevice(SkBudgeted,
+ skgpu::v1::Device::InitContents);
+ sk_sp<skgpu::v1::Device> createDevice(SkBudgeted,
const SkImageInfo&,
SkBackingFit,
int sampleCount,
@@ -129,7 +129,7 @@
GrProtected,
GrSurfaceOrigin,
const SkSurfaceProps&,
- skgpu::BaseDevice::InitContents);
+ skgpu::v1::Device::InitContents);
// If the passed in GrSurfaceProxy is renderable this will return a SurfaceDrawContext,
// otherwise it will return a SurfaceContext.
diff --git a/src/gpu/ganesh/v1/Device.cpp b/src/gpu/ganesh/v1/Device.cpp
index 06a6fc1..507e615 100644
--- a/src/gpu/ganesh/v1/Device.cpp
+++ b/src/gpu/ganesh/v1/Device.cpp
@@ -37,14 +37,17 @@
#include "src/gpu/ganesh/GrBlurUtils.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrGpu.h"
+#include "src/gpu/ganesh/GrProxyProvider.h"
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
#include "src/gpu/ganesh/GrStyle.h"
#include "src/gpu/ganesh/GrSurfaceProxyPriv.h"
#include "src/gpu/ganesh/GrTracing.h"
#include "src/gpu/ganesh/SkGr.h"
+#include "src/gpu/ganesh/SurfaceContext.h"
#include "src/gpu/ganesh/effects/GrDisableColorXP.h"
#include "src/gpu/ganesh/effects/GrRRectEffect.h"
#include "src/gpu/ganesh/geometry/GrStyledShape.h"
+#include "src/gpu/ganesh/v1/SurfaceDrawContext_v1.h"
#include "src/image/SkImage_Base.h"
#include "src/image/SkReadPixelsRec.h"
#include "src/image/SkSurface_Gpu.h"
@@ -116,13 +119,13 @@
namespace skgpu::v1 {
-sk_sp<BaseDevice> Device::Make(GrRecordingContext* rContext,
- GrColorType colorType,
- sk_sp<GrSurfaceProxy> proxy,
- sk_sp<SkColorSpace> colorSpace,
- GrSurfaceOrigin origin,
- const SkSurfaceProps& surfaceProps,
- InitContents init) {
+sk_sp<Device> Device::Make(GrRecordingContext* rContext,
+ GrColorType colorType,
+ sk_sp<GrSurfaceProxy> proxy,
+ sk_sp<SkColorSpace> colorSpace,
+ GrSurfaceOrigin origin,
+ const SkSurfaceProps& surfaceProps,
+ InitContents init) {
auto sdc = SurfaceDrawContext::Make(rContext,
colorType,
std::move(proxy),
@@ -133,9 +136,39 @@
return Device::Make(std::move(sdc), kPremul_SkAlphaType, init);
}
-sk_sp<BaseDevice> Device::Make(std::unique_ptr<SurfaceDrawContext> sdc,
- SkAlphaType alphaType,
- InitContents init) {
+SkImageInfo Device::MakeInfo(SurfaceContext* sc, DeviceFlags flags) {
+ SkColorType colorType = GrColorTypeToSkColorType(sc->colorInfo().colorType());
+ return SkImageInfo::Make(sc->width(), sc->height(), colorType,
+ flags & DeviceFlags::kIsOpaque ? kOpaque_SkAlphaType
+ : kPremul_SkAlphaType,
+ sc->colorInfo().refColorSpace());
+}
+
+
+/** Checks that the alpha type is legal and gets constructor flags. Returns false if device creation
+ should fail. */
+bool Device::CheckAlphaTypeAndGetFlags(SkAlphaType alphaType,
+ InitContents init,
+ DeviceFlags* flags) {
+ *flags = DeviceFlags::kNone;
+ switch (alphaType) {
+ case kPremul_SkAlphaType:
+ break;
+ case kOpaque_SkAlphaType:
+ *flags |= DeviceFlags::kIsOpaque;
+ break;
+ default: // If it is unpremul or unknown don't try to render
+ return false;
+ }
+ if (InitContents::kClear == init) {
+ *flags |= DeviceFlags::kNeedClear;
+ }
+ return true;
+}
+
+sk_sp<Device> Device::Make(std::unique_ptr<SurfaceDrawContext> sdc,
+ SkAlphaType alphaType,
+ InitContents init) {
if (!sdc) {
return nullptr;
}
@@ -155,16 +188,16 @@
return sk_sp<Device>(new Device(std::move(sdc), flags));
}
-sk_sp<BaseDevice> Device::Make(GrRecordingContext* rContext,
- SkBudgeted budgeted,
- const SkImageInfo& ii,
- SkBackingFit fit,
- int sampleCount,
- GrMipmapped mipmapped,
- GrProtected isProtected,
- GrSurfaceOrigin origin,
- const SkSurfaceProps& props,
- InitContents init) {
+sk_sp<Device> Device::Make(GrRecordingContext* rContext,
+ SkBudgeted budgeted,
+ const SkImageInfo& ii,
+ SkBackingFit fit,
+ int sampleCount,
+ GrMipmapped mipmapped,
+ GrProtected isProtected,
+ GrSurfaceOrigin origin,
+ const SkSurfaceProps& props,
+ InitContents init) {
if (!rContext) {
return nullptr;
}
@@ -186,9 +219,8 @@
}
Device::Device(std::unique_ptr<SurfaceDrawContext> sdc, DeviceFlags flags)
- : INHERITED(sk_ref_sp(sdc->recordingContext()),
- MakeInfo(sdc.get(), flags),
- sdc->surfaceProps())
+ : SkBaseDevice(MakeInfo(sdc.get(), flags), sdc->surfaceProps())
+ , fContext(sk_ref_sp(sdc->recordingContext()))
, fSDFTControl(sdc->recordingContext()->priv().getSDFTControl(
sdc->surfaceProps().isUseDeviceIndependentFonts()))
, fSurfaceDrawContext(std::move(sdc))
@@ -200,6 +232,8 @@
}
}
+Device::~Device() = default;
+
///////////////////////////////////////////////////////////////////////////////
bool Device::onReadPixels(const SkPixmap& pm, int x, int y) {
@@ -649,7 +683,7 @@
ASSERT_SINGLE_OWNER
GR_CREATE_TRACE_MARKER_CONTEXT("skgpu::v1::Device", "drawArc", fContext.get());
if (paint.getMaskFilter()) {
- this->INHERITED::drawArc(oval, startAngle, sweepAngle, useCenter, paint);
+ this->SkBaseDevice::drawArc(oval, startAngle, sweepAngle, useCenter, paint);
return;
}
GrPaint grPaint;
@@ -796,7 +830,7 @@
ASSERT_SINGLE_OWNER
// clear of the source device must occur before CHECK_SHOULD_DRAW
GR_CREATE_TRACE_MARKER_CONTEXT("skgpu::v1::Device", "drawDevice", fContext.get());
- this->INHERITED::drawDevice(device, sampling, paint);
+ this->SkBaseDevice::drawDevice(device, sampling, paint);
}
void Device::drawImageRect(const SkImage* image,
@@ -935,7 +969,7 @@
if (!fSurfaceDrawContext->drawFastShadow(this->clip(), this->localToDevice(), path, rec)) {
// failed to find an accelerated case
- this->INHERITED::drawShadow(path, rec);
+ this->SkBaseDevice::drawShadow(path, rec);
}
}
@@ -1179,12 +1213,20 @@
return;
}
}
- this->INHERITED::drawDrawable(canvas, drawable, matrix);
+ this->SkBaseDevice::drawDrawable(canvas, drawable, matrix);
}
///////////////////////////////////////////////////////////////////////////////
+GrSurfaceProxyView Device::readSurfaceView() {
+ return this->surfaceFillContext()->readSurfaceView();
+}
+
+GrRenderTargetProxy* Device::targetProxy() {
+ return this->readSurfaceView().asRenderTargetProxy();
+}
+
bool Device::wait(int numSemaphores,
const GrBackendSemaphore* waitSemaphores,
bool deleteSemaphoresAfterWait) {
@@ -1194,6 +1236,14 @@
deleteSemaphoresAfterWait);
}
+void Device::discard() {
+ fSurfaceDrawContext->discard();
+}
+
+void Device::resolveMSAA() {
+ fSurfaceDrawContext->resolveMSAA();
+}
+
bool Device::replaceBackingProxy(SkSurface::ContentChangeMode mode,
sk_sp<GrRenderTargetProxy> newRTP,
GrColorType grColorType,
@@ -1224,6 +1274,41 @@
return true;
}
+bool Device::replaceBackingProxy(SkSurface::ContentChangeMode mode) {
+ ASSERT_SINGLE_OWNER
+
+ const SkImageInfo& ii = this->imageInfo();
+ GrRenderTargetProxy* oldRTP = this->targetProxy();
+ GrSurfaceProxyView oldView = this->readSurfaceView();
+
+ auto grColorType = SkColorTypeToGrColorType(ii.colorType());
+ auto format = fContext->priv().caps()->getDefaultBackendFormat(grColorType, GrRenderable::kYes);
+ if (!format.isValid()) {
+ return false;
+ }
+
+ GrProxyProvider* proxyProvider = fContext->priv().proxyProvider();
+ // This entry point is used by SkSurface_Gpu::onCopyOnWrite so it must create a
+ // kExact-backed render target proxy
+ sk_sp<GrTextureProxy> proxy =
+ proxyProvider->createProxy(format,
+ ii.dimensions(),
+ GrRenderable::kYes,
+ oldRTP->numSamples(),
+ oldView.mipmapped(),
+ SkBackingFit::kExact,
+ oldRTP->isBudgeted(),
+ GrProtected::kNo,
+ /*label=*/"BaseDevice_ReplaceBackingProxy");
+ if (!proxy) {
+ return false;
+ }
+
+ return this->replaceBackingProxy(mode, sk_ref_sp(proxy->asRenderTargetProxy()),
+ grColorType, ii.refColorSpace(), oldView.origin(),
+ this->surfaceProps());
+}
+
void Device::asyncRescaleAndReadPixels(const SkImageInfo& info,
const SkIRect& srcRect,
RescaleGamma rescaleGamma,
diff --git a/src/gpu/ganesh/v1/Device_drawTexture.cpp b/src/gpu/ganesh/v1/Device_drawTexture.cpp
index 6bc48e8..22bbe1d 100644
--- a/src/gpu/ganesh/v1/Device_drawTexture.cpp
+++ b/src/gpu/ganesh/v1/Device_drawTexture.cpp
@@ -7,6 +7,7 @@
#include "src/gpu/ganesh/v1/Device_v1.h"
+#include "include/core/SkBitmap.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/private/SkTPin.h"
diff --git a/src/gpu/ganesh/v1/Device_v1.h b/src/gpu/ganesh/v1/Device_v1.h
index 3683813..ca74397 100644
--- a/src/gpu/ganesh/v1/Device_v1.h
+++ b/src/gpu/ganesh/v1/Device_v1.h
@@ -5,57 +5,72 @@
* found in the LICENSE file.
*/
-#ifndef SkGpuDevice_DEFINED
-#define SkGpuDevice_DEFINED
+#ifndef skgpu_v1_Device_DEFINED
+#define skgpu_v1_Device_DEFINED
-#include "include/core/SkBitmap.h"
-#include "include/core/SkPicture.h"
-#include "include/core/SkRegion.h"
#include "include/core/SkSurface.h"
#include "include/gpu/GrTypes.h"
-#include "src/gpu/ganesh/BaseDevice.h"
+#include "src/core/SkDevice.h"
#include "src/gpu/ganesh/SkGr.h"
#include "src/gpu/ganesh/v1/ClipStack.h"
-#include "src/gpu/ganesh/v1/SurfaceDrawContext_v1.h"
+#include "src/text/gpu/SDFTControl.h"
+class SkBitmap;
+class SkLatticeIter;
+class SkRegion;
class SkSpecialImage;
class SkSurface;
class SkSurface_Gpu;
class SkVertices;
+namespace skgpu {
+class SurfaceContext;
+class SurfaceFillContext;
+}
+
namespace skgpu::v1 {
/**
- * Subclass of BaseDevice, which directs all drawing to the GrGpu owned by the canvas.
+ * Subclass of SkBaseDevice, which directs all drawing to the GrGpu owned by the canvas.
*/
-class Device final : public BaseDevice {
+class Device final : public SkBaseDevice {
public:
+ enum class InitContents {
+ kClear,
+ kUninit
+ };
+
+ GrSurfaceProxyView readSurfaceView();
+ GrRenderTargetProxy* targetProxy();
+
+ GrRecordingContext* recordingContext() const { return fContext.get(); }
+
bool wait(int numSemaphores,
const GrBackendSemaphore* waitSemaphores,
- bool deleteSemaphoresAfterWait) override;
+ bool deleteSemaphoresAfterWait);
- void discard() override {
- fSurfaceDrawContext->discard();
- }
-
- void resolveMSAA() override {
- fSurfaceDrawContext->resolveMSAA();
- }
+ void discard();
+ void resolveMSAA();
bool replaceBackingProxy(SkSurface::ContentChangeMode,
sk_sp<GrRenderTargetProxy>,
GrColorType,
sk_sp<SkColorSpace>,
GrSurfaceOrigin,
- const SkSurfaceProps&) override;
- using BaseDevice::replaceBackingProxy;
+ const SkSurfaceProps&);
+ bool replaceBackingProxy(SkSurface::ContentChangeMode);
+
+ using RescaleGamma = SkImage::RescaleGamma;
+ using RescaleMode = SkImage::RescaleMode;
+ using ReadPixelsCallback = SkImage::ReadPixelsCallback;
+ using ReadPixelsContext = SkImage::ReadPixelsContext;
void asyncRescaleAndReadPixels(const SkImageInfo& info,
const SkIRect& srcRect,
RescaleGamma rescaleGamma,
RescaleMode rescaleMode,
ReadPixelsCallback callback,
- ReadPixelsContext context) override;
+ ReadPixelsContext context);
void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
sk_sp<SkColorSpace> dstColorSpace,
@@ -64,19 +79,19 @@
RescaleGamma rescaleGamma,
RescaleMode,
ReadPixelsCallback callback,
- ReadPixelsContext context) override;
+ ReadPixelsContext context);
/**
* This factory uses the color space, origin, surface properties, and initialization
* method along with the provided proxy to create the gpu device.
*/
- static sk_sp<BaseDevice> Make(GrRecordingContext*,
- GrColorType,
- sk_sp<GrSurfaceProxy>,
- sk_sp<SkColorSpace>,
- GrSurfaceOrigin,
- const SkSurfaceProps&,
- InitContents);
+ static sk_sp<Device> Make(GrRecordingContext*,
+ GrColorType,
+ sk_sp<GrSurfaceProxy>,
+ sk_sp<SkColorSpace>,
+ GrSurfaceOrigin,
+ const SkSurfaceProps&,
+ InitContents);
/**
* This factory uses the budgeted, imageInfo, fit, sampleCount, mipmapped, and isProtected
@@ -84,22 +99,22 @@
* origin, surface properties, and initialization method are then used (with the created proxy)
* to create the device.
*/
- static sk_sp<BaseDevice> Make(GrRecordingContext*,
- SkBudgeted,
- const SkImageInfo&,
- SkBackingFit,
- int sampleCount,
- GrMipmapped,
- GrProtected,
- GrSurfaceOrigin,
- const SkSurfaceProps&,
- InitContents);
+ static sk_sp<Device> Make(GrRecordingContext*,
+ SkBudgeted,
+ const SkImageInfo&,
+ SkBackingFit,
+ int sampleCount,
+ GrMipmapped,
+ GrProtected,
+ GrSurfaceOrigin,
+ const SkSurfaceProps&,
+ InitContents);
- ~Device() override {}
+ ~Device() override;
- SurfaceDrawContext* surfaceDrawContext() override;
+ SurfaceDrawContext* surfaceDrawContext();
const SurfaceDrawContext* surfaceDrawContext() const;
- skgpu::SurfaceFillContext* surfaceFillContext() override;
+ skgpu::SurfaceFillContext* surfaceFillContext();
SkStrikeDeviceInfo strikeDeviceInfo() const override;
@@ -150,6 +165,8 @@
bool android_utils_clipWithStencil() override;
+ Device* asGaneshDevice() override { return this; }
+
protected:
bool onReadPixels(const SkPixmap&, int, int) override;
bool onWritePixels(const SkPixmap&, int, int) override;
@@ -197,15 +214,28 @@
SkIRect onDevClipBounds() const override { return fClip.getConservativeBounds(); }
private:
+ enum class DeviceFlags {
+ kNone = 0,
+ kNeedClear = 1 << 0, //!< Surface requires an initial clear
+ kIsOpaque = 1 << 1, //!< Hint from client that rendering to this device will be
+ // opaque even if the config supports alpha.
+ };
+ GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(DeviceFlags);
+
+ static SkImageInfo MakeInfo(SurfaceContext*, DeviceFlags);
+ static bool CheckAlphaTypeAndGetFlags(SkAlphaType, InitContents, DeviceFlags*);
+
+ sk_sp<GrRecordingContext> fContext;
+
const sktext::gpu::SDFTControl fSDFTControl;
std::unique_ptr<SurfaceDrawContext> fSurfaceDrawContext;
ClipStack fClip;
- static sk_sp<BaseDevice> Make(std::unique_ptr<SurfaceDrawContext>,
- SkAlphaType,
- InitContents);
+ static sk_sp<Device> Make(std::unique_ptr<SurfaceDrawContext>,
+ SkAlphaType,
+ InitContents);
Device(std::unique_ptr<SurfaceDrawContext>, DeviceFlags);
@@ -257,11 +287,10 @@
const SkPaint&);
friend class ::SkSurface_Gpu; // for access to surfaceProps
- using INHERITED = BaseDevice;
};
+GR_MAKE_BITFIELD_CLASS_OPS(Device::DeviceFlags)
+
} // namespace skgpu::v1
-#undef GR_CLIP_STACK
-
-#endif
+#endif // skgpu_v1_Device_DEFINED
diff --git a/src/gpu/ganesh/v1/SurfaceFillContext_v1.h b/src/gpu/ganesh/v1/SurfaceFillContext_v1.h
index 812d9a7..758d775 100644
--- a/src/gpu/ganesh/v1/SurfaceFillContext_v1.h
+++ b/src/gpu/ganesh/v1/SurfaceFillContext_v1.h
@@ -20,7 +20,6 @@
class GrFragmentProcessor;
class GrImageContext;
-class GrOp;
class GrBackendFormat;
class GrRecordingContext;
class GrSurfaceProxyView;
diff --git a/src/gpu/ganesh/vk/GrVkSecondaryCBDrawContext.cpp b/src/gpu/ganesh/vk/GrVkSecondaryCBDrawContext.cpp
index 949058c..fa40ecb 100644
--- a/src/gpu/ganesh/vk/GrVkSecondaryCBDrawContext.cpp
+++ b/src/gpu/ganesh/vk/GrVkSecondaryCBDrawContext.cpp
@@ -47,7 +47,7 @@
imageInfo.refColorSpace(),
kTopLeft_GrSurfaceOrigin,
SkSurfacePropsCopyOrDefault(props),
- skgpu::BaseDevice::InitContents::kUninit);
+ skgpu::v1::Device::InitContents::kUninit);
if (!device) {
return nullptr;
}
@@ -56,7 +56,7 @@
props));
}
-GrVkSecondaryCBDrawContext::GrVkSecondaryCBDrawContext(sk_sp<skgpu::BaseDevice> device,
+GrVkSecondaryCBDrawContext::GrVkSecondaryCBDrawContext(sk_sp<skgpu::v1::Device> device,
const SkSurfaceProps* props)
: fDevice(device)
, fProps(SkSurfacePropsCopyOrDefault(props)) {}
diff --git a/src/gpu/ganesh/vk/GrVkSecondaryCBDrawContext_impl.h b/src/gpu/ganesh/vk/GrVkSecondaryCBDrawContext_impl.h
index 48b8b38..5cca04f 100644
--- a/src/gpu/ganesh/vk/GrVkSecondaryCBDrawContext_impl.h
+++ b/src/gpu/ganesh/vk/GrVkSecondaryCBDrawContext_impl.h
@@ -15,7 +15,7 @@
class GrBackendSemaphore;
class GrRecordingContext;
struct GrVkDrawableInfo;
-namespace skgpu { class BaseDevice; }
+namespace skgpu::v1 { class Device; }
class SkCanvas;
class SkDeferredDisplayList;
struct SkImageInfo;
@@ -114,9 +114,9 @@
bool isCompatible(const SkSurfaceCharacterization& characterization) const;
private:
- explicit GrVkSecondaryCBDrawContext(sk_sp<skgpu::BaseDevice>, const SkSurfaceProps*);
+ explicit GrVkSecondaryCBDrawContext(sk_sp<skgpu::v1::Device>, const SkSurfaceProps*);
- sk_sp<skgpu::BaseDevice> fDevice;
+ sk_sp<skgpu::v1::Device> fDevice;
std::unique_ptr<SkCanvas> fCachedCanvas;
const SkSurfaceProps fProps;
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 1ba0e01..c8abc31 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -16,7 +16,6 @@
#include "include/gpu/GrRecordingContext.h"
#include "src/core/SkImagePriv.h"
#include "src/core/SkSurfacePriv.h"
-#include "src/gpu/ganesh/BaseDevice.h"
#include "src/gpu/ganesh/GrAHardwareBufferUtils_impl.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrContextThreadSafeProxyPriv.h"
@@ -31,7 +30,7 @@
#if SK_SUPPORT_GPU
-SkSurface_Gpu::SkSurface_Gpu(sk_sp<skgpu::BaseDevice> device)
+SkSurface_Gpu::SkSurface_Gpu(sk_sp<skgpu::v1::Device> device)
: INHERITED(device->width(), device->height(), &device->surfaceProps())
, fDevice(std::move(device)) {
SkASSERT(fDevice->targetProxy()->priv().isExact());
@@ -44,7 +43,7 @@
return fDevice->recordingContext();
}
-skgpu::BaseDevice* SkSurface_Gpu::getDevice() {
+skgpu::v1::Device* SkSurface_Gpu::getDevice() {
return fDevice.get();
}
@@ -422,7 +421,7 @@
auto device = rContext->priv().createDevice(budgeted, c.imageInfo(), SkBackingFit::kExact,
c.sampleCount(), GrMipmapped(c.isMipMapped()),
c.isProtected(), c.origin(), c.surfaceProps(),
- skgpu::BaseDevice::InitContents::kClear);
+ skgpu::v1::Device::InitContents::kClear);
if (!device) {
return nullptr;
}
@@ -481,7 +480,7 @@
auto device = rContext->priv().createDevice(budgeted, info, SkBackingFit::kExact,
sampleCount, mipmapped, GrProtected::kNo, origin,
SkSurfacePropsCopyOrDefault(props),
- skgpu::BaseDevice::InitContents::kClear);
+ skgpu::v1::Device::InitContents::kClear);
if (!device) {
return nullptr;
}
@@ -523,7 +522,7 @@
auto device = rContext->priv().createDevice(grColorType, std::move(proxy),
std::move(colorSpace), origin,
SkSurfacePropsCopyOrDefault(props),
- skgpu::BaseDevice::InitContents::kUninit);
+ skgpu::v1::Device::InitContents::kUninit);
if (!device) {
return nullptr;
}
@@ -639,7 +638,7 @@
auto device = rContext->priv().createDevice(grColorType, std::move(proxy),
std::move(colorSpace), origin,
SkSurfacePropsCopyOrDefault(props),
- skgpu::BaseDevice::InitContents::kUninit);
+ skgpu::v1::Device::InitContents::kUninit);
if (!device) {
return nullptr;
}
diff --git a/src/image/SkSurface_Gpu.h b/src/image/SkSurface_Gpu.h
index b0b9795..4a7bc42 100644
--- a/src/image/SkSurface_Gpu.h
+++ b/src/image/SkSurface_Gpu.h
@@ -14,11 +14,11 @@
#if SK_SUPPORT_GPU
class GrBackendFormat;
-namespace skgpu { class BaseDevice; }
+namespace skgpu::v1 { class Device; }
class SkSurface_Gpu : public SkSurface_Base {
public:
- SkSurface_Gpu(sk_sp<skgpu::BaseDevice>);
+ SkSurface_Gpu(sk_sp<skgpu::v1::Device>);
~SkSurface_Gpu() override;
GrRecordingContext* onGetRecordingContext() override;
@@ -58,10 +58,10 @@
bool onDraw(sk_sp<const SkDeferredDisplayList>, SkIPoint offset) override;
sk_sp<const SkCapabilities> onCapabilities() override;
- skgpu::BaseDevice* getDevice();
+ skgpu::v1::Device* getDevice();
private:
- sk_sp<skgpu::BaseDevice> fDevice;
+ sk_sp<skgpu::v1::Device> fDevice;
using INHERITED = SkSurface_Base;
};
diff --git a/src/image/SkSurface_GpuMtl.mm b/src/image/SkSurface_GpuMtl.mm
index e6ffd29..29d2093 100644
--- a/src/image/SkSurface_GpuMtl.mm
+++ b/src/image/SkSurface_GpuMtl.mm
@@ -88,7 +88,7 @@
std::move(colorSpace),
origin,
SkSurfacePropsCopyOrDefault(surfaceProps),
- skgpu::BaseDevice::InitContents::kUninit);
+ skgpu::v1::Device::InitContents::kUninit);
if (!device) {
return nullptr;
}
@@ -157,7 +157,7 @@
std::move(colorSpace),
origin,
SkSurfacePropsCopyOrDefault(surfaceProps),
- skgpu::BaseDevice::InitContents::kUninit);
+ skgpu::v1::Device::InitContents::kUninit);
if (!device) {
return nullptr;
}
diff --git a/tests/DeviceTest.cpp b/tests/DeviceTest.cpp
index 5fb01d1..8855b7c 100644
--- a/tests/DeviceTest.cpp
+++ b/tests/DeviceTest.cpp
@@ -89,7 +89,7 @@
auto device = dContext->priv().createDevice(SkBudgeted::kNo, ii, SkBackingFit::kExact,
1, GrMipmapped::kNo, GrProtected::kNo,
kBottomLeft_GrSurfaceOrigin, SkSurfaceProps(),
- skgpu::BaseDevice::InitContents::kClear);
+ skgpu::v1::Device::InitContents::kClear);
SkBitmap bm;
SkAssertResult(bm.tryAllocN32Pixels(kWidth, kHeight));
diff --git a/tests/GrMipMappedTest.cpp b/tests/GrMipMappedTest.cpp
index 170e3cb..ac7a16b 100644
--- a/tests/GrMipMappedTest.cpp
+++ b/tests/GrMipMappedTest.cpp
@@ -15,7 +15,6 @@
#ifdef SK_DIRECT3D
#include "include/gpu/d3d/GrD3DTypes.h"
#endif
-#include "src/gpu/ganesh/BaseDevice.h"
#include "src/gpu/ganesh/GrBackendTextureImageGenerator.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrDrawingManager.h"
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index f87804e..96eb0e2 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -20,7 +20,6 @@
#include "src/core/SkCanvasPriv.h"
#include "src/core/SkDevice.h"
#include "src/core/SkUtils.h"
-#include "src/gpu/ganesh/BaseDevice.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrGpu.h"
#include "src/gpu/ganesh/GrGpuResourcePriv.h"