ae4bb98f13
This is a reland of c1916c34fe
As it turns out, benches are not always given a canvas.
Original change's description:
> Remove use of legacy display globals.
>
> In the ongoing effort to remove the display globals from Skia, allow
> their use only if SK_LEGACY_SURFACE_PROPS is defined. Do not define this
> in a normal Skia build and remove all use from Skia code.
>
> Change-Id: I9ff550f5db246b9024aac687a1bc01321f1be4c8
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319343
> Reviewed-by: Herb Derby <herb@google.com>
> Commit-Queue: Ben Wagner <bungeman@google.com>
Change-Id: I61a2ac058fafc99653e3304876cf4b97350dac8b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322490
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
44 lines
1.8 KiB
Plaintext
44 lines
1.8 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 "tools/skottie_ios_app/SkMetalViewBridge.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>
|
|
|
|
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];
|
|
|
|
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(GrDirectContext::MakeMetal((__bridge void*)device,
|
|
(__bridge void*)queue,
|
|
grContextOptions).release());
|
|
}
|
|
|
|
void SkMtkViewConfigForSkia(MTKView* mtkView) {
|
|
[mtkView setDepthStencilPixelFormat:MTLPixelFormatDepth32Float_Stencil8];
|
|
[mtkView setColorPixelFormat:MTLPixelFormatBGRA8Unorm];
|
|
[mtkView setSampleCount:1];
|
|
}
|