diff --git a/graphics/composer/2.1/default/Android.bp b/graphics/composer/2.1/default/Android.bp index 140e50ece7..b46a1debb3 100644 --- a/graphics/composer/2.1/default/Android.bp +++ b/graphics/composer/2.1/default/Android.bp @@ -17,6 +17,9 @@ cc_library_static { "libsync", "libutils", ], + header_libs: [ + "android.hardware.graphics.composer@2.1-command-buffer", + ], } cc_library_shared { @@ -41,6 +44,9 @@ cc_library_shared { "libhwc2on1adapter", "libhwc2onfbadapter", ], + header_libs: [ + "android.hardware.graphics.composer@2.1-command-buffer", + ], } cc_binary { @@ -65,10 +71,3 @@ cc_binary { "libutils", ], } - -cc_library_static { - name: "libhwcomposer-command-buffer", - defaults: ["hidl_defaults"], - shared_libs: ["android.hardware.graphics.composer@2.1"], - export_include_dirs: ["."], -} diff --git a/graphics/composer/2.1/default/ComposerClient.cpp b/graphics/composer/2.1/default/ComposerClient.cpp index 8aa9af0e97..0fcb9de80e 100644 --- a/graphics/composer/2.1/default/ComposerClient.cpp +++ b/graphics/composer/2.1/default/ComposerClient.cpp @@ -19,9 +19,8 @@ #include #include -#include "ComposerClient.h" #include "ComposerBase.h" -#include "IComposerCommandBuffer.h" +#include "ComposerClient.h" namespace android { namespace hardware { diff --git a/graphics/composer/2.1/default/ComposerClient.h b/graphics/composer/2.1/default/ComposerClient.h index fc5c223095..104ed5afcf 100644 --- a/graphics/composer/2.1/default/ComposerClient.h +++ b/graphics/composer/2.1/default/ComposerClient.h @@ -21,8 +21,8 @@ #include #include +#include #include -#include "IComposerCommandBuffer.h" #include "ComposerBase.h" namespace android { diff --git a/graphics/composer/2.1/default/OWNERS b/graphics/composer/2.1/default/OWNERS index 3aa5fa1ffd..4714be2d08 100644 --- a/graphics/composer/2.1/default/OWNERS +++ b/graphics/composer/2.1/default/OWNERS @@ -1,4 +1,5 @@ # Graphics team +courtneygo@google.com jessehall@google.com olv@google.com stoza@google.com diff --git a/graphics/composer/2.1/utils/OWNERS b/graphics/composer/2.1/utils/OWNERS new file mode 100644 index 0000000000..d515a23148 --- /dev/null +++ b/graphics/composer/2.1/utils/OWNERS @@ -0,0 +1,4 @@ +courtneygo@google.com +jessehall@google.com +olv@google.com +stoza@google.com diff --git a/graphics/composer/2.1/utils/command-buffer/Android.bp b/graphics/composer/2.1/utils/command-buffer/Android.bp new file mode 100644 index 0000000000..e8d41c2b9f --- /dev/null +++ b/graphics/composer/2.1/utils/command-buffer/Android.bp @@ -0,0 +1,7 @@ +cc_library_headers { + name: "android.hardware.graphics.composer@2.1-command-buffer", + defaults: ["hidl_defaults"], + vendor_available: true, + shared_libs: ["android.hardware.graphics.composer@2.1"], + export_include_dirs: ["include"], +} diff --git a/graphics/composer/2.1/default/IComposerCommandBuffer.h b/graphics/composer/2.1/utils/command-buffer/include/composer-command-buffer/2.1/ComposerCommandBuffer.h similarity index 69% rename from graphics/composer/2.1/default/IComposerCommandBuffer.h rename to graphics/composer/2.1/utils/command-buffer/include/composer-command-buffer/2.1/ComposerCommandBuffer.h index c752f8a469..df529ec615 100644 --- a/graphics/composer/2.1/default/IComposerCommandBuffer.h +++ b/graphics/composer/2.1/utils/command-buffer/include/composer-command-buffer/2.1/ComposerCommandBuffer.h @@ -18,7 +18,7 @@ #define ANDROID_HARDWARE_GRAPHICS_COMPOSER_COMMAND_BUFFER_H #ifndef LOG_TAG -#warn "IComposerCommandBuffer.h included without LOG_TAG" +#warn "ComposerCommandBuffer.h included without LOG_TAG" #endif #undef LOG_NDEBUG @@ -33,9 +33,9 @@ #include #include +#include #include #include -#include namespace android { namespace hardware { @@ -53,21 +53,15 @@ using CommandQueueType = MessageQueue; // This class helps build a command queue. Note that all sizes/lengths are in // units of uint32_t's. class CommandWriterBase { -public: - CommandWriterBase(uint32_t initialMaxSize) - : mDataMaxSize(initialMaxSize) - { + public: + CommandWriterBase(uint32_t initialMaxSize) : mDataMaxSize(initialMaxSize) { mData = std::make_unique(mDataMaxSize); reset(); } - virtual ~CommandWriterBase() - { - reset(); - } + virtual ~CommandWriterBase() { reset(); } - void reset() - { + void reset() { mDataWritten = 0; mCommandEnd = 0; @@ -82,16 +76,14 @@ public: mTemporaryHandles.clear(); } - IComposerClient::Command getCommand(uint32_t offset) - { + IComposerClient::Command getCommand(uint32_t offset) { uint32_t val = (offset < mDataWritten) ? mData[offset] : 0; - return static_cast(val & - static_cast(IComposerClient::Command::OPCODE_MASK)); + return static_cast( + val & static_cast(IComposerClient::Command::OPCODE_MASK)); } bool writeQueue(bool* outQueueChanged, uint32_t* outCommandLength, - hidl_vec* outCommandHandles) - { + hidl_vec* outCommandHandles) { if (mDataWritten == 0) { *outQueueChanged = false; *outCommandLength = 0; @@ -126,8 +118,7 @@ public: *outQueueChanged = false; } else { auto newQueue = std::make_unique(mDataMaxSize); - if (!newQueue->isValid() || - !newQueue->write(mData.get(), mDataWritten)) { + if (!newQueue->isValid() || !newQueue->write(mData.get(), mDataWritten)) { ALOGE("failed to prepare a new message queue "); return false; } @@ -137,39 +128,32 @@ public: } *outCommandLength = mDataWritten; - outCommandHandles->setToExternal( - const_cast(mDataHandles.data()), - mDataHandles.size()); + outCommandHandles->setToExternal(const_cast(mDataHandles.data()), + mDataHandles.size()); return true; } - const MQDescriptorSync* getMQDescriptor() const - { + const MQDescriptorSync* getMQDescriptor() const { return (mQueue) ? mQueue->getDesc() : nullptr; } static constexpr uint16_t kSelectDisplayLength = 2; - void selectDisplay(Display display) - { - beginCommand(IComposerClient::Command::SELECT_DISPLAY, - kSelectDisplayLength); + void selectDisplay(Display display) { + beginCommand(IComposerClient::Command::SELECT_DISPLAY, kSelectDisplayLength); write64(display); endCommand(); } static constexpr uint16_t kSelectLayerLength = 2; - void selectLayer(Layer layer) - { - beginCommand(IComposerClient::Command::SELECT_LAYER, - kSelectLayerLength); + void selectLayer(Layer layer) { + beginCommand(IComposerClient::Command::SELECT_LAYER, kSelectLayerLength); write64(layer); endCommand(); } static constexpr uint16_t kSetErrorLength = 2; - void setError(uint32_t location, Error error) - { + void setError(uint32_t location, Error error) { beginCommand(IComposerClient::Command::SET_ERROR, kSetErrorLength); write(location); writeSigned(static_cast(error)); @@ -177,25 +161,23 @@ public: } static constexpr uint32_t kPresentOrValidateDisplayResultLength = 1; - void setPresentOrValidateResult(uint32_t state) { - beginCommand(IComposerClient::Command::SET_PRESENT_OR_VALIDATE_DISPLAY_RESULT, kPresentOrValidateDisplayResultLength); - write(state); - endCommand(); + void setPresentOrValidateResult(uint32_t state) { + beginCommand(IComposerClient::Command::SET_PRESENT_OR_VALIDATE_DISPLAY_RESULT, + kPresentOrValidateDisplayResultLength); + write(state); + endCommand(); } void setChangedCompositionTypes(const std::vector& layers, - const std::vector& types) - { + const std::vector& types) { size_t totalLayers = std::min(layers.size(), types.size()); size_t currentLayer = 0; while (currentLayer < totalLayers) { - size_t count = std::min(totalLayers - currentLayer, - static_cast(kMaxLength) / 3); + size_t count = + std::min(totalLayers - currentLayer, static_cast(kMaxLength) / 3); - beginCommand( - IComposerClient::Command::SET_CHANGED_COMPOSITION_TYPES, - count * 3); + beginCommand(IComposerClient::Command::SET_CHANGED_COMPOSITION_TYPES, count * 3); for (size_t i = 0; i < count; i++) { write64(layers[currentLayer + i]); writeSigned(static_cast(types[currentLayer + i])); @@ -206,20 +188,16 @@ public: } } - void setDisplayRequests(uint32_t displayRequestMask, - const std::vector& layers, - const std::vector& layerRequestMasks) - { - size_t totalLayers = std::min(layers.size(), - layerRequestMasks.size()); + void setDisplayRequests(uint32_t displayRequestMask, const std::vector& layers, + const std::vector& layerRequestMasks) { + size_t totalLayers = std::min(layers.size(), layerRequestMasks.size()); size_t currentLayer = 0; while (currentLayer < totalLayers) { - size_t count = std::min(totalLayers - currentLayer, - static_cast(kMaxLength - 1) / 3); + size_t count = + std::min(totalLayers - currentLayer, static_cast(kMaxLength - 1) / 3); - beginCommand(IComposerClient::Command::SET_DISPLAY_REQUESTS, - 1 + count * 3); + beginCommand(IComposerClient::Command::SET_DISPLAY_REQUESTS, 1 + count * 3); write(displayRequestMask); for (size_t i = 0; i < count; i++) { write64(layers[currentLayer + i]); @@ -232,26 +210,21 @@ public: } static constexpr uint16_t kSetPresentFenceLength = 1; - void setPresentFence(int presentFence) - { - beginCommand(IComposerClient::Command::SET_PRESENT_FENCE, - kSetPresentFenceLength); + void setPresentFence(int presentFence) { + beginCommand(IComposerClient::Command::SET_PRESENT_FENCE, kSetPresentFenceLength); writeFence(presentFence); endCommand(); } - void setReleaseFences(const std::vector& layers, - const std::vector& releaseFences) - { + void setReleaseFences(const std::vector& layers, const std::vector& releaseFences) { size_t totalLayers = std::min(layers.size(), releaseFences.size()); size_t currentLayer = 0; while (currentLayer < totalLayers) { - size_t count = std::min(totalLayers - currentLayer, - static_cast(kMaxLength) / 3); + size_t count = + std::min(totalLayers - currentLayer, static_cast(kMaxLength) / 3); - beginCommand(IComposerClient::Command::SET_RELEASE_FENCES, - count * 3); + beginCommand(IComposerClient::Command::SET_RELEASE_FENCES, count * 3); for (size_t i = 0; i < count; i++) { write64(layers[currentLayer + i]); writeFence(releaseFences[currentLayer + i]); @@ -263,10 +236,8 @@ public: } static constexpr uint16_t kSetColorTransformLength = 17; - void setColorTransform(const float* matrix, ColorTransform hint) - { - beginCommand(IComposerClient::Command::SET_COLOR_TRANSFORM, - kSetColorTransformLength); + void setColorTransform(const float* matrix, ColorTransform hint) { + beginCommand(IComposerClient::Command::SET_COLOR_TRANSFORM, kSetColorTransformLength); for (int i = 0; i < 16; i++) { writeFloat(matrix[i]); } @@ -274,10 +245,8 @@ public: endCommand(); } - void setClientTarget(uint32_t slot, const native_handle_t* target, - int acquireFence, Dataspace dataspace, - const std::vector& damage) - { + void setClientTarget(uint32_t slot, const native_handle_t* target, int acquireFence, + Dataspace dataspace, const std::vector& damage) { bool doWrite = (damage.size() <= (kMaxLength - 4) / 4); size_t length = 4 + ((doWrite) ? damage.size() * 4 : 0); @@ -296,11 +265,8 @@ public: } static constexpr uint16_t kSetOutputBufferLength = 3; - void setOutputBuffer(uint32_t slot, const native_handle_t* buffer, - int releaseFence) - { - beginCommand(IComposerClient::Command::SET_OUTPUT_BUFFER, - kSetOutputBufferLength); + void setOutputBuffer(uint32_t slot, const native_handle_t* buffer, int releaseFence) { + beginCommand(IComposerClient::Command::SET_OUTPUT_BUFFER, kSetOutputBufferLength); write(slot); writeHandle(buffer, true); writeFence(releaseFence); @@ -308,67 +274,53 @@ public: } static constexpr uint16_t kValidateDisplayLength = 0; - void validateDisplay() - { - beginCommand(IComposerClient::Command::VALIDATE_DISPLAY, - kValidateDisplayLength); + void validateDisplay() { + beginCommand(IComposerClient::Command::VALIDATE_DISPLAY, kValidateDisplayLength); endCommand(); } static constexpr uint16_t kPresentOrValidateDisplayLength = 0; - void presentOrvalidateDisplay() - { + void presentOrvalidateDisplay() { beginCommand(IComposerClient::Command::PRESENT_OR_VALIDATE_DISPLAY, kPresentOrValidateDisplayLength); endCommand(); } static constexpr uint16_t kAcceptDisplayChangesLength = 0; - void acceptDisplayChanges() - { - beginCommand(IComposerClient::Command::ACCEPT_DISPLAY_CHANGES, - kAcceptDisplayChangesLength); + void acceptDisplayChanges() { + beginCommand(IComposerClient::Command::ACCEPT_DISPLAY_CHANGES, kAcceptDisplayChangesLength); endCommand(); } static constexpr uint16_t kPresentDisplayLength = 0; - void presentDisplay() - { - beginCommand(IComposerClient::Command::PRESENT_DISPLAY, - kPresentDisplayLength); + void presentDisplay() { + beginCommand(IComposerClient::Command::PRESENT_DISPLAY, kPresentDisplayLength); endCommand(); } static constexpr uint16_t kSetLayerCursorPositionLength = 2; - void setLayerCursorPosition(int32_t x, int32_t y) - { + void setLayerCursorPosition(int32_t x, int32_t y) { beginCommand(IComposerClient::Command::SET_LAYER_CURSOR_POSITION, - kSetLayerCursorPositionLength); + kSetLayerCursorPositionLength); writeSigned(x); writeSigned(y); endCommand(); } static constexpr uint16_t kSetLayerBufferLength = 3; - void setLayerBuffer(uint32_t slot, const native_handle_t* buffer, - int acquireFence) - { - beginCommand(IComposerClient::Command::SET_LAYER_BUFFER, - kSetLayerBufferLength); + void setLayerBuffer(uint32_t slot, const native_handle_t* buffer, int acquireFence) { + beginCommand(IComposerClient::Command::SET_LAYER_BUFFER, kSetLayerBufferLength); write(slot); writeHandle(buffer, true); writeFence(acquireFence); endCommand(); } - void setLayerSurfaceDamage( - const std::vector& damage) - { + void setLayerSurfaceDamage(const std::vector& damage) { bool doWrite = (damage.size() <= kMaxLength / 4); size_t length = (doWrite) ? damage.size() * 4 : 0; - beginCommand(IComposerClient::Command::SET_LAYER_SURFACE_DAMAGE, - length); + beginCommand(IComposerClient::Command::SET_LAYER_SURFACE_DAMAGE, length); // When there are too many rectangles in the damage region and doWrite // is false, we write no rectangle at all which means the entire // layer is damaged. @@ -379,94 +331,76 @@ public: } static constexpr uint16_t kSetLayerBlendModeLength = 1; - void setLayerBlendMode(IComposerClient::BlendMode mode) - { - beginCommand(IComposerClient::Command::SET_LAYER_BLEND_MODE, - kSetLayerBlendModeLength); + void setLayerBlendMode(IComposerClient::BlendMode mode) { + beginCommand(IComposerClient::Command::SET_LAYER_BLEND_MODE, kSetLayerBlendModeLength); writeSigned(static_cast(mode)); endCommand(); } static constexpr uint16_t kSetLayerColorLength = 1; - void setLayerColor(IComposerClient::Color color) - { - beginCommand(IComposerClient::Command::SET_LAYER_COLOR, - kSetLayerColorLength); + void setLayerColor(IComposerClient::Color color) { + beginCommand(IComposerClient::Command::SET_LAYER_COLOR, kSetLayerColorLength); writeColor(color); endCommand(); } static constexpr uint16_t kSetLayerCompositionTypeLength = 1; - void setLayerCompositionType(IComposerClient::Composition type) - { + void setLayerCompositionType(IComposerClient::Composition type) { beginCommand(IComposerClient::Command::SET_LAYER_COMPOSITION_TYPE, - kSetLayerCompositionTypeLength); + kSetLayerCompositionTypeLength); writeSigned(static_cast(type)); endCommand(); } static constexpr uint16_t kSetLayerDataspaceLength = 1; - void setLayerDataspace(Dataspace dataspace) - { - beginCommand(IComposerClient::Command::SET_LAYER_DATASPACE, - kSetLayerDataspaceLength); + void setLayerDataspace(Dataspace dataspace) { + beginCommand(IComposerClient::Command::SET_LAYER_DATASPACE, kSetLayerDataspaceLength); writeSigned(static_cast(dataspace)); endCommand(); } static constexpr uint16_t kSetLayerDisplayFrameLength = 4; - void setLayerDisplayFrame(const IComposerClient::Rect& frame) - { + void setLayerDisplayFrame(const IComposerClient::Rect& frame) { beginCommand(IComposerClient::Command::SET_LAYER_DISPLAY_FRAME, - kSetLayerDisplayFrameLength); + kSetLayerDisplayFrameLength); writeRect(frame); endCommand(); } static constexpr uint16_t kSetLayerPlaneAlphaLength = 1; - void setLayerPlaneAlpha(float alpha) - { - beginCommand(IComposerClient::Command::SET_LAYER_PLANE_ALPHA, - kSetLayerPlaneAlphaLength); + void setLayerPlaneAlpha(float alpha) { + beginCommand(IComposerClient::Command::SET_LAYER_PLANE_ALPHA, kSetLayerPlaneAlphaLength); writeFloat(alpha); endCommand(); } static constexpr uint16_t kSetLayerSidebandStreamLength = 1; - void setLayerSidebandStream(const native_handle_t* stream) - { + void setLayerSidebandStream(const native_handle_t* stream) { beginCommand(IComposerClient::Command::SET_LAYER_SIDEBAND_STREAM, - kSetLayerSidebandStreamLength); + kSetLayerSidebandStreamLength); writeHandle(stream); endCommand(); } static constexpr uint16_t kSetLayerSourceCropLength = 4; - void setLayerSourceCrop(const IComposerClient::FRect& crop) - { - beginCommand(IComposerClient::Command::SET_LAYER_SOURCE_CROP, - kSetLayerSourceCropLength); + void setLayerSourceCrop(const IComposerClient::FRect& crop) { + beginCommand(IComposerClient::Command::SET_LAYER_SOURCE_CROP, kSetLayerSourceCropLength); writeFRect(crop); endCommand(); } static constexpr uint16_t kSetLayerTransformLength = 1; - void setLayerTransform(Transform transform) - { - beginCommand(IComposerClient::Command::SET_LAYER_TRANSFORM, - kSetLayerTransformLength); + void setLayerTransform(Transform transform) { + beginCommand(IComposerClient::Command::SET_LAYER_TRANSFORM, kSetLayerTransformLength); writeSigned(static_cast(transform)); endCommand(); } - void setLayerVisibleRegion( - const std::vector& visible) - { + void setLayerVisibleRegion(const std::vector& visible) { bool doWrite = (visible.size() <= kMaxLength / 4); size_t length = (doWrite) ? visible.size() * 4 : 0; - beginCommand(IComposerClient::Command::SET_LAYER_VISIBLE_REGION, - length); + beginCommand(IComposerClient::Command::SET_LAYER_VISIBLE_REGION, length); // When there are too many rectangles in the visible region and // doWrite is false, we write no rectangle at all which means the // entire layer is visible. @@ -477,20 +411,16 @@ public: } static constexpr uint16_t kSetLayerZOrderLength = 1; - void setLayerZOrder(uint32_t z) - { - beginCommand(IComposerClient::Command::SET_LAYER_Z_ORDER, - kSetLayerZOrderLength); + void setLayerZOrder(uint32_t z) { + beginCommand(IComposerClient::Command::SET_LAYER_Z_ORDER, kSetLayerZOrderLength); write(z); endCommand(); } -protected: - void beginCommand(IComposerClient::Command command, uint16_t length) - { + protected: + void beginCommand(IComposerClient::Command command, uint16_t length) { if (mCommandEnd) { - LOG_FATAL("endCommand was not called before command 0x%x", - command); + LOG_FATAL("endCommand was not called before command 0x%x", command); } growData(1 + length); @@ -499,8 +429,7 @@ protected: mCommandEnd = mDataWritten + length; } - void endCommand() - { + void endCommand() { if (!mCommandEnd) { LOG_FATAL("beginCommand was not called"); } else if (mDataWritten > mCommandEnd) { @@ -516,67 +445,48 @@ protected: mCommandEnd = 0; } - void write(uint32_t val) - { - mData[mDataWritten++] = val; - } + void write(uint32_t val) { mData[mDataWritten++] = val; } - void writeSigned(int32_t val) - { - memcpy(&mData[mDataWritten++], &val, sizeof(val)); - } + void writeSigned(int32_t val) { memcpy(&mData[mDataWritten++], &val, sizeof(val)); } - void writeFloat(float val) - { - memcpy(&mData[mDataWritten++], &val, sizeof(val)); - } + void writeFloat(float val) { memcpy(&mData[mDataWritten++], &val, sizeof(val)); } - void write64(uint64_t val) - { + void write64(uint64_t val) { uint32_t lo = static_cast(val & 0xffffffff); uint32_t hi = static_cast(val >> 32); write(lo); write(hi); } - void writeRect(const IComposerClient::Rect& rect) - { + void writeRect(const IComposerClient::Rect& rect) { writeSigned(rect.left); writeSigned(rect.top); writeSigned(rect.right); writeSigned(rect.bottom); } - void writeRegion(const std::vector& region) - { + void writeRegion(const std::vector& region) { for (const auto& rect : region) { writeRect(rect); } } - void writeFRect(const IComposerClient::FRect& rect) - { + void writeFRect(const IComposerClient::FRect& rect) { writeFloat(rect.left); writeFloat(rect.top); writeFloat(rect.right); writeFloat(rect.bottom); } - void writeColor(const IComposerClient::Color& color) - { - write((color.r << 0) | - (color.g << 8) | - (color.b << 16) | - (color.a << 24)); + void writeColor(const IComposerClient::Color& color) { + write((color.r << 0) | (color.g << 8) | (color.b << 16) | (color.a << 24)); } // ownership of handle is not transferred - void writeHandle(const native_handle_t* handle, bool useCache) - { + void writeHandle(const native_handle_t* handle, bool useCache) { if (!handle) { - writeSigned(static_cast((useCache) ? - IComposerClient::HandleIndex::CACHED : - IComposerClient::HandleIndex::EMPTY)); + writeSigned(static_cast((useCache) ? IComposerClient::HandleIndex::CACHED + : IComposerClient::HandleIndex::EMPTY)); return; } @@ -584,14 +494,10 @@ protected: writeSigned(mDataHandles.size() - 1); } - void writeHandle(const native_handle_t* handle) - { - writeHandle(handle, false); - } + void writeHandle(const native_handle_t* handle) { writeHandle(handle, false); } // ownership of fence is transferred - void writeFence(int fence) - { + void writeFence(int fence) { native_handle_t* handle = nullptr; if (fence >= 0) { handle = getTemporaryHandle(1, 0); @@ -607,8 +513,7 @@ protected: writeHandle(handle); } - native_handle_t* getTemporaryHandle(int numFds, int numInts) - { + native_handle_t* getTemporaryHandle(int numFds, int numInts) { native_handle_t* handle = native_handle_create(numFds, numInts); if (handle) { mTemporaryHandles.push_back(handle); @@ -616,16 +521,14 @@ protected: return handle; } - static constexpr uint16_t kMaxLength = - std::numeric_limits::max(); + static constexpr uint16_t kMaxLength = std::numeric_limits::max(); -private: - void growData(uint32_t grow) - { + private: + void growData(uint32_t grow) { uint32_t newWritten = mDataWritten + grow; if (newWritten < mDataWritten) { - LOG_ALWAYS_FATAL("buffer overflowed; data written %" PRIu32 - ", growing by %" PRIu32, mDataWritten, grow); + LOG_ALWAYS_FATAL("buffer overflowed; data written %" PRIu32 ", growing by %" PRIu32, + mDataWritten, grow); } if (newWritten <= mDataMaxSize) { @@ -651,7 +554,7 @@ private: uint32_t mCommandEnd; std::vector mDataHandles; - std::vector mTemporaryHandles; + std::vector mTemporaryHandles; std::unique_ptr mQueue; }; @@ -659,14 +562,10 @@ private: // This class helps parse a command queue. Note that all sizes/lengths are in // units of uint32_t's. class CommandReaderBase { -public: - CommandReaderBase() : mDataMaxSize(0) - { - reset(); - } + public: + CommandReaderBase() : mDataMaxSize(0) { reset(); } - bool setMQDescriptor(const MQDescriptorSync& descriptor) - { + bool setMQDescriptor(const MQDescriptorSync& descriptor) { mQueue = std::make_unique(descriptor, false); if (mQueue->isValid()) { return true; @@ -676,9 +575,7 @@ public: } } - bool readQueue(uint32_t commandLength, - const hidl_vec& commandHandles) - { + bool readQueue(uint32_t commandLength, const hidl_vec& commandHandles) { if (!mQueue) { return false; } @@ -689,8 +586,7 @@ public: mData = std::make_unique(mDataMaxSize); } - if (commandLength > mDataMaxSize || - !mQueue->read(mData.get(), commandLength)) { + if (commandLength > mDataMaxSize || !mQueue->read(mData.get(), commandLength)) { ALOGE("failed to read commands from message queue"); return false; } @@ -699,15 +595,13 @@ public: mDataRead = 0; mCommandBegin = 0; mCommandEnd = 0; - mDataHandles.setToExternal( - const_cast(commandHandles.data()), - commandHandles.size()); + mDataHandles.setToExternal(const_cast(commandHandles.data()), + commandHandles.size()); return true; } - void reset() - { + void reset() { mDataSize = 0; mDataRead = 0; mCommandBegin = 0; @@ -715,15 +609,10 @@ public: mDataHandles.setToExternal(nullptr, 0); } -protected: - bool isEmpty() const - { - return (mDataRead >= mDataSize); - } + protected: + bool isEmpty() const { return (mDataRead >= mDataSize); } - bool beginCommand(IComposerClient::Command* outCommand, - uint16_t* outLength) - { + bool beginCommand(IComposerClient::Command* outCommand, uint16_t* outLength) { if (mCommandEnd) { LOG_FATAL("endCommand was not called for last command"); } @@ -734,13 +623,11 @@ protected: static_cast(IComposerClient::Command::LENGTH_MASK); uint32_t val = read(); - *outCommand = static_cast( - val & opcode_mask); + *outCommand = static_cast(val & opcode_mask); *outLength = static_cast(val & length_mask); if (mDataRead + *outLength > mDataSize) { - ALOGE("command 0x%x has invalid command length %" PRIu16, - *outCommand, *outLength); + ALOGE("command 0x%x has invalid command length %" PRIu16, *outCommand, *outLength); // undo the read() above mDataRead--; return false; @@ -751,8 +638,7 @@ protected: return true; } - void endCommand() - { + void endCommand() { if (!mCommandEnd) { LOG_FATAL("beginCommand was not called"); } else if (mDataRead > mCommandEnd) { @@ -767,83 +653,68 @@ protected: mCommandEnd = 0; } - uint32_t getCommandLoc() const - { - return mCommandBegin; - } + uint32_t getCommandLoc() const { return mCommandBegin; } - uint32_t read() - { - return mData[mDataRead++]; - } + uint32_t read() { return mData[mDataRead++]; } - int32_t readSigned() - { + int32_t readSigned() { int32_t val; memcpy(&val, &mData[mDataRead++], sizeof(val)); return val; } - float readFloat() - { + float readFloat() { float val; memcpy(&val, &mData[mDataRead++], sizeof(val)); return val; } - uint64_t read64() - { + uint64_t read64() { uint32_t lo = read(); uint32_t hi = read(); return (static_cast(hi) << 32) | lo; } - IComposerClient::Color readColor() - { + IComposerClient::Color readColor() { uint32_t val = read(); return IComposerClient::Color{ - static_cast((val >> 0) & 0xff), - static_cast((val >> 8) & 0xff), - static_cast((val >> 16) & 0xff), - static_cast((val >> 24) & 0xff), + static_cast((val >> 0) & 0xff), static_cast((val >> 8) & 0xff), + static_cast((val >> 16) & 0xff), static_cast((val >> 24) & 0xff), }; } // ownership of handle is not transferred - const native_handle_t* readHandle(bool* outUseCache) - { + const native_handle_t* readHandle(bool* outUseCache) { const native_handle_t* handle = nullptr; int32_t index = readSigned(); switch (index) { - case static_cast(IComposerClient::HandleIndex::EMPTY): - *outUseCache = false; - break; - case static_cast(IComposerClient::HandleIndex::CACHED): - *outUseCache = true; - break; - default: - if (static_cast(index) < mDataHandles.size()) { - handle = mDataHandles[index].getNativeHandle(); - } else { - ALOGE("invalid handle index %zu", static_cast(index)); - } - *outUseCache = false; - break; + case static_cast(IComposerClient::HandleIndex::EMPTY): + *outUseCache = false; + break; + case static_cast(IComposerClient::HandleIndex::CACHED): + *outUseCache = true; + break; + default: + if (static_cast(index) < mDataHandles.size()) { + handle = mDataHandles[index].getNativeHandle(); + } else { + ALOGE("invalid handle index %zu", static_cast(index)); + } + *outUseCache = false; + break; } return handle; } - const native_handle_t* readHandle() - { + const native_handle_t* readHandle() { bool useCache; return readHandle(&useCache); } // ownership of fence is transferred - int readFence() - { + int readFence() { auto handle = readHandle(); if (!handle || handle->numFds == 0) { return -1; @@ -864,7 +735,7 @@ protected: return fd; } -private: + private: std::unique_ptr mQueue; uint32_t mDataMaxSize; std::unique_ptr mData; @@ -879,10 +750,10 @@ private: hidl_vec mDataHandles; }; -} // namespace V2_1 -} // namespace composer -} // namespace graphics -} // namespace hardware -} // namespace android +} // namespace V2_1 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android -#endif // ANDROID_HARDWARE_GRAPHICS_COMPOSER_COMMAND_BUFFER_H +#endif // ANDROID_HARDWARE_GRAPHICS_COMPOSER_COMMAND_BUFFER_H diff --git a/graphics/composer/2.1/vts/functional/Android.bp b/graphics/composer/2.1/vts/functional/Android.bp index 1ba7c9a1b2..40f18c0067 100644 --- a/graphics/composer/2.1/vts/functional/Android.bp +++ b/graphics/composer/2.1/vts/functional/Android.bp @@ -28,9 +28,11 @@ cc_library_static { "libsync", ], static_libs: [ - "libhwcomposer-command-buffer", "VtsHalHidlTargetTestBase", ], + header_libs: [ + "android.hardware.graphics.composer@2.1-command-buffer", + ], cflags: [ "-Wall", "-Wextra", @@ -58,7 +60,9 @@ cc_test { "android.hardware.graphics.mapper@2.0", "libVtsHalGraphicsComposerTestUtils", "libVtsHalGraphicsMapperTestUtils", - "libhwcomposer-command-buffer", "libnativehelper", ], + header_libs: [ + "android.hardware.graphics.composer@2.1-command-buffer", + ], } diff --git a/graphics/composer/2.1/vts/functional/TestCommandReader.h b/graphics/composer/2.1/vts/functional/TestCommandReader.h index 657a46374d..ae25d2d6d9 100644 --- a/graphics/composer/2.1/vts/functional/TestCommandReader.h +++ b/graphics/composer/2.1/vts/functional/TestCommandReader.h @@ -17,7 +17,7 @@ #ifndef TEST_COMMAND_READER_H #define TEST_COMMAND_READER_H -#include +#include namespace android { namespace hardware { diff --git a/graphics/composer/2.1/vts/functional/VtsHalGraphicsComposerTestUtils.h b/graphics/composer/2.1/vts/functional/VtsHalGraphicsComposerTestUtils.h index 4e69f61b87..29b9de35a7 100644 --- a/graphics/composer/2.1/vts/functional/VtsHalGraphicsComposerTestUtils.h +++ b/graphics/composer/2.1/vts/functional/VtsHalGraphicsComposerTestUtils.h @@ -23,8 +23,8 @@ #include #include -#include #include +#include #include #include "TestCommandReader.h"