Cleanup SkGpuDevice factory functions a bit
This CL:
Clumps the proxy creation & device creation parameters together in the factories
Makes the raw SkGpuDevice factory take a "const SkSurfaceProps&"
Makes both the proxy-wrapping & raw factories call the SDC-based factory
Change-Id: I73fe88b639c015691fbbccdd9ff0acf2f0dad34c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/410956
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/core/SkDeferredDisplayListRecorder.cpp b/src/core/SkDeferredDisplayListRecorder.cpp
index a1dd373..5ce559a 100644
--- a/src/core/SkDeferredDisplayListRecorder.cpp
+++ b/src/core/SkDeferredDisplayListRecorder.cpp
@@ -186,8 +186,8 @@
auto device = SkGpuDevice::Make(fContext.get(),
grColorType,
- fCharacterization.refColorSpace(),
fTargetProxy,
+ fCharacterization.refColorSpace(),
fCharacterization.origin(),
fCharacterization.surfaceProps(),
SkBaseGpuDevice::kUninit_InitContents);
diff --git a/src/core/SkSpecialSurface.cpp b/src/core/SkSpecialSurface.cpp
index 97d53a3..916d655 100644
--- a/src/core/SkSpecialSurface.cpp
+++ b/src/core/SkSpecialSurface.cpp
@@ -164,8 +164,8 @@
}
auto device = SkGpuDevice::Make(rContext, SkBudgeted::kYes, ii, SkBackingFit::kApprox, 1,
- kBottomLeft_GrSurfaceOrigin, &props, GrMipmapped::kNo,
- GrProtected::kNo, SkGpuDevice::kUninit_InitContents);
+ GrMipmapped::kNo, GrProtected::kNo, kBottomLeft_GrSurfaceOrigin,
+ props, SkGpuDevice::kUninit_InitContents);
if (!device) {
return nullptr;
}
diff --git a/src/gpu/GrOnFlushResourceProvider.cpp b/src/gpu/GrOnFlushResourceProvider.cpp
index e2bcacc..599073e 100644
--- a/src/gpu/GrOnFlushResourceProvider.cpp
+++ b/src/gpu/GrOnFlushResourceProvider.cpp
@@ -32,16 +32,16 @@
return nullptr;
}
- auto surfaceDrawContext = GrSurfaceDrawContext::Make(context, colorType, std::move(colorSpace),
- std::move(proxy), origin, props, true);
+ auto sdc = GrSurfaceDrawContext::Make(context, colorType, std::move(proxy),
+ std::move(colorSpace), origin, props, true);
- if (!surfaceDrawContext) {
+ if (!sdc) {
return nullptr;
}
- surfaceDrawContext->discard();
+ sdc->discard();
- return surfaceDrawContext;
+ return sdc;
}
void GrOnFlushResourceProvider::addTextureResolveTask(sk_sp<GrTextureProxy> textureProxy,
diff --git a/src/gpu/GrSurfaceDrawContext.cpp b/src/gpu/GrSurfaceDrawContext.cpp
index 15f2cd1..4dddf1d 100644
--- a/src/gpu/GrSurfaceDrawContext.cpp
+++ b/src/gpu/GrSurfaceDrawContext.cpp
@@ -92,28 +92,28 @@
GrDrawingManager* fDrawingManager;
};
-std::unique_ptr<GrSurfaceDrawContext> GrSurfaceDrawContext::Make(GrRecordingContext* context,
+std::unique_ptr<GrSurfaceDrawContext> GrSurfaceDrawContext::Make(GrRecordingContext* rContext,
GrColorType colorType,
- sk_sp<SkColorSpace> colorSpace,
sk_sp<GrSurfaceProxy> proxy,
+ sk_sp<SkColorSpace> colorSpace,
GrSurfaceOrigin origin,
const SkSurfaceProps& surfaceProps,
bool flushTimeOpsTask) {
- if (!proxy) {
+ if (!rContext || !proxy) {
return nullptr;
}
const GrBackendFormat& format = proxy->backendFormat();
GrSwizzle readSwizzle, writeSwizzle;
if (colorType != GrColorType::kUnknown) {
- readSwizzle = context->priv().caps()->getReadSwizzle(format, colorType);
- writeSwizzle = context->priv().caps()->getWriteSwizzle(format, colorType);
+ readSwizzle = rContext->priv().caps()->getReadSwizzle(format, colorType);
+ writeSwizzle = rContext->priv().caps()->getWriteSwizzle(format, colorType);
}
GrSurfaceProxyView readView ( proxy, origin, readSwizzle);
GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle);
- return std::make_unique<GrSurfaceDrawContext>(context,
+ return std::make_unique<GrSurfaceDrawContext>(rContext,
std::move(readView),
std::move(writeView),
colorType,
@@ -171,7 +171,7 @@
}
std::unique_ptr<GrSurfaceDrawContext> GrSurfaceDrawContext::Make(
- GrRecordingContext* context,
+ GrRecordingContext* rContext,
GrColorType colorType,
sk_sp<SkColorSpace> colorSpace,
SkBackingFit fit,
@@ -182,26 +182,26 @@
GrProtected isProtected,
GrSurfaceOrigin origin,
SkBudgeted budgeted) {
- auto format = context->priv().caps()->getDefaultBackendFormat(colorType, GrRenderable::kYes);
+ auto format = rContext->priv().caps()->getDefaultBackendFormat(colorType, GrRenderable::kYes);
if (!format.isValid()) {
return nullptr;
}
- sk_sp<GrTextureProxy> proxy = context->priv().proxyProvider()->createProxy(format,
- dimensions,
- GrRenderable::kYes,
- sampleCnt,
- mipMapped,
- fit,
- budgeted,
- isProtected);
+ sk_sp<GrTextureProxy> proxy = rContext->priv().proxyProvider()->createProxy(format,
+ dimensions,
+ GrRenderable::kYes,
+ sampleCnt,
+ mipMapped,
+ fit,
+ budgeted,
+ isProtected);
if (!proxy) {
return nullptr;
}
- return GrSurfaceDrawContext::Make(context,
+ return GrSurfaceDrawContext::Make(rContext,
colorType,
- std::move(colorSpace),
std::move(proxy),
+ std::move(colorSpace),
origin,
surfaceProps);
}
@@ -243,7 +243,7 @@
return nullptr;
}
- return GrSurfaceDrawContext::Make(context, colorType, std::move(colorSpace), std::move(proxy),
+ return GrSurfaceDrawContext::Make(context, colorType, std::move(proxy), std::move(colorSpace),
origin, surfaceProps);
}
diff --git a/src/gpu/GrSurfaceDrawContext.h b/src/gpu/GrSurfaceDrawContext.h
index 68cfce1..d1f3397 100644
--- a/src/gpu/GrSurfaceDrawContext.h
+++ b/src/gpu/GrSurfaceDrawContext.h
@@ -59,8 +59,8 @@
public:
static std::unique_ptr<GrSurfaceDrawContext> Make(GrRecordingContext*,
GrColorType,
- sk_sp<SkColorSpace>,
sk_sp<GrSurfaceProxy>,
+ sk_sp<SkColorSpace>,
GrSurfaceOrigin,
const SkSurfaceProps&,
bool flushTimeOpsTask = false);
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 1b6c00b..88df88c 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -74,63 +74,64 @@
sk_sp<SkGpuDevice> SkGpuDevice::Make(GrRecordingContext* rContext,
GrColorType colorType,
- sk_sp<SkColorSpace> colorSpace,
sk_sp<GrSurfaceProxy> proxy,
+ sk_sp<SkColorSpace> colorSpace,
GrSurfaceOrigin origin,
const SkSurfaceProps& surfaceProps,
InitContents init) {
auto sdc = GrSurfaceDrawContext::Make(rContext,
colorType,
- std::move(colorSpace),
std::move(proxy),
+ std::move(colorSpace),
origin,
surfaceProps);
+
+ return SkGpuDevice::Make(std::move(sdc), nullptr, init);
+}
+
+sk_sp<SkGpuDevice> SkGpuDevice::Make(std::unique_ptr<GrSurfaceDrawContext> sdc,
+ const SkImageInfo* ii,
+ InitContents init) {
if (!sdc) {
return nullptr;
}
- return SkGpuDevice::Make(std::move(sdc), init);
-}
-
-sk_sp<SkGpuDevice> SkGpuDevice::Make(std::unique_ptr<GrSurfaceDrawContext> surfaceDrawContext,
- InitContents init) {
- if (!surfaceDrawContext) {
- return nullptr;
- }
-
- GrRecordingContext* rContext = surfaceDrawContext->recordingContext();
+ GrRecordingContext* rContext = sdc->recordingContext();
if (rContext->abandoned()) {
return nullptr;
}
- SkColorType ct = GrColorTypeToSkColorType(surfaceDrawContext->colorInfo().colorType());
+ SkColorType ct = GrColorTypeToSkColorType(sdc->colorInfo().colorType());
unsigned flags;
if (!rContext->colorTypeSupportedAsSurface(ct) ||
- !CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) {
+ !CheckAlphaTypeAndGetFlags(ii, init, &flags)) {
return nullptr;
}
- return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(surfaceDrawContext), flags));
+ return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(sdc), flags));
}
-sk_sp<SkGpuDevice> SkGpuDevice::Make(GrRecordingContext* rContext, SkBudgeted budgeted,
- const SkImageInfo& info, SkBackingFit fit, int sampleCount,
- GrSurfaceOrigin origin, const SkSurfaceProps* props,
- GrMipmapped mipMapped, GrProtected isProtected,
+sk_sp<SkGpuDevice> SkGpuDevice::Make(GrRecordingContext* rContext,
+ SkBudgeted budgeted,
+ const SkImageInfo& ii,
+ SkBackingFit fit,
+ int sampleCount,
+ GrMipmapped mipMapped,
+ GrProtected isProtected,
+ GrSurfaceOrigin origin,
+ const SkSurfaceProps& props,
InitContents init) {
- unsigned flags;
- if (!rContext->colorTypeSupportedAsSurface(info.colorType()) ||
- !CheckAlphaTypeAndGetFlags(&info, init, &flags)) {
- return nullptr;
- }
+ auto sdc = MakeSurfaceDrawContext(rContext,
+ budgeted,
+ ii,
+ fit,
+ sampleCount,
+ mipMapped,
+ isProtected,
+ origin,
+ props);
- auto sdc = MakeSurfaceDrawContext(rContext, budgeted, info, fit, sampleCount, origin,
- props, mipMapped, isProtected);
- if (!sdc) {
- return nullptr;
- }
-
- return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(sdc), flags));
+ return SkGpuDevice::Make(std::move(sdc), &ii, init);
}
static SkImageInfo make_info(GrSurfaceDrawContext* context, bool opaque) {
@@ -170,10 +171,10 @@
const SkImageInfo& origInfo,
SkBackingFit fit,
int sampleCount,
- GrSurfaceOrigin origin,
- const SkSurfaceProps* surfaceProps,
GrMipmapped mipmapped,
- GrProtected isProtected) {
+ GrProtected isProtected,
+ GrSurfaceOrigin origin,
+ const SkSurfaceProps& surfaceProps) {
if (!rContext) {
return nullptr;
}
@@ -182,7 +183,7 @@
// they need to be exact.
return GrSurfaceDrawContext::Make(
rContext, SkColorTypeToGrColorType(origInfo.colorType()), origInfo.refColorSpace(),
- fit, origInfo.dimensions(), SkSurfacePropsCopyOrDefault(surfaceProps),
+ fit, origInfo.dimensions(), surfaceProps,
sampleCount, mipmapped, isProtected, origin, budgeted);
}
@@ -266,10 +267,10 @@
this->imageInfo(),
SkBackingFit::kExact,
fSurfaceDrawContext->numSamples(),
- fSurfaceDrawContext->origin(),
- &this->surfaceProps(),
fSurfaceDrawContext->mipmapped(),
- GrProtected::kNo);
+ GrProtected::kNo,
+ fSurfaceDrawContext->origin(),
+ this->surfaceProps());
if (!newSDC) {
return;
}
@@ -1031,7 +1032,7 @@
// Skia's convention is to only clear a device if it is non-opaque.
InitContents init = cinfo.fInfo.isOpaque() ? kUninit_InitContents : kClear_InitContents;
- return SkGpuDevice::Make(std::move(sdc), init).release();
+ return SkGpuDevice::Make(std::move(sdc), &cinfo.fInfo, init).release();
}
sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfaceProps& props) {
diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h
index d53e261..f574fbd 100644
--- a/src/gpu/SkGpuDevice.h
+++ b/src/gpu/SkGpuDevice.h
@@ -44,8 +44,8 @@
*/
static sk_sp<SkGpuDevice> Make(GrRecordingContext*,
GrColorType,
- sk_sp<SkColorSpace>,
sk_sp<GrSurfaceProxy>,
+ sk_sp<SkColorSpace>,
GrSurfaceOrigin,
const SkSurfaceProps&,
InitContents);
@@ -61,10 +61,10 @@
const SkImageInfo&,
SkBackingFit,
int sampleCount,
- GrSurfaceOrigin,
- const SkSurfaceProps*,
GrMipmapped,
GrProtected,
+ GrSurfaceOrigin,
+ const SkSurfaceProps&,
InitContents);
~SkGpuDevice() override {}
@@ -181,7 +181,9 @@
static bool CheckAlphaTypeAndGetFlags(const SkImageInfo* info, InitContents init,
unsigned* flags);
- static sk_sp<SkGpuDevice> Make(std::unique_ptr<GrSurfaceDrawContext>, InitContents);
+ static sk_sp<SkGpuDevice> Make(std::unique_ptr<GrSurfaceDrawContext>,
+ const SkImageInfo*,
+ InitContents);
SkGpuDevice(std::unique_ptr<GrSurfaceDrawContext>, unsigned flags);
@@ -216,10 +218,10 @@
const SkImageInfo&,
SkBackingFit,
int sampleCount,
- GrSurfaceOrigin,
- const SkSurfaceProps*,
GrMipmapped,
- GrProtected);
+ GrProtected,
+ GrSurfaceOrigin,
+ const SkSurfaceProps&);
friend class SkSurface_Gpu; // for access to surfaceProps
using INHERITED = SkBaseGpuDevice;
diff --git a/src/gpu/vk/GrVkSecondaryCBDrawContext.cpp b/src/gpu/vk/GrVkSecondaryCBDrawContext.cpp
index f33d2bb..b53981d 100644
--- a/src/gpu/vk/GrVkSecondaryCBDrawContext.cpp
+++ b/src/gpu/vk/GrVkSecondaryCBDrawContext.cpp
@@ -44,8 +44,8 @@
auto device = SkGpuDevice::Make(rContext,
SkColorTypeToGrColorType(imageInfo.colorType()),
- imageInfo.refColorSpace(),
std::move(proxy),
+ imageInfo.refColorSpace(),
kTopLeft_GrSurfaceOrigin,
SkSurfacePropsCopyOrDefault(props),
SkGpuDevice::kUninit_InitContents);
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 433da1b..0d9a4d7 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -414,8 +414,8 @@
}
auto device = SkGpuDevice::Make(rContext, budgeted, c.imageInfo(), SkBackingFit::kExact,
- c.sampleCount(), c.origin(), &c.surfaceProps(),
- GrMipmapped(c.isMipMapped()), c.isProtected(),
+ c.sampleCount(), GrMipmapped(c.isMipMapped()), c.isProtected(),
+ c.origin(), c.surfaceProps(),
SkBaseGpuDevice::kClear_InitContents);
if (!device) {
return nullptr;
@@ -473,8 +473,8 @@
}
sk_sp<SkGpuDevice> device(SkGpuDevice::Make(rContext, budgeted, info, SkBackingFit::kExact,
- sampleCount, origin, props, mipMapped,
- GrProtected::kNo,
+ sampleCount, mipMapped, GrProtected::kNo, origin,
+ SkSurfacePropsCopyOrDefault(props),
SkBaseGpuDevice::kClear_InitContents));
if (!device) {
return nullptr;
@@ -515,8 +515,8 @@
return nullptr;
}
- auto device = SkGpuDevice::Make(rContext, grColorType, std::move(colorSpace),
- std::move(proxy), origin, SkSurfacePropsCopyOrDefault(props),
+ auto device = SkGpuDevice::Make(rContext, grColorType, std::move(proxy), std::move(colorSpace),
+ origin, SkSurfacePropsCopyOrDefault(props),
SkBaseGpuDevice::kUninit_InitContents);
if (!device) {
return nullptr;
@@ -627,7 +627,7 @@
return nullptr;
}
- auto device = SkGpuDevice::Make(context, grColorType, std::move(colorSpace), std::move(proxy),
+ auto device = SkGpuDevice::Make(context, grColorType, std::move(proxy), std::move(colorSpace),
origin, SkSurfacePropsCopyOrDefault(props),
SkBaseGpuDevice::kUninit_InitContents);
if (!device) {
diff --git a/src/image/SkSurface_GpuMtl.mm b/src/image/SkSurface_GpuMtl.mm
index 48b27b6..7bee00a 100644
--- a/src/image/SkSurface_GpuMtl.mm
+++ b/src/image/SkSurface_GpuMtl.mm
@@ -86,8 +86,8 @@
auto device = SkGpuDevice::Make(rContext,
grColorType,
- std::move(colorSpace),
std::move(proxy),
+ std::move(colorSpace),
origin,
SkSurfacePropsCopyOrDefault(surfaceProps),
SkBaseGpuDevice::kUninit_InitContents);
@@ -155,8 +155,8 @@
auto device = SkGpuDevice::Make(rContext,
grColorType,
- std::move(colorSpace),
std::move(proxy),
+ std::move(colorSpace),
origin,
SkSurfacePropsCopyOrDefault(surfaceProps),
SkBaseGpuDevice::kUninit_InitContents);
diff --git a/tests/DeviceTest.cpp b/tests/DeviceTest.cpp
index 9d3db89..8a3268c 100644
--- a/tests/DeviceTest.cpp
+++ b/tests/DeviceTest.cpp
@@ -85,8 +85,8 @@
SkImageInfo ii = SkImageInfo::MakeN32Premul(2*kWidth, 2*kHeight);
sk_sp<SkBaseDevice> gpuDev(SkGpuDevice::Make(context, SkBudgeted::kNo, ii, SkBackingFit::kExact,
- 1, kBottomLeft_GrSurfaceOrigin, nullptr,
- GrMipmapped::kNo, GrProtected::kNo,
+ 1, GrMipmapped::kNo, GrProtected::kNo,
+ kBottomLeft_GrSurfaceOrigin, SkSurfaceProps(),
SkBaseGpuDevice::kClear_InitContents));
SkBitmap bm;
diff --git a/tests/GrMipMappedTest.cpp b/tests/GrMipMappedTest.cpp
index 1ec5eeb..237b10c 100644
--- a/tests/GrMipMappedTest.cpp
+++ b/tests/GrMipMappedTest.cpp
@@ -385,8 +385,8 @@
auto rtc = GrSurfaceDrawContext::Make(rContext,
colorType,
- nullptr,
std::move(renderTarget),
+ nullptr,
kTopLeft_GrSurfaceOrigin,
SkSurfaceProps(),
false);
@@ -446,7 +446,7 @@
mipmapProxy->markMipmapsClean();
auto mipmapRTC = GrSurfaceDrawContext::Make(
- dContext.get(), colorType, nullptr, mipmapProxy, kTopLeft_GrSurfaceOrigin,
+ dContext.get(), colorType, mipmapProxy, nullptr, kTopLeft_GrSurfaceOrigin,
SkSurfaceProps(), false);
mipmapRTC->clear(SkPMColor4f{.1f, .2f, .3f, .4f});