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>
This commit is contained in:
parent
7c76b09445
commit
3eb813e0cc
@ -307,7 +307,7 @@ public:
|
||||
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 @@ public:
|
||||
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,
|
||||
|
@ -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<SkSurface> SkSurface::MakeFromCAMetalLayer(GrContext* context,
|
||||
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 @@ sk_sp<SkSurface> SkSurface::MakeFromCAMetalLayer(GrContext* context,
|
||||
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 @@ sk_sp<SkSurface> SkSurface::MakeFromMTKView(GrContext* context,
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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 GrDirectContextRelease { void operator()(GrDirectContext*); };
|
||||
using GrContextHolder = std::unique_ptr<GrDirectContext, GrDirectContextRelease>;
|
||||
|
||||
// Wrapper around GrContext::MakeGL
|
||||
// Wrapper around GrDirectContext::MakeGL
|
||||
GrContextHolder SkMakeGLContext();
|
||||
|
||||
#endif // GrContextHolder_DEFINED
|
||||
|
@ -12,7 +12,7 @@
|
||||
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>);
|
||||
|
||||
|
@ -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 @@ sk_sp<SkSurface> SkMtkViewToSurface(MTKView* mtkView, GrContext* grContext) {
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user