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
|
instantiated; may not be nullptr
|
||||||
@return created SkSurface, or nullptr
|
@return created SkSurface, or nullptr
|
||||||
*/
|
*/
|
||||||
static sk_sp<SkSurface> MakeFromCAMetalLayer(GrContext* context,
|
static sk_sp<SkSurface> MakeFromCAMetalLayer(GrRecordingContext* context,
|
||||||
GrMTLHandle layer,
|
GrMTLHandle layer,
|
||||||
GrSurfaceOrigin origin,
|
GrSurfaceOrigin origin,
|
||||||
int sampleCnt,
|
int sampleCnt,
|
||||||
@ -334,7 +334,7 @@ public:
|
|||||||
fonts; may be nullptr
|
fonts; may be nullptr
|
||||||
@return created SkSurface, or nullptr
|
@return created SkSurface, or nullptr
|
||||||
*/
|
*/
|
||||||
static sk_sp<SkSurface> MakeFromMTKView(GrContext* context,
|
static sk_sp<SkSurface> MakeFromMTKView(GrRecordingContext* context,
|
||||||
GrMTLHandle mtkView,
|
GrMTLHandle mtkView,
|
||||||
GrSurfaceOrigin origin,
|
GrSurfaceOrigin origin,
|
||||||
int sampleCnt,
|
int sampleCnt,
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
#include "include/core/SkSurface.h"
|
#include "include/core/SkSurface.h"
|
||||||
#include "include/gpu/GrBackendSurface.h"
|
#include "include/gpu/GrBackendSurface.h"
|
||||||
#include "include/gpu/mtl/GrMtlTypes.h"
|
#include "include/gpu/mtl/GrMtlTypes.h"
|
||||||
#include "src/gpu/GrContextPriv.h"
|
|
||||||
#include "src/gpu/GrProxyProvider.h"
|
#include "src/gpu/GrProxyProvider.h"
|
||||||
|
#include "src/gpu/GrRecordingContextPriv.h"
|
||||||
#include "src/gpu/GrRenderTargetContext.h"
|
#include "src/gpu/GrRenderTargetContext.h"
|
||||||
#include "src/gpu/GrResourceProvider.h"
|
#include "src/gpu/GrResourceProvider.h"
|
||||||
#include "src/gpu/GrResourceProviderPriv.h"
|
#include "src/gpu/GrResourceProviderPriv.h"
|
||||||
@ -26,7 +26,7 @@
|
|||||||
#import <QuartzCore/CAMetalLayer.h>
|
#import <QuartzCore/CAMetalLayer.h>
|
||||||
#import <MetalKit/MetalKit.h>
|
#import <MetalKit/MetalKit.h>
|
||||||
|
|
||||||
sk_sp<SkSurface> SkSurface::MakeFromCAMetalLayer(GrContext* context,
|
sk_sp<SkSurface> SkSurface::MakeFromCAMetalLayer(GrRecordingContext* rContext,
|
||||||
GrMTLHandle layer,
|
GrMTLHandle layer,
|
||||||
GrSurfaceOrigin origin,
|
GrSurfaceOrigin origin,
|
||||||
int sampleCnt,
|
int sampleCnt,
|
||||||
@ -34,8 +34,8 @@ sk_sp<SkSurface> SkSurface::MakeFromCAMetalLayer(GrContext* context,
|
|||||||
sk_sp<SkColorSpace> colorSpace,
|
sk_sp<SkColorSpace> colorSpace,
|
||||||
const SkSurfaceProps* surfaceProps,
|
const SkSurfaceProps* surfaceProps,
|
||||||
GrMTLHandle* drawable) {
|
GrMTLHandle* drawable) {
|
||||||
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
|
||||||
const GrCaps* caps = context->priv().caps();
|
const GrCaps* caps = rContext->priv().caps();
|
||||||
|
|
||||||
CAMetalLayer* metalLayer = (__bridge CAMetalLayer*)layer;
|
CAMetalLayer* metalLayer = (__bridge CAMetalLayer*)layer;
|
||||||
GrBackendFormat backendFormat = GrBackendFormat::MakeMtl(metalLayer.pixelFormat);
|
GrBackendFormat backendFormat = GrBackendFormat::MakeMtl(metalLayer.pixelFormat);
|
||||||
@ -90,23 +90,23 @@ sk_sp<SkSurface> SkSurface::MakeFromCAMetalLayer(GrContext* context,
|
|||||||
GrSurfaceProxyView readView(proxy, origin, readSwizzle);
|
GrSurfaceProxyView readView(proxy, origin, readSwizzle);
|
||||||
GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle);
|
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,
|
std::move(writeView), grColorType,
|
||||||
colorSpace, surfaceProps);
|
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;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
sk_sp<SkSurface> SkSurface::MakeFromMTKView(GrContext* context,
|
sk_sp<SkSurface> SkSurface::MakeFromMTKView(GrRecordingContext* rContext,
|
||||||
GrMTLHandle view,
|
GrMTLHandle view,
|
||||||
GrSurfaceOrigin origin,
|
GrSurfaceOrigin origin,
|
||||||
int sampleCnt,
|
int sampleCnt,
|
||||||
SkColorType colorType,
|
SkColorType colorType,
|
||||||
sk_sp<SkColorSpace> colorSpace,
|
sk_sp<SkColorSpace> colorSpace,
|
||||||
const SkSurfaceProps* surfaceProps) {
|
const SkSurfaceProps* surfaceProps) {
|
||||||
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
|
||||||
const GrCaps* caps = context->priv().caps();
|
const GrCaps* caps = rContext->priv().caps();
|
||||||
|
|
||||||
MTKView* mtkView = (__bridge MTKView*)view;
|
MTKView* mtkView = (__bridge MTKView*)view;
|
||||||
GrBackendFormat backendFormat = GrBackendFormat::MakeMtl(mtkView.colorPixelFormat);
|
GrBackendFormat backendFormat = GrBackendFormat::MakeMtl(mtkView.colorPixelFormat);
|
||||||
@ -160,11 +160,11 @@ sk_sp<SkSurface> SkSurface::MakeFromMTKView(GrContext* context,
|
|||||||
GrSurfaceProxyView readView(proxy, origin, readSwizzle);
|
GrSurfaceProxyView readView(proxy, origin, readSwizzle);
|
||||||
GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle);
|
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,
|
std::move(writeView), grColorType,
|
||||||
colorSpace, surfaceProps);
|
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;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,12 +5,13 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
class GrContext;
|
class GrDirectContext;
|
||||||
|
|
||||||
// A struct to take ownership of a GrContext.
|
// A struct to take ownership of a GrDirectContext.
|
||||||
struct GrContextRelease { void operator()(GrContext*); };
|
struct GrDirectContextRelease { void operator()(GrDirectContext*); };
|
||||||
using GrContextHolder = std::unique_ptr<GrContext, GrContextRelease>;
|
using GrContextHolder = std::unique_ptr<GrDirectContext, GrDirectContextRelease>;
|
||||||
|
|
||||||
// Wrapper around GrContext::MakeGL
|
// Wrapper around GrDirectContext::MakeGL
|
||||||
GrContextHolder SkMakeGLContext();
|
GrContextHolder SkMakeGLContext();
|
||||||
|
|
||||||
#endif // GrContextHolder_DEFINED
|
#endif // GrContextHolder_DEFINED
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
class SkSurface;
|
class SkSurface;
|
||||||
template <typename T> class sk_sp;
|
template <typename T> class sk_sp;
|
||||||
|
|
||||||
sk_sp<SkSurface> SkMtkViewToSurface(MTKView*, GrContext*);
|
sk_sp<SkSurface> SkMtkViewToSurface(MTKView*, GrRecordingContext*);
|
||||||
|
|
||||||
GrContextHolder SkMetalDeviceToGrContext(id<MTLDevice>, id<MTLCommandQueue>);
|
GrContextHolder SkMetalDeviceToGrContext(id<MTLDevice>, id<MTLCommandQueue>);
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
#import <Metal/Metal.h>
|
#import <Metal/Metal.h>
|
||||||
#import <MetalKit/MetalKit.h>
|
#import <MetalKit/MetalKit.h>
|
||||||
|
|
||||||
sk_sp<SkSurface> SkMtkViewToSurface(MTKView* mtkView, GrContext* grContext) {
|
sk_sp<SkSurface> SkMtkViewToSurface(MTKView* mtkView, GrRecordingContext* rContext) {
|
||||||
if (!grContext ||
|
if (!rContext ||
|
||||||
MTLPixelFormatDepth32Float_Stencil8 != [mtkView depthStencilPixelFormat] ||
|
MTLPixelFormatDepth32Float_Stencil8 != [mtkView depthStencilPixelFormat] ||
|
||||||
MTLPixelFormatBGRA8Unorm != [mtkView colorPixelFormat]) {
|
MTLPixelFormatBGRA8Unorm != [mtkView colorPixelFormat]) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -25,15 +25,15 @@ sk_sp<SkSurface> SkMtkViewToSurface(MTKView* mtkView, GrContext* grContext) {
|
|||||||
const SkSurfaceProps surfaceProps(SkSurfaceProps::kLegacyFontHost_InitType);
|
const SkSurfaceProps surfaceProps(SkSurfaceProps::kLegacyFontHost_InitType);
|
||||||
int sampleCount = (int)[mtkView sampleCount];
|
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);
|
colorType, colorSpace, &surfaceProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
GrContextHolder SkMetalDeviceToGrContext(id<MTLDevice> device, id<MTLCommandQueue> queue) {
|
GrContextHolder SkMetalDeviceToGrContext(id<MTLDevice> device, id<MTLCommandQueue> queue) {
|
||||||
GrContextOptions grContextOptions; // set different options here.
|
GrContextOptions grContextOptions; // set different options here.
|
||||||
return GrContextHolder(GrContext::MakeMetal((__bridge void*)device,
|
return GrContextHolder(GrDirectContext::MakeMetal((__bridge void*)device,
|
||||||
(__bridge void*)queue,
|
(__bridge void*)queue,
|
||||||
grContextOptions).release());
|
grContextOptions).release());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkMtkViewConfigForSkia(MTKView* mtkView) {
|
void SkMtkViewConfigForSkia(MTKView* mtkView) {
|
||||||
|
Loading…
Reference in New Issue
Block a user