|
17 | 17 |
|
18 | 18 | namespace flutter { |
19 | 19 |
|
| 20 | +// TOOD(cbracken): https://github.com/flutter/flutter/issues/157942 |
| 21 | +struct MetalObjCFields { |
| 22 | + id<MTLDevice> device; |
| 23 | + id<MTLCommandQueue> command_queue; |
| 24 | +}; |
| 25 | + |
20 | 26 | TestMetalContext::TestMetalContext() { |
21 | 27 | id<MTLDevice> device = MTLCreateSystemDefaultDevice(); |
22 | 28 | if (!device) { |
|
43 | 49 | "and command queue."; |
44 | 50 | } |
45 | 51 |
|
46 | | - // Retain and transfer to non-ARC-managed pointers. |
47 | | - // TODO(cbracken): https://github.com/flutter/flutter/issues/157942 |
48 | | - device_ = (__bridge_retained void*)device; |
49 | | - command_queue_ = (__bridge_retained void*)command_queue; |
| 52 | + metal_ = std::make_unique<MetalObjCFields>(MetalObjCFields{device, command_queue}); |
50 | 53 | } |
51 | 54 |
|
52 | 55 | TestMetalContext::~TestMetalContext() { |
53 | 56 | std::scoped_lock lock(textures_mutex_); |
54 | 57 | textures_.clear(); |
55 | | - if (device_) { |
56 | | - // Release and transfer to ARC-managed pointer. |
57 | | - // TODO(cbracken): https://github.com/flutter/flutter/issues/157942 |
58 | | - id<MTLDevice> device = // NOLINT(clang-analyzer-deadcode.DeadStores) |
59 | | - (__bridge_transfer id<MTLDevice>)device_; |
60 | | - device = nil; |
61 | | - } |
62 | | - if (command_queue_) { |
63 | | - // Release and transfer to ARC-managed pointer. |
64 | | - // TODO(cbracken): https://github.com/flutter/flutter/issues/157942 |
65 | | - id<MTLCommandQueue> command_queue = // NOLINT(clang-analyzer-deadcode.DeadStores) |
66 | | - (__bridge_transfer id<MTLCommandQueue>)command_queue_; |
67 | | - command_queue = nil; |
68 | | - } |
| 58 | + metal_.reset(); |
69 | 59 | } |
70 | 60 |
|
71 | 61 | void* TestMetalContext::GetMetalDevice() const { |
72 | | - return device_; |
| 62 | + return metal_ ? (__bridge void*)metal_->device : nil; |
73 | 63 | } |
74 | 64 |
|
75 | 65 | void* TestMetalContext::GetMetalCommandQueue() const { |
76 | | - return command_queue_; |
| 66 | + return metal_ ? (__bridge void*)metal_->command_queue : nil; |
77 | 67 | } |
78 | 68 |
|
79 | 69 | sk_sp<GrDirectContext> TestMetalContext::GetSkiaContext() const { |
|
98 | 88 | return {.texture_id = -1, .texture = nullptr}; |
99 | 89 | } |
100 | 90 |
|
101 | | - id<MTLDevice> device = (__bridge id<MTLDevice>)GetMetalDevice(); |
102 | | - id<MTLTexture> texture = [device newTextureWithDescriptor:texture_descriptor]; |
| 91 | + if (!metal_) { |
| 92 | + FML_CHECK(false) << "Invalid Metal device."; |
| 93 | + return {.texture_id = -1, .texture = nullptr}; |
| 94 | + } |
| 95 | + |
| 96 | + id<MTLTexture> texture = [metal_->device newTextureWithDescriptor:texture_descriptor]; |
103 | 97 | if (!texture) { |
104 | 98 | FML_CHECK(false) << "Could not create texture from texture descriptor."; |
105 | 99 | return {.texture_id = -1, .texture = nullptr}; |
|
0 commit comments