1 关键字

GPU渲染、CPU合成

2 问题描述

代码版本:OpenHarmony-4.0-Release

问题描述:如何设置CPU合成

3 解决方案

在调试GPU渲染和硬件合成过程中,可能需要CPU合成进行对比验证。

3.1 设置合成类型 GRAPHIC_COMPOSITION_CLIENT
param set rosen.client_composition.enabled 1

设置合成类型为GRAPHIC_COMPOSITION_CLIENT,此时不走display_gfx中的硬件合成,通过Redraw函数进行CPU合成或者GPU合成。

参考//foundation/graphic/graphic_2d/rosen/modules/render_service/core/pipeline/rs_physical_screen_processor.cpp中的Redraw函数:

void RSPhysicalScreenProcessor::Redraw(const sptr<Surface>& surface, const std::vector<LayerInfoPtr>& layers)
{
    RS_TRACE_NAME("Redraw");
    if (surface == nullptr) {
        RS_LOGE("RSPhysicalScreenProcessor::Redraw: surface is null.");
        return;
    }

    RS_LOGD("RsDebug RSPhysicalScreenProcessor::Redraw flush frame buffer start");
    bool forceCPU = RSBaseRenderEngine::NeedForceCPU(layers);
    auto renderFrame = renderEngine_->RequestFrame(surface, renderFrameConfig_, forceCPU);
    if (renderFrame == nullptr) {
        RS_LOGE("RsDebug RSPhysicalScreenProcessor::Redraw: failed to request frame.");
        return;
    }

    auto canvas = renderFrame->GetCanvas();
    if (canvas == nullptr) {
        RS_LOGE("RsDebug RSPhysicalScreenProcessor::Redraw: canvas is nullptr.");
        return;
    }
#ifndef USE_ROSEN_DRAWING
    canvas->concat(screenTransformMatrix_);
#else
    canvas->ConcatMatrix(screenTransformMatrix_);
#endif
    renderEngine_->DrawLayers(*canvas, layers, forceCPU, mirrorAdaptiveCoefficient_);
    renderFrame->Flush();
    RS_LOGD("RsDebug RSPhysicalScreenProcessor::Redraw flush frame buffer end");
}

3.2 设置forceCPU标志

默认情况使用GPU绘制,合成一帧送显图像。可以通过设置forceCPU标志,强制进行CPU绘制,进行合成。

默认情况假设GPU不支持yuv格式或色域变换,此时需要进行CPU绘制。

bool RSBaseRenderEngine::NeedForceCPU(const std::vector<LayerInfoPtr>& layers)
{
    bool forceCPU = false;
    
    for (const auto& layer: layers) {
        if (layer == nullptr) {
            continue;
        }

        auto buffer = layer->GetBuffer();
        if (buffer == nullptr) {
            continue;
        }

#ifndef RS_ENABLE_EGLIMAGE
        const auto bufferFormat = buffer->GetFormat();
        if (bufferFormat == GRAPHIC_PIXEL_FMT_YCRCB_420_SP || bufferFormat == GRAPHIC_PIXEL_FMT_YCBCR_420_SP) {
            forceCPU = true;
            break;
        }
#endif

        GraphicColorGamut srcGamut = static_cast<GraphicColorGamut>(buffer->GetSurfaceBufferColorGamut());
        GraphicColorGamut dstGamut = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB;
        if (srcGamut != dstGamut) {
            forceCPU = true;
            break;
        }
    }

    return forceCPU;
}
Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐