skia2/tools/skottie_ios_app/SkMetalViewBridge.mm

46 lines
1.9 KiB
Plaintext
Raw Normal View History

// 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 "tools/skottie_ios_app/SkMetalViewBridge.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkSurface.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrContextOptions.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/mtl/GrMtlTypes.h"
#import <Metal/Metal.h>
#import <MetalKit/MetalKit.h>
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>
2020-09-23 18:01:58 +00:00
sk_sp<SkSurface> SkMtkViewToSurface(MTKView* mtkView, GrRecordingContext* rContext) {
if (!rContext ||
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;
int sampleCount = (int)[mtkView sampleCount];
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>
2020-09-23 18:01:58 +00:00
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.
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>
2020-09-23 18:01:58 +00:00
return GrContextHolder(GrDirectContext::MakeMetal((__bridge void*)device,
(__bridge void*)queue,
grContextOptions).release());
}
void SkMtkViewConfigForSkia(MTKView* mtkView) {
[mtkView setDepthStencilPixelFormat:MTLPixelFormatDepth32Float_Stencil8];
[mtkView setColorPixelFormat:MTLPixelFormatBGRA8Unorm];
[mtkView setSampleCount:1];
}