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 <ui/DisplayState.h> 20 21 #include "LayerTransactionTest.h" 22 23 namespace android { 24 25 using android::hardware::graphics::common::V1_1::BufferUsage; 26 27 class LayerRenderPathTestHarness { 28 public: LayerRenderPathTestHarness(LayerTransactionTest * delegate,RenderPath renderPath)29 LayerRenderPathTestHarness(LayerTransactionTest* delegate, RenderPath renderPath) 30 : mDelegate(delegate), mRenderPath(renderPath) {} 31 getScreenCapture()32 std::unique_ptr<ScreenCapture> getScreenCapture() { 33 switch (mRenderPath) { 34 case RenderPath::SCREENSHOT: 35 return mDelegate->screenshot(); 36 case RenderPath::VIRTUAL_DISPLAY: 37 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; 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")); 54 consumer->setDefaultBufferSize(resolution.getWidth(), resolution.getHeight()); 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); 67 t.setDisplayProjection(vDisplay, displayState.orientation, 68 Rect(displayState.viewport), Rect(resolution)); 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: LayerTypeTransactionHarness(uint32_t layerType)87 LayerTypeTransactionHarness(uint32_t layerType) : mLayerType(layerType) {} 88 89 sp<SurfaceControl> createLayer(const char* name, uint32_t width, uint32_t height, 90 uint32_t flags = 0, SurfaceControl* parent = nullptr, 91 uint32_t* outTransformHint = nullptr, 92 PixelFormat format = PIXEL_FORMAT_RGBA_8888) { 93 // if the flags already have a layer type specified, return an error 94 if (flags & ISurfaceComposerClient::eFXSurfaceMask) { 95 return nullptr; 96 } 97 return LayerTransactionTest::createLayer(name, width, height, flags | mLayerType, parent, 98 outTransformHint, format); 99 } 100 fillLayerColor(const sp<SurfaceControl> & layer,const Color & color,int32_t bufferWidth,int32_t bufferHeight)101 void fillLayerColor(const sp<SurfaceControl>& layer, const Color& color, int32_t bufferWidth, 102 int32_t bufferHeight) { 103 ASSERT_NO_FATAL_FAILURE(LayerTransactionTest::fillLayerColor(mLayerType, layer, color, 104 bufferWidth, bufferHeight)); 105 } 106 fillLayerQuadrant(const sp<SurfaceControl> & layer,int32_t bufferWidth,int32_t bufferHeight,const Color & topLeft,const Color & topRight,const Color & bottomLeft,const Color & bottomRight)107 void fillLayerQuadrant(const sp<SurfaceControl>& layer, int32_t bufferWidth, 108 int32_t bufferHeight, const Color& topLeft, const Color& topRight, 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 121