14629417cb
* Turns out that dealloc is unnecessary. Some compilers give an error when it is there. * Use __bridge cast, since some compilers require it. Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac-Clang-arm64-Debug-iOS_Metal Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac-Clang-arm64-Release-iOS_Metal Change-Id: I42d9ef16a5d6425c98a8a2b564bf4a06f26886f5 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/257677 Commit-Queue: Jim Van Verth <jvanverth@google.com> Auto-Submit: Hal Canary <halcanary@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com>
53 lines
2.3 KiB
Plaintext
53 lines
2.3 KiB
Plaintext
// Copyright 2019 Google LLC.
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "experimental/skottie_ios/SkMetalViewBridge.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
#include "include/gpu/GrBackendSurface.h"
|
|
#include "include/gpu/GrContext.h"
|
|
#include "include/gpu/GrContextOptions.h"
|
|
#include "include/gpu/mtl/GrMtlTypes.h"
|
|
|
|
#import <Metal/Metal.h>
|
|
#import <MetalKit/MetalKit.h>
|
|
|
|
sk_sp<SkSurface> SkMtkViewToSurface(MTKView* mtkView, GrContext* grContext) {
|
|
if (![[mtkView currentDrawable] texture] ||
|
|
!grContext ||
|
|
MTLPixelFormatDepth32Float_Stencil8 != [mtkView depthStencilPixelFormat] ||
|
|
MTLPixelFormatBGRA8Unorm != [mtkView colorPixelFormat]) {
|
|
return nullptr;
|
|
}
|
|
const SkColorType colorType = kBGRA_8888_SkColorType; // MTLPixelFormatBGRA8Unorm
|
|
sk_sp<SkColorSpace> colorSpace = nullptr; // MTLPixelFormatBGRA8Unorm
|
|
const GrSurfaceOrigin origin = kTopLeft_GrSurfaceOrigin;
|
|
const SkSurfaceProps surfaceProps(SkSurfaceProps::kLegacyFontHost_InitType);
|
|
int sampleCount = (int)[mtkView sampleCount];
|
|
CGSize size = [mtkView drawableSize];
|
|
int width = (int)size.width;
|
|
int height = (int)size.height;
|
|
|
|
GrMtlTextureInfo fbInfo;
|
|
fbInfo.fTexture.retain((__bridge const void*)([[mtkView currentDrawable] texture]));
|
|
if (sampleCount == 1) {
|
|
GrBackendRenderTarget backendRT(width, height, 1, fbInfo);
|
|
return SkSurface::MakeFromBackendRenderTarget(grContext, backendRT, origin,
|
|
colorType, colorSpace, &surfaceProps);
|
|
} else {
|
|
GrBackendTexture backendTexture(width, height, GrMipMapped::kNo, fbInfo);
|
|
return SkSurface::MakeFromBackendTexture(grContext, backendTexture, origin, sampleCount,
|
|
colorType, colorSpace, &surfaceProps);
|
|
}
|
|
}
|
|
|
|
sk_sp<GrContext> SkMetalDeviceToGrContext(id<MTLDevice> device, id<MTLCommandQueue> queue, const GrContextOptions& opts) {
|
|
return GrContext::MakeMetal((__bridge void*)device, (__bridge void*)queue, opts);
|
|
}
|
|
|
|
void SkMtkViewConfigForSkia(MTKView* mtkView) {
|
|
[mtkView setDepthStencilPixelFormat:MTLPixelFormatDepth32Float_Stencil8];
|
|
[mtkView setColorPixelFormat:MTLPixelFormatBGRA8Unorm];
|
|
[mtkView setSampleCount:1];
|
|
}
|