/* * Copyright (C) 2016 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. */ #ifndef _HWC2_TEST_PROPERTIES_H #define _HWC2_TEST_PROPERTIES_H #include #include #include #include #define HWC2_INCLUDE_STRINGIFICATION #define HWC2_USE_CPP11 #include #undef HWC2_INCLUDE_STRINGIFICATION #undef HWC2_USE_CPP11 enum class Hwc2TestCoverage { Default = 0, Basic, Complete, }; enum class Hwc2TestPropertyName { BlendMode = 1, BufferArea, Color, Composition, CursorPosition, Dataspace, DisplayFrame, PlaneAlpha, SourceCrop, SurfaceDamage, Transform, }; typedef struct { int32_t width; int32_t height; } Area; typedef struct { uint32_t width; uint32_t height; } UnsignedArea; class Hwc2TestContainer { public: virtual ~Hwc2TestContainer() = default; /* Resets the container */ virtual void reset() = 0; /* Attempts to advance to the next valid value. Returns true if one can be * found */ virtual bool advance() = 0; virtual std::string dump() const = 0; /* Returns true if the container supports the given composition type */ virtual bool isSupported(hwc2_composition_t composition) = 0; }; template class Hwc2TestProperty : public Hwc2TestContainer { public: Hwc2TestProperty(Hwc2TestCoverage coverage, const std::vector& completeList, const std::vector& basicList, const std::vector& defaultList, const std::array& compositionSupport) : Hwc2TestProperty((coverage == Hwc2TestCoverage::Complete)? completeList: (coverage == Hwc2TestCoverage::Basic)? basicList : defaultList, compositionSupport) { } Hwc2TestProperty(const std::vector& list, const std::array& compositionSupport) : mList(list), mCompositionSupport(compositionSupport) { } void reset() override { mListIdx = 0; } bool advance() override { if (mListIdx + 1 < mList.size()) { mListIdx++; updateDependents(); return true; } reset(); updateDependents(); return false; } T get() const { return mList.at(mListIdx); } virtual bool isSupported(hwc2_composition_t composition) { return mCompositionSupport.at(composition); } protected: /* If a derived class has dependents, override this function */ virtual void updateDependents() { } const std::vector& mList; size_t mListIdx = 0; const std::array& mCompositionSupport; }; class Hwc2TestBuffer; class Hwc2TestSourceCrop; class Hwc2TestSurfaceDamage; class Hwc2TestBufferArea : public Hwc2TestProperty { public: Hwc2TestBufferArea(Hwc2TestCoverage coverage, const Area& displayArea); std::string dump() const override; void setDependent(Hwc2TestBuffer* buffer); void setDependent(Hwc2TestSourceCrop* sourceCrop); void setDependent(Hwc2TestSurfaceDamage* surfaceDamage); protected: void update(); void updateDependents() override; const std::vector& mScalars; static const std::vector mDefaultScalars; static const std::vector mBasicScalars; static const std::vector mCompleteScalars; Area mDisplayArea; Hwc2TestBuffer* mBuffer = nullptr; Hwc2TestSourceCrop* mSourceCrop = nullptr; Hwc2TestSurfaceDamage* mSurfaceDamage = nullptr; std::vector mBufferAreas; static const std::array mCompositionSupport; }; class Hwc2TestColor; class Hwc2TestBlendMode : public Hwc2TestProperty { public: explicit Hwc2TestBlendMode(Hwc2TestCoverage coverage); std::string dump() const override; void setDependent(Hwc2TestColor* color); protected: void updateDependents() override; Hwc2TestColor* mColor = nullptr; static const std::vector mDefaultBlendModes; static const std::vector mBasicBlendModes; static const std::vector mCompleteBlendModes; static const std::array mCompositionSupport; }; class Hwc2TestColor : public Hwc2TestProperty { public: explicit Hwc2TestColor(Hwc2TestCoverage coverage, hwc2_blend_mode_t blendMode = HWC2_BLEND_MODE_NONE); std::string dump() const override; void updateBlendMode(hwc2_blend_mode_t blendMode); protected: void update(); std::vector mBaseColors; static const std::vector mDefaultBaseColors; static const std::vector mBasicBaseColors; static const std::vector mCompleteBaseColors; hwc2_blend_mode_t mBlendMode; std::vector mColors; static const std::array mCompositionSupport; }; class Hwc2TestComposition : public Hwc2TestProperty { public: explicit Hwc2TestComposition(Hwc2TestCoverage coverage); std::string dump() const override; protected: static const std::vector mDefaultCompositions; static const std::vector mBasicCompositions; static const std::vector mCompleteCompositions; static const std::array mCompositionSupport; }; class Hwc2TestDataspace : public Hwc2TestProperty { public: explicit Hwc2TestDataspace(Hwc2TestCoverage coverage); std::string dump() const override; protected: static const std::vector defaultDataspaces; static const std::vector basicDataspaces; static const std::vector completeDataspaces; static const std::array mCompositionSupport; }; class Hwc2TestVirtualBuffer; class Hwc2TestDisplayDimension : public Hwc2TestProperty { public: explicit Hwc2TestDisplayDimension(Hwc2TestCoverage coverage); std::string dump() const; void setDependent(Hwc2TestVirtualBuffer* buffer); private: void updateDependents(); std::set mBuffers; static const std::vector mDefaultDisplayDimensions; static const std::vector mBasicDisplayDimensions; static const std::vector mCompleteDisplayDimensions; static const std::array mCompositionSupport; }; class Hwc2TestDisplayFrame : public Hwc2TestProperty { public: Hwc2TestDisplayFrame(Hwc2TestCoverage coverage, const Area& displayArea); std::string dump() const override; protected: void update(); const std::vector& mFrectScalars; const static std::vector mDefaultFrectScalars; const static std::vector mBasicFrectScalars; const static std::vector mCompleteFrectScalars; Area mDisplayArea; std::vector mDisplayFrames; static const std::array mCompositionSupport; }; class Hwc2TestPlaneAlpha : public Hwc2TestProperty { public: explicit Hwc2TestPlaneAlpha(Hwc2TestCoverage coverage); std::string dump() const override; protected: static const std::vector mDefaultPlaneAlphas; static const std::vector mBasicPlaneAlphas; static const std::vector mCompletePlaneAlphas; static const std::array mCompositionSupport; }; class Hwc2TestSourceCrop : public Hwc2TestProperty { public: explicit Hwc2TestSourceCrop(Hwc2TestCoverage coverage, const Area& bufferArea = {0, 0}); std::string dump() const override; void updateBufferArea(const Area& bufferArea); protected: void update(); const std::vector& mFrectScalars; const static std::vector mDefaultFrectScalars; const static std::vector mBasicFrectScalars; const static std::vector mCompleteFrectScalars; Area mBufferArea; std::vector mSourceCrops; static const std::array mCompositionSupport; }; class Hwc2TestSurfaceDamage : public Hwc2TestProperty { public: explicit Hwc2TestSurfaceDamage(Hwc2TestCoverage coverage); ~Hwc2TestSurfaceDamage(); std::string dump() const override; void updateBufferArea(const Area& bufferArea); protected: void update(); void freeSurfaceDamages(); const std::vector> &mRegionScalars; const static std::vector> mDefaultRegionScalars; const static std::vector> mBasicRegionScalars; const static std::vector> mCompleteRegionScalars; Area mBufferArea = {0, 0}; std::vector mSurfaceDamages; static const std::array mCompositionSupport; }; class Hwc2TestTransform : public Hwc2TestProperty { public: explicit Hwc2TestTransform(Hwc2TestCoverage coverage); std::string dump() const override; protected: static const std::vector mDefaultTransforms; static const std::vector mBasicTransforms; static const std::vector mCompleteTransforms; static const std::array mCompositionSupport; }; class Hwc2TestVisibleRegion { public: ~Hwc2TestVisibleRegion(); std::string dump() const; void set(const android::Region& visibleRegion); hwc_region_t get() const; void release(); protected: hwc_region_t mVisibleRegion = {0, nullptr}; }; #endif /* ifndef _HWC2_TEST_PROPERTIES_H */