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

Commit 830137fc authored by Peiyong Lin's avatar Peiyong Lin
Browse files

[Graphics] Add setLayerColorTransform.

This patch adds HAL API to set per-layer color transformation with a 4x4
matrix. Given a 4x4 matrix, the matrix will be applied on the current layer
before composition.

BUG: 111562338
Test: Build, flash and boot, run VtsHalGraphicsComposerV2_3TargetTest
Change-Id: I673cfc2745d35947107dcab19f383ba5a8067605
parent 82ef3872
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ hidl_interface {
    ],
    interfaces: [
        "android.hardware.graphics.common@1.0",
        "android.hardware.graphics.common@1.1",
        "android.hardware.graphics.composer@2.1",
        "android.hardware.graphics.composer@2.2",
        "android.hidl.base@1.0",
+71 −0
Original line number Diff line number Diff line
@@ -16,12 +16,58 @@

package android.hardware.graphics.composer@2.3;

import android.hardware.graphics.composer@2.1::IComposerClient.Command;
import @2.2::IComposerClient;
import @2.1::Display;
import @2.1::Error;

interface IComposerClient extends @2.2::IComposerClient {

    enum Command : @2.2::IComposerClient.Command {
        /**
         * SET_LAYER_COLOR_TRANSFORM has this pseudo prototype
         *
         *   setLayerColorTransform(float[16] matrix);
         *
         * This command has the following binary layout in bytes:
         *
         *     0 - 16 * 4: matrix
         *
         * Sets a matrix for color transform which will be applied on this layer
         * before composition.
         *
         * If the device is not capable of apply the matrix on this layer, it must force
         * this layer to client composition during VALIDATE_DISPLAY.
         *
         * The matrix provided is an affine color transformation of the following
         * form:
         *
         * |r.r r.g r.b 0|
         * |g.r g.g g.b 0|
         * |b.r b.g b.b 0|
         * |Tr  Tg  Tb  1|
         *
         * This matrix must be provided in row-major form:
         *
         * {r.r, r.g, r.b, 0, g.r, ...}.
         *
         * Given a matrix of this form and an input color [R_in, G_in, B_in],
         * the input color must first be converted to linear space
         * [R_linear, G_linear, B_linear], then the output linear color
         * [R_out_linear, G_out_linear, B_out_linear] will be:
         *
         * R_out_linear = R_linear * r.r + G_linear * g.r + B_linear * b.r + Tr
         * G_out_linear = R_linear * r.g + G_linear * g.g + B_linear * b.g + Tg
         * B_out_linear = R_linear * r.b + G_linear * g.b + B_linear * b.b + Tb
         *
         * [R_out_linear, G_out_linear, B_out_linear] must then be converted to
         * gamma space: [R_out, G_out, B_out] before blending.
         *
         * @param matrix is a 4x4 transform matrix (16 floats) as described above.
         */
        SET_LAYER_COLOR_TRANSFORM = 0x40d << @2.1::IComposerClient.Command:OPCODE_SHIFT,
    };

    /**
     * Returns the port and data that describe a physical display. The port is
     * a unique number that identifies a physical connector (e.g. eDP, HDMI)
@@ -42,4 +88,29 @@ interface IComposerClient extends @2.2::IComposerClient {
                          uint8_t port,
                          vec<uint8_t> data);

    /**
     * Executes commands from the input command message queue. Return values
     * generated by the input commands are written to the output command
     * message queue in the form of value commands.
     *
     * @param inLength is the length of input commands.
     * @param inHandles is an array of handles referenced by the input
     *        commands.
     * @return error is NONE upon success. Otherwise,
     *         BAD_PARAMETER when inLength is not equal to the length of
     *                       commands in the input command message queue.
     *         NO_RESOURCES when the output command message queue was not
     *                      properly drained.
     * @param outQueueChanged indicates whether the output command message
     *        queue has changed.
     * @param outLength is the length of output commands.
     * @param outHandles is an array of handles referenced by the output
     *        commands.
     */
    executeCommands_2_3(uint32_t inLength,
                        vec<handle> inHandles)
             generates (Error error,
                        bool outQueueChanged,
                        uint32_t outLength,
                        vec<handle> outHandles);
};
+15 −0
Original line number Diff line number Diff line
cc_library_headers {
    name: "android.hardware.graphics.composer@2.3-command-buffer",
    defaults: ["hidl_defaults"],
    vendor_available: true,
    shared_libs: [
        "android.hardware.graphics.composer@2.1",
        "android.hardware.graphics.composer@2.2",
        "android.hardware.graphics.composer@2.3",
    ],
    header_libs: [
        "android.hardware.graphics.composer@2.1-command-buffer",
        "android.hardware.graphics.composer@2.2-command-buffer",
    ],
    export_include_dirs: ["include"],
}
+76 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#ifndef LOG_TAG
#warn "ComposerCommandBuffer.h included without LOG_TAG"
#endif

#undef LOG_NDEBUG
#define LOG_NDEBUG 0

#include <android/hardware/graphics/composer/2.3/IComposer.h>
#include <android/hardware/graphics/composer/2.3/IComposerClient.h>
#include <composer-command-buffer/2.2/ComposerCommandBuffer.h>

namespace android {
namespace hardware {
namespace graphics {
namespace composer {
namespace V2_3 {

using android::hardware::MessageQueue;
using android::hardware::graphics::composer::V2_1::Error;
using android::hardware::graphics::composer::V2_1::IComposerCallback;
using android::hardware::graphics::composer::V2_1::Layer;
using android::hardware::graphics::composer::V2_3::IComposerClient;

// This class helps build a command queue.  Note that all sizes/lengths are in
// units of uint32_t's.
class CommandWriterBase : public V2_2::CommandWriterBase {
   public:
    CommandWriterBase(uint32_t initialMaxSize) : V2_2::CommandWriterBase(initialMaxSize) {}

    static constexpr uint16_t kSetLayerColorTransformLength = 16;
    void setLayerColorTransform(const float* matrix) {
        beginCommand_2_3(IComposerClient::Command::SET_LAYER_COLOR_TRANSFORM,
                         kSetLayerColorTransformLength);
        for (int i = 0; i < 16; i++) {
            writeFloat(matrix[i]);
        }
        endCommand();
    }

   protected:
    void beginCommand_2_3(IComposerClient::Command command, uint16_t length) {
        V2_2::CommandWriterBase::beginCommand_2_2(
            static_cast<V2_2::IComposerClient::Command>(static_cast<int32_t>(command)), length);
    }
};

// This class helps parse a command queue.  Note that all sizes/lengths are in
// units of uint32_t's.
class CommandReaderBase : public V2_2::CommandReaderBase {
   public:
    CommandReaderBase() : V2_2::CommandReaderBase(){};
};

}  // namespace V2_3
}  // namespace composer
}  // namespace graphics
}  // namespace hardware
}  // namespace android
+2 −0
Original line number Diff line number Diff line
@@ -26,9 +26,11 @@ cc_library_headers {
    ],
    header_libs: [
        "android.hardware.graphics.composer@2.2-hal",
        "android.hardware.graphics.composer@2.3-command-buffer",
    ],
    export_header_lib_headers: [
        "android.hardware.graphics.composer@2.2-hal",
        "android.hardware.graphics.composer@2.3-command-buffer",
    ],
    export_include_dirs: ["include"],
}
Loading