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