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/DisplayEventReceiver.h>
21 #include <gui/ISurfaceComposer.h>
22 #include <gui/BufferItemConsumer.h>
23 #include <gui/SurfaceComposerClient.h>
24 #include <gui/SurfaceControl.h>
25 #include <gui/Surface.h>
26 #include <ui/DisplayInfo.h>
27 #include <utils/Looper.h>
28 
29 #include <thread>
30 #include <atomic>
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 getBuiltInDisplay();
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(),
49                 "Must be called before surface is created");
50         mRenderOffscreen = renderOffscreen;
51     }
52 
53     sp<Surface> surface();
54 
55     void waitForVsync();
56 
57 private:
58     void createSurface();
59     void createWindowSurface();
60     void createOffscreenSurface();
61 
62     sp<SurfaceComposerClient> mSurfaceComposerClient;
63     sp<SurfaceControl> mSurfaceControl;
64     sp<BufferItemConsumer> mConsumer;
65     DisplayEventReceiver mDisplayEventReceiver;
66     sp<Looper> mLooper;
67     sp<Surface> mSurface;
68     bool mRenderOffscreen;
69 };
70 
71 } // namespace test
72 } // namespace uirenderer
73 } // namespace android
74 
75 #endif
76