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 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 19 | #include <ui/DisplayState.h> |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 20 | |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 21 | #include "LayerTransactionTest.h" |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 22 | |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 23 | namespace android { |
| 24 | |
| 25 | using android::hardware::graphics::common::V1_1::BufferUsage; |
| 26 | |
| 27 | class LayerRenderPathTestHarness { |
| 28 | public: |
| 29 | LayerRenderPathTestHarness(LayerTransactionTest* delegate, RenderPath renderPath) |
| 30 | : mDelegate(delegate), mRenderPath(renderPath) {} |
| 31 | |
| 32 | std::unique_ptr<ScreenCapture> getScreenCapture() { |
| 33 | switch (mRenderPath) { |
| 34 | case RenderPath::SCREENSHOT: |
| 35 | return mDelegate->screenshot(); |
| 36 | case RenderPath::VIRTUAL_DISPLAY: |
| 37 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 38 | const auto displayToken = SurfaceComposerClient::getInternalDisplayToken(); |
| 39 | |
| 40 | ui::DisplayState displayState; |
| 41 | SurfaceComposerClient::getDisplayState(displayToken, &displayState); |
| 42 | |
| 43 | DisplayConfig displayConfig; |
| 44 | SurfaceComposerClient::getActiveDisplayConfig(displayToken, &displayConfig); |
| 45 | const ui::Size& resolution = displayConfig.resolution; |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 46 | |
| 47 | sp<IBinder> vDisplay; |
| 48 | sp<IGraphicBufferProducer> producer; |
| 49 | sp<IGraphicBufferConsumer> consumer; |
| 50 | sp<BufferItemConsumer> itemConsumer; |
| 51 | BufferQueue::createBufferQueue(&producer, &consumer); |
| 52 | |
| 53 | consumer->setConsumerName(String8("Virtual disp consumer")); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 54 | consumer->setDefaultBufferSize(resolution.getWidth(), resolution.getHeight()); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 55 | |
| 56 | itemConsumer = new BufferItemConsumer(consumer, |
| 57 | // Sample usage bits from screenrecord |
| 58 | GRALLOC_USAGE_HW_VIDEO_ENCODER | |
| 59 | GRALLOC_USAGE_SW_READ_OFTEN); |
| 60 | |
| 61 | vDisplay = SurfaceComposerClient::createDisplay(String8("VirtualDisplay"), |
| 62 | false /*secure*/); |
| 63 | |
| 64 | SurfaceComposerClient::Transaction t; |
| 65 | t.setDisplaySurface(vDisplay, producer); |
| 66 | t.setDisplayLayerStack(vDisplay, 0); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 67 | t.setDisplayProjection(vDisplay, displayState.orientation, |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 68 | Rect(displayState.layerStackSpaceRect), Rect(resolution)); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 69 | t.apply(); |
| 70 | SurfaceComposerClient::Transaction().apply(true); |
| 71 | BufferItem item; |
| 72 | itemConsumer->acquireBuffer(&item, 0, true); |
| 73 | auto sc = std::make_unique<ScreenCapture>(item.mGraphicBuffer); |
| 74 | itemConsumer->releaseBuffer(item); |
| 75 | SurfaceComposerClient::destroyDisplay(vDisplay); |
| 76 | return sc; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | protected: |
| 81 | LayerTransactionTest* mDelegate; |
| 82 | RenderPath mRenderPath; |
| 83 | }; |
| 84 | |
| 85 | class LayerTypeTransactionHarness : public LayerTransactionTest { |
| 86 | public: |
| 87 | LayerTypeTransactionHarness(uint32_t layerType) : mLayerType(layerType) {} |
| 88 | |
| 89 | sp<SurfaceControl> createLayer(const char* name, uint32_t width, uint32_t height, |
Valerie Hau | 1acd696 | 2019-10-28 16:35:48 -0700 | [diff] [blame] | 90 | uint32_t flags = 0, SurfaceControl* parent = nullptr, |
chaviw | debadb8 | 2020-03-26 14:57:24 -0700 | [diff] [blame] | 91 | uint32_t* outTransformHint = nullptr, |
| 92 | PixelFormat format = PIXEL_FORMAT_RGBA_8888) { |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 93 | // if the flags already have a layer type specified, return an error |
| 94 | if (flags & ISurfaceComposerClient::eFXSurfaceMask) { |
| 95 | return nullptr; |
| 96 | } |
Valerie Hau | 1acd696 | 2019-10-28 16:35:48 -0700 | [diff] [blame] | 97 | return LayerTransactionTest::createLayer(name, width, height, flags | mLayerType, parent, |
chaviw | debadb8 | 2020-03-26 14:57:24 -0700 | [diff] [blame] | 98 | outTransformHint, format); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame^] | 101 | void fillLayerColor(const sp<SurfaceControl>& layer, const Color& color, uint32_t bufferWidth, |
| 102 | uint32_t bufferHeight) { |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 103 | ASSERT_NO_FATAL_FAILURE(LayerTransactionTest::fillLayerColor(mLayerType, layer, color, |
| 104 | bufferWidth, bufferHeight)); |
| 105 | } |
| 106 | |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame^] | 107 | void fillLayerQuadrant(const sp<SurfaceControl>& layer, uint32_t bufferWidth, |
| 108 | uint32_t bufferHeight, const Color& topLeft, const Color& topRight, |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 109 | const Color& bottomLeft, const Color& bottomRight) { |
| 110 | ASSERT_NO_FATAL_FAILURE(LayerTransactionTest::fillLayerQuadrant(mLayerType, layer, |
| 111 | bufferWidth, bufferHeight, |
| 112 | topLeft, topRight, |
| 113 | bottomLeft, bottomRight)); |
| 114 | } |
| 115 | |
| 116 | protected: |
| 117 | uint32_t mLayerType; |
| 118 | }; |
| 119 | } // namespace android |
| 120 | #endif |