forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move metal drawable management to ObjC
- Loading branch information
1 parent
4601d2c
commit 39d436a
Showing
6 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...ose/ui/ui-uikit/src/uikitMain/objc/CMPUIKitUtils/CMPUIKitUtils/CMPMetalDrawablesHandler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// CMPMetalDrawablesHandler.h | ||
// CMPUIKitUtils | ||
// | ||
// Created by Ilia.Semenov on 07/06/2024. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <QuartzCore/QuartzCore.h> | ||
#import <Metal/Metal.h> | ||
|
||
#import "CMPMacros.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface CMPMetalDrawablesHandler : NSObject | ||
|
||
- (instancetype)initWithMetalLayer:(CAMetalLayer *)metalLayer; | ||
|
||
- (void * __nullable CMP_OWNED)nextDrawable; | ||
- (void)releaseDrawable:(void * CMP_CONSUMED)drawablePtr; | ||
- (void * CMP_BORROWED)drawableTexture:(void * CMP_BORROWED)drawablePtr; | ||
- (void)presentDrawable:(void * CMP_CONSUMED)drawablePtr; | ||
- (void)scheduleDrawablePresentation:(void * CMP_CONSUMED)drawablePtr onCommandBuffer:(id <MTLCommandBuffer>)commandBuffer; | ||
|
||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
63 changes: 63 additions & 0 deletions
63
...ose/ui/ui-uikit/src/uikitMain/objc/CMPUIKitUtils/CMPUIKitUtils/CMPMetalDrawablesHandler.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// CMPMetalDrawablesHandler.m | ||
// CMPUIKitUtils | ||
// | ||
// Created by Ilia.Semenov on 07/06/2024. | ||
// | ||
|
||
#import "CMPMetalDrawablesHandler.h" | ||
|
||
@implementation CMPMetalDrawablesHandler { | ||
CAMetalLayer *_metalLayer; | ||
} | ||
|
||
- (instancetype)initWithMetalLayer:(CAMetalLayer *)metalLayer { | ||
self = [super init]; | ||
if (self) { | ||
_metalLayer = metalLayer; | ||
} | ||
return self; | ||
} | ||
|
||
- (void * __nullable CMP_OWNED)nextDrawable { | ||
id <CAMetalDrawable> drawable = [_metalLayer nextDrawable]; | ||
|
||
if (drawable) { | ||
void *ptr = (__bridge_retained void *)drawable; | ||
return ptr; | ||
} else { | ||
return NULL; | ||
} | ||
} | ||
|
||
- (void)releaseDrawable:(void * CMP_CONSUMED)drawablePtr { | ||
assert(drawablePtr != NULL); | ||
|
||
id <CAMetalDrawable> drawable __unused = (__bridge_transfer id <CAMetalDrawable>)drawablePtr; | ||
// drawable will be released by ARC | ||
} | ||
|
||
- (void * CMP_BORROWED)drawableTexture:(void * CMP_BORROWED)drawablePtr { | ||
assert(drawablePtr != NULL); | ||
|
||
id <CAMetalDrawable> drawable = (__bridge id <CAMetalDrawable>)drawablePtr; | ||
id <MTLTexture> texture = drawable.texture; | ||
void *texturePtr = (__bridge void *)texture; | ||
return texturePtr; | ||
} | ||
|
||
- (void)presentDrawable:(void * CMP_CONSUMED)drawablePtr { | ||
assert(drawablePtr != NULL); | ||
|
||
id <CAMetalDrawable> drawable __unused = (__bridge_transfer id <CAMetalDrawable>)drawablePtr; | ||
[drawable present]; | ||
} | ||
|
||
- (void)scheduleDrawablePresentation:(void * CMP_CONSUMED)drawablePtr onCommandBuffer:(id <MTLCommandBuffer>)commandBuffer { | ||
assert(drawablePtr != NULL); | ||
|
||
id <CAMetalDrawable> drawable __unused = (__bridge_transfer id <CAMetalDrawable>)drawablePtr; | ||
[commandBuffer presentDrawable:drawable]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters