blob: a361b1e956887a611ce287130eb1010f67681c5a [file] [log] [blame]
Valerie Hau9cfc6d82019-09-23 13:54:07 -07001/*
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 Laskowski3cb3d4e2019-11-21 11:14:45 -080019#include <ui/DisplayState.h>
Valerie Hau9cfc6d82019-09-23 13:54:07 -070020
Valerie Hau9cfc6d82019-09-23 13:54:07 -070021#include "LayerTransactionTest.h"
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080022
Valerie Hau9cfc6d82019-09-23 13:54:07 -070023namespace android {
24
25using android::hardware::graphics::common::V1_1::BufferUsage;
26
27class LayerRenderPathTestHarness {
28public:
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 Laskowski3cb3d4e2019-11-21 11:14:45 -080038 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 Hau9cfc6d82019-09-23 13:54:07 -070046
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 Laskowski3cb3d4e2019-11-21 11:14:45 -080054 consumer->setDefaultBufferSize(resolution.getWidth(), resolution.getHeight());
Valerie Hau9cfc6d82019-09-23 13:54:07 -070055
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 Laskowski3cb3d4e2019-11-21 11:14:45 -080067 t.setDisplayProjection(vDisplay, displayState.orientation,
Marin Shalamanov6ad317c2020-07-29 23:34:07 +020068 Rect(displayState.layerStackSpaceRect), Rect(resolution));
Valerie Hau9cfc6d82019-09-23 13:54:07 -070069 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
80protected:
81 LayerTransactionTest* mDelegate;
82 RenderPath mRenderPath;
83};
84
85class LayerTypeTransactionHarness : public LayerTransactionTest {
86public:
87 LayerTypeTransactionHarness(uint32_t layerType) : mLayerType(layerType) {}
88
89 sp<SurfaceControl> createLayer(const char* name, uint32_t width, uint32_t height,
Valerie Hau1acd6962019-10-28 16:35:48 -070090 uint32_t flags = 0, SurfaceControl* parent = nullptr,
chaviwdebadb82020-03-26 14:57:24 -070091 uint32_t* outTransformHint = nullptr,
92 PixelFormat format = PIXEL_FORMAT_RGBA_8888) {
Valerie Hau9cfc6d82019-09-23 13:54:07 -070093 // if the flags already have a layer type specified, return an error
94 if (flags & ISurfaceComposerClient::eFXSurfaceMask) {
95 return nullptr;
96 }
Valerie Hau1acd6962019-10-28 16:35:48 -070097 return LayerTransactionTest::createLayer(name, width, height, flags | mLayerType, parent,
chaviwdebadb82020-03-26 14:57:24 -070098 outTransformHint, format);
Valerie Hau9cfc6d82019-09-23 13:54:07 -070099 }
100
Marin Shalamanov46084422020-10-13 12:33:42 +0200101 void fillLayerColor(const sp<SurfaceControl>& layer, const Color& color, uint32_t bufferWidth,
102 uint32_t bufferHeight) {
Valerie Hau9cfc6d82019-09-23 13:54:07 -0700103 ASSERT_NO_FATAL_FAILURE(LayerTransactionTest::fillLayerColor(mLayerType, layer, color,
104 bufferWidth, bufferHeight));
105 }
106
Marin Shalamanov46084422020-10-13 12:33:42 +0200107 void fillLayerQuadrant(const sp<SurfaceControl>& layer, uint32_t bufferWidth,
108 uint32_t bufferHeight, const Color& topLeft, const Color& topRight,
Valerie Hau9cfc6d82019-09-23 13:54:07 -0700109 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
116protected:
117 uint32_t mLayerType;
118};
119} // namespace android
120#endif