baseline: preserve initial 大鱼调色 FxPlug Xcode project

这个提交包含在:
mac 于 2026-10-31 01:06:40 +08:00 提交
当前提交 10987dd6bc
22 个文件已更改
+2270

没有与搜索条件相匹配的文件

+92
查看文件
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>____XPCService</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSHumanReadableCopyright</key>
<string></string>
<key>PlugInKit</key>
<dict>
<key>Attributes</key>
<dict>
<key>com.apple.protocol</key>
<string>FxPlug</string>
<key>com.apple.version</key>
<string>1.1</string>
</dict>
<key>PrincipalClass</key>
<string>FxPrincipal</string>
<key>Protocol</key>
<string>PROXPCProtocol</string>
<key>Subsystems</key>
<array>
<string>NSViewService_PKSubsystem</string>
</array>
</dict>
<key>ProPlugDictionaryVersion</key>
<string>1.0</string>
<key>ProPlugDynamicRegistration</key>
<false/>
<key>ProPlugPlugInGroupList</key>
<array>
<dict>
<key>groupName</key>
<string>大鱼调色 Group</string>
<key>uuid</key>
<string>19E2727A-6BCD-4656-B270-7E2BF482A692</string>
</dict>
</array>
<key>ProPlugPlugInList</key>
<array>
<dict>
<key>className</key>
<string>____PlugIn</string>
<key>displayName</key>
<string>____::FxPlug Name</string>
<key>group</key>
<string>19E2727A-6BCD-4656-B270-7E2BF482A692</string>
<key>infoString</key>
<string>____::FxPlug Description</string>
<key>protocolNames</key>
<array>
<string>FxFilter</string>
</array>
<key>uuid</key>
<string>1C17B73B-F229-4C09-A434-EAF6DFF5F22A</string>
<key>version</key>
<string>1.0</string>
</dict>
</array>
<key>XPCService</key>
<dict>
<key>ServiceType</key>
<string>Application</string>
<key>JoinExistingSession</key>
<true/>
<key>RunLoopType</key>
<string>_NSApplicationMain</string>
<key>_AdditionalSubServices</key>
<dict>
<key>viewbridge</key>
<true/>
</dict>
</dict>
</dict>
</plist>
+28
查看文件
@@ -0,0 +1,28 @@
//
// MetalDeviceCache.h
// 大鱼调色
//
// Created by mac on 2026/10/31.
//
#import <Metal/Metal.h>
#import <FxPlug/FxPlugSDK.h>
@class MetalDeviceCacheItem;
@interface MetalDeviceCache : NSObject
{
NSMutableArray<MetalDeviceCacheItem*>* deviceCaches;
}
+ (MetalDeviceCache*)deviceCache;
+ (MTLPixelFormat)MTLPixelFormatForImageTile:(FxImageTile*)imageTile;
- (id<MTLDevice>)deviceWithRegistryID:(uint64_t)registryID;
- (id<MTLRenderPipelineState>)pipelineStateWithRegistryID:(uint64_t)registryID
pixelFormat:(MTLPixelFormat)pixFormat;
- (id<MTLCommandQueue>)commandQueueWithRegistryID:(uint64_t)registryID
pixelFormat:(MTLPixelFormat)pixFormat;
- (void)returnCommandQueueToCache:(id<MTLCommandQueue>)commandQueue;
@end
+339
查看文件
@@ -0,0 +1,339 @@
//
// MetalDeviceCache.m
// 大鱼调色
//
// Created by mac on 2026/10/31.
//
#import "MetalDeviceCache.h"
const NSUInteger kMaxCommandQueues = 5;
static NSString* kKey_InUse = @"InUse";
static NSString* kKey_CommandQueue = @"CommandQueue";
static MetalDeviceCache* gDeviceCache = nil;
@interface MetalDeviceCacheItem : NSObject
@property (readonly) id<MTLDevice> gpuDevice;
@property (readonly) id<MTLRenderPipelineState> pipelineState;
@property (retain) NSMutableArray<NSMutableDictionary*>* commandQueueCache;
@property (readonly) NSLock* commandQueueCacheLock;
@property (readonly) MTLPixelFormat pixelFormat;
- (instancetype)initWithDevice:(id<MTLDevice>)device
pixelFormat:(MTLPixelFormat)pixFormat;
- (id<MTLCommandQueue>)getNextFreeCommandQueue;
- (void)returnCommandQueue:(id<MTLCommandQueue>)commandQueue;
- (BOOL)containsCommandQueue:(id<MTLCommandQueue>)commandQueue;
@end
@implementation MetalDeviceCacheItem
- (instancetype)initWithDevice:(id<MTLDevice>)device
pixelFormat:(MTLPixelFormat)pixFormat;
{
self = [super init];
if (self != nil)
{
_gpuDevice = [device retain];
_commandQueueCache = [[NSMutableArray alloc] initWithCapacity:kMaxCommandQueues];
for (NSUInteger i = 0; (_commandQueueCache != nil) && (i < kMaxCommandQueues); i++)
{
NSMutableDictionary* commandDict = [NSMutableDictionary dictionary];
[commandDict setObject:[NSNumber numberWithBool:NO]
forKey:kKey_InUse];
id<MTLCommandQueue> commandQueue = [_gpuDevice newCommandQueue];
[commandDict setObject:commandQueue
forKey:kKey_CommandQueue];
[_commandQueueCache addObject:commandDict];
}
// Load all the shader files with a .metal file extension in the project
id<MTLLibrary> defaultLibrary = [[_gpuDevice newDefaultLibrary] autorelease];
// Load the vertex function from the library
id<MTLFunction> vertexFunction = [[defaultLibrary newFunctionWithName:@"vertexShader"] autorelease];
// Load the fragment function from the library
id<MTLFunction> fragmentFunction = [[defaultLibrary newFunctionWithName:@"fragmentShader"] autorelease];
// Configure a pipeline descriptor that is used to create a pipeline state
MTLRenderPipelineDescriptor *pipelineStateDescriptor = [[[MTLRenderPipelineDescriptor alloc] init] autorelease];
pipelineStateDescriptor.label = @"Simple Pipeline";
pipelineStateDescriptor.vertexFunction = vertexFunction;
pipelineStateDescriptor.fragmentFunction = fragmentFunction;
pipelineStateDescriptor.colorAttachments[0].pixelFormat = pixFormat;
_pixelFormat = pixFormat;
NSError* error = nil;
_pipelineState = [_gpuDevice newRenderPipelineStateWithDescriptor:pipelineStateDescriptor
error:&error];
if (error != nil)
{
NSLog (@"Error generating brightness pipeline state: %@", error);
}
if (_commandQueueCache != nil)
{
_commandQueueCacheLock = [[NSLock alloc] init];
}
if ((_gpuDevice == nil) || (_commandQueueCache == nil) || (_commandQueueCacheLock == nil) ||
(_pipelineState == nil))
{
[self release];
self = nil;
}
}
return self;
}
- (void)dealloc
{
[_gpuDevice release];
[_commandQueueCache release];
[_commandQueueCacheLock release];
[_pipelineState release];
[super dealloc];
}
- (id<MTLCommandQueue>)getNextFreeCommandQueue
{
id<MTLCommandQueue> result = nil;
[_commandQueueCacheLock lock];
NSUInteger index = 0;
while ((result == nil) && (index < kMaxCommandQueues))
{
NSMutableDictionary* nextCommandQueue = [_commandQueueCache objectAtIndex:index];
NSNumber* inUse = [nextCommandQueue objectForKey:kKey_InUse];
if (![inUse boolValue])
{
[nextCommandQueue setObject:[NSNumber numberWithBool:YES]
forKey:kKey_InUse];
result = [nextCommandQueue objectForKey:kKey_CommandQueue];
}
index++;
}
[_commandQueueCacheLock unlock];
return result;
}
- (void)returnCommandQueue:(id<MTLCommandQueue>)commandQueue
{
[_commandQueueCacheLock lock];
BOOL found = false;
NSUInteger index = 0;
while ((!found) && (index < kMaxCommandQueues))
{
NSMutableDictionary* nextCommandQueuDict = [_commandQueueCache objectAtIndex:index];
id<MTLCommandQueue> nextCommandQueue = [nextCommandQueuDict objectForKey:kKey_CommandQueue];
if (nextCommandQueue == commandQueue)
{
found = YES;
[nextCommandQueuDict setObject:[NSNumber numberWithBool:NO]
forKey:kKey_InUse];
}
index++;
}
[_commandQueueCacheLock unlock];
}
- (BOOL)containsCommandQueue:(id<MTLCommandQueue>)commandQueue
{
BOOL found = NO;
NSUInteger index = 0;
while ((!found) && (index < kMaxCommandQueues))
{
NSMutableDictionary* nextCommandQueuDict = [_commandQueueCache objectAtIndex:index];
id<MTLCommandQueue> nextCommandQueue = [nextCommandQueuDict objectForKey:kKey_CommandQueue];
if (nextCommandQueue == commandQueue)
{
found = YES;
}
index++;
}
return found;
}
@end
@implementation MetalDeviceCache
+ (MTLPixelFormat)MTLPixelFormatForImageTile:(FxImageTile*)imageTile
{
MTLPixelFormat result = MTLPixelFormatRGBA16Float;
switch (imageTile.ioSurface.pixelFormat)
{
case kCVPixelFormatType_128RGBAFloat:
result = MTLPixelFormatRGBA32Float;
break;
case kCVPixelFormatType_32BGRA:
result = MTLPixelFormatBGRA8Unorm;
break;
default:
break;
}
return result;
}
+ (MetalDeviceCache*)deviceCache;
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
gDeviceCache = [[MetalDeviceCache alloc] init];
});
return gDeviceCache;
}
- (instancetype)init
{
self = [super init];
if (self != nil)
{
NSArray<id<MTLDevice>>* devices = MTLCopyAllDevices();
deviceCaches = [[NSMutableArray alloc] initWithCapacity:devices.count];
for (id<MTLDevice> nextDevice in devices)
{
MetalDeviceCacheItem* newCacheItem = [[[MetalDeviceCacheItem alloc] initWithDevice:nextDevice
pixelFormat:MTLPixelFormatRGBA16Float]
autorelease];
[deviceCaches addObject:newCacheItem];
}
[devices release];
}
return self;
}
- (void)dealloc
{
[deviceCaches release];
[super dealloc];
}
- (id<MTLDevice>)deviceWithRegistryID:(uint64_t)registryID
{
for (MetalDeviceCacheItem* nextCacheItem in deviceCaches)
{
if (nextCacheItem.gpuDevice.registryID == registryID)
{
return nextCacheItem.gpuDevice;
}
}
return nil;
}
- (id<MTLRenderPipelineState>)pipelineStateWithRegistryID:(uint64_t)registryID
pixelFormat:(MTLPixelFormat)pixFormat
{
for (MetalDeviceCacheItem* nextCacheItem in deviceCaches)
{
if ((nextCacheItem.gpuDevice.registryID == registryID) &&
(nextCacheItem.pixelFormat == pixFormat))
{
return nextCacheItem.pipelineState;
}
}
// Didn't find one, so create one with the right settings
NSArray<id<MTLDevice>>* devices = MTLCopyAllDevices();
id<MTLDevice> device = nil;
for (id<MTLDevice> nextDevice in devices)
{
if (nextDevice.registryID == registryID)
{
device = nextDevice;
}
}
id<MTLRenderPipelineState> result = nil;
if (device != nil)
{
MetalDeviceCacheItem* newCacheItem = [[[MetalDeviceCacheItem alloc] initWithDevice:device
pixelFormat:pixFormat]
autorelease];
if (newCacheItem != nil)
{
[deviceCaches addObject:newCacheItem];
result = newCacheItem.pipelineState;
}
}
[devices release];
return result;
}
- (id<MTLCommandQueue>)commandQueueWithRegistryID:(uint64_t)registryID
pixelFormat:(MTLPixelFormat)pixFormat;
{
for (MetalDeviceCacheItem* nextCacheItem in deviceCaches)
{
if ((nextCacheItem.gpuDevice.registryID == registryID) &&
(nextCacheItem.pixelFormat == pixFormat))
{
return [nextCacheItem getNextFreeCommandQueue];
}
}
// Didn't find one, so create one with the right settings
NSArray<id<MTLDevice>>* devices = MTLCopyAllDevices();
id<MTLDevice> device = nil;
for (id<MTLDevice> nextDevice in devices)
{
if (nextDevice.registryID == registryID)
{
device = nextDevice;
}
}
id<MTLCommandQueue> result = nil;
if (device != nil)
{
MetalDeviceCacheItem* newCacheItem = [[[MetalDeviceCacheItem alloc] initWithDevice:device
pixelFormat:pixFormat]
autorelease];
if (newCacheItem != nil)
{
[deviceCaches addObject:newCacheItem];
result = [newCacheItem getNextFreeCommandQueue];
}
}
[devices release];
return result;
}
- (void)returnCommandQueueToCache:(id<MTLCommandQueue>)commandQueue;
{
for (MetalDeviceCacheItem* nextCacheItem in deviceCaches)
{
if ([nextCacheItem containsCommandQueue:commandQueue])
{
[nextCacheItem returnCommandQueue:commandQueue];
break;
}
}
}
@end
@@ -0,0 +1,83 @@
//
// TileableRemoteBrightness.metal
// 大鱼调色
//
// Created by mac on 2026/10/31.
//
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
#include "TileableRemoteBrightnessShaderTypes.h"
typedef struct
{
// The [[position]] attribute of this member indicates that this value is the clip space
// position of the vertex when this structure is returned from the vertex function
float4 clipSpacePosition [[position]];
// Since this member does not have a special attribute, the rasterizer interpolates
// its value with the values of the other triangle vertices and then passes
// the interpolated value to the fragment shader for each fragment in the triangle
float2 textureCoordinate;
} RasterizerData;
vertex RasterizerData
vertexShader(uint vertexID [[vertex_id]],
constant Vertex2D *vertexArray [[buffer(BVI_Vertices)]],
constant vector_uint2 *viewportSizePointer [[buffer(BVI_ViewportSize)]])
{
RasterizerData out;
// Index into our array of positions to get the current vertex
// Our positions are specified in pixel dimensions (i.e. a value of 100 is 100 pixels from
// the origin)
float2 pixelSpacePosition = vertexArray[vertexID].position.xy;
// Get the size of the drawable so that we can convert to normalized device coordinates,
float2 viewportSize = float2(*viewportSizePointer);
// The output position of every vertex shader is in clip space (also known as normalized device
// coordinate space, or NDC). A value of (-1.0, -1.0) in clip-space represents the
// lower-left corner of the viewport whereas (1.0, 1.0) represents the upper-right corner of
// the viewport.
// In order to convert from positions in pixel space to positions in clip space we divide the
// pixel coordinates by half the size of the viewport.
out.clipSpacePosition.xy = pixelSpacePosition / (viewportSize / 2.0);
// Set the z component of our clip space position 0 (since we're only rendering in
// 2-Dimensions for this sample)
out.clipSpacePosition.z = 0.0;
// Set the w component to 1.0 since we don't need a perspective divide, which is also not
// necessary when rendering in 2-Dimensions
out.clipSpacePosition.w = 1.0;
// Pass our input textureCoordinate straight to our output RasterizerData. This value will be
// interpolated with the other textureCoordinate values in the vertices that make up the
// triangle.
out.textureCoordinate = vertexArray[vertexID].textureCoordinate;
return out;
}
// Fragment function
fragment float4 fragmentShader(RasterizerData in [[stage_in]],
texture2d<half> colorTexture [[ texture(BTI_InputImage) ]],
constant float* brightness [[ buffer(BFI_Brightness) ]])
{
constexpr sampler textureSampler (mag_filter::linear,
min_filter::linear);
// Sample the texture to obtain a color
half4 colorSample = colorTexture.sample(textureSampler, in.textureCoordinate);
const half hBrightness = static_cast<half>(*brightness);
colorSample.rgb = colorSample.rgb * hBrightness;
// We return the color of the texture
return float4(colorSample);
}
@@ -0,0 +1,32 @@
//
// TileableRemoteBrightnessShaderTypes.h
// 大鱼调色
//
// Created by mac on 2026/10/31.
//
#ifndef TileableRemoteBrightnessShaderTypes_h
#define TileableRemoteBrightnessShaderTypes_h
#import <simd/simd.h>
typedef enum BrightnessVertexInputIndex {
BVI_Vertices = 0,
BVI_ViewportSize = 1
} BrightnessVertexInputIndex;
typedef enum BrightnessTextureIndex {
BTI_InputImage = 0
} BrightnessTextureIndex;
typedef enum BrightnessFragmentIndex {
BFI_Brightness = 0
} BrightnessFragmentIndex;
typedef struct Vertex2D {
vector_float2 position;
vector_float2 textureCoordinate;
} Vertex2D;
#endif /* TileableRemoteBrightnessShaderTypes_h */
+8
查看文件
@@ -0,0 +1,8 @@
//___FILEHEADER___
#import <Foundation/Foundation.h>
#import <FxPlug/FxPlugSDK.h>
@interface ___PACKAGENAMEASIDENTIFIER___PlugIn : NSObject <FxTileableEffect>
@property (assign) id<PROAPIAccessing> apiManager;
@end
+315
查看文件
@@ -0,0 +1,315 @@
//___FILEHEADER___
#import "___PACKAGENAMEASIDENTIFIER___PlugIn.h"
#import <IOSurface/IOSurfaceObjC.h>
#import "TileableRemoteBrightnessShaderTypes.h"
#import "MetalDeviceCache.h"
@implementation ___PACKAGENAMEASIDENTIFIER___PlugIn
//---------------------------------------------------------
// initWithAPIManager:
//
// This method is called when a plug-in is first loaded, and
// is a good point to conduct any checks for anti-piracy or
// system compatibility. Returning NULL means that a plug-in
// chooses not to be accessible for some reason.
//---------------------------------------------------------
- (nullable instancetype)initWithAPIManager:(id<PROAPIAccessing>)newApiManager;
{
self = [super init];
if (self != nil)
{
_apiManager = newApiManager;
}
return self;
}
//---------------------------------------------------------
// properties
//
// This method should return an NSDictionary defining the
// properties of the effect.
//---------------------------------------------------------
- (BOOL)properties:(NSDictionary * _Nonnull *)properties
error:(NSError * _Nullable *)error
{
*properties = @{
kFxPropertyKey_MayRemapTime : [NSNumber numberWithBool:NO],
kFxPropertyKey_PixelTransformSupport : [NSNumber numberWithInt:kFxPixelTransform_ScaleTranslate],
kFxPropertyKey_VariesWhenParamsAreStatic : [NSNumber numberWithBool:NO]
};
return YES;
}
//---------------------------------------------------------
// addParametersWithError
//
// This method is where a plug-in defines its list of parameters.
//---------------------------------------------------------
- (BOOL)addParametersWithError:(NSError**)error
{
id<FxParameterCreationAPI_v5> paramAPI = [_apiManager apiForProtocol:@protocol(FxParameterCreationAPI_v5)];
if (paramAPI == nil)
{
NSDictionary* userInfo = @{
NSLocalizedDescriptionKey : @"Unable to obtain an FxPlug API Object"
};
if (error != NULL)
*error = [NSError errorWithDomain:FxPlugErrorDomain
code:kFxError_APIUnavailable
userInfo:userInfo];
return NO;
}
if (![paramAPI addFloatSliderWithName:@"Brightness"
parameterID:1
defaultValue:1.0
parameterMin:0.0
parameterMax:100.0
sliderMin:0.0
sliderMax:10.0
delta:0.1
parameterFlags:kFxParameterFlag_DEFAULT])
{
NSDictionary* userInfo = @{
NSLocalizedDescriptionKey : @"Unable to add brightness slider"
};
if (error != NULL)
*error = [NSError errorWithDomain:FxPlugErrorDomain
code:kFxError_InvalidParameter
userInfo:userInfo];
return NO;
}
return YES;
}
//---------------------------------------------------------
// pluginState:atTime:quality:error
//
// Your plug-in should get its parameter values, do any calculations it needs to
// from those values, and package up the result to be used later with rendering.
// The host application will call this method before rendering. The
// FxParameterRetrievalAPI* is valid during this call. Use it to get the values of
// your plug-in's parameters, then put those values or the results of any calculations
// you need to do with those parameters to render into an NSData that you return
// to the host application. The host will pass it back to you during subsequent calls.
// Do not re-use the NSData; always create a new one as this method may be called
// on multiple threads at the same time.
//---------------------------------------------------------
- (BOOL)pluginState:(NSData**)pluginState
atTime:(CMTime)renderTime
quality:(FxQuality)qualityLevel
error:(NSError**)error
{
BOOL succeeded = NO;
id<FxParameterRetrievalAPI_v6> paramGetAPI = [_apiManager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];
if (paramGetAPI != nil)
{
double brightness = 1.0;
[paramGetAPI getFloatValue:&brightness
fromParameter:1
atTime:renderTime];
*pluginState = [NSData dataWithBytes:&brightness
length:sizeof(brightness)];
if (*pluginState != nil)
{
succeeded = YES;
}
}
else
{
if (error != NULL)
*error = [NSError errorWithDomain:FxPlugErrorDomain
code:kFxError_ThirdPartyDeveloperStart + 20
userInfo:@{
NSLocalizedDescriptionKey :
@"Unable to retrieve FxParameterRetrievalAPI_v6 in \
[-pluginStateAtTime:]" }];
}
return succeeded;
}
//---------------------------------------------------------
// destinationImageRect:sourceImages:destinationImage:pluginState:atTime:error
//
// This method will calculate the rectangular bounds of the output
// image given the various inputs and plug-in state
// at the given render time.
// It will pass in an array of images, the plug-in state
// returned from your plug-in's -pluginStateAtTime:error: method,
// and the render time.
//---------------------------------------------------------
- (BOOL)destinationImageRect:(FxRect *)destinationImageRect
sourceImages:(NSArray<FxImageTile *> *)sourceImages
destinationImage:(nonnull FxImageTile *)destinationImage
pluginState:(NSData *)pluginState
atTime:(CMTime)renderTime
error:(NSError * _Nullable *)outError
{
if (sourceImages.count < 1)
{
NSLog (@"No inputImages list");
return NO;
}
// In the case of a filter that only changed RGB values,
// the output rect is the same as the input rect.
*destinationImageRect = sourceImages [ 0 ].imagePixelBounds;
return YES;
}
//---------------------------------------------------------
// sourceTileRect:sourceImageIndex:sourceImages:destinationTileRect:destinationImage:pluginState:atTime:error
//
// Calculate tile of the source image we need
// to render the given output tile.
//---------------------------------------------------------
- (BOOL)sourceTileRect:(FxRect *)sourceTileRect
sourceImageIndex:(NSUInteger)sourceImageIndex
sourceImages:(NSArray<FxImageTile *> *)sourceImages
destinationTileRect:(FxRect)destinationTileRect
destinationImage:(FxImageTile *)destinationImage
pluginState:(NSData *)pluginState
atTime:(CMTime)renderTime
error:(NSError * _Nullable *)outError
{
// Since this is a color-only filter, the input tile will be the same size as the output tile
*sourceTileRect = destinationTileRect;
return YES;
}
//---------------------------------------------------------
// renderDestinationImage:sourceImages:pluginState:atTime:error:
//
// The host will call this method when it wants your plug-in to render an image
// tile of the output image. It will pass in each of the input tiles needed as well
// as the plug-in state needed for the calculations. Your plug-in should do all its
// rendering in this method. It should not attempt to use the FxParameterRetrievalAPI*
// object as it is invalid at this time. Note that this method will be called on
// multiple threads at the same time.
//---------------------------------------------------------
- (BOOL)renderDestinationImage:(FxImageTile *)destinationImage
sourceImages:(NSArray<FxImageTile *> *)sourceImages
pluginState:(NSData *)pluginState
atTime:(CMTime)renderTime
error:(NSError * _Nullable *)outError
{
if ((pluginState == nil) || (sourceImages [ 0 ].ioSurface == nil) || (destinationImage.ioSurface == nil))
{
NSDictionary* userInfo = @{
NSLocalizedDescriptionKey : @"Invalid plugin state received from host"
};
if (outError != NULL)
*outError = [NSError errorWithDomain:FxPlugErrorDomain
code:kFxError_InvalidParameter
userInfo:userInfo];
return NO;
}
// This is where you would access parameter values and other info about the source tile
// from the pluginState.
double brightness = 0.0;
[pluginState getBytes:&brightness
length:sizeof(brightness)];
// Set up the renderer, in this case we are using Metal.
MetalDeviceCache* deviceCache = [MetalDeviceCache deviceCache];
MTLPixelFormat pixelFormat = [MetalDeviceCache MTLPixelFormatForImageTile:destinationImage];
id<MTLCommandQueue> commandQueue = [deviceCache commandQueueWithRegistryID:sourceImages[0].deviceRegistryID
pixelFormat:pixelFormat];
if (commandQueue == nil)
{
return NO;
}
id<MTLCommandBuffer> commandBuffer = [commandQueue commandBuffer];
commandBuffer.label = @"DynamicRegXPC Command Buffer";
[commandBuffer enqueue];
id<MTLTexture> inputTexture = [sourceImages[0] metalTextureForDevice:[deviceCache deviceWithRegistryID:sourceImages[0].deviceRegistryID]];
id<MTLTexture> outputTexture = [destinationImage metalTextureForDevice:[deviceCache deviceWithRegistryID:destinationImage.deviceRegistryID]];
MTLRenderPassColorAttachmentDescriptor* colorAttachmentDescriptor = [[MTLRenderPassColorAttachmentDescriptor alloc] init];
colorAttachmentDescriptor.texture = outputTexture;
colorAttachmentDescriptor.clearColor = MTLClearColorMake(1.0, 0.5, 0.0, 1.0);
colorAttachmentDescriptor.loadAction = MTLLoadActionClear;
MTLRenderPassDescriptor* renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];
renderPassDescriptor.colorAttachments [ 0 ] = colorAttachmentDescriptor;
id<MTLRenderCommandEncoder> commandEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor];
// Rendering
float outputWidth = (float)(destinationImage.tilePixelBounds.right - destinationImage.tilePixelBounds.left);
float outputHeight = (float)(destinationImage.tilePixelBounds.top - destinationImage.tilePixelBounds.bottom);
Vertex2D vertices[] = {
{ { outputWidth / 2.0, -outputHeight / 2.0 }, { 1.0, 1.0 } },
{ { -outputWidth / 2.0, -outputHeight / 2.0 }, { 0.0, 1.0 } },
{ { outputWidth / 2.0, outputHeight / 2.0 }, { 1.0, 0.0 } },
{ { -outputWidth / 2.0, outputHeight / 2.0 }, { 0.0, 0.0 } }
};
MTLViewport viewport = {
0, 0, outputWidth, outputHeight, -1.0, 1.0
};
[commandEncoder setViewport:viewport];
id<MTLRenderPipelineState> pipelineState = [deviceCache pipelineStateWithRegistryID:sourceImages[0].deviceRegistryID
pixelFormat:pixelFormat];
[commandEncoder setRenderPipelineState:pipelineState];
[commandEncoder setVertexBytes:vertices
length:sizeof(vertices)
atIndex:BVI_Vertices];
simd_uint2 viewportSize = {
(unsigned int)(outputWidth),
(unsigned int)(outputHeight)
};
[commandEncoder setVertexBytes:&viewportSize
length:sizeof(viewportSize)
atIndex:BVI_ViewportSize];
[commandEncoder setFragmentTexture:inputTexture
atIndex:BTI_InputImage];
float fragmentBrightness = (float)brightness;
[commandEncoder setFragmentBytes:&fragmentBrightness
length:sizeof(fragmentBrightness)
atIndex:BFI_Brightness];
[commandEncoder drawPrimitives:MTLPrimitiveTypeTriangleStrip
vertexStart:0
vertexCount:4];
[commandEncoder endEncoding];
[commandBuffer commit];
[commandBuffer waitUntilCompleted];
[colorAttachmentDescriptor release];
[deviceCache returnCommandQueueToCache:commandQueue];
return YES;
}
@end
@@ -0,0 +1,3 @@
/* Localized versions of Info.plist keys */
"____::FxPlug Name" = "大鱼调色";
@@ -0,0 +1,4 @@
/* Localized versions of Info.plist keys */
"____::FxPlug Description" = "A helpful description of\nwhat this plugin does.";
+6
查看文件
@@ -0,0 +1,6 @@
#import <FxPlug/FxPlugSDK.h>
int main(int argc, const char *argv[])
{
[FxPrincipal startServicePrincipal];
}