• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 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 ANDROID_DISPLAY_HARDWARE_BASE_H
18 #define ANDROID_DISPLAY_HARDWARE_BASE_H
19 
20 #include <stdint.h>
21 #include <utils/RefBase.h>
22 #include <utils/threads.h>
23 #include <linux/kd.h>
24 #include <linux/vt.h>
25 #include "Barrier.h"
26 
27 namespace android {
28 
29 class SurfaceFlinger;
30 
31 class DisplayHardwareBase
32 {
33 public:
34                 DisplayHardwareBase(
35                         const sp<SurfaceFlinger>& flinger,
36                         uint32_t displayIndex);
37 
38                 ~DisplayHardwareBase();
39 
40     // console managment
41     void releaseScreen() const;
42     void acquireScreen() const;
43     bool isScreenAcquired() const;
44 
45     bool canDraw() const;
46     void setCanDraw(bool canDraw);
47 
48 
49 private:
50     class DisplayEventThreadBase : public Thread {
51     protected:
52         wp<SurfaceFlinger> mFlinger;
53     public:
54         DisplayEventThreadBase(const sp<SurfaceFlinger>& flinger);
55         virtual ~DisplayEventThreadBase();
onFirstRef()56         virtual void onFirstRef() {
57             run("DisplayEventThread", PRIORITY_URGENT_DISPLAY);
58         }
acquireScreen()59         virtual status_t acquireScreen() const { return NO_ERROR; };
releaseScreen()60         virtual status_t releaseScreen() const { return NO_ERROR; };
61         virtual status_t initCheck() const = 0;
62     };
63 
64     class DisplayEventThread : public DisplayEventThreadBase
65     {
66         mutable Barrier mBarrier;
67     public:
68                 DisplayEventThread(const sp<SurfaceFlinger>& flinger);
69         virtual ~DisplayEventThread();
70         virtual bool threadLoop();
71         virtual status_t readyToRun();
72         virtual status_t releaseScreen() const;
73         virtual status_t initCheck() const;
74     };
75 
76     class ConsoleManagerThread : public DisplayEventThreadBase
77     {
78         int consoleFd;
79         int vt_num;
80         int prev_vt_num;
81         vt_mode vm;
82         static void sigHandler(int sig);
83         static pid_t sSignalCatcherPid;
84     public:
85                 ConsoleManagerThread(const sp<SurfaceFlinger>& flinger);
86         virtual ~ConsoleManagerThread();
87         virtual bool threadLoop();
88         virtual status_t readyToRun();
89         virtual void requestExit();
90         virtual status_t releaseScreen() const;
91         virtual status_t initCheck() const;
92     };
93 
94     sp<DisplayEventThreadBase>  mDisplayEventThread;
95     mutable int                 mCanDraw;
96     mutable int                 mScreenAcquired;
97 };
98 
99 }; // namespace android
100 
101 #endif // ANDROID_DISPLAY_HARDWARE_BASE_H
102