Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 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 | #ifndef ANDROID_TRANSACTION_TEST_HARNESSES |
| 17 | #define ANDROID_TRANSACTION_TEST_HARNESSES |
| 18 | |
| 19 | /*#include <algorithm> |
| 20 | #include <chrono> |
| 21 | #include <cinttypes> |
| 22 | #include <functional> |
| 23 | #include <limits> |
| 24 | #include <ostream> |
| 25 | |
| 26 | #include <android/native_window.h> |
| 27 | |
| 28 | #include <binder/ProcessState.h> |
| 29 | #include <gui/BufferItemConsumer.h> |
| 30 | #include <gui/IProducerListener.h> |
| 31 | #include <gui/ISurfaceComposer.h> |
| 32 | #include <gui/LayerState.h> |
| 33 | #include <gui/Surface.h> |
| 34 | #include <gui/SurfaceComposerClient.h> |
| 35 | #include <hardware/hwcomposer_defs.h> |
| 36 | #include <private/android_filesystem_config.h> |
| 37 | #include <private/gui/ComposerService.h> |
| 38 | |
| 39 | #include <ui/DisplayInfo.h> |
| 40 | |
| 41 | #include <math.h> |
| 42 | #include <math/vec3.h> |
| 43 | #include <sys/types.h> |
| 44 | #include <unistd.h> |
| 45 | |
| 46 | #include "BufferGenerator.h" |
| 47 | */ |
| 48 | #include "LayerTransactionTest.h" |
| 49 | /*#include "utils/CallbackUtils.h" |
| 50 | #include "utils/ColorUtils.h" |
| 51 | #include "utils/ScreenshotUtils.h" |
| 52 | #include "utils/TransactionUtils.h" |
| 53 | */ |
| 54 | namespace android { |
| 55 | |
| 56 | using android::hardware::graphics::common::V1_1::BufferUsage; |
| 57 | |
| 58 | class LayerRenderPathTestHarness { |
| 59 | public: |
| 60 | LayerRenderPathTestHarness(LayerTransactionTest* delegate, RenderPath renderPath) |
| 61 | : mDelegate(delegate), mRenderPath(renderPath) {} |
| 62 | |
| 63 | std::unique_ptr<ScreenCapture> getScreenCapture() { |
| 64 | switch (mRenderPath) { |
| 65 | case RenderPath::SCREENSHOT: |
| 66 | return mDelegate->screenshot(); |
| 67 | case RenderPath::VIRTUAL_DISPLAY: |
| 68 | |
| 69 | const auto mainDisplay = SurfaceComposerClient::getInternalDisplayToken(); |
| 70 | DisplayInfo mainDisplayInfo; |
| 71 | SurfaceComposerClient::getDisplayInfo(mainDisplay, &mainDisplayInfo); |
| 72 | |
| 73 | sp<IBinder> vDisplay; |
| 74 | sp<IGraphicBufferProducer> producer; |
| 75 | sp<IGraphicBufferConsumer> consumer; |
| 76 | sp<BufferItemConsumer> itemConsumer; |
| 77 | BufferQueue::createBufferQueue(&producer, &consumer); |
| 78 | |
| 79 | consumer->setConsumerName(String8("Virtual disp consumer")); |
| 80 | consumer->setDefaultBufferSize(mainDisplayInfo.w, mainDisplayInfo.h); |
| 81 | |
| 82 | itemConsumer = new BufferItemConsumer(consumer, |
| 83 | // Sample usage bits from screenrecord |
| 84 | GRALLOC_USAGE_HW_VIDEO_ENCODER | |
| 85 | GRALLOC_USAGE_SW_READ_OFTEN); |
| 86 | |
| 87 | vDisplay = SurfaceComposerClient::createDisplay(String8("VirtualDisplay"), |
| 88 | false /*secure*/); |
| 89 | |
| 90 | SurfaceComposerClient::Transaction t; |
| 91 | t.setDisplaySurface(vDisplay, producer); |
| 92 | t.setDisplayLayerStack(vDisplay, 0); |
| 93 | t.setDisplayProjection(vDisplay, mainDisplayInfo.orientation, |
| 94 | Rect(mainDisplayInfo.viewportW, mainDisplayInfo.viewportH), |
| 95 | Rect(mainDisplayInfo.w, mainDisplayInfo.h)); |
| 96 | t.apply(); |
| 97 | SurfaceComposerClient::Transaction().apply(true); |
| 98 | BufferItem item; |
| 99 | itemConsumer->acquireBuffer(&item, 0, true); |
| 100 | auto sc = std::make_unique<ScreenCapture>(item.mGraphicBuffer); |
| 101 | itemConsumer->releaseBuffer(item); |
| 102 | SurfaceComposerClient::destroyDisplay(vDisplay); |
| 103 | return sc; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | protected: |
| 108 | LayerTransactionTest* mDelegate; |
| 109 | RenderPath mRenderPath; |
| 110 | }; |
| 111 | |
| 112 | class LayerTypeTransactionHarness : public LayerTransactionTest { |
| 113 | public: |
| 114 | LayerTypeTransactionHarness(uint32_t layerType) : mLayerType(layerType) {} |
| 115 | |
| 116 | sp<SurfaceControl> createLayer(const char* name, uint32_t width, uint32_t height, |
Valerie Hau | 1acd696 | 2019-10-28 16:35:48 -0700 | [diff] [blame^] | 117 | uint32_t flags = 0, SurfaceControl* parent = nullptr, |
| 118 | uint32_t* outTransformHint = nullptr) { |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 119 | // if the flags already have a layer type specified, return an error |
| 120 | if (flags & ISurfaceComposerClient::eFXSurfaceMask) { |
| 121 | return nullptr; |
| 122 | } |
Valerie Hau | 1acd696 | 2019-10-28 16:35:48 -0700 | [diff] [blame^] | 123 | return LayerTransactionTest::createLayer(name, width, height, flags | mLayerType, parent, |
| 124 | outTransformHint); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | void fillLayerColor(const sp<SurfaceControl>& layer, const Color& color, int32_t bufferWidth, |
| 128 | int32_t bufferHeight) { |
| 129 | ASSERT_NO_FATAL_FAILURE(LayerTransactionTest::fillLayerColor(mLayerType, layer, color, |
| 130 | bufferWidth, bufferHeight)); |
| 131 | } |
| 132 | |
| 133 | void fillLayerQuadrant(const sp<SurfaceControl>& layer, int32_t bufferWidth, |
| 134 | int32_t bufferHeight, const Color& topLeft, const Color& topRight, |
| 135 | const Color& bottomLeft, const Color& bottomRight) { |
| 136 | ASSERT_NO_FATAL_FAILURE(LayerTransactionTest::fillLayerQuadrant(mLayerType, layer, |
| 137 | bufferWidth, bufferHeight, |
| 138 | topLeft, topRight, |
| 139 | bottomLeft, bottomRight)); |
| 140 | } |
| 141 | |
| 142 | protected: |
| 143 | uint32_t mLayerType; |
| 144 | }; |
| 145 | } // namespace android |
| 146 | #endif |