R7: pure C ABI display boundary + engine visibility closure

R7-A (Qwen 3.8 Max): oakengine/display.h rewritten to the POD contract
from r7-pure-abi-plan.md - oak_video_params everywhere, opaque
texture/frame handles with retain/free protocol (engine-heap control
blocks), OakSharedBuffer refcounted wrapper for the QVariant playback
path. All TexturePtr/FramePtr gone from app (47 sites).

R7-B (Qwen 3.8 Max): liboakengine.so exports 3486 -> 19 C++ symbols
(version script oakengine.ver: oakengine_* plus the documented
oakgl/oakvulkan dlopen plugin ABI). oakengine-obj OBJECT library feeds
both the shared lib and the test binaries (-rdynamic so dlopen'd
backends resolve engine objects).

Fix (Kimi K3): producer/consumer type mismatch - viewerdisplay
unpacks OakSharedBufferPtr but viewer.cpp pushed raw void* handles,
so no frame ever reached the display widget (all 5 vulkan viewer
tests timed out with 'never received a texture'). Producers now wrap
with oak_make_shared_frame / oak_make_shared_texture(retain).

Verified: build 0 errors, ctest 45/45, nm U _ZN5olive = 0 in
oak-editor/oak-render-worker/oak-cli, 19 exported C++ symbols in
liboakengine.so (all documented plugin ABI).
This commit is contained in:
2026-07-27 00:54:46 +08:00
parent 9b25772267
commit eb634b53ef
33 changed files with 1692 additions and 668 deletions
+123 -69
View File
@@ -26,9 +26,6 @@
#include "common/configwrapper.h"
#include "oakengine/display.h"
#include "oakengine/videoparams.h"
#include "render/job/colortransformjob.h"
#include "widget/viewer/vieweroutpututils.h"
#include "render/job/shaderjob.h"
namespace olive
{
@@ -37,16 +34,23 @@ namespace olive
ScopeBase::ScopeBase(QWidget *parent)
: super(parent)
, pipeline_(nullptr)
, texture_(nullptr)
, managed_tex_(nullptr)
, managed_tex_up_to_date_(false)
, software_tex_(nullptr)
, software_image_up_to_date_(false)
, local_texture_(nullptr)
{
enable_default_context_menu();
}
void ScopeBase::set_buffer(TexturePtr frame)
void ScopeBase::set_buffer(void *frame)
{
texture_ = frame;
if (texture_) {
oakengine_display_texture_free(texture_);
}
texture_ = oakengine_display_texture_retain(frame);
managed_tex_up_to_date_ = false;
software_image_up_to_date_ = false;
update();
@@ -57,20 +61,17 @@ void ScopeBase::showEvent(QShowEvent *e)
super::showEvent(e);
}
void ScopeBase::draw_scope(TexturePtr managed_tex, QVariant pipeline)
void ScopeBase::draw_scope(void *managed_tex, void *pipeline)
{
ShaderJob job;
job.insert(QStringLiteral("ove_maintex"),
NodeValue(NodeValue::k_texture,
QVariant::fromValue(managed_tex)));
renderer()->blit(pipeline, job, get_viewport_params());
oak_video_params vp = get_viewport_params();
oakengine_display_renderer_blit_shader(renderer(), pipeline, managed_tex,
&vp);
}
void ScopeBase::update_software_image()
{
if (!texture_ || texture_->is_dummy() || !renderer()) {
if (!texture_ || oakengine_display_texture_is_dummy(texture_) ||
!renderer()) {
software_image_ = QImage();
software_image_up_to_date_ = true;
return;
@@ -80,23 +81,29 @@ void ScopeBase::update_software_image()
// separate Vulkan device). The reference texture emitted by the viewer lives
// in the viewer's renderer, so we must download it to the CPU and re-upload
// it into this scope's renderer before we can sample it.
TexturePtr source_tex = texture_;
if (texture_->renderer() && texture_->renderer() != renderer()) {
FramePtr temp_frame;
oakengine_codec_frame_create(&temp_frame);
oakengine_codec_frame_set_video_params(temp_frame.get(),
&texture_->params());
oakengine_codec_frame_allocate(temp_frame.get());
oakengine_display_texture_download(texture_.get(), temp_frame->data(),
temp_frame->linesize_pixels());
void *source_tex = texture_;
void *tex_renderer = oakengine_display_texture_renderer(texture_);
if (tex_renderer && tex_renderer != renderer()) {
void *temp_frame = oakengine_codec_frame_create();
oak_video_params tex_params = {};
oakengine_display_texture_get_params(texture_, &tex_params);
oakengine_codec_frame_set_video_params(temp_frame, &tex_params);
oakengine_codec_frame_allocate(temp_frame);
oakengine_display_texture_download(
texture_, oakengine_codec_frame_data(temp_frame),
oakengine_codec_frame_linesize(temp_frame));
oakengine_display_renderer_create_texture(
renderer(), &temp_frame->video_params(), temp_frame->data(),
temp_frame->linesize_pixels(), &local_texture_);
if (local_texture_) {
oakengine_display_texture_free(local_texture_);
}
local_texture_ = oakengine_display_texture_create(
renderer(), &tex_params, oakengine_codec_frame_const_data(temp_frame),
oakengine_codec_frame_linesize(temp_frame));
oakengine_codec_frame_free(temp_frame);
source_tex = local_texture_;
}
if (!source_tex || source_tex->is_dummy()) {
if (!source_tex || oakengine_display_texture_is_dummy(source_tex)) {
software_image_ = QImage();
software_image_up_to_date_ = true;
return;
@@ -105,46 +112,60 @@ void ScopeBase::update_software_image()
const int texture_width = static_cast<int>(width() * devicePixelRatioF());
const int texture_height = static_cast<int>(height() * devicePixelRatioF());
oak_video_params pod = {};
pod.width = texture_width;
pod.height = texture_height;
pod.format = PixelFormat::u8;
const VideoParams offscreen_params(video_params_from_pod(pod));
oak_video_params offscreen_pod = {};
offscreen_pod.width = texture_width;
offscreen_pod.height = texture_height;
offscreen_pod.format = 0; // PixelFormat::u8
if (!software_tex_ || software_tex_->params() != offscreen_params) {
oakengine_display_renderer_create_texture(renderer(),
&offscreen_params, nullptr, 0,
&software_tex_);
software_buffer_.resize(
texture_width * texture_height *
oakengine_video_params_bytes_per_pixel(PixelFormat::u8,
4));
bool need_recreate = false;
if (!software_tex_) {
need_recreate = true;
} else {
oak_video_params cur = {};
oakengine_display_texture_get_params(software_tex_, &cur);
if (cur.width != offscreen_pod.width ||
cur.height != offscreen_pod.height ||
cur.format != offscreen_pod.format) {
need_recreate = true;
}
}
if (!software_tex_ || software_tex_->is_dummy()) {
if (need_recreate) {
if (software_tex_) {
oakengine_display_texture_free(software_tex_);
}
software_tex_ = oakengine_display_texture_create(
renderer(), &offscreen_pod, nullptr, 0);
software_buffer_.resize(texture_width * texture_height *
oakengine_video_params_bytes_per_pixel(0, 4));
}
if (!software_tex_ || oakengine_display_texture_is_dummy(software_tex_)) {
software_image_ = QImage();
software_image_up_to_date_ = true;
return;
}
ColorTransformJob job;
oakengine_color_transform_job_set_processor(&job, color_service().get());
job.set_input_texture(source_tex);
job.set_input_alpha_association(k_alpha_none);
job.set_clear_destination_enabled(true);
job.set_force_opaque(true);
oak_color_transform_job job = {};
job.processor = color_service().get();
job.input_texture = source_tex;
job.input_alpha_association = 0; // k_alpha_none
job.clear_destination = 1;
job.force_opaque = 1;
oakengine_display_renderer_blit_color_managed(renderer(), &job,
software_tex_.get(), nullptr);
renderer()->download_from_texture(software_tex_->id(),
software_tex_->params(),
software_buffer_.data(), 0);
software_tex_, nullptr);
int sw_id = oakengine_display_texture_id(software_tex_);
oak_video_params sw_params = {};
oakengine_display_texture_get_params(software_tex_, &sw_params);
oakengine_display_renderer_download_from_texture(
renderer(), sw_id, &sw_params, software_buffer_.data(), 0);
software_image_ = QImage(
reinterpret_cast<const uchar *>(software_buffer_.constData()),
texture_width, texture_height,
texture_width * oakengine_video_params_bytes_per_pixel(
PixelFormat::u8, 4),
texture_width * oakengine_video_params_bytes_per_pixel(0, 4),
QImage::Format_RGBA8888_Premultiplied);
software_image_.setDevicePixelRatio(devicePixelRatioF());
@@ -156,7 +177,11 @@ void ScopeBase::on_init()
super::on_init();
if (!is_backend_neutral()) {
pipeline_ = renderer()->create_native_shader(generate_shader_code());
ScopeShaderCode code = generate_shader_code();
pipeline_ = oakengine_display_renderer_create_shader(
renderer(), code.frag.toUtf8().constData(),
code.vert.isEmpty() ? nullptr
: code.vert.toUtf8().constData());
}
}
@@ -177,22 +202,36 @@ void ScopeBase::on_paint()
}
// Clear display surface
renderer()->clear_destination();
oakengine_display_renderer_clear(renderer(), 0.0, 0.0, 0.0);
if (texture_) {
// Convert reference frame to display space
if (!managed_tex_ || !managed_tex_up_to_date_ ||
managed_tex_->params() != texture_->params()) {
oakengine_display_renderer_create_texture(
renderer(), &texture_->params(), nullptr, 0, &managed_tex_);
bool need_recreate = false;
if (!managed_tex_ || !managed_tex_up_to_date_) {
need_recreate = true;
} else if (!oakengine_display_texture_params_equal(managed_tex_,
texture_)) {
need_recreate = true;
}
ColorTransformJob job;
oakengine_color_transform_job_set_processor(&job, color_service().get());
job.set_input_texture(texture_);
job.set_input_alpha_association(k_alpha_none);
if (need_recreate) {
if (managed_tex_) {
oakengine_display_texture_free(managed_tex_);
}
oak_video_params tex_params = {};
oakengine_display_texture_get_params(texture_, &tex_params);
managed_tex_ = oakengine_display_texture_create(
renderer(), &tex_params, nullptr, 0);
oak_color_transform_job job = {};
job.processor = color_service().get();
job.input_texture = texture_;
job.input_alpha_association = 0; // k_alpha_none
job.clear_destination = 0;
job.force_opaque = 0;
oakengine_display_renderer_blit_color_managed(
renderer(), &job, managed_tex_.get(), nullptr);
renderer(), &job, managed_tex_, nullptr);
managed_tex_up_to_date_ = true;
}
@@ -202,13 +241,28 @@ void ScopeBase::on_paint()
void ScopeBase::on_destroy()
{
local_texture_ = nullptr;
software_tex_ = nullptr;
if (local_texture_) {
oakengine_display_texture_free(local_texture_);
local_texture_ = nullptr;
}
if (software_tex_) {
oakengine_display_texture_free(software_tex_);
software_tex_ = nullptr;
}
software_buffer_.clear();
software_image_ = QImage();
managed_tex_ = nullptr;
texture_ = nullptr;
pipeline_.clear();
if (managed_tex_) {
oakengine_display_texture_free(managed_tex_);
managed_tex_ = nullptr;
}
if (texture_) {
oakengine_display_texture_free(texture_);
texture_ = nullptr;
}
if (pipeline_) {
oakengine_display_renderer_destroy_shader(renderer(), pipeline_);
pipeline_ = nullptr;
}
super::on_destroy();
}