1 /* 2 * Copyright 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <android-base/unique_fd.h> 20 #include <android/hardware/graphics/composer/2.2/IComposerClient.h> 21 #include <composer-command-buffer/2.2/ComposerCommandBuffer.h> 22 #include <composer-vts/2.1/GraphicsComposerCallback.h> 23 #include <composer-vts/2.1/TestCommandReader.h> 24 #include <composer-vts/2.2/ComposerVts.h> 25 #include <renderengine/RenderEngine.h> 26 27 #include <memory> 28 29 namespace android { 30 namespace hardware { 31 namespace graphics { 32 namespace composer { 33 namespace V2_2 { 34 namespace vts { 35 36 using android::hardware::hidl_handle; 37 using common::V1_1::BufferUsage; 38 using common::V1_1::Dataspace; 39 using common::V1_1::PixelFormat; 40 using renderengine::LayerSettings; 41 using V2_1::Display; 42 using V2_1::Layer; 43 using V2_1::vts::TestCommandReader; 44 45 static const IComposerClient::Color BLACK = {0, 0, 0, 0xff}; 46 static const IComposerClient::Color RED = {0xff, 0, 0, 0xff}; 47 static const IComposerClient::Color TRANSLUCENT_RED = {0xff, 0, 0, 0x33}; 48 static const IComposerClient::Color GREEN = {0, 0xff, 0, 0xff}; 49 static const IComposerClient::Color BLUE = {0, 0, 0xff, 0xff}; 50 51 class TestRenderEngine; 52 53 class TestLayer { 54 public: TestLayer(const std::shared_ptr<ComposerClient> & client,Display display)55 TestLayer(const std::shared_ptr<ComposerClient>& client, Display display) 56 : mLayer(client->createLayer(display, kBufferSlotCount)), mComposerClient(client) {} 57 58 // ComposerClient will take care of destroying layers, no need to explicitly 59 // call destroyLayers here ~TestLayer()60 virtual ~TestLayer(){}; 61 62 virtual void write(const std::shared_ptr<CommandWriterBase>& writer); 63 virtual LayerSettings toRenderEngineLayerSettings(); 64 setDisplayFrame(IComposerClient::Rect frame)65 void setDisplayFrame(IComposerClient::Rect frame) { mDisplayFrame = frame; } setSourceCrop(IComposerClient::FRect crop)66 void setSourceCrop(IComposerClient::FRect crop) { mSourceCrop = crop; } setZOrder(uint32_t z)67 void setZOrder(uint32_t z) { mZOrder = z; } 68 setSurfaceDamage(std::vector<IComposerClient::Rect> surfaceDamage)69 void setSurfaceDamage(std::vector<IComposerClient::Rect> surfaceDamage) { 70 mSurfaceDamage = surfaceDamage; 71 } 72 setTransform(Transform transform)73 void setTransform(Transform transform) { mTransform = transform; } setAlpha(float alpha)74 void setAlpha(float alpha) { mAlpha = alpha; } setBlendMode(IComposerClient::BlendMode blendMode)75 void setBlendMode(IComposerClient::BlendMode blendMode) { mBlendMode = blendMode; } 76 77 static constexpr uint32_t kBufferSlotCount = 64; 78 79 IComposerClient::Rect mDisplayFrame = {0, 0, 0, 0}; 80 uint32_t mZOrder = 0; 81 std::vector<IComposerClient::Rect> mSurfaceDamage; 82 Transform mTransform = static_cast<Transform>(0); 83 IComposerClient::FRect mSourceCrop = {0, 0, 0, 0}; 84 float mAlpha = 1.0; 85 IComposerClient::BlendMode mBlendMode = IComposerClient::BlendMode::NONE; 86 87 protected: 88 Layer mLayer; 89 90 private: 91 std::shared_ptr<ComposerClient> const mComposerClient; 92 }; 93 94 class TestColorLayer : public TestLayer { 95 public: TestColorLayer(const std::shared_ptr<ComposerClient> & client,Display display)96 TestColorLayer(const std::shared_ptr<ComposerClient>& client, Display display) 97 : TestLayer{client, display} {} 98 99 void write(const std::shared_ptr<CommandWriterBase>& writer) override; 100 101 LayerSettings toRenderEngineLayerSettings() override; 102 setColor(IComposerClient::Color color)103 void setColor(IComposerClient::Color color) { mColor = color; } 104 105 private: 106 IComposerClient::Color mColor = {0xff, 0xff, 0xff, 0xff}; 107 }; 108 109 class TestBufferLayer : public TestLayer { 110 public: 111 TestBufferLayer( 112 const std::shared_ptr<ComposerClient>& client, TestRenderEngine& renderEngine, 113 Display display, int32_t width, int32_t height, PixelFormat format, 114 IComposerClient::Composition composition = IComposerClient::Composition::DEVICE); 115 116 void write(const std::shared_ptr<CommandWriterBase>& writer) override; 117 118 LayerSettings toRenderEngineLayerSettings() override; 119 120 void fillBuffer(std::vector<IComposerClient::Color> expectedColors); 121 122 void setBuffer(std::vector<IComposerClient::Color> colors); 123 124 void setDataspace(Dataspace dataspace, const std::shared_ptr<CommandWriterBase>& writer); 125 126 void setToClientComposition(const std::shared_ptr<CommandWriterBase>& writer); 127 128 uint32_t mWidth; 129 uint32_t mHeight; 130 uint32_t mLayerCount; 131 PixelFormat mFormat; 132 uint64_t mUsage; 133 134 protected: 135 IComposerClient::Composition mComposition; 136 TestRenderEngine& mRenderEngine; 137 sp<GraphicBuffer> mBuffer; 138 }; 139 140 class ReadbackHelper { 141 public: 142 static std::string getColorModeString(ColorMode mode); 143 144 static std::string getDataspaceString(Dataspace dataspace); 145 146 static Dataspace getDataspaceForColorMode(ColorMode mode); 147 148 static int32_t GetBytesPerPixel(PixelFormat pixelFormat); 149 150 static void fillBuffer(int32_t width, int32_t height, uint32_t stride, void* bufferData, 151 PixelFormat pixelFormat, 152 std::vector<IComposerClient::Color> desiredPixelColors); 153 154 static void clearColors(std::vector<IComposerClient::Color>& expectedColors, int32_t width, 155 int32_t height, int32_t displayWidth); 156 157 static void fillColorsArea(std::vector<IComposerClient::Color>& expectedColors, int32_t stride, 158 IComposerClient::Rect area, IComposerClient::Color color); 159 160 static bool readbackSupported(const PixelFormat& pixelFormat, const Dataspace& dataspace, 161 const Error error); 162 163 static const std::vector<ColorMode> colorModes; 164 static const std::vector<Dataspace> dataspaces; 165 166 static void compareColorBuffers(std::vector<IComposerClient::Color>& expectedColors, 167 void* bufferData, const uint32_t stride, const uint32_t width, 168 const uint32_t height, const PixelFormat pixelFormat); 169 }; 170 171 class ReadbackBuffer { 172 public: 173 ReadbackBuffer(Display display, const std::shared_ptr<ComposerClient>& client, uint32_t width, 174 uint32_t height, PixelFormat pixelFormat, Dataspace dataspace); 175 176 void setReadbackBuffer(); 177 178 void checkReadbackBuffer(std::vector<IComposerClient::Color> expectedColors); 179 180 protected: 181 uint32_t mWidth; 182 uint32_t mHeight; 183 uint32_t mLayerCount; 184 PixelFormat mFormat; 185 uint64_t mUsage; 186 sp<GraphicBuffer> mBuffer; 187 PixelFormat mPixelFormat; 188 Dataspace mDataspace; 189 Display mDisplay; 190 std::shared_ptr<ComposerClient> mComposerClient; 191 }; 192 193 } // namespace vts 194 } // namespace V2_2 195 } // namespace composer 196 } // namespace graphics 197 } // namespace hardware 198 } // namespace android 199