AEJoy —— AE 插件开发中的 SmartFX (九)

328 阅读3分钟

「这是我参与11月更文挑战的第 19 天,活动详情查看:2021最后一次更文挑战」。

参加该活动的第 36 篇文章

正文

运行时的标记

通常情况下,给定 PF_RenderRequestmax_result_rect 将被裁剪到任何被应用遮罩的边界。

然而,如果 PF_OutFlag2_REVEALS_ZERO_ALPHA 被设置,那么 max_result_rect 将是层的大小。

Flag On The Play

Normally, the max_result_rect of a given PF_RenderRequest will be cropped to the bounds of any applied mask.

However, if PF_OutFlag2_REVEALS_ZERO_ALPHA is set, the max_result_rect will be the size of the layer.

PF_Cmd_SMART_RENDER

对于每个预渲染,该 effect 将最多接收一个 PF_Cmd_SMART_RENDER 调用。

注意,渲染可能永远不会被调用。After Effects 可能只是想执行一些边界计算,或者它可能随后发现一个 effect 的输出根本不需要(这可能发生,例如,如果轨道遮罩Track Matte 的预渲染阶段返回一个不与 effect 的输出相交的矩形)。

所有的 effect 必须能够处理预渲染,没有渲染,没有泄漏资源或进入不稳定的状态。

PF_Cmd_SMART_RENDER 期间,额外的参数指向一个 PF_SmartRenderExtra

PF_Cmd_SMART_RENDER

The effect will receive at most one PF_Cmd_SMART_RENDER call for each pre-render.

Note that render may never be called at all. After Effects may have only wanted to to perform some bounds computations, or it may have subsequently discovered that an effect’s output is not needed at all (which can happen, for example, if the pre-render phase for a track matte returns a rectangle that does not intersect the effect’s output.)

All effects must be able to handle Pre-Render without Render without leaking resources or otherwise entering an unstable state.

During PF_Cmd_SMART_RENDER, the extra parameter points to a PF_SmartRenderExtra.

PF_SmartRenderExtra

PF_SmartRenderInput

由一个 PF_RenderRequest、位深度和一个指向 pre_render_data 的指针(在 PF_Cmd_SMART_PRE_RENDER 期间分配)三者组成。

这个 PF_SmartRenderInput 和对应于 PF_Cmd_SMART_PRE_RENDER 阶段被传入的是相同的。

PF_SmartRenderCallbacks

PF_Err checkout_layer_pixels(
  PF_ProgPtr      effect_ref,
  A_long          checkout_idL,
  PF_EffectWorld  **pixels);

这用于实际访问在 PF_Cmd_SMART_PRE_RENDER 期间 checked out 的层中的像素。

返回的 PF_EffectWorld 在当前命令期间有效,直到 checked in 为止。

在先前的 PF_Cmd_SMART_PRERENDER 期间中使用 checkout_idL 时,只允许调用 checkout_layer_pixels 一次。在 PF_Cmd_SMART_PRERENDER 期间和 PF_Cmd_SMART_RENDER 期间的 check out 数量之间必须有一一对应的映射。

要在一个层上多次调用 checkout_layer_pixels,你应该在 PF_Cmd_SMART_PRERENDER 阶段,在同一层上使用不同的(独一无二的) checkout_idL,再次调用 checkout_layer,然后使用该 checkout_idLPF_Cmd_SMART_RENDER 中执行另一个 checkout_layer_pixels

PF_Err checkin_layer_pixels(
  PF_ProgPtr  effect_ref,
  A_long      checkout_idL);

它没有必要调用(After Effects 会在 effect 从 PF_Cmd_SMART_RENDER 返回时清除所有这些校验),但对于释放内存很有用。

PF_Err checkout_output(
  PF_ProgPtr      effect_ref,
  PF_EffectWorld  **output);

检索输出缓冲区。注意,在至少一个输入被 check out 之前, effect 是不允许 check out 输出的(除非效果根本没有输入)。

注意: 为了优化内存使用,请求输出的时间越晚越好,每次请求输入越少越好。

PF_SmartRenderExtra

PF_SmartRenderInput

Consists of a PF_RenderRequest, the bitdepth, and a pointer to pre_render_data (allocated during PF_Cmd_SMART_PRE_RENDER).

This PF_SmartRenderInput is identical to that passed in the corresponding PF_Cmd_SMART_PRE_RENDER.

PF_SmartRenderCallbacks

PF_Err checkout_layer_pixels(
  PF_ProgPtr      effect_ref,
  A_long          checkout_idL,
  PF_EffectWorld  **pixels);

This is used to actually access the pixels in layers checked out during PF_Cmd_SMART_PRE_RENDER.

The returned PF_EffectWorld is valid for duration of current command or until checked in.

You are only allowed to call checkout_layer_pixels only once with the checkout_idL used earlier in PF_Cmd_SMART_PRERENDER. There must be a one-to-one mapping between the number of checkouts made in PF_Cmd_SMART_PRERENDER and PF_Cmd_SMART_RENDER.

To call checkout_layer_pixels more than once on a layer, you should call checkout_layer on the same layer again with a different unique checkout_idL in PF_Cmd_SMART_PRERENDER and then use that checkout_idL to do another checkout_layer_pixels in PF_Cmd_SMART_RENDER.

PF_Err checkin_layer_pixels(
  PF_ProgPtr  effect_ref,
  A_long      checkout_idL);

It isn’t necessary to call (After Effects cleans up all such checkouts when the effect returns from PF_Cmd_SMART_RENDER), but useful to free up memory.

PF_Err checkout_output(
  PF_ProgPtr      effect_ref,
  PF_EffectWorld  **output);

Retrieves the output buffer. Note that effects are not allowed to check out output until at least one input has been checked out (unless the effect has no inputs at all).

NOTE: For optimal memory usage, request the output as late as possible, and request inputs as few at a time as possible.