• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 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_GPUSERVICE_H
18 #define ANDROID_GPUSERVICE_H
19 
20 #include <binder/IInterface.h>
21 #include <cutils/compiler.h>
22 #include <graphicsenv/GpuStatsInfo.h>
23 #include <graphicsenv/IGpuService.h>
24 #include <serviceutils/PriorityDumper.h>
25 
26 #include <mutex>
27 #include <thread>
28 #include <vector>
29 
30 namespace android {
31 
32 namespace gpuwork {
33 class GpuWork;
34 }
35 
36 class GpuMem;
37 class GpuStats;
38 class GpuMemTracer;
39 
40 class GpuService : public BnGpuService, public PriorityDumper {
41 public:
42     static const char* const SERVICE_NAME ANDROID_API;
43 
44     GpuService() ANDROID_API;
45     ~GpuService();
46 
47 protected:
48     status_t shellCommand(int in, int out, int err, std::vector<String16>& args) override;
49 
50 private:
51     /*
52      * IGpuService interface
53      */
54     void setGpuStats(const std::string& driverPackageName, const std::string& driverVersionName,
55                      uint64_t driverVersionCode, int64_t driverBuildTime,
56                      const std::string& appPackageName, const int32_t vulkanVersion,
57                      GpuStatsInfo::Driver driver, bool isDriverLoaded,
58                      int64_t driverLoadingTime) override;
59     void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode,
60                         const GpuStatsInfo::Stats stats, const uint64_t value) override;
61     void setTargetStatsArray(const std::string& appPackageName,
62                         const uint64_t driverVersionCode, const GpuStatsInfo::Stats stats,
63                         const uint64_t* values, const uint32_t valueCount) override;
64     void setUpdatableDriverPath(const std::string& driverPath) override;
65     std::string getUpdatableDriverPath() override;
66     void toggleAngleAsSystemDriver(bool enabled) override;
67 
68     /*
69      * IBinder interface
70      */
dump(int fd,const Vector<String16> & args)71     status_t dump(int fd, const Vector<String16>& args) override { return priorityDump(fd, args); }
72 
73     /*
74      * Debugging & dumpsys
75      */
dumpCritical(int fd,const Vector<String16> &,bool asProto)76     status_t dumpCritical(int fd, const Vector<String16>& /*args*/, bool asProto) override {
77         return doDump(fd, Vector<String16>(), asProto);
78     }
79 
dumpAll(int fd,const Vector<String16> & args,bool asProto)80     status_t dumpAll(int fd, const Vector<String16>& args, bool asProto) override {
81         return doDump(fd, args, asProto);
82     }
83 
84     status_t doDump(int fd, const Vector<String16>& args, bool asProto);
85 
86     /*
87      * Attributes
88      */
89     std::shared_ptr<GpuMem> mGpuMem;
90     std::shared_ptr<gpuwork::GpuWork> mGpuWork;
91     std::unique_ptr<GpuStats> mGpuStats;
92     std::unique_ptr<GpuMemTracer> mGpuMemTracer;
93     std::mutex mLock;
94     std::string mDeveloperDriverPath;
95     std::unique_ptr<std::thread> mGpuMemAsyncInitThread;
96     std::unique_ptr<std::thread> mGpuWorkAsyncInitThread;
97 };
98 
99 } // namespace android
100 
101 #endif // ANDROID_GPUSERVICE_H
102