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

Commit a682c3db authored by Peiyong Lin's avatar Peiyong Lin Committed by Android (Google) Code Review
Browse files

Merge "[HWC] Add setLayerFloatColor API into HAL."

parents ea0856ff ab505aaf
Loading
Loading
Loading
Loading
+30 −10
Original line number Diff line number Diff line
@@ -81,6 +81,14 @@ interface IComposerClient extends @2.1::IComposerClient {
        float value;
    };

    struct FloatColor {
        float r;
        float g;
        float b;
        float a;
    };

    enum Command : @2.1::IComposerClient.Command {
        /**
         * setPerFrameMetadata(Display display, vec<PerFrameMetadata> data)
         * Sets the PerFrameMetadata for the display. This metadata must be used
@@ -91,8 +99,20 @@ interface IComposerClient extends @2.1::IComposerClient {
         * SET_PER_FRAME_METADATA is the command used by the buffered transport
         * mechanism.
         */
    enum Command : @2.1::IComposerClient.Command {
        SET_PER_FRAME_METADATA = 0x207 << @2.1::IComposerClient.Command:OPCODE_SHIFT,

        /**
         * SET_LAYER_COLOR has this pseudo prototype
         *
         *   setLayerColor(FloatColor color);
         *
         * Sets the color of the given layer. If the composition type of the layer
         * is not Composition::SOLID_COLOR, this call must succeed and have no
         * other effect.
         *
         * @param color is the new color using float type.
         */
        SET_LAYER_FLOAT_COLOR = 0x40c << @2.1::IComposerClient.Command:OPCODE_SHIFT,
    };

    /**
+26 −2
Original line number Diff line number Diff line
@@ -64,8 +64,16 @@ class CommandWriterBase : public V2_1::CommandWriterBase {
   public:
    CommandWriterBase(uint32_t initialMaxSize) : V2_1::CommandWriterBase(initialMaxSize) {}

    static constexpr uint16_t kSetLayerFloatColorLength = 4;
    void setLayerFloatColor(IComposerClient::FloatColor color) {
        beginCommand_2_2(IComposerClient::Command::SET_LAYER_FLOAT_COLOR,
                         kSetLayerFloatColorLength);
        writeFloatColor(color);
        endCommand();
    }

    void setPerFrameMetadata(const hidl_vec<IComposerClient::PerFrameMetadata>& metadataVec) {
        beginCommand2_2(IComposerClient::Command::SET_PER_FRAME_METADATA, metadataVec.size() * 2);
        beginCommand_2_2(IComposerClient::Command::SET_PER_FRAME_METADATA, metadataVec.size() * 2);
        for (const auto& metadata : metadataVec) {
            writeSigned(static_cast<int32_t>(metadata.key));
            writeFloat(metadata.value);
@@ -74,10 +82,17 @@ class CommandWriterBase : public V2_1::CommandWriterBase {
    }

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

    void writeFloatColor(const IComposerClient::FloatColor& color) {
        writeFloat(color.r);
        writeFloat(color.g);
        writeFloat(color.b);
        writeFloat(color.a);
    }
};

// This class helps parse a command queue.  Note that all sizes/lengths are in
@@ -85,6 +100,15 @@ class CommandWriterBase : public V2_1::CommandWriterBase {
class CommandReaderBase : public V2_1::CommandReaderBase {
   public:
    CommandReaderBase() : V2_1::CommandReaderBase(){};

   protected:
    IComposerClient::FloatColor readFloatColor() {
        float r = readFloat();
        float g = readFloat();
        float b = readFloat();
        float a = readFloat();
        return IComposerClient::FloatColor{r, g, b, a};
    }
};

}  // namespace V2_2
+14 −0
Original line number Diff line number Diff line
@@ -224,6 +224,20 @@ TEST_F(GraphicsComposerHidlTest, getReadbackBufferAttributes) {
    mComposerClient->getReadbackBufferAttributes(mPrimaryDisplay, &pixelFormat, &dataspace);
}

/**
 * Test IComposerClient::Command::SET_LAYER_FLOAT_COLOR.
 */
TEST_F(GraphicsComposerHidlCommandTest, SET_LAYER_FLOAT_COLOR) {
    V2_1::Layer layer;
    ASSERT_NO_FATAL_FAILURE(layer =
                                mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));

    mWriter->selectDisplay(mPrimaryDisplay);
    mWriter->selectLayer(layer);
    mWriter->setLayerFloatColor(IComposerClient::FloatColor{1.0, 1.0, 1.0, 1.0});
    mWriter->setLayerFloatColor(IComposerClient::FloatColor{0.0, 0.0, 0.0, 0.0});
}

}  // namespace
}  // namespace tests
}  // namespace V2_2