1 /* 2 * Copyright (C) 2014 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 #ifndef TESTCONTEXT_H 18 #define TESTCONTEXT_H 19 20 #include <gui/BufferItemConsumer.h> 21 #include <gui/DisplayEventReceiver.h> 22 #include <gui/ISurfaceComposer.h> 23 #include <gui/Surface.h> 24 #include <gui/SurfaceComposerClient.h> 25 #include <gui/SurfaceControl.h> 26 #include <ui/DisplayInfo.h> 27 #include <utils/Looper.h> 28 29 #include <atomic> 30 #include <thread> 31 32 namespace android { 33 namespace uirenderer { 34 namespace test { 35 36 extern DisplayInfo gDisplay; 37 #define dp(x) ((x)*android::uirenderer::test::gDisplay.density) 38 39 DisplayInfo getInternalDisplay(); 40 41 class TestContext { 42 public: 43 TestContext(); 44 ~TestContext(); 45 46 // Must be called before surface(); setRenderOffscreen(bool renderOffscreen)47 void setRenderOffscreen(bool renderOffscreen) { 48 LOG_ALWAYS_FATAL_IF(mSurface.get(), "Must be called before surface is created"); 49 mRenderOffscreen = renderOffscreen; 50 } 51 52 sp<Surface> surface(); 53 54 void waitForVsync(); 55 56 private: 57 void createSurface(); 58 void createWindowSurface(); 59 void createOffscreenSurface(); 60 61 sp<SurfaceComposerClient> mSurfaceComposerClient; 62 sp<SurfaceControl> mSurfaceControl; 63 sp<BufferItemConsumer> mConsumer; 64 DisplayEventReceiver mDisplayEventReceiver; 65 sp<Looper> mLooper; 66 sp<Surface> mSurface; 67 bool mRenderOffscreen; 68 }; 69 70 } // namespace test 71 } // namespace uirenderer 72 } // namespace android 73 74 #endif 75