Reland "Migrate metal tools away from GrContext"
This reverts commit 18f4b1c7e31a3543159fb0e6f9dd08521a3337d7.
Reason for revert: Fixed iOS
Original change's description:
> Revert "Migrate metal tools away from GrContext"
>
> This reverts commit 3eb813e0cc134767a10e9efd4811fc519eccb280.
>
> Reason for revert: Broke iOS
>
> Original change's description:
> > Migrate metal tools away from GrContext
> >
> > Change-Id: I73a73ca5d088c35acd23be3336d8d1e3e859a82e
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318760
> > Commit-Queue: Brian Salomon <bsalomon@google.com>
> > Auto-Submit: Adlai Holler <adlai@google.com>
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
>
> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
>
> Change-Id: Idf74c936cfe8481e18455dcc0faa21155884b198
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319017
> Reviewed-by: Adlai Holler <adlai@google.com>
> Commit-Queue: Adlai Holler <adlai@google.com>
TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
Change-Id: I6e14a333be4a960af0434bbcb6ce9a1a2271dca6
Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac-Clang-arm64-Debug-iOS_Metal,Test-iOS-Clang-iPhone11-GPU-AppleA13-arm64-Debug-All-Metal,Test-Mac10.13-Clang-MacBook10.1-GPU-IntelHD615-x86_64-Debug-All-Metal,Test-Mac10.13-Clang-MacBook10.1-GPU-IntelHD615-x86_64-Debug-All-DDL3_Metal
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319018
Commit-Queue: Adlai Holler <adlai@google.com>
Reviewed-by: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/experimental/minimal_ios_mtl_skia_app/main.mm b/experimental/minimal_ios_mtl_skia_app/main.mm
index 26ef3bd..ba54917 100644
--- a/experimental/minimal_ios_mtl_skia_app/main.mm
+++ b/experimental/minimal_ios_mtl_skia_app/main.mm
@@ -14,6 +14,7 @@
#include "include/core/SkTime.h"
#include "include/effects/SkGradientShader.h"
#include "include/gpu/GrBackendSurface.h"
+#include "include/gpu/GrDirectContext.h"
#include "include/gpu/mtl/GrMtlTypes.h"
#import <Metal/Metal.h>
@@ -41,7 +42,7 @@
////////////////////////////////////////////////////////////////////////////////
@interface AppViewDelegate : NSObject <MTKViewDelegate>
-@property (assign, nonatomic) GrContext* grContext; // non-owning pointer.
+@property (assign, nonatomic) GrDirectContext* grContext; // non-owning pointer.
@property (assign, nonatomic) id<MTLCommandQueue> metalQueue;
@end
diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h
index 5236d95..9db228a 100644
--- a/include/core/SkSurface.h
+++ b/include/core/SkSurface.h
@@ -307,7 +307,7 @@
instantiated; may not be nullptr
@return created SkSurface, or nullptr
*/
- static sk_sp<SkSurface> MakeFromCAMetalLayer(GrContext* context,
+ static sk_sp<SkSurface> MakeFromCAMetalLayer(GrRecordingContext* context,
GrMTLHandle layer,
GrSurfaceOrigin origin,
int sampleCnt,
@@ -334,7 +334,7 @@
fonts; may be nullptr
@return created SkSurface, or nullptr
*/
- static sk_sp<SkSurface> MakeFromMTKView(GrContext* context,
+ static sk_sp<SkSurface> MakeFromMTKView(GrRecordingContext* context,
GrMTLHandle mtkView,
GrSurfaceOrigin origin,
int sampleCnt,
diff --git a/src/image/SkSurface_GpuMtl.mm b/src/image/SkSurface_GpuMtl.mm
index deab4fe..b41e2f3 100644
--- a/src/image/SkSurface_GpuMtl.mm
+++ b/src/image/SkSurface_GpuMtl.mm
@@ -9,8 +9,8 @@
#include "include/core/SkSurface.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/mtl/GrMtlTypes.h"
-#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrProxyProvider.h"
+#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrRenderTargetContext.h"
#include "src/gpu/GrResourceProvider.h"
#include "src/gpu/GrResourceProviderPriv.h"
@@ -26,7 +26,7 @@
#import <QuartzCore/CAMetalLayer.h>
#import <MetalKit/MetalKit.h>
-sk_sp<SkSurface> SkSurface::MakeFromCAMetalLayer(GrContext* context,
+sk_sp<SkSurface> SkSurface::MakeFromCAMetalLayer(GrRecordingContext* rContext,
GrMTLHandle layer,
GrSurfaceOrigin origin,
int sampleCnt,
@@ -34,8 +34,8 @@
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps,
GrMTLHandle* drawable) {
- GrProxyProvider* proxyProvider = context->priv().proxyProvider();
- const GrCaps* caps = context->priv().caps();
+ GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
+ const GrCaps* caps = rContext->priv().caps();
CAMetalLayer* metalLayer = (__bridge CAMetalLayer*)layer;
GrBackendFormat backendFormat = GrBackendFormat::MakeMtl(metalLayer.pixelFormat);
@@ -90,23 +90,23 @@
GrSurfaceProxyView readView(proxy, origin, readSwizzle);
GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle);
- auto rtc = std::make_unique<GrRenderTargetContext>(context, std::move(readView),
+ auto rtc = std::make_unique<GrRenderTargetContext>(rContext, std::move(readView),
std::move(writeView), grColorType,
colorSpace, surfaceProps);
- sk_sp<SkSurface> surface = SkSurface_Gpu::MakeWrappedRenderTarget(context, std::move(rtc));
+ sk_sp<SkSurface> surface = SkSurface_Gpu::MakeWrappedRenderTarget(rContext, std::move(rtc));
return surface;
}
-sk_sp<SkSurface> SkSurface::MakeFromMTKView(GrContext* context,
+sk_sp<SkSurface> SkSurface::MakeFromMTKView(GrRecordingContext* rContext,
GrMTLHandle view,
GrSurfaceOrigin origin,
int sampleCnt,
SkColorType colorType,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps) {
- GrProxyProvider* proxyProvider = context->priv().proxyProvider();
- const GrCaps* caps = context->priv().caps();
+ GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
+ const GrCaps* caps = rContext->priv().caps();
MTKView* mtkView = (__bridge MTKView*)view;
GrBackendFormat backendFormat = GrBackendFormat::MakeMtl(mtkView.colorPixelFormat);
@@ -160,11 +160,11 @@
GrSurfaceProxyView readView(proxy, origin, readSwizzle);
GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle);
- auto rtc = std::make_unique<GrRenderTargetContext>(context, std::move(readView),
+ auto rtc = std::make_unique<GrRenderTargetContext>(rContext, std::move(readView),
std::move(writeView), grColorType,
colorSpace, surfaceProps);
- sk_sp<SkSurface> surface = SkSurface_Gpu::MakeWrappedRenderTarget(context, std::move(rtc));
+ sk_sp<SkSurface> surface = SkSurface_Gpu::MakeWrappedRenderTarget(rContext, std::move(rtc));
return surface;
}
diff --git a/tools/skottie_ios_app/GrContextHolder.h b/tools/skottie_ios_app/GrContextHolder.h
index eed4d9d..6320ea3 100644
--- a/tools/skottie_ios_app/GrContextHolder.h
+++ b/tools/skottie_ios_app/GrContextHolder.h
@@ -5,12 +5,13 @@
#include <memory>
-class GrContext;
+class GrDirectContext;
-// A struct to take ownership of a GrContext.
-struct GrContextRelease { void operator()(GrContext*); };
-using GrContextHolder = std::unique_ptr<GrContext, GrContextRelease>;
+// A struct to take ownership of a GrDirectContext.
+struct GrContextRelease { void operator()(GrDirectContext*); };
+using GrContextHolder = std::unique_ptr<GrDirectContext, GrContextRelease>;
-// Wrapper around GrContext::MakeGL
+// Wrapper around GrDirectContext::MakeGL
GrContextHolder SkMakeGLContext();
+
#endif // GrContextHolder_DEFINED
diff --git a/tools/skottie_ios_app/GrContextHolder.mm b/tools/skottie_ios_app/GrContextHolder.mm
index 21e38df..e1b9635 100644
--- a/tools/skottie_ios_app/GrContextHolder.mm
+++ b/tools/skottie_ios_app/GrContextHolder.mm
@@ -13,14 +13,14 @@
#ifdef SK_GL
GrContextHolder SkMakeGLContext() {
- return GrContextHolder(GrContext::MakeGL(nullptr, GrContextOptions()).release());
+ return GrContextHolder(GrDirectContext::MakeGL(nullptr, GrContextOptions()).release());
}
#endif
-void GrContextRelease::operator()(GrContext* ptr) { SkSafeUnref(ptr); }
+void GrContextRelease::operator()(GrDirectContext* ptr) { SkSafeUnref(ptr); }
#else
-void GrContextRelease::operator()(GrContext*) { SkASSERT(false); }
+void GrContextRelease::operator()(GrDirectContext*) { SkDEBUGFAIL(""); }
#endif
diff --git a/tools/skottie_ios_app/SkMetalViewBridge.h b/tools/skottie_ios_app/SkMetalViewBridge.h
index 1c2c2f0..dc8e873 100644
--- a/tools/skottie_ios_app/SkMetalViewBridge.h
+++ b/tools/skottie_ios_app/SkMetalViewBridge.h
@@ -9,10 +9,11 @@
#include <memory>
+class GrRecordingContext;
class SkSurface;
template <typename T> class sk_sp;
-sk_sp<SkSurface> SkMtkViewToSurface(MTKView*, GrContext*);
+sk_sp<SkSurface> SkMtkViewToSurface(MTKView*, GrRecordingContext*);
GrContextHolder SkMetalDeviceToGrContext(id<MTLDevice>, id<MTLCommandQueue>);
diff --git a/tools/skottie_ios_app/SkMetalViewBridge.mm b/tools/skottie_ios_app/SkMetalViewBridge.mm
index 6fa5117..dd5de64 100644
--- a/tools/skottie_ios_app/SkMetalViewBridge.mm
+++ b/tools/skottie_ios_app/SkMetalViewBridge.mm
@@ -12,8 +12,8 @@
#import <Metal/Metal.h>
#import <MetalKit/MetalKit.h>
-sk_sp<SkSurface> SkMtkViewToSurface(MTKView* mtkView, GrContext* grContext) {
- if (!grContext ||
+sk_sp<SkSurface> SkMtkViewToSurface(MTKView* mtkView, GrRecordingContext* rContext) {
+ if (!rContext ||
MTLPixelFormatDepth32Float_Stencil8 != [mtkView depthStencilPixelFormat] ||
MTLPixelFormatBGRA8Unorm != [mtkView colorPixelFormat]) {
return nullptr;
@@ -25,15 +25,15 @@
const SkSurfaceProps surfaceProps(SkSurfaceProps::kLegacyFontHost_InitType);
int sampleCount = (int)[mtkView sampleCount];
- return SkSurface::MakeFromMTKView(grContext, (__bridge GrMTLHandle)mtkView, origin, sampleCount,
+ return SkSurface::MakeFromMTKView(rContext, (__bridge GrMTLHandle)mtkView, origin, sampleCount,
colorType, colorSpace, &surfaceProps);
}
GrContextHolder SkMetalDeviceToGrContext(id<MTLDevice> device, id<MTLCommandQueue> queue) {
GrContextOptions grContextOptions; // set different options here.
- return GrContextHolder(GrContext::MakeMetal((__bridge void*)device,
- (__bridge void*)queue,
- grContextOptions).release());
+ return GrContextHolder(GrDirectContext::MakeMetal((__bridge void*)device,
+ (__bridge void*)queue,
+ grContextOptions).release());
}
void SkMtkViewConfigForSkia(MTKView* mtkView) {