1 /*
2  * Copyright 2019 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 #pragma once
18 
19 #include <binder/IInterface.h>
20 #include <cutils/compiler.h>
21 #include <graphicsenv/GpuStatsInfo.h>
22 
23 #include <vector>
24 
25 namespace android {
26 
27 /*
28  * This class defines the Binder IPC interface for GPU-related queries and
29  * control.
30  */
31 class IGpuService : public IInterface {
32 public:
33     DECLARE_META_INTERFACE(GpuService)
34 
35     // set GPU stats from GraphicsEnvironment.
36     virtual void setGpuStats(const std::string& driverPackageName,
37                              const std::string& driverVersionName, uint64_t driverVersionCode,
38                              int64_t driverBuildTime, const std::string& appPackageName,
39                              const int32_t vulkanVersion, GpuStatsInfo::Driver driver,
40                              bool isDriverLoaded, int64_t driverLoadingTime) = 0;
41 
42     // set target stats.
43     virtual void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode,
44                                 const GpuStatsInfo::Stats stats, const uint64_t value = 0) = 0;
45     virtual void setTargetStatsArray(const std::string& appPackageName,
46                                      const uint64_t driverVersionCode,
47                                      const GpuStatsInfo::Stats stats, const uint64_t* values,
48                                      const uint32_t valueCount) = 0;
49     virtual void addVulkanEngineName(const std::string& appPackageName,
50                                      const uint64_t driverVersionCode, const char* engineName) = 0;
51 
52     // setter and getter for updatable driver path.
53     virtual void setUpdatableDriverPath(const std::string& driverPath) = 0;
54     virtual std::string getUpdatableDriverPath() = 0;
55 
56     // sets ANGLE as system GLES driver if enabled==true by setting persist.graphics.egl to true.
57     virtual void toggleAngleAsSystemDriver(bool enabled) = 0;
58 };
59 
60 class BnGpuService : public BnInterface<IGpuService> {
61 public:
62     enum IGpuServiceTag {
63         SET_GPU_STATS = IBinder::FIRST_CALL_TRANSACTION,
64         SET_TARGET_STATS,
65         SET_UPDATABLE_DRIVER_PATH,
66         GET_UPDATABLE_DRIVER_PATH,
67         TOGGLE_ANGLE_AS_SYSTEM_DRIVER,
68         SET_TARGET_STATS_ARRAY,
69         ADD_VULKAN_ENGINE_NAME,
70         // Always append new enum to the end.
71     };
72 
73     status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply,
74                         uint32_t flags = 0) override;
75 
76 protected:
77     virtual status_t shellCommand(int in, int out, int err, std::vector<String16>& args) = 0;
78 };
79 
80 } // namespace android
81