Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b29c7724 authored by John Reck's avatar John Reck
Browse files

Ensure GL & Gralloc both support FP16 before using it

Change-Id: I3bda750b6011d9a69969fc938a230c2445ee8dae
Merged-In: Id8a53885178d698c7b2fd6fc5ea8d4e36ce2ef15
Fixes: 77973662
Test: builds & CTS passes
parent eb43503f
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -266,6 +266,26 @@ private:
    GLuint mTexture = 0;
};

static bool isFP16Supported(const sk_sp<GrContext>& grContext) {
    static std::once_flag sOnceFlag;
    static bool supported = false;

    std::call_once(sOnceFlag, [](const sk_sp<GrContext>& grContext) {
        if (!grContext->caps()->isConfigTexturable(kRGBA_half_GrPixelConfig)) {
            supported = false;
            return;
        }

        sp<GraphicBuffer> buffer = new GraphicBuffer(1, 1, PIXEL_FORMAT_RGBA_FP16,
                GraphicBuffer::USAGE_HW_TEXTURE | GraphicBuffer::USAGE_SW_WRITE_NEVER |
                        GraphicBuffer::USAGE_SW_READ_NEVER, "tempFp16Buffer");
        status_t error = buffer->initCheck();
        supported = !error;
    }, grContext);

    return supported;
}

sk_sp<Bitmap> SkiaOpenGLPipeline::allocateHardwareBitmap(renderthread::RenderThread& renderThread,
                                                         SkBitmap& skBitmap) {
    renderThread.eglManager().initialize();
@@ -287,7 +307,7 @@ sk_sp<Bitmap> SkiaOpenGLPipeline::allocateHardwareBitmap(renderthread::RenderThr
            type = GL_UNSIGNED_BYTE;
            break;
        case kRGBA_F16_SkColorType:
            isSupported = grContext->caps()->isConfigTexturable(kRGBA_half_GrPixelConfig);
            isSupported = isFP16Supported(grContext);
            if (isSupported) {
                type = GL_HALF_FLOAT;
                pixelFormat = PIXEL_FORMAT_RGBA_FP16;