Flutter Engine
The Flutter Engine
GraphiteMtlTestContext.mm
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
17
18#import <Metal/Metal.h>
19
20namespace skiatest::graphite {
21
22std::unique_ptr<GraphiteTestContext> MtlTestContext::Make() {
23 sk_cfp<id<MTLDevice>> device;
24#ifdef SK_BUILD_FOR_MAC
25 sk_cfp<NSArray<id <MTLDevice>>*> availableDevices(MTLCopyAllDevices());
26 // Choose the non-integrated CPU if available
27 for (id<MTLDevice> dev in availableDevices.get()) {
28 if (!dev.isLowPower) {
29 // This retain is necessary because when the NSArray goes away it will delete the
30 // device entry otherwise.
31 device.retain(dev);
32 break;
33 }
34 if (dev.isRemovable) {
35 device.retain(dev);
36 break;
37 }
38 }
39 if (!device) {
40 device.reset(MTLCreateSystemDefaultDevice());
41 }
42#else
43 device.reset(MTLCreateSystemDefaultDevice());
44#endif
45
46 skgpu::graphite::MtlBackendContext backendContext = {};
47 backendContext.fDevice.retain(device.get());
48 backendContext.fQueue.reset([*device newCommandQueue]);
49
50 return std::unique_ptr<GraphiteTestContext>(new MtlTestContext(backendContext));
51}
52
55}
56
57std::unique_ptr<skgpu::graphite::Context> MtlTestContext::makeContext(const TestOptions& options) {
58 SkASSERT(!options.fNeverYieldToWebGPU);
59 skgpu::graphite::ContextOptions revisedContextOptions(options.fContextOptions);
60 skgpu::graphite::ContextOptionsPriv contextOptionsPriv;
61 if (!options.fContextOptions.fOptionsPriv) {
62 revisedContextOptions.fOptionsPriv = &contextOptionsPriv;
63 }
64 // Needed to make synchronous readPixels work
65 revisedContextOptions.fOptionsPriv->fStoreContextRefInRecorder = true;
66
67 return skgpu::graphite::ContextFactory::MakeMetal(fMtl, revisedContextOptions);
68}
69
70} // namespace skiatest::graphite
const char * options
#define SkASSERT(cond)
Definition: SkAssert.h:116
skgpu::graphite::MtlBackendContext fMtl
static std::unique_ptr< GraphiteTestContext > Make()
MtlTestContext(const skgpu::graphite::MtlBackendContext &mtl)
std::unique_ptr< skgpu::graphite::Context > makeContext(const TestOptions &) override
skgpu::ContextType contextType() override
VkDevice device
Definition: main.cc:53
SK_API std::unique_ptr< Context > MakeMetal(const MtlBackendContext &, const ContextOptions &)
ContextType
Definition: ContextType.h:19
ContextOptionsPriv * fOptionsPriv