1 /* 2 * Copyright (C) 2018 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 <memory> 20 #include <string> 21 #include <unordered_map> 22 #include <unordered_set> 23 #include <vector> 24 25 #include <android/hardware/graphics/composer/2.2/IComposer.h> 26 #include <android/hardware/graphics/composer/2.2/IComposerClient.h> 27 #include <composer-command-buffer/2.2/ComposerCommandBuffer.h> 28 #include <composer-vts/2.1/ComposerVts.h> 29 #include <mapper-vts/2.1/MapperVts.h> 30 #include <utils/StrongPointer.h> 31 32 namespace android { 33 namespace hardware { 34 namespace graphics { 35 namespace composer { 36 namespace V2_2 { 37 namespace vts { 38 39 using common::V1_0::Hdr; 40 using common::V1_1::ColorMode; 41 using common::V1_1::Dataspace; 42 using common::V1_1::PixelFormat; 43 using common::V1_1::RenderIntent; 44 using IMapper2_1 = android::hardware::graphics::mapper::V2_1::IMapper; 45 using IMapper3 = android::hardware::graphics::mapper::V3_0::IMapper; 46 using IMapper4 = android::hardware::graphics::mapper::V4_0::IMapper; 47 using Gralloc2 = android::hardware::graphics::mapper::V2_0::vts::Gralloc; 48 using Gralloc2_1 = android::hardware::graphics::mapper::V2_1::vts::Gralloc; 49 using Gralloc3 = android::hardware::graphics::mapper::V3_0::vts::Gralloc; 50 using Gralloc4 = android::hardware::graphics::mapper::V4_0::vts::Gralloc; 51 52 class ComposerClient; 53 54 // A wrapper to IComposer. 55 class Composer : public V2_1::vts::Composer { 56 public: 57 using V2_1::vts::Composer::Composer; 58 59 std::unique_ptr<ComposerClient> createClient(); 60 }; 61 62 // A wrapper to IComposerClient. 63 class ComposerClient : public V2_1::vts::ComposerClient { 64 public: ComposerClient(const sp<IComposerClient> & client)65 explicit ComposerClient(const sp<IComposerClient>& client) 66 : V2_1::vts::ComposerClient(client), mClient(client) {} 67 68 sp<IComposerClient> getRaw() const; 69 70 void execute(V2_1::vts::TestCommandReader* reader, CommandWriterBase* writer); 71 72 std::vector<IComposerClient::PerFrameMetadataKey> getPerFrameMetadataKeys(Display display); 73 74 Display createVirtualDisplay_2_2(uint32_t width, uint32_t height, PixelFormat formatHint, 75 uint32_t outputBufferSlotCount, PixelFormat* outFormat); 76 bool getClientTargetSupport_2_2(Display display, uint32_t width, uint32_t height, 77 PixelFormat format, Dataspace dataspace); 78 void setPowerMode_2_2(Display display, IComposerClient::PowerMode mode); 79 void setReadbackBuffer(Display display, const native_handle_t* buffer, int32_t releaseFence); 80 void getReadbackBufferAttributes(Display display, PixelFormat* outPixelFormat, 81 Dataspace* outDataspace); 82 void getReadbackBufferFence(Display display, int32_t* outFence); 83 84 std::vector<ColorMode> getColorModes(Display display); 85 std::vector<RenderIntent> getRenderIntents(Display display, ColorMode mode); 86 void setColorMode(Display display, ColorMode mode, RenderIntent intent); 87 88 std::array<float, 16> getDataspaceSaturationMatrix(Dataspace dataspace); 89 90 private: 91 const sp<IComposerClient> mClient; 92 }; 93 94 class Gralloc : public V2_1::vts::Gralloc { 95 public: 96 using NativeHandleWrapper = V2_1::vts::NativeHandleWrapper; 97 98 Gralloc(); 99 const NativeHandleWrapper allocate(uint32_t width, uint32_t height, uint32_t layerCount, 100 PixelFormat format, uint64_t usage, bool import = true, 101 uint32_t* outStride = nullptr) { 102 return V2_1::vts::Gralloc::allocate( 103 width, height, layerCount, 104 static_cast<android::hardware::graphics::common::V1_0::PixelFormat>(format), usage, 105 import, outStride); 106 } 107 108 bool validateBufferSize(const native_handle_t* bufferHandle, uint32_t width, uint32_t height, 109 uint32_t layerCount, PixelFormat format, uint64_t usage, 110 uint32_t stride); 111 112 protected: 113 std::shared_ptr<Gralloc2_1> mGralloc2_1 = nullptr; 114 }; 115 116 } // namespace vts 117 } // namespace V2_2 118 } // namespace composer 119 } // namespace graphics 120 } // namespace hardware 121 } // namespace android 122